GNOME Bugzilla – Bug 171551
fix unwanted whitespace added when indenting
Last modified: 2014-02-15 12:53:14 UTC
gedit does not remove the trailing spaces; they're useless, and a lot of common editors remove them. test it by creating a line, say "abc " (with these extra spaces). save the file. then close it. open it again and there it is: all the useless spaces are back again. it should remove those spaces either when saving the file (very common) or when going to a different line (very common too). it shouldnt be all that hard to implement this. if someone could throw some light on me about it... i might give it a try!
I like it, but I think the feature should be implemented as a plugin. Implementation should be easy: get the current document, for each line get the iter at the end of the line and remove blank spaces. You may atke a look at the indent plugin.
I have just tried with vim... it does not remove the trailing spaces. I think the vim behavior is the right way. How can the editor know if the user wanted to add these spaces on purpose? BTW, I think there is a bug in GtkTextView or most probably in GtkSourceView (it could be in the auto-indentation algorithm) that leads to have a lot of undesired trailing spaces. I just noticed it yesterday. BTW, how do other editors bahave in this case? It would be cool if you could give it a try (I mean fixing the bug and see if it solves your problem). Feel free to search for me (paolo) on #gedit, if you need some help. Changing product to GtkSourceView
yes, i think you're right, it keeps adding spaces at the end of the line with the identation thing! ok, so here it is what i am thinking that i can do.. i will try to make a plugin that removes those spaces when the user saves the file. this might be sufficient. does the plugin scheme in gedit allow this type of thing? i mean, auto running a plugin's procedure when the user saves the document?
Well, I think the right fix here is fixing the problem of auto-indentation not writing a plugin that it is only a patch for mitigating another problem.
Changing title to reflect the bug in the indentation code. Removing spaces is a gedit issue.
Created attachment 51429 [details] [review] patch simple patch that fixes one of the whitespaces problems: avoids inserting lines consisting of just indentation when pressing enter enter. More cases needs to be covered though.
Created attachment 51431 [details] [review] irc log small irc log where we discuss this stuff a little (part in italian, sorry guys)
Created attachment 93903 [details] [review] updated patch This patch is an update to the older one. I applied the older patch to a recent version of gtksourceview, and noticed that it did not seem to work well in some (common) cases, for example: [tab]some_function_call(); when the user hits enter at the end of that line, it will become [tab]some_function_call(); [tab] and when the user hits enter again, for some reason it becomes [tab]some_function_call(); [tab] [tab] leaving the unwanted tab in-between. I re-wrote the loop to accomplish this; I hope it doesn't break anything. This patch does not apply cleanly to the latest development version of gtksourceview, but the conflicts are trivially resolved (essentially just replacing the old loop with the new one).
+ /* abort if we've reached the end of the line */ + if (ch == '\r' || ch == '\n') { break; is not correct: lines can also end with Unicode Paragraph Separator character. I think you should keep using gtk_text_iter_ends_line like in my old patch to instead of a explicit check. Another thing that looks wrong to me is that you insert before the whitespace line but then do not move the cursor back to the end of the line you just moved down.
Now when we have something like: [tab]blah\n [tab] and we press \n we get: [tab]blah\n empty line\n [tab] So I think this is fixed now.
let's close it then