0

I've been using notepad and notepad++ since forever, but now that i've been coding more I'm using Sublime Text 3. One feature of notepad that I miss most is the .LOG command.

When a file has .LOG on the beginning, every time you open it, it will append the current date and time, it's great for log and journal keeping.

I wonder if there's a similar feature or plugin in sublime text, or how could I implement this?

1 Answer 1

2

You could write a simple plugin for that, along the lines of the following snippet:

import sublime, sublime_plugin
import datetime

class LOGListener(sublime_plugin.EventListener):

  def on_load(self, view):
    if view.substr(sublime.Region(0,4)) == ".LOG":
      line = "[%s] " % str(datetime.datetime.now())
      view.run_command( "move_to", {"to": "eof", "extend": False})
      view.run_command("insert", {"characters": line})

Another idea is to get the date/time added at the beginning of a line every time you press ENTER. To do that you can define a command and bind it to the ENTER key but to restrict it to LOG files you need to somehow define the corresponding scopes (which can be done).

2
  • actually, the notepad behavior is not triggered when the file ends with the .log extension, but for any text files tha has .LOG written on the first line..
    – sigmaxf
    Sep 17, 2015 at 16:39
  • @raphadko ah that's easily fixed, will edit in a min
    – Bordaigorl
    Sep 17, 2015 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .