@@ -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 {