summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrotzeit <brotzeitmacher@gmail.com>2021-11-26 19:59:47 +0100
committerbrotzeit <brotzeitmacher@gmail.com>2021-11-26 20:13:02 +0100
commite2c3a7a6d43139291ea9dfe99afc53803d000427 (patch)
treea69019813975fb6335b0bd6e3eee074dcc0615a5
parentaadd1dd8f0780692aea1637569aeadfa8f78fd5a (diff)
downloadrust-mode-e2c3a7a6d43139291ea9dfe99afc53803d000427.tar.gz
allow changing rustfmt hook funtctions
-rw-r--r--rust-mode.el15
-rw-r--r--rust-rustfmt.el4
2 files changed, 14 insertions, 5 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 15f536e..4f7b005 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -31,6 +31,16 @@ This variable might soon be remove again.")
(defvar electric-pair-skip-self)
(defvar electric-indent-chars)
+(defcustom rust-before-save-hook 'rust-before-save-method
+ "Function for formatting before save."
+ :type 'function
+ :group 'rust-mode)
+
+(defcustom rust-after-save-hook 'rust-after-save-method
+ "Default method to handle rustfmt invocation after save."
+ :type 'function
+ :group 'rust-mode)
+
;;; Customization
(defgroup rust-mode nil
@@ -264,9 +274,8 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
'rust-electric-pair-inhibit-predicate-wrap)
(setq-local electric-pair-skip-self 'rust-electric-pair-skip-self-wrap)
- (add-hook 'before-save-hook 'rust-before-save-hook nil t)
- (add-hook 'after-save-hook 'rust-after-save-hook nil t)
- )
+ (add-hook 'before-save-hook rust-before-save-hook nil t)
+ (add-hook 'after-save-hook rust-after-save-hook nil t))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
diff --git a/rust-rustfmt.el b/rust-rustfmt.el
index ddab81f..0690b84 100644
--- a/rust-rustfmt.el
+++ b/rust-rustfmt.el
@@ -347,7 +347,7 @@ Return the created process."
;;; Hooks
-(defun rust-before-save-hook ()
+(defun rust-before-save-method ()
(when rust-format-on-save
(condition-case e
(rust-format-buffer)
@@ -355,7 +355,7 @@ Return the created process."
(car e)
(cdr e))))))
-(defun rust-after-save-hook ()
+(defun rust-after-save-method ()
(when rust-format-on-save
(if (not (executable-find rust-rustfmt-bin))
(error "Could not locate executable \"%s\"" rust-rustfmt-bin)