aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--book/src/generated/typable-cmd.md1
-rw-r--r--helix-term/src/commands/typed.rs25
2 files changed, 26 insertions, 0 deletions
diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md
index 05a0985b..49e7e778 100644
--- a/book/src/generated/typable-cmd.md
+++ b/book/src/generated/typable-cmd.md
@@ -44,6 +44,7 @@
| `:show-directory`, `:pwd` | Show the current working directory. |
| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
| `:reload` | Discard changes and reload from the source file. |
+| `:update` | Write changes only if the file has been modified. |
| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 7ea4c801..9b79c3e6 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -1029,6 +1029,24 @@ fn reload(
})
}
+/// Update the [`Document`] if it has been modified.
+fn update(
+ cx: &mut compositor::Context,
+ args: &[Cow<str>],
+ event: PromptEvent,
+) -> anyhow::Result<()> {
+ if event != PromptEvent::Validate {
+ return Ok(());
+ }
+
+ let (_view, doc) = current!(cx.editor);
+ if doc.is_modified() {
+ write(cx, args, event)
+ } else {
+ Ok(())
+ }
+}
+
fn lsp_restart(
cx: &mut compositor::Context,
_args: &[Cow<str>],
@@ -1958,6 +1976,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
completer: None,
},
TypableCommand {
+ name: "update",
+ aliases: &[],
+ doc: "Write changes only if the file has been modified.",
+ fun: update,
+ completer: None,
+ },
+ TypableCommand {
name: "lsp-restart",
aliases: &[],
doc: "Restarts the Language Server that is in use by the current doc",