on master help sign in
fix(commands): run fmt for all documents being closed (#1444)

When writing all documents, fmt wouldn't be run. Run fmt in close all implementation so that all documents are formatted if necessary. Fixes: https://github.com/helix-editor/helix/issues/1442

commit38ca8daa09d18d78ca48ae4edd0ca33c67e65f24 authorMatouš Dzivjak <matousdzivjak@gmail.com> dateSun 16 Jan 2022, 02:39 (5 years ago) parent62c78c0
1 file changed+18−4
helix-term/src/commands.rs+18−4
helix-term/src/commands.rs+18−4
@@ -2279,7 +2279,7 @@ pub mod cmd {
22792279 force: bool,
22802280 ) -> anyhow::Result<()> {
22812281 let mut errors = String::new();
2282−
2282+ let jobs = &mut cx.jobs;
22832283 // save all documents
22842284 for doc in &mut cx.editor.documents.values_mut() {
22852285 if doc.path().is_none() {
@@ -2287,9 +2287,23 @@ pub mod cmd {
22872287 continue;
22882288 }
22892289
2290− // TODO: handle error.
2291− let handle = doc.save();
2292− cx.jobs.add(Job::new(handle).wait_before_exiting());
2290+ if !doc.is_modified() {
2291+ continue;
2292+ }
2293+
2294+ let fmt = doc.auto_format().map(|fmt| {
2295+ let shared = fmt.shared();
2296+ let callback = make_format_callback(
2297+ doc.id(),
2298+ doc.version(),
2299+ Modified::SetUnmodified,
2300+ shared.clone(),
2301+ );
2302+ jobs.callback(callback);
2303+ shared
2304+ });
2305+ let future = doc.format_and_save(fmt);
2306+ jobs.add(Job::new(future).wait_before_exiting());
22932307 }
22942308
22952309 if quit {