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"],