After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 171551 - fix unwanted whitespace added when indenting
fix unwanted whitespace added when indenting
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
git master
Other All
: High normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on: 107044
Blocks:
 
 
Reported: 2005-03-25 05:55 UTC by Ricardo Lenz
Modified: 2014-02-15 12:53 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
patch (2.88 KB, patch)
2005-08-27 18:30 UTC, Paolo Borelli
none Details | Review
irc log (7.67 KB, patch)
2005-08-27 18:34 UTC, Paolo Borelli
none Details | Review
updated patch (2.60 KB, patch)
2007-08-18 17:12 UTC, Javeed Shaikh
none Details | Review

Description Ricardo Lenz 2005-03-25 05:55:00 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!
Comment 1 Paolo Borelli 2005-03-25 08:27:05 UTC
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.
Comment 2 Paolo Maggi 2005-03-25 08:38:57 UTC
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
Comment 3 Ricardo Lenz 2005-03-25 22:08:46 UTC
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?
Comment 4 Paolo Maggi 2005-03-30 08:55:53 UTC
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.
Comment 5 Jeroen Zwartepoorte 2005-08-05 10:50:52 UTC
Changing title to reflect the bug in the indentation code. Removing spaces is a
gedit issue.
Comment 6 Paolo Borelli 2005-08-27 18:30:45 UTC
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.
Comment 7 Paolo Borelli 2005-08-27 18:34:07 UTC
Created attachment 51431 [details] [review]
irc log

small irc log where we discuss this stuff a little (part in italian, sorry
guys)
Comment 8 Javeed Shaikh 2007-08-18 17:12:38 UTC
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).
Comment 9 Paolo Borelli 2007-09-09 10:02:10 UTC
+		/* 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.
Comment 10 Ignacio Casal Quinteiro (nacho) 2009-12-02 20:12:53 UTC
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.
Comment 11 Paolo Borelli 2009-12-29 14:40:59 UTC
let's close it then