editorconfig / editorconfig-notepad-plus-plus

EditorConfig plugin for Notepad++
http://editorconfig.org
GNU General Public License v2.0
192 stars 30 forks source link

SaveAll doesn't apply editorconfig settings to all files being saved #46

Open alankilborn opened 1 year ago

alankilborn commented 1 year ago

When executing a "Save All" command in Notepad++, version 0.4.0.0 of the editorconfig plugin doesn't apply its settings to all of the files being saved. Specifically, it will only act upon the currently active file tab if that file needs saving. All of the other (currently inactive) filetabs to be saved will not receive the settings.

It can be demo'd with the attached fileset. Three text files all have trailing whitespace. The editorconfig file indicates that this should be eliminated when saving. Extract all files to a folder and then open the 3 .txt files into Notepad++ which has editorconfig plugin installed. Make a slight change to the first character on line 1 of each of the 3 filetabs, without saving. Make sure test1.txt is the currently active file and invoke File > Save All. Observe that trailing whitespace is eliminated from test1.txt (the active filetab) but although test2.txt and test3.txt are now saved, their trailing whitespace has not been removed.

editorconfig_test.zip

alankilborn commented 1 year ago

No comments? Not even some agreement that it appears to be working as I described?

ffes commented 3 months ago

I can confirm that the problem exists, but I am not sure why yet. The event NPPN_FILEBEFORESAVE is called and handled for every open file but for some reason it doesn't work as expected.

I need to dig into this a bit deeper.

alankilborn commented 3 weeks ago

The event NPPN_FILEBEFORESAVE is called and handled for every open file but for some reason it doesn't work as expected.

You mean "...for every modified file".

It could be (didn't look really deeply) that you are using Notepad++ commands (e.g. IDM_EDIT_TRIMTRAILING) that act on the active buffer/tab, without making the buffer recevied via NPPN_FILEBEFORESAVE the active buffer first. Making it the active buffer would (obviously) activate the tab, so the Notepad++ UI would change, so you might want to remember which file the user has active when Save All was invoked, and restore it later (so user doesn't wonder why his active tab changed).

pryrt commented 2 weeks ago

Because of this (and other instances of plugins and scripts acting on the active buffer instead of the notification's BufferID for NPPN_FILEBEFORESAVE and similar notifications, the NPP User Manual has been updated to share the best practice for BufferID, and specifically calls it out in the NPPN_FILEBEFORESAVE documentation.

But following that sequence in the Manual is highly recommended for any plugin that implements a callback for NPPN_FILEBEFORESAVE, and especially for any callback that might be used in a Save All circumstance, like in this plugin.

ffes commented 1 week ago

Thanks for the reference.

This indeed is something that needs to be fixed. I didn't look into it yet, other then reading the comments here.