From 81c69f9b69704614c42004f4e4309f6ccef188e3 Mon Sep 17 00:00:00 2001 From: Em Zhan Date: Sun, 10 Sep 2023 18:36:01 -0500 Subject: [PATCH] Insert before and regardless of auto-format --- helix-term/src/commands/typed.rs | 56 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 419be5db5401..0d142b8f0837 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -335,6 +335,10 @@ fn write_impl( let (view, doc) = current!(cx.editor); let path = path.map(AsRef::as_ref); + if config.insert_final_newline { + insert_final_newline(doc, view); + } + let fmt = if config.auto_format { doc.auto_format().map(|fmt| { let callback = make_format_callback( @@ -352,9 +356,6 @@ fn write_impl( }; if fmt.is_none() { - if config.insert_final_newline { - insert_final_newline(doc, view); - } let id = doc.id(); cx.editor.save(id, path, force)?; } @@ -675,7 +676,6 @@ pub fn write_all_impl( let jobs = &mut cx.jobs; let current_view = view!(cx.editor); - // save all documents let saves: Vec<_> = cx .editor .documents @@ -706,35 +706,35 @@ pub fn write_all_impl( current_view.id }; - let fmt = if config.auto_format { - doc.auto_format().map(|fmt| { - let callback = make_format_callback( - doc.id(), - doc.version(), - target_view, - fmt, - Some((None, force)), - ); - jobs.add(Job::with_callback(callback).wait_before_exiting()); - }) - } else { - None - }; - - if fmt.is_none() { - return Some((doc.id(), target_view)); - } - - None + Some((doc.id(), target_view)) }) .collect(); - // manually call save for the rest of docs that don't have a formatter - for (doc_id, view_id) in saves { + for (doc_id, target_view) in saves { + let doc = doc_mut!(cx.editor, &doc_id); + if config.insert_final_newline { - insert_final_newline(doc_mut!(cx.editor, &doc_id), view_mut!(cx.editor, view_id)); + insert_final_newline(doc, view_mut!(cx.editor, target_view)); + } + + let fmt = if config.auto_format { + doc.auto_format().map(|fmt| { + let callback = make_format_callback( + doc_id, + doc.version(), + target_view, + fmt, + Some((None, force)), + ); + jobs.add(Job::with_callback(callback).wait_before_exiting()); + }) + } else { + None + }; + + if fmt.is_none() { + cx.editor.save::(doc_id, None, force)?; } - cx.editor.save::(doc_id, None, force)?; } if !errors.is_empty() && !force {