aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorKitsu2023-05-09 20:21:29 +0000
committerGitHub2023-05-09 20:21:29 +0000
commit92c328c088ae818338237d7f11644ba079c54648 (patch)
tree58e1ab6252e28df097081828262a852786d08567 /helix-term
parent8424f387b582ed793663f95ee570e709dff20dd6 (diff)
Add wbc and wbc! commands (#6947)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands/typed.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index fe92798b..16ee83d7 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -382,6 +382,36 @@ fn force_write(
write_impl(cx, args.first(), true)
}
+fn write_buffer_close(
+ cx: &mut compositor::Context,
+ args: &[Cow<str>],
+ event: PromptEvent,
+) -> anyhow::Result<()> {
+ if event != PromptEvent::Validate {
+ return Ok(());
+ }
+
+ write_impl(cx, args.first(), false)?;
+
+ let document_ids = buffer_gather_paths_impl(cx.editor, args);
+ buffer_close_by_ids_impl(cx, &document_ids, false)
+}
+
+fn force_write_buffer_close(
+ cx: &mut compositor::Context,
+ args: &[Cow<str>],
+ event: PromptEvent,
+) -> anyhow::Result<()> {
+ if event != PromptEvent::Validate {
+ return Ok(());
+ }
+
+ write_impl(cx, args.first(), true)?;
+
+ let document_ids = buffer_gather_paths_impl(cx.editor, args);
+ buffer_close_by_ids_impl(cx, &document_ids, false)
+}
+
fn new_file(
cx: &mut compositor::Context,
_args: &[Cow<str>],
@@ -2287,11 +2317,25 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "write!",
aliases: &["w!"],
- doc: "Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write some/path.txt)",
+ doc: "Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write! some/path.txt)",
fun: force_write,
signature: CommandSignature::positional(&[completers::filename]),
},
TypableCommand {
+ name: "write-buffer-close",
+ aliases: &["wbc"],
+ doc: "Write changes to disk and closes the buffer. Accepts an optional path (:write-buffer-close some/path.txt)",
+ fun: write_buffer_close,
+ signature: CommandSignature::positional(&[completers::filename]),
+ },
+ TypableCommand {
+ name: "write-buffer-close!",
+ aliases: &["wbc!"],
+ doc: "Force write changes to disk creating necessary subdirectories and closes the buffer. Accepts an optional path (:write-buffer-close! some/path.txt)",
+ fun: force_write_buffer_close,
+ signature: CommandSignature::positional(&[completers::filename]),
+ },
+ TypableCommand {
name: "new",
aliases: &["n"],
doc: "Create a new scratch buffer.",