8

I'm using notepad++ for couple of months now and gone through all the settings but can't find a way to make the npp to close when I close the last tab. It would always start a new empty document.

Any ideas how can I make the npp to close upon closing the last document?

4 Answers 4

6

The latest update of Notepad++ includes the functionality of closing the application after closing the last tab.

To update Notepad++, go to ?>Update Notepad++ and follow the install wizard.

When update is complete, you will have the option within the Settings>Preferences menu to "Exit on close the last tab" (under Tab Bar input group).

Sign up to request clarification or add additional context in comments.

1 Comment

As of Notepad++ v7.5.3, the use of the startup.py with PythonScript has some issues when used as the Git editor. If a file is closed via the PythonScript, then it just seems to hang the Git process. The notepad++ instance visually looks closed, but remains around according to Process Explorer. Using @Sebastian's suggestion worked for me.
3

This is totally based on ufo's code. Only that it works when you close the last document be it new or not, and it doesn't freeze npp.

For the sake of brevity, here follows the steps again:

  1. Install the Python Script plug-in
  2. On Plugins > Python Script > Configuration change Initialisation mode from LAZY to ATSARTUP
  3. Open up ...\Notepad++\plugins\PythonScript\scripts\startup.py and place following code at the end of it.
  4. Save and restart Npp to load the script.

    from threading import Timer def shutdownNppOnLastFileClosed(args): def closeNpp(): notepad.menuCommand(MENUCOMMAND.FILE_EXIT) files = notepad.getFiles() if len(files) == 2: t = Timer(0.1, closeNpp) t.start() notepad.callback(shutdownNppOnLastFileClosed, [NOTIFICATION.FILEBEFORECLOSE]) 

2 Comments

As of December 2024, Notepad++ still does not exit when the last document is closed. The Python Script plugin didn't work for me in Notepad++ v8.1.9.3 (2021) on Windows 11. I ran Notepad++ in the command terminal and didn't see any console output, even when I put syntax errors in the startup.py, so I don't think the plugin is working.
Actually, maybe it works after reloading Notepad++ a few times. But I had to change if len(files) == 2 to if len(files) == 1.
2

If you're familiar with Python, you could try the Python Script plug-in for N++. You would set up a callback script for the document-closed-event. Inside it do some iteration through all opened docs, and when there's only 1 left with no text in it, then terminate N++.

Personally I mapped the keys "Alt + x" to "Exit" Notepad++, which is easier to grap then the usually working "Alt + F4".

/EDIT

I actually quite liked your idea, so I've quickly tried it myself. It took ~20 minutes to figure it out. Here's a complete solution:

  1. Install the plug-in Python Script (link above)
  2. Go to Plugins > Python > Configuration and change Initialisation mode from LAZY to ATSARTUP
  3. Open up "...\Notepad++\plugins\PythonScript\scripts\startup.py" and place following code at the end of it: Seems like the code tags don't work below a numbered list, so click me to see the code
def shutdownNppOnLastFileClosed(args): import os files = notepad.getFiles() # there are always at least 2 'buffers' open in N++ if len(files) == 2: currentBufferID = notepad.getCurrentBufferID() for (filename, bufferID, index, view) in files: if os.path.exists(filename): break notepad.activateBufferID(bufferID) if editor.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]) 

1 Comment

it has a bug - when no saved documents open - opened only (one && empty && not changed) document - it's not work
0

notepad++ is a MDI form application,like the MS OFFICE,close the child MDI form will not affect the main appliaction,so,i think it's no idea unless you rebuild the source of nodepad++.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.