diff options
author | unrelentingtech | 2022-05-02 14:31:07 +0000 |
---|---|---|
committer | GitHub | 2022-05-02 14:31:07 +0000 |
commit | 20162a426b991f1a07f347f8180480871d15a27a (patch) | |
tree | 9ce6a587f2dc1eeb4662007864910acc1f30c574 /helix-term/src | |
parent | f9baced216df60122f2aae08d382931d77901ca9 (diff) |
feat(commands): make it possible to disable format-on-save via the 'auto-format' option (#2321)
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands/typed.rs | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ec86e446..68aa7703 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -195,6 +195,7 @@ fn write_impl( path: Option<&Cow<str>>, force: bool, ) -> anyhow::Result<()> { + let auto_format = cx.editor.config().auto_format; let jobs = &mut cx.jobs; let doc = doc_mut!(cx.editor); @@ -205,17 +206,21 @@ fn write_impl( if doc.path().is_none() { bail!("cannot write a buffer without a filename"); } - let fmt = doc.auto_format().map(|fmt| { - let shared = fmt.shared(); - let callback = make_format_callback( - doc.id(), - doc.version(), - Modified::SetUnmodified, - shared.clone(), - ); - jobs.callback(callback); - shared - }); + let fmt = if auto_format { + doc.auto_format().map(|fmt| { + let shared = fmt.shared(); + let callback = make_format_callback( + doc.id(), + doc.version(), + Modified::SetUnmodified, + shared.clone(), + ); + jobs.callback(callback); + shared + }) + } else { + None + }; let future = doc.format_and_save(fmt, force); cx.jobs.add(Job::new(future).wait_before_exiting()); @@ -454,6 +459,7 @@ fn write_all_impl( force: bool, ) -> anyhow::Result<()> { let mut errors = String::new(); + let auto_format = cx.editor.config().auto_format; let jobs = &mut cx.jobs; // save all documents for doc in &mut cx.editor.documents.values_mut() { @@ -466,17 +472,21 @@ fn write_all_impl( continue; } - let fmt = doc.auto_format().map(|fmt| { - let shared = fmt.shared(); - let callback = make_format_callback( - doc.id(), - doc.version(), - Modified::SetUnmodified, - shared.clone(), - ); - jobs.callback(callback); - shared - }); + let fmt = if auto_format { + doc.auto_format().map(|fmt| { + let shared = fmt.shared(); + let callback = make_format_callback( + doc.id(), + doc.version(), + Modified::SetUnmodified, + shared.clone(), + ); + jobs.callback(callback); + shared + }) + } else { + None + }; let future = doc.format_and_save(fmt, force); jobs.add(Job::new(future).wait_before_exiting()); } |