Author Topic: highlighting trailing spaces  (Read 4983 times)

dbbd

  • Community Member
  • Posts: 32
  • Hero Points: 0
highlighting trailing spaces
« on: September 21, 2010, 02:18:18 PM »
I'd like to highlight trailing spaces (use some color different from background for all spaces before end of line)

I cannot figure out how to do that with slick.
(I'm an old emacs user)

Dan

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: highlighting trailing spaces
« Reply #1 on: September 21, 2010, 03:04:39 PM »
No, I don't think we have an option for that. Is there some reason you are keeping trailing spaces around? Why not just delete them? There is an option under File  Options > Save to "Strip trailing spaces".

dbbd

  • Community Member
  • Posts: 32
  • Hero Points: 0
Re: highlighting trailing spaces
« Reply #2 on: September 21, 2010, 08:42:41 PM »
I'm working on an existing code base with hundreds of thousands of lines.
I do not want to create huge diffs since the version control is a dinosaur (clearcase) and people are upset when I create full file diffs.
I'd like to manually fix only areas I work on anyway, so highlighting trailing spaces is very helpful.
In emacs I use a regexp to do that. I tried to use the symbol highlighting in slick, and added a regexp,
but seems it does not really work that way.

How about a general purpose regexp highlighting feature, that can be used for various ad-hoc purposes?
kind of a semi-permanent search pattern?

Thanks,
Dan

David_O

  • Senior Community Member
  • Posts: 152
  • Hero Points: 8
Re: highlighting trailing spaces
« Reply #3 on: September 21, 2010, 09:07:40 PM »
Try Ctrl+F to bring up the Find tab of the Find and Replace tool window.  Put

   [ \t]*$

in the Search for text box.  Pick whatever is appropriate for your needs in the Look in box.  In the Search options section of the tab, click Use and pick 'Regular Expression (UNIX)'.  Also click on the Highlight all matches options box.

You could also do this from the command line with the following:

  /[ \t]*$/U*#

Let us know if this does not give you what you need.

Thanks,
« Last Edit: September 21, 2010, 09:14:20 PM by David_O »

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: highlighting trailing spaces
« Reply #4 on: September 22, 2010, 09:56:53 AM »
You might be interested in this macro.  It strips trailing whitespace only from modified lines on save.

SlickEdit tends to leave trailing whitespace on edited lines (an example is if you split a line just after whitespace), and it doesn't have a way to highlight trailing whitespace.  This appears to be because a lot of people work in small teams with code bases that are fully under their control, and configure their editors to always trim trailing whitespace.  Of course that is extremely problematic in large teams or diverse code bases, but the only other option in SlickEdit is to never strip, but since the only way SlickEdit manages trailing whitespace is unilaterally at save via an option (but not dynamically while editing) it ends up meaning that SlickEdit adds to the trailing whitespace pollution.

Sidebar...

Another editor I use has _before_command_ and _after_command_ hooks, which enabled me to write a macro in that editor to dynamically strip trailing whitespace as I edit, and only in the lines I've edited.

SlickEdit does not have these hooks, so the closest thing I was able to achieve in SlickEdit was the macro above.  It's not ideal, but it is a good enough solution that I don't whine much about it.  :)  Those two hooks sure would be handy, though.  The first thing I would do is port a macro (written by me, no copyright issues) that automatically fixes the indentation of the current line after the cursor moves off of it, if the line was edited.

dbbd

  • Community Member
  • Posts: 32
  • Hero Points: 0
Re: highlighting trailing spaces
« Reply #5 on: September 26, 2010, 07:36:54 AM »
Thanks for all the answers.

What I ended up doing, is change the symbol coloring background of space (without enabling symbol coloring), and enable view->spaces.
Now all my spaces a a bit darker than regular background (I use a similar trick for tabs in Makefiles).

Dan