on master help sign in
Add wbc and wbc! commands (#6947)
commit92c328c088ae818338237d7f11644ba079c54648 authorKitsu <mail@kitsu.me> dateTue 9 May 2023, 17:21 (3 years ago) parent8424f38
2 files changed+48−2
book/src/generated/typable-cmd.md+3−1 helix-term/src/commands/typed.rs+45−1
book/src/generated/typable-cmd.md+3−1
@@ -12,7 +12,9 @@
1212| `:buffer-next`, `:bn`, `:bnext` | Goto next buffer. |
1313| `:buffer-previous`, `:bp`, `:bprev` | Goto previous buffer. |
1414| `:write`, `:w` | Write changes to disk. Accepts an optional path (:write some/path.txt) |
15−| `:write!`, `:w!` | Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write some/path.txt) |
15+| `:write!`, `:w!` | Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write! some/path.txt) |
16+| `:write-buffer-close`, `:wbc` | Write changes to disk and closes the buffer. Accepts an optional path (:write-buffer-close some/path.txt) |
17+| `: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) |
1618| `:new`, `:n` | Create a new scratch buffer. |
1719| `:format`, `:fmt` | Format the file using the LSP formatter. |
1820| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.) |
helix-term/src/commands/typed.rs+45−1
@@ -382,6 +382,36 @@ fn force_write(
382382 write_impl(cx, args.first(), true)
383383}
384384
385+fn write_buffer_close(
386+ cx: &mut compositor::Context,
387+ args: &[Cow<str>],
388+ event: PromptEvent,
389+) -> anyhow::Result<()> {
390+ if event != PromptEvent::Validate {
391+ return Ok(());
392+ }
393+
394+ write_impl(cx, args.first(), false)?;
395+
396+ let document_ids = buffer_gather_paths_impl(cx.editor, args);
397+ buffer_close_by_ids_impl(cx, &document_ids, false)
398+}
399+
400+fn force_write_buffer_close(
401+ cx: &mut compositor::Context,
402+ args: &[Cow<str>],
403+ event: PromptEvent,
404+) -> anyhow::Result<()> {
405+ if event != PromptEvent::Validate {
406+ return Ok(());
407+ }
408+
409+ write_impl(cx, args.first(), true)?;
410+
411+ let document_ids = buffer_gather_paths_impl(cx.editor, args);
412+ buffer_close_by_ids_impl(cx, &document_ids, false)
413+}
414+
385415fn new_file(
386416 cx: &mut compositor::Context,
387417 _args: &[Cow<str>],
@@ -2287,10 +2317,24 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
22872317 TypableCommand {
22882318 name: "write!",
22892319 aliases: &["w!"],
2290− doc: "Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write some/path.txt)",
2320+ doc: "Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write! some/path.txt)",
22912321 fun: force_write,
22922322 signature: CommandSignature::positional(&[completers::filename]),
22932323 },
2324+ TypableCommand {
2325+ name: "write-buffer-close",
2326+ aliases: &["wbc"],
2327+ doc: "Write changes to disk and closes the buffer. Accepts an optional path (:write-buffer-close some/path.txt)",
2328+ fun: write_buffer_close,
2329+ signature: CommandSignature::positional(&[completers::filename]),
2330+ },
2331+ TypableCommand {
2332+ name: "write-buffer-close!",
2333+ aliases: &["wbc!"],
2334+ doc: "Force write changes to disk creating necessary subdirectories and closes the buffer. Accepts an optional path (:write-buffer-close! some/path.txt)",
2335+ fun: force_write_buffer_close,
2336+ signature: CommandSignature::positional(&[completers::filename]),
2337+ },
22942338 TypableCommand {
22952339 name: "new",
22962340 aliases: &["n"],