diff options
| author | Steven Allen <steven@stebalien.com> | 2016-03-07 17:26:27 -0500 |
|---|---|---|
| committer | Steven Allen <steven@stebalien.com> | 2016-03-07 18:10:10 -0500 |
| commit | beec95a510a239f3ac6670bcd4ad4345a5495ae1 (patch) | |
| tree | 45900562b80dcbdd500b0a84c779516bba907cea /rust-mode.el | |
| parent | 351732107d4073892b752038228072482b6ebdf6 (diff) | |
| download | rust-mode-beec95a510a239f3ac6670bcd4ad4345a5495ae1.tar.gz | |
Allow disabling rustfmt with a dir-local/file-local variable
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/rust-mode.el b/rust-mode.el index 56657d6..13b8c3b 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 @@ -1317,9 +1317,7 @@ 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 'after-revert-hook 'rust--after-revert-hook 'LOCAL) - - (when rust-format-on-save - (rust-enable-format-on-save))) + (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. |
