branch: scratch/editorconfig-cc
commit e7a0874591b23885e10dc322211ff9f77b944dae
Author: Hong Xu <[email protected]>
Commit: Stefan Monnier <[email protected]>
Add hook mechanism.
---
editorconfig.el | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/editorconfig.el b/editorconfig.el
index baeb8350cf..c09496a74a 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -50,6 +50,27 @@
:type 'string
:group 'editorconfig)
+(defcustom edconf-custom-hooks ()
+ "A list of custom hooks after loading common EditorConfig settings
+
+Each element in this list is a hook function. This hook function takes one
+parameter, which is a property hash table. The value of properties can be
+obtained through gethash function.
+
+The hook does not have to be coding style related; you can add whatever
+functionality you want. For example, the following is an example to add a new
+property emacs_linum to decide whether to show line numbers on the left
+
+(add-to-list 'edconf-custom-hooks
+ '(lambda (props)
+ (let ((show-line-num (gethash 'emacs_linum props)))
+ (cond ((equal show-line-num \"true\") (linum-mode 1))
+ ((equal show-line-num \"false\") (linum-mode 0))))))
+
+"
+ :type '(lambda (properties) (body))
+ :group 'editorconfig)
+
(defun edconf-string-integer-p (string)
"Whether a string representing integer"
(if (stringp string)
@@ -90,6 +111,8 @@
)
(defun edconf-find-file-hook ()
- (edconf-set-line-length (gethash 'max_line_length props)))
+ (edconf-set-line-length (gethash 'max_line_length props))
+ (dolist (hook edconf-custom-hooks)
+ (funcall hook props)))
(provide 'editorconfig)