diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index c2c7e2dea14c..f63dd7afbbe9 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -19,6 +19,7 @@ | `:write-buffer-close!`, `:wbc!` | Force write changes to disk creating necessary subdirectories and closes the buffer. Accepts an optional path (:write-buffer-close! some/path.txt) | | `:new`, `:n` | Create a new scratch buffer. | | `:format`, `:fmt` | Format the file using an external formatter or language server. | +| `:trim-trailing-whitespace` | Trim trailing whitespace in document. | | `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.) | | `:line-ending` | Set the document's default line ending. Options: crlf, lf. | | `:earlier`, `:ear` | Jump back to an earlier point in edit history. Accepts a number of steps or a time span. | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 85cf6b1d1290..ba54990c617e 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -422,6 +422,19 @@ fn write_impl( Ok(()) } +fn trim_trailing_whitespace_cmd( + cx: &mut compositor::Context, + _args: Args, + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + let (view, doc) = current!(cx.editor); + trim_trailing_whitespace(doc, view.id); + Ok(()) +} + /// Trim all whitespace preceding line-endings in a document. fn trim_trailing_whitespace(doc: &mut Document, view_id: ViewId) { let text = doc.text(); @@ -3104,6 +3117,17 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ ..Signature::DEFAULT }, }, + TypableCommand { + name: "trim-trailing-whitespace", + aliases: &[], + doc: "Trim trailing whitespace in document.", + fun: trim_trailing_whitespace_cmd, + completer: CommandCompleter::none(), + signature: Signature { + positionals: (0, Some(0)), + ..Signature::DEFAULT + }, + }, TypableCommand { name: "indent-style", aliases: &[],