diff options
author | Gaurav Tyagi | 2022-10-26 02:58:49 +0000 |
---|---|---|
committer | GitHub | 2022-10-26 02:58:49 +0000 |
commit | ba9e50e93b43f102de352ead57c28d86c34a7c73 (patch) | |
tree | 3352681874f10d763416ccdd068a443c32e78bd9 /helix-term/src/commands | |
parent | 65edf9c19880fe4fd068db6d86c4c2830c8a91f6 (diff) |
Add `:update` that will write the changes if the file has been modified. (#4426)
* add command update that will write the changes if file hasn been modified
* add docs
* update the docs
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r-- | helix-term/src/commands/typed.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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", |