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 551708 - highlight trailing spaces
highlight trailing spaces
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
2.0.x
Other All
: Normal enhancement
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
: 577593 (view as bug list)
Depends on:
Blocks: 558002
 
 
Reported: 2008-09-10 19:15 UTC by Damien Nozay
Modified: 2010-01-09 23:43 UTC
See Also:
GNOME target: ---
GNOME version: 2.19/2.20


Attachments
higlight trailing spaces in C (5.09 KB, patch)
2008-09-15 22:36 UTC, Damien Nozay
none Details | Review
higlight trailing spaces (styles) (5.09 KB, patch)
2008-09-15 22:41 UTC, Damien Nozay
none Details | Review
higlight trailing spaces in python (5.09 KB, patch)
2008-09-15 22:43 UTC, Damien Nozay
none Details | Review
Highlight invalid whitespace in files which are not whitespace dependent (22.66 KB, patch)
2009-08-04 21:50 UTC, Philip Withnall
none Details | Review

Description Damien Nozay 2008-09-10 19:15:35 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"/>
Comment 1 Damien Nozay 2008-09-15 22:36:23 UTC
Created attachment 118798 [details] [review]
higlight trailing spaces in C
Comment 2 Damien Nozay 2008-09-15 22:41:50 UTC
Created attachment 118799 [details] [review]
higlight trailing spaces (styles)
Comment 3 Damien Nozay 2008-09-15 22:43:18 UTC
Created attachment 118800 [details] [review]
higlight trailing spaces in python
Comment 4 Damien Nozay 2008-09-15 22:48:53 UTC
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 5 Damien Nozay 2008-09-15 22:48:55 UTC
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 6 Damien Nozay 2008-09-15 22:49:23 UTC
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"/>
Comment 7 Yevgen Muntyan 2008-12-30 22:10:24 UTC
Doesn't gtksourceview already do something like that? In any case, syntax highlighting is not the way to draw trailing spaces.
Comment 8 Ignacio Casal Quinteiro (nacho) 2008-12-30 22:45:51 UTC
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.
Comment 9 Philip Withnall 2009-08-04 12:48:40 UTC
*** Bug 577593 has been marked as a duplicate of this bug. ***
Comment 10 Philip Withnall 2009-08-04 21:50:21 UTC
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.
Comment 11 Ignacio Casal Quinteiro (nacho) 2010-01-09 23:43:48 UTC
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.