branch: elpa/rust-mode
commit bc0df03bec8b92e8aded61cce364a0386e8c04b2
Merge: 0914b48 1492106
Author: Micah Chalmer <[email protected]>
Commit: Micah Chalmer <[email protected]>
Merge pull request #135 from Stebalien/file-local
Allow disabling rustfmt with a dir-local/file-local variable
---
rust-mode.el | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 8590da2..43245e4 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1258,12 +1258,12 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(defun rust-enable-format-on-save ()
"Enable formatting using rustfmt when saving buffer."
(interactive)
- (add-hook 'before-save-hook #'rust-format-buffer nil t))
+ (setq-local rust-format-on-save t))
(defun rust-disable-format-on-save ()
"Disable formatting using rustfmt when saving buffer."
(interactive)
- (remove-hook 'before-save-hook #'rust-format-buffer t))
+ (setq-local rust-format-on-save nil))
;; For compatibility with Emacs < 24, derive conditionally
(defalias 'rust-parent-mode
@@ -1316,10 +1316,8 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(setq-local end-of-defun-function 'rust-end-of-defun)
(setq-local parse-sexp-lookup-properties t)
(setq-local electric-pair-inhibit-predicate
'rust-electric-pair-inhibit-predicate-wrap)
- (add-hook 'after-revert-hook 'rust--after-revert-hook 'LOCAL)
-
- (when rust-format-on-save
- (rust-enable-format-on-save)))
+ (add-hook 'after-revert-hook 'rust--after-revert-hook nil t)
+ (add-hook 'before-save-hook 'rust--before-save-hook nil t))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
@@ -1341,6 +1339,9 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(funcall font-lock-ensure-fn))
)
+(defun rust--before-save-hook ()
+ (when rust-format-on-save (rust-format-buffer)))
+
;; Issue #6887: Rather than inheriting the 'gnu compilation error
;; regexp (which is broken on a few edge cases), add our own 'rust
;; compilation error regexp and use it instead.