@@ -267,30 +267,32 @@ fn write_impl(
267267 path: Option<&Cow<str>>,
268268 force: bool,
269269) -> anyhow::Result<()> {
270− let auto_format = cx.editor.config().auto_format;
270+ let editor_auto_fmt = cx.editor.config().auto_format;
271271 let jobs = &mut cx.jobs;
272272 let doc = doc_mut!(cx.editor);
273+ let path = path.map(AsRef::as_ref);
273274
274275 if doc.path().is_none() {
275276 bail!("cannot write a buffer without a filename");
276277 }
277− let fmt = if auto_format {
278+
279+ let fmt = if editor_auto_fmt {
278280 doc.auto_format().map(|fmt| {
279− let shared = fmt.shared();
280− let callback = make_format_callback(doc.id(), doc.version(), shared.clone());
281+ let callback = make_format_callback(
282+ doc.id(),
283+ doc.version(),
284+ fmt,
285+ Some((path.map(Into::into), force)),
286+ );
287+
281288 jobs.add(Job::with_callback(callback).wait_before_exiting());
282− shared
283289 })
284290 } else {
285291 None
286292 };
287293
288− doc.format_and_save(fmt, path.map(AsRef::as_ref), force)?;
289−
290− if path.is_some() {
291− let id = doc.id();
292− doc.detect_language(cx.editor.syn_loader.clone());
293− let _ = cx.editor.refresh_language_server(id);
294+ if fmt.is_none() {
295+ doc.save(path, force)?;
294296 }
295297
296298 Ok(())
@@ -345,7 +347,7 @@ fn format(
345347
346348 let doc = doc!(cx.editor);
347349 if let Some(format) = doc.format() {
348− let callback = make_format_callback(doc.id(), doc.version(), format);
350+ let callback = make_format_callback(doc.id(), doc.version(), format, None);
349351 cx.jobs.callback(callback);
350352 }
351353
@@ -592,16 +594,17 @@ fn write_all_impl(
592594
593595 let fmt = if auto_format {
594596 doc.auto_format().map(|fmt| {
595− let shared = fmt.shared();
596− let callback = make_format_callback(doc.id(), doc.version(), shared.clone());
597+ let callback =
598+ make_format_callback(doc.id(), doc.version(), fmt, Some((None, force)));
597599 jobs.callback(callback);
598− shared
599600 })
600601 } else {
601602 None
602603 };
603604
604− doc.format_and_save::<_, PathBuf>(fmt, None, force)?;
605+ if fmt.is_none() {
606+ doc.save::<PathBuf>(None, force)?;
607+ }
605608 }
606609
607610 if quit {