From 47afdbf84c8c88646a56cc490dc784cee4f9b8f1 Mon Sep 17 00:00:00 2001 From: Phyfl <100218248+Phyfl@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:50:34 +0200 Subject: [PATCH] Added force version of command xit, called force_xit. --- helix-term/src/commands/typed.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ac9212461..fec440223 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -85,6 +85,25 @@ fn xit( quit(cx, &[], event) } +fn force_xit( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +)-> anyhow::Result<()> { + + if event != PromptEvent::Validate { + return Ok(()); + } + + let (_view, doc) = current!(cx.editor); + + if doc.is_modified() { + write_impl(cx, args.first(), true)?; + } + cx.block_try_flush_writes()?; + quit(cx, &[], event) +} + fn quit(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { log::debug!("quitting..."); @@ -2547,6 +2566,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: xit, signature: CommandSignature::positional(&[completers::filename]), }, + TypableCommand { + name: "xit!", + aliases: &["x!"], + doc: "Write changes to disk if any are made. Otherwise just close. Doesn't require a path if buffer is not modified. Force write.", + fun: force_xit, + signature: CommandSignature::positional(&[completers::filename]), + }, TypableCommand { name: "quit", aliases: &["q"],