GNOME Bugzilla – Bug 551708
highlight trailing spaces
Last modified: 2010-01-09 23:43:48 UTC
highlighting trailing spaces would help to: - see what 'remove trailing spaces' will remove (maybe some of them are important for formatting!) - spot when we get bad habits. - spot when copy/paste some extra/unneeded spaces thanks Other information: diff -rup /tmp/gtksourceview-2.0/language-specs/c.lang /usr/share/gtksourceview-2.0/language-specs/c.lang --- /tmp/gtksourceview-2.0/language-specs/c.lang 2008-09-10 11:55:58.000000000 -0700 +++ /usr/share/gtksourceview-2.0/language-specs/c.lang 2008-09-10 10:48:12.000000000 -0700 @@ -48,6 +48,7 @@ <style id="octal" _name="Octal number" map-to="def:base-n-integer"/> <style id="hexadecimal" _name="Hexadecimal number" map-to="def:base-n-integer"/> <style id="boolean" _name="Boolean value" map-to="def:boolean"/> + <style id="trailspaces" _name="Trailing spaces" map-to="def:trailspaces"/> </styles> <definitions> @@ -78,6 +79,10 @@ <context id="c"> <include> + <context id="trailspaces" style-ref="trailspaces"> + <match>\s+$</match> + </context> + <!-- gtk-doc --> <context ref="gtk-doc:inline-docs-section"/> diff -rup /tmp/gtksourceview-2.0/styles/classic.xml /usr/share/gtksourceview-2.0/styles/classic.xml --- /tmp/gtksourceview-2.0/styles/classic.xml 2008-09-10 11:55:21.000000000 -0700 +++ /usr/share/gtksourceview-2.0/styles/classic.xml 2008-09-10 12:00:42.000000000 -0700 @@ -65,6 +65,7 @@ <style name="def:type" foreground="green" bold="true"/> <!-- Others --> + <style name="def:trailspaces" background="#d00000"/> <style name="def:preprocessor" foreground="purple"/> <style name="def:error" background="red" bold="true"/> <style name="def:note" foreground="blue" background="yellow" bold="true"/> diff -rup /tmp/gtksourceview-2.0/styles/kate.xml /usr/share/gtksourceview-2.0/styles/kate.xml --- /tmp/gtksourceview-2.0/styles/kate.xml 2008-09-10 11:55:21.000000000 -0700 +++ /usr/share/gtksourceview-2.0/styles/kate.xml 2008-09-10 12:01:19.000000000 -0700 @@ -73,6 +73,7 @@ <style name="def:type" foreground="dark-red"/> <!-- Others --> + <style name="def:trailspaces" background="#d00000"/> <style name="def:preprocessor" bold="true"/> <style name="def:note" foreground="white" background="#FFCCCC" bold="true" italic="false"/> <style name="def:error" foreground="red" underline="true"/> diff -rup /tmp/gtksourceview-2.0/styles/oblivion.xml /usr/share/gtksourceview-2.0/styles/oblivion.xml --- /tmp/gtksourceview-2.0/styles/oblivion.xml 2008-09-10 11:56:13.000000000 -0700 +++ /usr/share/gtksourceview-2.0/styles/oblivion.xml 2008-09-10 12:01:38.000000000 -0700 @@ -73,6 +73,7 @@ <style name="search-match" foreground="aluminium1" background="chameleon3"/> <!-- Comments --> + <style name="def:trailspaces" background="scarletred1"/> <style name="def:comment" foreground="aluminium4"/> <style name="def:sheband" foreground="aluminium4" bold="true"/> <style name="def:doc-comment-element" italic="true"/> @@ -94,6 +95,7 @@ <style name="def:type" foreground="chameleon1" bold="true"/> <!-- Others --> + <style name="def:trailspaces" background="#d00000"/> <style name="def:preprocessor" foreground="plum1"/> <style name="def:error" foreground="aluminium1" background="scarletred2" bold="true"/> <style name="def:note" background="butter1" foreground="aluminium4" bold="true"/> diff -rup /tmp/gtksourceview-2.0/styles/tango.xml /usr/share/gtksourceview-2.0/styles/tango.xml --- /tmp/gtksourceview-2.0/styles/tango.xml 2008-09-10 11:55:21.000000000 -0700 +++ /usr/share/gtksourceview-2.0/styles/tango.xml 2008-09-10 12:02:17.000000000 -0700 @@ -87,6 +87,7 @@ <style name="def:type" foreground="chameleon3" bold="true"/> <!-- Others --> + <style name="def:trailspaces" background="#d00000"/> <style name="def:preprocessor" foreground="chocolate3"/> <style name="def:error" background="scarletred2" bold="true"/> <style name="def:note" background="orange1" bold="true"/>
Created attachment 118798 [details] [review] higlight trailing spaces in C
Created attachment 118799 [details] [review] higlight trailing spaces (styles)
Created attachment 118800 [details] [review] higlight trailing spaces in python
Comment on attachment 118799 [details] [review] higlight trailing spaces (styles) >diff -purr /tmp/gtksourceview-2.0/language-specs/def.lang /usr/share/gtksourceview-2.0/language-specs/def.lang >--- /tmp/gtksourceview-2.0/language-specs/def.lang 2008-09-10 11:55:21.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/language-specs/def.lang 2008-09-15 15:27:29.000000000 -0700 >@@ -139,6 +139,7 @@ > <!-- Text that stands out, HTML links, e-mail addresses, etc. --> > <style id="underlined" _name="Underlined"/> > >+ <style id="trailspaces" _name="Trailing spaces" /> > </styles> > > <definitions> >@@ -179,6 +180,10 @@ > <match>\%{float}</match> > </context> > >+ <context id="trailspaces" style-ref="trailspaces"> >+ <match>\s+$</match> >+ </context> >+ > <!-- FIXME no \n in patterns! --> > <define-regex id="net-address" extended="true" case-sensitive="false"> > \%[ # separator >diff -purr /tmp/gtksourceview-2.0/language-specs/python.lang /usr/share/gtksourceview-2.0/language-specs/python.lang >--- /tmp/gtksourceview-2.0/language-specs/python.lang 2008-09-10 11:55:21.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/language-specs/python.lang 2008-09-15 15:22:35.000000000 -0700 >@@ -121,6 +121,7 @@ > > <context id="python"> > <include> >+ <context ref="def:trailspaces"/> > <context ref="def:shebang"/> > <context ref="def:shell-like-comment"/> > <context ref="def:line-continue"/> >diff -purr /tmp/gtksourceview-2.0/styles/classic.xml /usr/share/gtksourceview-2.0/styles/classic.xml >--- /tmp/gtksourceview-2.0/styles/classic.xml 2008-09-10 11:55:21.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/styles/classic.xml 2008-09-10 12:00:42.000000000 -0700 >@@ -65,6 +65,7 @@ > <style name="def:type" foreground="green" bold="true"/> > > <!-- Others --> >+ <style name="def:trailspaces" background="#d00000"/> > <style name="def:preprocessor" foreground="purple"/> > <style name="def:error" background="red" bold="true"/> > <style name="def:note" foreground="blue" background="yellow" bold="true"/> >diff -purr /tmp/gtksourceview-2.0/styles/kate.xml /usr/share/gtksourceview-2.0/styles/kate.xml >--- /tmp/gtksourceview-2.0/styles/kate.xml 2008-09-10 11:55:21.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/styles/kate.xml 2008-09-10 12:01:19.000000000 -0700 >@@ -73,6 +73,7 @@ > <style name="def:type" foreground="dark-red"/> > > <!-- Others --> >+ <style name="def:trailspaces" background="#d00000"/> > <style name="def:preprocessor" bold="true"/> > <style name="def:note" foreground="white" background="#FFCCCC" bold="true" italic="false"/> > <style name="def:error" foreground="red" underline="true"/> >diff -purr /tmp/gtksourceview-2.0/styles/oblivion.xml /usr/share/gtksourceview-2.0/styles/oblivion.xml >--- /tmp/gtksourceview-2.0/styles/oblivion.xml 2008-09-10 11:56:13.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/styles/oblivion.xml 2008-09-10 12:01:38.000000000 -0700 >@@ -73,6 +73,7 @@ > <style name="search-match" foreground="aluminium1" background="chameleon3"/> > > <!-- Comments --> >+ <style name="def:trailspaces" background="scarletred1"/> > <style name="def:comment" foreground="aluminium4"/> > <style name="def:sheband" foreground="aluminium4" bold="true"/> > <style name="def:doc-comment-element" italic="true"/> >@@ -94,6 +95,7 @@ > <style name="def:type" foreground="chameleon1" bold="true"/> > > <!-- Others --> >+ <style name="def:trailspaces" background="#d00000"/> > <style name="def:preprocessor" foreground="plum1"/> > <style name="def:error" foreground="aluminium1" background="scarletred2" bold="true"/> > <style name="def:note" background="butter1" foreground="aluminium4" bold="true"/> >diff -purr /tmp/gtksourceview-2.0/styles/tango.xml /usr/share/gtksourceview-2.0/styles/tango.xml >--- /tmp/gtksourceview-2.0/styles/tango.xml 2008-09-10 11:55:21.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/styles/tango.xml 2008-09-10 12:02:17.000000000 -0700 >@@ -87,6 +87,7 @@ > <style name="def:type" foreground="chameleon3" bold="true"/> > > <!-- Others --> >+ <style name="def:trailspaces" background="#d00000"/> > <style name="def:preprocessor" foreground="chocolate3"/> > <style name="def:error" background="scarletred2" bold="true"/> > <style name="def:note" background="orange1" bold="true"/>
Comment on attachment 118798 [details] [review] higlight trailing spaces in C >diff -purr /tmp/gtksourceview-2.0/language-specs/c.lang /usr/share/gtksourceview-2.0/language-specs/c.lang >--- /tmp/gtksourceview-2.0/language-specs/c.lang 2008-09-10 11:55:58.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/language-specs/c.lang 2008-09-15 15:27:37.000000000 -0700 >@@ -77,6 +77,7 @@ > > <context id="c"> > <include> >+ <context ref="def:trailspaces"/> > > <!-- gtk-doc --> > <context ref="gtk-doc:inline-docs-section"/>
Comment on attachment 118800 [details] [review] higlight trailing spaces in python >diff -purr /tmp/gtksourceview-2.0/language-specs/python.lang /usr/share/gtksourceview-2.0/language-specs/python.lang >--- /tmp/gtksourceview-2.0/language-specs/python.lang 2008-09-10 11:55:21.000000000 -0700 >+++ /usr/share/gtksourceview-2.0/language-specs/python.lang 2008-09-15 15:22:35.000000000 -0700 >@@ -121,6 +121,7 @@ > > <context id="python"> > <include> >+ <context ref="def:trailspaces"/> > <context ref="def:shebang"/> > <context ref="def:shell-like-comment"/> > <context ref="def:line-continue"/>
Doesn't gtksourceview already do something like that? In any case, syntax highlighting is not the way to draw trailing spaces.
I do not like the syntax highlighting appproach either. I think would be better doing it in the way we draw, \n, \t etc. I tried to implemented it but I didn't get it working in a good way.
*** Bug 577593 has been marked as a duplicate of this bug. ***
Created attachment 139912 [details] [review] Highlight invalid whitespace in files which are not whitespace dependent Here's a patch to optionally highlight invalid whitespace (tabs/spaces before newline, and spaces before tabs anywhere else) in files which are written in a non-whitespace dependent language. Currently, it adds the appropriate property to c.lang to mark it as non-whitespace dependent. Further patches could add the property to other languages.
Jesse implemented a way to highlight white spaces using the draw spaces flags, so I'm closing this as FIXED. Feel free to reopen or fill another bug if you think that something is missing. Thanks for the report.