GNOME Bugzilla – Bug 721469
Automatic indentation should not add trailing whitespace
Last modified: 2016-11-26 22:46:59 UTC
Simple example: try to edit this code with Enable Automatic Indentation set: #include <stdio.h> int main (void) { printf ("hello world\n"); } Move the cursor to the end of the line with the printf and hit Enter. The next line starts indented two spaces, as expected: great if you want to write some code on that line. But instead of placing code on that line, decide that you want to leave a blank line between that and the next statement, so hit Enter again and add another line of code. Now you have, with underscores representing spaces: #include <stdio.h> int main (void) { __printf ("hello world\n"); __ __printf ("hm\n"); } The line in the middle is widely considered to be a whitespace error, which many projects (e.g. GTK+) don't allow in patches. Other editors with automatic indentation, such as Anjuta, will immediately delete the whitespace they added if you don't write anything on that line. gedit should do the same (or else grow an option for removing trailing whitespace from modified lines when saving, as suggested in Bug #305816). FWIW, I disable automatic indentation in gedit for this reason.
At some point we changed the behavior to the one you are proposing, but we got a lot of negative feedback on it (see #617907, #653409, #617681). In the end, we decided to revert to the old behavior. I'm personally in the camp that it's of great annoyance to keep these spaces, but I suppose it all depends on what you use gedit for. Apparently not everyone agrees to the same thing. I've created a plugin a while ago that strips the spaces, you can find it here: https://github.com/jessevdk/gedit-stripper-plugin In the end, I think it would be great to make stripping these spaces a user preference in gtksourceview/gedit since some people clearly prefer one over the other, but there doesn't seem to be a majority either way.
For reference, bug #617907, bug #653409 and bug #617681
(In reply to comment #1) > In the end, I think it would be great to make stripping these spaces a user > preference in gtksourceview/gedit since some people clearly prefer one over the > other, but there doesn't seem to be a majority either way. Oh, I was not aware that there were users that desire this trailing whitespace. My $0.02: a preference that controls this behavior of automatic indentation might be confusing. Perhaps that plugin (which does exactly what I want, thanks!) could live in gedit-plugins, or better, be installed by default? (Or better, be enabled by default? It doesn't make sense to me that automatic indentation should be incompatible with many open source projects....)
Because the bug is actually a feature, nothing more will be done.