Skip to content

Commit ee262cc

Browse files
authored
Merge pull request #266 from brotzeit/format-on-save
throw error in after-save-hook instead of before-save-hook
2 parents 256db76 + 9154e0e commit ee262cc

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rust-mode.el

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,8 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
15551555
(setq-local parse-sexp-lookup-properties t)
15561556
(setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap)
15571557

1558-
(add-hook 'before-save-hook 'rust--before-save-hook nil t)
1558+
(add-hook 'before-save-hook 'rust-before-save-hook nil t)
1559+
(add-hook 'after-save-hook 'rust-after-save-hook nil t)
15591560

15601561
(setq-local rust-buffer-project nil)
15611562

@@ -1571,9 +1572,17 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
15711572
(require 'rust-mode)
15721573
(rust-mode))
15731574

1574-
(defun rust--before-save-hook ()
1575-
(when rust-format-on-save (rust-format-buffer)))
1576-
1575+
(defun rust-before-save-hook ()
1576+
(when rust-format-on-save
1577+
(condition-case nil
1578+
(rust-format-buffer)
1579+
(error nil))))
1580+
1581+
(defun rust-after-save-hook ()
1582+
(when rust-format-on-save
1583+
(unless (executable-find rust-rustfmt-bin)
1584+
(error "Could not locate executable \"%s\"" rust-rustfmt-bin))))
1585+
15771586
(defvar rustc-compilation-regexps
15781587
(let ((file "\\([^\n]+\\)")
15791588
(start-line "\\([0-9]+\\)")

0 commit comments

Comments
 (0)