1

In notepad++, many times I have hundreds of tabs and leave unsaved text files for weeks before I finally save them. When I do, I would like to save them not with the current timestamp, but with the timestamp of when I actually last modified them (i.e. the timestamp of the appropriate backup file in c:\Documents and Settings\<USER>\Appplication Data\Notepad++\backup\. Is it possible in Notepad++? How?

  • 1
    By unsaved files do you mean existing files (e.g. effects.js) or new files? (e.g. new44). Or both? Also, are you open to any coding in order to achieve requested behavior (e.g. writing your N++ plugin)? – miroxlav Oct 8 '16 at 8:33
  • @miroxlav: actually, both :-) in fact, both variants will be in the backup directory with the right timestamp so it shouldn't be a problem. And I would prefer not to code of course (but writing a script would be much easier than having to compile and build something) – Tomas Oct 8 '16 at 10:21
2

I think this is exactly what plugins are for. I am not sure about existing plugin for this, but you should be able to achieve your goal with relatively simple plugin. Create a plugin which will create a command "Save with last modified timestamp" (Edit: ...and map it to Ctrl+S originally used for Save).

When invoked:

  1. Asks for save file name. (It is trivial using standard Windows FileSaveDialog. Almost a copy-paste from N++ source for Save As....)
  2. Saves the file into specified location. (Almost a copy-paste as well...)
  3. Retrieves last modification timestamp from file backup of that file. (Location of the backup file is known to N++. Once you have the file path, getting the timestamp should be a single API call.)
  4. Sets last modification timestamp to file saved in step 2. (Again, should be nothing more than a single API call.)

And you can enjoy timestamp values you expect.

Here are Plugin Resources including Plugin Development Quck Start Guide and Technical information on coding a plugin. Based on your StackOverflow profile, this should not be very diffictult thing for you. Checking the resources, plugins can be developed in 4-5 various programming languages. Perhaps C or C# could suit you the best. Also it is possible you can write the entire thing in Python script. Just install N++ Python Script plugin and you can go way of scripting. However, I am not sure whether all necessary N++ internals (e.g. location of backup file) are available for running scripts. If not, you might need to work that around.

| improve this answer | |
  • Thanks!! It's great that it can be done using a plugin!!! I thought patch will be necessary. And scripting is great too!! Though I don't know python.... Anyway t would be desirable not to create a new command, but to change the behavior of "Save". Because I know myself and I am 100% sure that I will forget not to use save but to use some special new command.... So the best solution is to add a settings option that tells Save to use either current or last modified date as the timestamp. Is that possible in a plugin? – Tomas Oct 8 '16 at 10:28
  • @Tomas: Your plugin can have options, although not in main Options dialog, but on its own. I believe that modifying Save implemented in core to check value of option set somewhere is not possible without changes in the core. But I think you still can create a new command (as described in the answer) and then simply map it to Ctrl+S which was used for Save. (Using the Keyboard Mapper.) And then hide the toolbar with original Save icon to prevent accidentally clicking it. – miroxlav Oct 9 '16 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.