Menu

#81 WhiteSpace: remove trailing spaces from the edited line

open
nobody
WhiteSpace (5)
5
2012-04-06
2008-05-16
No

When editing source files, indentation automatically inserts spaces. For someone like me who is "a little pedantic", these trailing spaces hanging around are less than ideal. And there are many other situations where trailing spaces can be left "hanging around".

What would be good is for jEdit to be a little smarter about spaces. These features should probably be optional, or implemented via a plugin.

Suggestion 1: "virtual spaces"
When auto-indenting, don't actually insert spaces immediately. Just position the cursor at the appropriate column. _If_ the user then types something on that line, _then_ spaces can actually be inserted. _If_ the user doesn't type something on that line (e.g. move away from that line, or hit Enter for the next line), then no spaces are left on that line.

Suggestion 2: automatic removal of trailing spaces
When a user has edited a line, and then moves away from that line, automatically remove trailing spaces on that line.

Note: Don't change lines that the user hasn't edited. The WhiteSpace plugin has an option to remove trailing spaces when a file is saved. But this has the disadvantage that when editing a file in a multiple-developer scenario, and other developers _do_ leave trailing spaces, and using version control, a particular check-in of edits will potentially show many lines changed simply due to trailing spaces being removed. But I just want to be tidy within the scope of my own edits, and not fiddle with spaces throughout the rest of the file.

Discussion

  • Matthieu Casanova

    Logged In: YES
    user_id=285591
    Originator: NO

    Hi, did you try the Whitespace plugin ?
    It has an option to remove trailing whitespace before saving files

     
  • Robert Schwenn

    Robert Schwenn - 2008-05-16

    Logged In: YES
    user_id=1486645
    Originator: NO

    There are related requests: #1574625, #1869411.

     
  • Kazutoshi Satoda

    Logged In: YES
    user_id=1483238
    Originator: NO

    I have not used the The WhiteSpace plugin's option because
    the same reason Craig said. Now I got inspired Suggestion 2
    and made a quick implementation in a few lines of bsh.

    if (textArea.isEditable()) {
    int lineIndex = textArea.getCaretLine();
    textArea.insertEnterAndIndent();
    textArea.getBuffer().removeTrailingWhiteSpace(new int [] {lineIndex});
    } else {
    textArea.getToolkit().beep();
    }

    Binding this to ENTER, I'm feeling happy for now. I'll
    continue testing this in real work.

    Having this as an action in WhiteSpace plugin may be a
    solution for this request?

     
  • Alan Ezust

    Alan Ezust - 2008-05-30

    Logged In: YES
    user_id=935841
    Originator: NO

    Moving this to Plugin Feature Requests,
    and changing subject to be related to WhiteSpace plugin.
    If someone woudl like to enhance the WhiteSpace plugin to include these missing features, please submit a patch to the plugin patches tracker.

     
  • Alan Ezust

    Alan Ezust - 2008-05-30
    • summary: Virtual space, remove trailing spaces --> WhiteSpace: Virtual space, remove trailing spaces
     
  • Jarek Czekalski

    Jarek Czekalski - 2012-02-10
    • labels: --> WhiteSpace
     
  • Jarek Czekalski

    Jarek Czekalski - 2012-02-10

    Suggestion 1 seems unrealistic and would rather be a core feature. The only open case is now the second suggestion. Yeah, it would be a safe feature that could be always on.

     
  • Jarek Czekalski

    Jarek Czekalski - 2012-02-10
    • summary: WhiteSpace: Virtual space, remove trailing spaces --> WhiteSpace: remove trailing spaces from the edited line
    • status: open --> pending-rejected
     
  • Jarek Czekalski

    Jarek Czekalski - 2012-04-06
    • status: pending-rejected --> open
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.