on master help sign in
Add `:update` that will write the changes if the file has been modified. (#4426)
ba9e50eGaurav Tyagi
book/src/generated/typable-cmd.md+1
@@ -44,6 +44,7 @@
44| `:show-directory`, `:pwd` | Show the current working directory. |
44| `:show-directory`, `:pwd` | Show the current working directory. |
45| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
45| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
46| `:reload` | Discard changes and reload from the source file. |
46| `:reload` | Discard changes and reload from the source file. |
47+| `:update` | Write changes only if the file has been modified. |
47| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
48| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
48| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
49| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
49| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
50| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
helix-term/src/commands/typed.rs+25
@@ -1029,6 +1029,24 @@ fn reload(
1029 })
1029 })
1030}
1030}
1031
1031
1032+/// Update the [`Document`] if it has been modified.
1033+fn update(
1034+ cx: &mut compositor::Context,
1035+ args: &[Cow<str>],
1036+ event: PromptEvent,
1037+) -> anyhow::Result<()> {
1038+ if event != PromptEvent::Validate {
1039+ return Ok(());
1040+ }
1041+
1042+ let (_view, doc) = current!(cx.editor);
1043+ if doc.is_modified() {
1044+ write(cx, args, event)
1045+ } else {
1046+ Ok(())
1047+ }
1048+}
1049+
1032fn lsp_restart(
1050fn lsp_restart(
1033 cx: &mut compositor::Context,
1051 cx: &mut compositor::Context,
1034 _args: &[Cow<str>],
1052 _args: &[Cow<str>],
@@ -1957,6 +1975,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1957 fun: reload,
1975 fun: reload,
1958 completer: None,
1976 completer: None,
1959 },
1977 },
1978+ TypableCommand {
1979+ name: "update",
1980+ aliases: &[],
1981+ doc: "Write changes only if the file has been modified.",
1982+ fun: update,
1983+ completer: None,
1984+ },
1960 TypableCommand {
1985 TypableCommand {
1961 name: "lsp-restart",
1986 name: "lsp-restart",
1962 aliases: &[],
1987 aliases: &[],