The Initialisation mode has to be ATSTARTUP and the code is placed at the end of the startup.py
defshutdownNppOnLastFileClosed(args):importosfiles=notepad.getFiles()# there are always at least 2 'buffers' open in N++iflen(files)==2:currentBufferID=notepad.getCurrentBufferID()for(filename,bufferID,index,view)infiles:ifos.path.exists(filename):breaknotepad.activateBufferID(bufferID)ifeditor.getLength()>0:break# TODO: just to be on the safe side - if we# reached here, we actually should also check# if the 2 left empty buffers are not unsaved,# but I couldn't find a way to do that.else:# following 'menuCommand' looks cleaner than# the 'sys.exit' but it currently deadlocks N++:#notepad.menuCommand(MENUCOMMAND.FILE_EXIT)sys.exit(0)notepad.activateBufferID(currentBufferID)notepad.callback(shutdownNppOnLastFileClosed,[NOTIFICATION.FILECLOSED])
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just saw this idea on Stackoverflow and had to try it:
http://stackoverflow.com/questions/10343102/closing-notepad-when-the-last-document-is-closed
The Initialisation mode has to be ATSTARTUP and the code is placed at the end of the startup.py