Skip to content

Commit beec95a

Browse files
committed
Allow disabling rustfmt with a dir-local/file-local variable
1 parent 3517321 commit beec95a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

rust-mode.el

Lines changed: 6 additions & 5 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
@@ -1317,9 +1317,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
13171317
(setq-local parse-sexp-lookup-properties t)
13181318
(setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap)
13191319
(add-hook 'after-revert-hook 'rust--after-revert-hook 'LOCAL)
1320-
1321-
(when rust-format-on-save
1322-
(rust-enable-format-on-save)))
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)