Skip to content

Commit bc0df03

Browse files
committed
Merge pull request #135 from Stebalien/file-local
Allow disabling rustfmt with a dir-local/file-local variable
2 parents 0914b48 + 1492106 commit bc0df03

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

rust-mode.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,12 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
12581258
(defun rust-enable-format-on-save ()
12591259
"Enable formatting using rustfmt when saving buffer."
12601260
(interactive)
1261-
(add-hook 'before-save-hook #'rust-format-buffer nil t))
1261+
(setq-local rust-format-on-save t))
12621262

12631263
(defun rust-disable-format-on-save ()
12641264
"Disable formatting using rustfmt when saving buffer."
12651265
(interactive)
1266-
(remove-hook 'before-save-hook #'rust-format-buffer t))
1266+
(setq-local rust-format-on-save nil))
12671267

12681268
;; For compatibility with Emacs < 24, derive conditionally
12691269
(defalias 'rust-parent-mode
@@ -1316,10 +1316,8 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
13161316
(setq-local end-of-defun-function 'rust-end-of-defun)
13171317
(setq-local parse-sexp-lookup-properties t)
13181318
(setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap)
1319-
(add-hook 'after-revert-hook 'rust--after-revert-hook 'LOCAL)
1320-
1321-
(when rust-format-on-save
1322-
(rust-enable-format-on-save)))
1319+
(add-hook 'after-revert-hook 'rust--after-revert-hook nil t)
1320+
(add-hook 'before-save-hook 'rust--before-save-hook nil t))
13231321

13241322
;;;###autoload
13251323
(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."
13411339
(funcall font-lock-ensure-fn))
13421340
)
13431341

1342+
(defun rust--before-save-hook ()
1343+
(when rust-format-on-save (rust-format-buffer)))
1344+
13441345
;; Issue #6887: Rather than inheriting the 'gnu compilation error
13451346
;; regexp (which is broken on a few edge cases), add our own 'rust
13461347
;; compilation error regexp and use it instead.

0 commit comments

Comments
 (0)