Author Topic: Syntax highlight trailing whitespace  (Read 3449 times)

groman

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Syntax highlight trailing whitespace
« on: October 05, 2013, 05:23:29 pm »
I know there are some old messages about this recommending the use of a macro that is bound to a key, but that's not an OK flow for me.
All the other editors I use (Sublime, VIM, etc.) can be configured to actively show me trailing whitespace as bright red as part of overall syntax highlighting.

SlickEdit seems particularly naughty about leaving trailing whitespace everywhere when I edit, and I can't find a way to make it prominent without making ALL whitespace prominent. The general flow is when I edit a dozen or so files, go to commit in git and my pre-commit hook rejects them because of added trailing whitespace. I then have to re-open all those files one by one in vim, go to the lines mentioned by the hook and delete the trailing white space, add, and try committing again -- i.e. impractical.

I also can't strip trailing whitespace on save simply because I'm often editing files that already have trailing whitespace and I don't want to change to make commits that change every line.

Any suggestions?

LBCEi

  • Senior Community Member
  • Posts: 168
  • Hero Points: 11
Re: Syntax highlight trailing whitespace
« Reply #1 on: October 05, 2013, 06:32:22 pm »
There is an option to trim trailing whitespace on save ONLY from lines that were edited.  Perhaps this would help.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Syntax highlight trailing whitespace
« Reply #2 on: October 06, 2013, 01:23:48 am »
The point is that it's a bit sloppy for an editor to insert little bits of trailing whitespace in the first place.  An option to strip it afterwards shouldn't be necessary.  But yes, the option for stripping trailing whitespace only from edited lines can clean up after that, and I absolutely rely on it (stripping from all lines creates superfluous diff churn in source control systems, and leads to unnecessary merge conflicts later on).

LBCEi

  • Senior Community Member
  • Posts: 168
  • Hero Points: 11
Re: Syntax highlight trailing whitespace
« Reply #3 on: October 06, 2013, 01:35:50 am »
I agree that it would be 'sloppy' for an editor to insert trailing whitespace arbitrarily on its own, but I've never seen any evidence that SE is doing this.  Have you?

What I've seen is whitespace changes showing up in files edited by other developers that are not using SE (both trailing spaces and tab/space indent diffs).  As hard as I try I can't seem to get everyone on the same page as far as these 'trivial' issues.

In Nirvana we would all be using SE with the same formatting settings.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Syntax highlight trailing whitespace
« Reply #4 on: October 06, 2013, 07:26:03 pm »
Yes, SE inserts trailing whitespace on its own in various cases.  One case I remember offhand is "{spc}*{spc}{eol}" instead of "{spc}*{eol}" for an empty line while editing multiline comments (and word wrap/reflow add the spaces back if you manually delete them).  I don't remember all the cases I encountered, and I didn't have time to compile a list (esp. with repro steps), but it happened enough that I needed to make a macro to strip whitespace from edited lines.  Eventually that got built into the editor.  Don't get me wrong, though -- the macro (and now feature) compensates for my own typing habits as well :) not just for what the editor does.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1032
  • Hero Points: 88
Re: Syntax highlight trailing whitespace
« Reply #5 on: October 08, 2013, 01:50:13 pm »
Another possible source of spurious trailing spaces came up in a support case yesterday.  If you've got any of the "Beautify on X" settings enabled, check your beautifier profile and make sure Spacing -> Statements -> General -> "Space after semicolon" is turned off.  Normally, that should only take effect for multiple statements on a single line, but when beautifying snippets, another rule can mistakenly interfere and leave the trailing space.  I can't hotfix it, so the workaround will have to suffice for now.

@chrisant - yeah, the comment editing and wrapping code needs a fix for that.  I thought there was already a bug opened for that, but I can't seem to find it. 

Highlighting trailing space does seem like a good feature request, I'll open that up.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Syntax highlight trailing whitespace
« Reply #6 on: October 08, 2013, 06:05:28 pm »
Awesome, thanks Patrick on all counts.  :)

FWIW, in my case I don't think it's the beautifier since I first noticed the issue in v12 (before the beautifier worked while you type), I never explicitly invoke the beautifier.  I should turn off the "trim trailing whitespace" option for a few days and see what, if any, issues I still encounter.  I'll try to find time for that.

P.S.  I would like to use the beautifier more often, but I work in a large team and I can't beautify whole files without administrative repercussions ;) and beautifying a selection seems to often fail if the selection is inside certain scopes or crosses scope boundaries, etc.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Syntax highlight trailing whitespace
« Reply #7 on: October 28, 2013, 04:46:10 am »
Here's an example where SE inserts trailing whitespace on its own.

In a C++ file with a JavaDoc comment, each time you press Enter at the end of a line, SE appends a trailing space to the line and then starts a new line.  And with comment wrap on, most attempts at trying to remove the trailing space join the following line as well (deleting both the trailing space and also the line break and comment border from the next line).

Code: [Select]
/**
 * Downloads the file if necessary.
 */

REPRO:
1.  Turn on View Special Characters for Tabs and Spaces.
2.  Paste the snippet above into a C++ file.
3.  Put the insertion point immediately after the period at the end of the "Downloads the file" line.
4.  Press Enter.

EXPECTED RESULT = The current line doesn't get altered, a new line " * "gets inserted after the current line, and the insertion point goes at the end of the new line ({space}{star}{space}{insertionPoint}).

ACTUAL RESULT = Almost matches the expected result, except:
1.  Pressing Enter on the current line (the "Downloads the file" line) appends a trailing space as well.
2.  Most attempts at trying to delete the extra space (e.g. Del or Backspace) have a side effect of also joining the next line to the current line.