12

Removing trailing white space for all lines has already been answered: How to auto-remove trailing whitespace in Eclipse?

However, I haven't been able to try to find a way to do so for only the lines that I edited.

Please don't mark this as duplicate of the above because the answer is not in the above and the question is now 5 years old and kinda forgotten about.

The reason is that I want to maintain my commits clean, so that you can see which lines I actually edited. Otherwise there is a big mess and you can't tell what I've done. I would then deal with remaining trailing whitespace in other commits.

Has anyone been able to do this?

Things tried:

AnyEdit

Only has option to remove all lines

Eclipse -> Save actions > * > 'remove trailing white spaces on all lines'

Removes on all lines.

Eclipse ctrl+3 -> remove white space

Removes on all lines.

Community
  • 1
  • 1
Leo Ufimtsev
  • 6,240
  • 5
  • 40
  • 48
  • 5
    step1: remove trailing whitespace for all the codebase, step2: commit that, then you can remove them normally, AFAIK there's no other way (or you'll have to write your own plugin) –  Jan 08 '15 at 15:34
  • Hmmm, it seems that way :-/. – Leo Ufimtsev Jan 08 '15 at 16:12
  • Patch to change 2708 lines from our code base ^_^: https://git.eclipse.org/r/#/c/39216/ – Leo Ufimtsev Jan 08 '15 at 16:13
  • 1
    It would either need to work on save and just trim the lines that had been altered. Or could integrate with your version control system and apply the trim to the edited lines before committing. It's a nice idea though. I've previously had to resort to what @RC. suggested, or at least doing it on a file by file basis. – Dan Temple Jan 08 '15 at 17:12
  • Thank you for the suggestion. We put the project settings into the git repo and now force everyone to clear whitespaces. – Leo Ufimtsev Jan 10 '15 at 02:53

1 Answers1

3

Enable on save formatting for edited lines only: SaveActions>Perform the selected actions on save>Format source code>Format edited lines. Tested it with this settings:

SaveActions>Perform the selected actions on save>Format source code>Format edited lines

With this settings whitespaces have been removed only for edited lines. There is no option to remove trailing white spaces in formatter settings so I guess it is doing that by default.

I tested it with Eclipse 4.3.2 (Kepler SR2)

Piro
  • 1,367
  • 2
  • 19
  • 40
  • Funny, I posted this question when I was an intern. In the mean time I'm actually an Eclipse contributor. Thanks for answering. – Leo Ufimtsev Mar 23 '18 at 16:16
  • 1
    This does not really answer the original question. Formatting does many other things, besides removing whitespace. – Per Mildner Mar 19 '19 at 14:58