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