summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorMicah Chalmer <micah@micahchalmer.net>2016-03-07 23:15:55 -0500
committerMicah Chalmer <micah@micahchalmer.net>2016-03-07 23:15:55 -0500
commitbc0df03bec8b92e8aded61cce364a0386e8c04b2 (patch)
tree1bbf17b1be5c0f4183041b1023019f0bf1f008f2 /rust-mode.el
parent0914b48b082c326160fbce2e6d47a468514323cf (diff)
parent1492106b02a7e833e2d1aa47243a900237905ded (diff)
downloadrust-mode-bc0df03bec8b92e8aded61cce364a0386e8c04b2.tar.gz
Merge pull request #135 from Stebalien/file-local
Allow disabling rustfmt with a dir-local/file-local variable
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el13
1 files 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.