Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :write-without-auto-format commands #4909

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ fn write_impl(
cx: &mut compositor::Context,
path: Option<&Cow<str>>,
force: bool,
auto_format: bool,
) -> anyhow::Result<()> {
let editor_auto_fmt = cx.editor.config().auto_format;
let jobs = &mut cx.jobs;
let (view, doc) = current!(cx.editor);
let path = path.map(AsRef::as_ref);

let fmt = if editor_auto_fmt {
let fmt = if auto_format {
doc.auto_format().map(|fmt| {
let callback = make_format_callback(
doc.id(),
Expand Down Expand Up @@ -307,7 +307,19 @@ fn write(
return Ok(());
}

write_impl(cx, args.first(), false)
write_impl(cx, args.first(), false, cx.editor.config().auto_format)
}

fn write_without_auto_format(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}

write_impl(cx, args.first(), false, false)
}

fn force_write(
Expand All @@ -319,7 +331,19 @@ fn force_write(
return Ok(());
}

write_impl(cx, args.first(), true)
write_impl(cx, args.first(), true, cx.editor.config().auto_format)
}

fn force_write_without_auto_format(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}

write_impl(cx, args.first(), true, false)
}

fn new_file(
Expand Down Expand Up @@ -517,7 +541,7 @@ fn write_quit(
return Ok(());
}

write_impl(cx, args.first(), false)?;
write_impl(cx, args.first(), false, cx.editor.config().auto_format)?;
cx.block_try_flush_writes()?;
quit(cx, &[], event)
}
Expand All @@ -531,7 +555,7 @@ fn force_write_quit(
return Ok(());
}

write_impl(cx, args.first(), true)?;
write_impl(cx, args.first(), true, cx.editor.config().auto_format)?;
cx.block_try_flush_writes()?;
force_quit(cx, &[], event)
}
Expand Down Expand Up @@ -1869,13 +1893,27 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: write,
completer: Some(completers::filename),
},
TypableCommand {
name: "write-without-auto-format",
aliases: &[],
doc: "Similar to :write but without auto format",
fun: write_without_auto_format,
completer: Some(completers::filename),
},
TypableCommand {
name: "write!",
aliases: &["w!"],
doc: "Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write some/path.txt)",
fun: force_write,
completer: Some(completers::filename),
},
TypableCommand {
name: "write-without-auto-format!",
aliases: &[],
doc: "Similar to :write! but without auto format",
fun: force_write_without_auto_format,
completer: Some(completers::filename),
},
TypableCommand {
name: "new",
aliases: &["n"],
Expand Down