Keep “Remember current session” AND prompt to save unsaved files?



  • I don’t mind the “Remember current session for next launch” feature, but what I hate about it is that it automatically disables the program prompting to save unsaved files when I exit. Often I’m working on files which are shared via Dropbox or Google Drive, and I want to be sure the changes I’ve made will be reflected in the cloud version. If I neglect to save, obviously, they won’t be. But at the same time, I do like the re-opening of the current session, especially the ability to have files that I’m working with temporarily, and don’t actually need to save as real files.

    I’ve looked all through the settings, and can’t find anything about prompting to save. Is there a plugin (or a setting I’ve missed) that will re-enable that prompt without having to disable the saved-session behavior?



  • When I have

    ☑ Remember current session for next lauch
    ☐ Enable session snapshot and periodic backup
    

    It gives me most of the behavior your described: it will load the most recent files every time I run Notepad++, but it will still prompt me to save before I exit. (This is actually my default setting.)

    But you have the contradictory requirements of wanting a prompt when there’s a named file with changes, but not wanting a prompt for unnamed files with changes. To keep the unnamed files, you have to have the snapshot/backup enabled, which then gets rid of prompting. Sorry, prompting is an all or nothing affair: if you want NPP to prompt you to save named files that are changed, NPP will also prompt you to save (and name) unnamed files: NPP cannot know whether it’s an unnamed file that you want to remain unnamed, or an unnamed file that you actually wanted to name, but forgot to do it yourself.

    Personally, I find relying on unnamed files still existing on the next load dangerous, and mildly disingenuous to yourself: dangerous, because you never know when something will go wrong with that unnamed file (see, for example, this FAQ), and it gets you in the habit of not being in control of saving and tracking your own work; and disingenuous, because despite claims that you don’t want to “save [it] as a real file”, that’s exactly what Notepad++ is doing: it’s saving it as a real file in your %AppData%\Notepad++ hierarchy (or in the executable’s hierarchy in portable/standalone NPP). For my temporary data, I keep it in a file I’ve always got open, which I call “Peter’s scratchpad”, and I intentionally save that file often, and clean it out when the data becomes irrelevant.



  • @Matt-McDowall

    I found it kind of hard to pull your use-case out of your description. I think I get it, but I’m left with a nagging question: Is it true that, upon quitting Notepad++, you’d like it to save to disk all files with a real name, and leave all unnamed files unsaved but “still there” in the session that will be resumed when you next run? If so, then why prompt at all (I’m keying on your posting title: “…AND prompt to save unsaved files”) for the named files–just save 'em if they need saving.

    Like @PeterJones I am not a big fan of unnamed files and letting Notepad++ manage those as well as named files with changes across Notepad++ runs…it should be fine, but…

    Anyway, you can script a solution to your problem, with Pythonscript for example, but there are a couple of caveats:

    • You have to exit Notepad++ by running the script to get the behavior. It can be tied to a keycombo or a toolbar button, so this isn’t a HUGE deal, but training yourself to quit Notepad++ a different way (e.g. if you have been closing it via the X in the corner of the window for years…) can be a hurdle…

    • It is kind of slow if you have a large number of (named) tabs open…maybe this makes it too “painful”…YMMV

    This script will:

    • Save any named files with changes to their filepaths on disk
    • Leave alone any unnamed (e.g. new 1, new 3, etc.) files with changes–they will appear at the next run of Notepad++ with red tab icons and the same contents as when Notepad++ was previously quit
    • Exit Notepad+±-no prompts to save anything will occur (going with what I assume is wanted here–just save the named files)

    So here’s the script, rather minimalistic, feel free to improve on it:

    for (filename, bufferID, index, view) in notepad.getFiles():
        if not filename.startswith('new '):
            notepad.activateIndex(view, index)
            if editor.getModify(): notepad.save()
    

    To use the script you should make sure these 2 Preferences in the Backup section are ticked :

    • Remember current session
    • Enable session snapshot

    Thus:
    Imgur

    By the way, Notepad++ has a “shutdown” notification, so one would think that this behavior could be tied into that. I experimented with that, but I found that by the time the Pythonscript code gets the notification, notepad.getFiles() doesn’t have the data on all the editor tabs the user had open – I guess it is called after Notepad++ closes all of the files on its way to bed?



  • @PeterJones Yeah, I know I have nearly-contradictory requirements, and honestly I was doubtful I could find a solution. I think your strategy of keeping a “scratchpad” file will probably work for me. Not a great habit to have multiple unnamed files open anyway. I’ll go with that, I suppose.



  • @Matt-McDowall

    Suggestion: Consider the TakeNotes plugin.


Log in to reply