Hey there,
I was looking through the preferences for Geany today and decided to try this one since I occasionally have an unwanted space or tab at the end of a line:
Edit --> Preferences --> Files --> Saving files --> Strip trailing spaces and tabs
I turned it on and it works great on lines with a trailing space or tab, but I noticed a behavior I consider unwanted and I'm wondering if this is by design or if it's something that ought to get fixed:
If you put your cursor on a blank line and tab over three times and save the file, Geany strips those three tabs out even though they're leading tabs (they're not trailing after anything).
For the purposes I have for that option, Geany saving me from the trailing spaces or tabs I occasionally litter a file with wouldn't be worth the many times that Geany would prevent the cursor from being in exactly the spot I want it in (three tabs over or whatever) on save, so I'm going to turn that off again for now.
What I'd like is for Geany to only strip trailing spaces or tabs from lines that also contain something other than tabs or spaces. Is there any chance that that's what was intended and that it just needs fixing or is it behaving as intended?
It's working as intended.
When people say "trailing" they usually mean "at the end of the line". And certainly if a line only has whitespace, then ALL of the whitespace on that line should be considered BOTH leading AND trailing.
Philosophically, if you consider a "saved file" as a finished product, then it makes sense that there would be no lines with only whitespace.
I personally wouldn't want there to be saved whitespace which only exists to allow the cursor to go there simply because the cursor happens to be there at save time. The only argument that might sway me is that whitespace *up to the current indent level* should be preserved. This would be more complicated and possibly unreliable (what if the file isn't properly/consistently indented?) than simply removing all end-of-line whitespace; and as far as I can tell, pretty nonstandard among editors.
I think the best setup for you, given your preferences, would be to not have Geany automatically strip whitespace, but to write a script that goes through a file (or a whole project) and strips the whitespace that *you* want to strip. You would of course run this script manually yourself every so often, or include it in your commit process, or make a Geany plugin for it, etc.
John Y.
Hey there,
John Yeung wrote:
It's working as intended.
I figured as much. It was worth asking, though.
When people say "trailing" they usually mean "at the end of the line". And certainly if a line only has whitespace, then ALL of the whitespace on that line should be considered BOTH leading AND trailing.
This was where there were shades of grey since it's then at the beginning.
Philosophically, if you consider a "saved file" as a finished product, then it makes sense that there would be no lines with only whitespace.
A saved file can be in an unfinished state if you intend to continue to work on it later. I often do this.
Another type of saved file can be considered finished when you create it as a template, but unfinished when you use it as a template for whatever it is you're creating with it. I often do this. As an example, I create a template that has specific levels of indentation. I decide I want the cursor at this level of indentation when I go to that line in the file. That way I don't have to tab over every time I load that template and wish to type on that particular line.
I personally wouldn't want there to be saved whitespace which only exists to allow the cursor to go there simply because the cursor happens to be there at save time. The only argument that might sway me is that whitespace *up to the current indent level* should be preserved. This would be more complicated and possibly unreliable (what if the file isn't properly/consistently indented?) than simply removing all end-of-line whitespace; and as far as I can tell, pretty nonstandard among editors.
No idea, but it sounds like you might accept my use case as a valid reason for wanting such a thing, at least.
I think the best setup for you, given your preferences, would be to not have Geany automatically strip whitespace, but to write a script that goes through a file (or a whole project) and strips the whitespace that *you* want to strip. You would of course run this script manually yourself every so often, or include it in your commit process, or make a Geany plugin for it, etc.
Yep. The indentations are important enough to me and the trailing spaces and tabs happen infrequently enough that it's worth it for me to not use that option and to toss together a little script if manually checking for and getting rid of them becomes too much of a chore.
Thanks for the reply.
On 2017-09-03 11:05 AM, Little Girl wrote:
Hey there,
I was looking through the preferences for Geany today and decided to try this one since I occasionally have an unwanted space or tab at the end of a line:
Edit --> Preferences --> Files --> Saving files --> Strip trailing spaces and tabs
I turned it on and it works great on lines with a trailing space or tab, but I noticed a behavior I consider unwanted and I'm wondering if this is by design or if it's something that ought to get fixed:
If you put your cursor on a blank line and tab over three times and save the file, Geany strips those three tabs out even though they're leading tabs (they're not trailing after anything).
It's by design, though both ways have their pros and cons.
If I remember correctly VisualStudio has a nice (if complicated to implement) solution, it never saved the superfluous whitespaces, but graphically, in the editor it appeared to leave them alone so it didn't cause you to re-indent while editing after a save.
For the purposes I have for that option, Geany saving me from the trailing spaces or tabs I occasionally litter a file with wouldn't be worth the many times that Geany would prevent the cursor from being in exactly the spot I want it in (three tabs over or whatever) on save, so I'm going to turn that off again for now.
What I'd like is for Geany to only strip trailing spaces or tabs from lines that also contain something other than tabs or spaces. Is there any chance that that's what was intended and that it just needs fixing or is it behaving as intended?
It could be made an option, for example as in this this pull request:
https://github.com/geany/geany/pull/128
Of course it would take someone to update it and try and get it merged. Speaking only for myself, I'd never use this option/feature, and so, with my limited time, have never dedicated any towards reviewing and merging it.
You could also do as John mentioned and write a little script to do it as you like, and you could even make it a command for "Send Selection to Command" so that you could do <Ctrl>+a, <Ctrl>+1, <Ctrl>+s to strip the whole file while saving, to your preference.
For inspiration, there is a script in Geany's scripts directory called `rstrip-whitespace.py` which could be trivially adapted to do as above.
Regards, Matthew Brush
Hey there,
Matthew Brush wrote:
On 2017-09-03 11:05 AM, Little Girl wrote:
Edit --> Preferences --> Files --> Saving files --> Strip trailing spaces and tabs
[SNIP]
If you put your cursor on a blank line and tab over three times and save the file, Geany strips those three tabs out even though they're leading tabs (they're not trailing after anything).
It's by design, though both ways have their pros and cons.
Yep, I had figured that might be the case.
If I remember correctly VisualStudio has a nice (if complicated to implement) solution, it never saved the superfluous whitespaces, but graphically, in the editor it appeared to leave them alone so it didn't cause you to re-indent while editing after a save.
That doesn't sound like it would quite be a solution, either.
What I'd like is for Geany to only strip trailing spaces or tabs from lines that also contain something other than tabs or spaces. Is there any chance that that's what was intended and that it just needs fixing or is it behaving as intended?
It could be made an option, for example as in this this pull request:
That might be nice.
Of course it would take someone to update it and try and get it merged.
Maybe someone will at some point.
Speaking only for myself, I'd never use this option/feature, and so, with my limited time, have never dedicated any towards reviewing and merging it.
Please don't do it on my account. I haven't used it in the past, just messed around with it today, and can continue on as I've been doing.
You could also do as John mentioned and write a little script to do it as you like, and you could even make it a command for "Send Selection to Command" so that you could do <Ctrl>+a, <Ctrl>+1, <Ctrl>+s to strip the whole file while saving, to your preference.
For inspiration, there is a script in Geany's scripts directory called `rstrip-whitespace.py` which could be trivially adapted to do as above.
Thanks. I'll take a look.
It is annoying to have the cursor on a blank line slam left when the file is saved while its still open.
If I remember correctly VisualStudio has a nice (if complicated to implement) solution, it never saved the superfluous whitespaces, but graphically, in the editor it appeared to leave them alone so it didn't cause you to re-indent while editing after a save.
Maybe that could be easily implemented by simply not changing the buffer on save, sure it leaves the spaces on the ends of the lines in the buffer too, but they get stripped again on the next save so it doesn't matter. If you really want to strip them in the buffer you should use the menu item rather than (ab)using save.
It doesn't keep the indents after close, but that seems a reasonable compromise for a simple change.
Cheers Lex