aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatouš Dzivjak2022-01-16 01:39:49 +0000
committerGitHub2022-01-16 01:39:49 +0000
commit38ca8daa09d18d78ca48ae4edd0ca33c67e65f24 (patch)
tree3b1753469105542aa57a08b3c59eafc2d9146283
parent62c78c061c165a874fde95cd8d99da32499f5c18 (diff)
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
-rw-r--r--helix-term/src/commands.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 1a53f14e..c14216c0 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2279,7 +2279,7 @@ pub mod cmd {
force: bool,
) -> anyhow::Result<()> {
let mut errors = String::new();
-
+ let jobs = &mut cx.jobs;
// save all documents
for doc in &mut cx.editor.documents.values_mut() {
if doc.path().is_none() {
@@ -2287,9 +2287,23 @@ pub mod cmd {
continue;
}
- // TODO: handle error.
- let handle = doc.save();
- cx.jobs.add(Job::new(handle).wait_before_exiting());
+ if !doc.is_modified() {
+ 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 future = doc.format_and_save(fmt);
+ jobs.add(Job::new(future).wait_before_exiting());
}
if quit {