.LOG

2013-08-21
2013-08-21
  • Sascha Offe
    Sascha Offe
    2013-08-21

    Maybe I haven’t looked hard enough, but I couldn't find a way for Notepad++ to handle a .LOG entry like the Windows Notepad does http://support.microsoft.com/kb/260563/en-us, so I wrote this:

    Log.py

    from Npp import *
    import datetime
    
    BufferIDList = set()
    
    def updateLog (args):
        editor.gotoLine(0)
    
        if editor.getCurLine().startswith(".LOG"):
            bid = notepad.getCurrentBufferID()
    
            if bid not in BufferIDList:
                BufferIDList.add(bid)
    
                editor.gotoLine(editor.getLineCount())
                editor.appendText("%s\n\n" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                editor.gotoLine(editor.getLineCount())
                editor.scrollCaret()
    
    def clearBufferIDList (args):
        try:
            BufferIDList.remove(args["bufferID"])
        except ValueError:
            pass
    
    notepad.callback(clearBufferIDList, [NOTIFICATION.FILECLOSED])
    
    # Tried FILEOPENED before, but had problems with it (wrong buffer getting updated, not updated at all or delayed...).
    notepad.callback(updateLog, [NOTIFICATION.BUFFERACTIVATED])
    

    startup.py

    from Log import updateLog
    updateLog(0)