@@ -1258,12 +1258,12 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
1258
1258
(defun rust-enable-format-on-save ()
1259
1259
" Enable formatting using rustfmt when saving buffer."
1260
1260
(interactive )
1261
- (add-hook 'before-save-hook # ' rust-format-buffer nil t ))
1261
+ (setq-local rust-format-on-save t ))
1262
1262
1263
1263
(defun rust-disable-format-on-save ()
1264
1264
" Disable formatting using rustfmt when saving buffer."
1265
1265
(interactive )
1266
- (remove-hook 'before-save-hook # ' rust-format-buffer t ))
1266
+ (setq-local rust-format-on-save nil ))
1267
1267
1268
1268
; ; For compatibility with Emacs < 24, derive conditionally
1269
1269
(defalias 'rust-parent-mode
@@ -1317,9 +1317,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
1317
1317
(setq-local parse-sexp-lookup-properties t )
1318
1318
(setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap )
1319
1319
(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 ))
1323
1321
1324
1322
;;;### autoload
1325
1323
(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."
1341
1339
(funcall font-lock-ensure-fn))
1342
1340
)
1343
1341
1342
+ (defun rust--before-save-hook ()
1343
+ (when rust-format-on-save (rust-format-buffer)))
1344
+
1344
1345
; ; Issue #6887: Rather than inheriting the 'gnu compilation error
1345
1346
; ; regexp (which is broken on a few edge cases), add our own 'rust
1346
1347
; ; compilation error regexp and use it instead.
0 commit comments