diff options
| author | brotzeit <brotzeitmacher@gmail.com> | 2018-03-23 10:00:17 +0100 |
|---|---|---|
| committer | brotzeit <brotzeitmacher@gmail.com> | 2018-03-23 10:06:09 +0100 |
| commit | 3613551fefe4dbec3829347685196b177ccf80ff (patch) | |
| tree | f8cc0894bdefb4be2ddfc3d7a24a97a96f5f8eca /rust-mode.el | |
| parent | 1275a1996329a72d1bdd833e653f21303bc1f498 (diff) | |
| download | rust-mode-3613551fefe4dbec3829347685196b177ccf80ff.tar.gz | |
throw error in after-save-hook instead of before-save-hook
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/rust-mode.el b/rust-mode.el index 011f615..6317033 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -1555,7 +1555,8 @@ This is written mainly to be used as `end-of-defun-function' for Rust." (setq-local parse-sexp-lookup-properties t) (setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap) - (add-hook 'before-save-hook 'rust--before-save-hook nil t) + (add-hook 'before-save-hook 'rust-before-save-hook nil t) + (add-hook 'after-save-hook 'rust-after-save-hook nil t) (setq-local rust-buffer-project nil) @@ -1571,9 +1572,17 @@ This is written mainly to be used as `end-of-defun-function' for Rust." (require 'rust-mode) (rust-mode)) -(defun rust--before-save-hook () - (when rust-format-on-save (rust-format-buffer))) - +(defun rust-before-save-hook () + (when rust-format-on-save + (condition-case rustfmt-err + (rust-format-buffer) + (error nil)))) + +(defun rust-after-save-hook () + (when rust-format-on-save + (unless (executable-find rust-rustfmt-bin) + (error "Could not locate executable \"%s\"" rust-rustfmt-bin)))) + (defvar rustc-compilation-regexps (let ((file "\\([^\n]+\\)") (start-line "\\([0-9]+\\)") |
