-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add trim
to remove trailing whitespace
#3674
Conversation
trim_whitespace
to remove trailing whitespacetrim
to remove trailing whitespace
For me yes, but i don't know if others agree |
c1f913d
to
44e5a40
Compare
helix-term/src/commands/typed.rs
Outdated
if mode == "all" || mode == "lines" { | ||
let mut lines = doc.text().lines_at(doc.text().len_lines()).reversed(); | ||
let mut pos = doc.text().len_chars(); | ||
|
||
// The last non-empty line char index. | ||
let start = lines | ||
.find_map(|line| { | ||
if line_ending::rope_end_without_line_ending(&line) != 0 { | ||
Some(pos) | ||
} else { | ||
pos -= line.len_chars(); | ||
None | ||
} | ||
}) | ||
.unwrap_or(0); | ||
let end = doc.text().len_chars(); | ||
let transaction = Transaction::change(doc.text(), [(start, end, None)].into_iter()); | ||
doc.apply(&transaction, view.id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does lines
do? Does it only trim the last trailing line in the file, or does it trim all newlines? I think the latter is achievable with J
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It trims all the trailing lines in the file. Should I delete this?
fn trim(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) -> anyhow::Result<()> { | ||
if event != PromptEvent::Validate { | ||
return Ok(()); | ||
} | ||
|
||
use helix_core::line_ending; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command should work on text inside the selection, or if it's a single cursor selection then it should default to the whole file
i am not sure if this may be desired, but an option to trim on |
Someone could follow up on that with a PR. I'm not personally interested in implementing it. |
I guess this gonna be me then. :) |
Is this still being worked on? 👀 |
I'm unsure @koalalorenzo, but as a workaround you can use
That will override an existing formatter, but I figure most language formatters ( |
I would eagerly looking forward to a command to trim trailing whitespace (and eventually trim on save as well). Any update on when this will be merged? Thanks! |
oh, didn't think of that (I suppose via |
The "trim final newlines" ( If this PR gets refactored, enabling "trim trailing whitespace from all lines" (
|
Superseded by #8366 |
Resolves #1481
Currently it doesn't delete empty trailing lines. Is this a desired behavior?