Merge pull request #1 from Phyfl/patch-1

Added force version of command xit, called force_xit.
pull/11849/head
williamporomaa 2 months ago committed by GitHub
commit f2565c2a88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -85,6 +85,25 @@ fn xit(
quit(cx, &[], event) quit(cx, &[], event)
} }
fn force_xit(
cx: &mut compositor::Context,
args: &[Cow<str>],
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<str>], event: PromptEvent) -> anyhow::Result<()> { fn quit(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) -> anyhow::Result<()> {
log::debug!("quitting..."); log::debug!("quitting...");
@ -2547,6 +2566,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: xit, fun: xit,
signature: CommandSignature::positional(&[completers::filename]), 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 { TypableCommand {
name: "quit", name: "quit",
aliases: &["q"], aliases: &["q"],

Loading…
Cancel
Save