[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/hook-helpers dff9910 10/19: Added `define-hook-function'
From: |
Ian Dunn |
Subject: |
[elpa] scratch/hook-helpers dff9910 10/19: Added `define-hook-function' to allow defining a function to be added to multiple hooks. |
Date: |
Sun, 23 Apr 2017 12:50:40 -0400 (EDT) |
branch: scratch/hook-helpers
commit dff991047a70cd98cf4329f9f2b92157783bd6cc
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Added `define-hook-function' to allow defining a function to be added to
multiple hooks.
* hook-helpers.el (define-hook-function): Added.
---
hook-helpers.el | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/hook-helpers.el b/hook-helpers.el
index 1e27d4b..c4b781b 100644
--- a/hook-helpers.el
+++ b/hook-helpers.el
@@ -34,10 +34,6 @@
;; redundant hook functions. It gives a cleaner look and feel to Emacs
;; configuration files, and could even be used in actual libraries.
-;; TODO:
-
-;; - List hook helpers? Is this useful to anyone?
-
;;; Code:
(defconst hook-helper--helper-prefix "hook-helper")
@@ -87,9 +83,21 @@ quoted. The keywords are:
(function ,func-sym)
,append)))))
+(cl-defmacro remove-hook-helper (hook &key name (suffix "hook"))
+ "Remove a hook helper from HOOK-hook.
+
+NAME and SUFFIX are exactly as in ‘define-hook-helper’, and can
+be used to find the exact helper to remove."
+ (let ((func-sym (intern (format "%s--%s%s" hook-helper--helper-prefix
(symbol-name hook) (if name (concat "/" (symbol-name name)) "")))))
+ `(remove-hook (quote ,(intern (concat (symbol-name hook) "-" suffix)))
(function ,func-sym))))
+
;;;###autoload
(defmacro define-hook-function (function args &optional docstring &rest body)
- "Define FUNCTION to be a function, then add it to hooks."
+ "Define FUNCTION to be a function, then add it to hooks.
+
+The hooks to add are specified by the :hooks keyword. This is a
+simple list of hooks, unquoted, and the new function is added to
+each one."
(declare (indent defun) (doc-string 3))
;; From `define-derived-mode'
(when (and docstring (not (stringp docstring)))
@@ -101,14 +109,15 @@ quoted. The keywords are:
(let ((hooks nil))
(while (keywordp (car body))
(pcase (pop body)
- ;; Why is hooks a keyword? It's required.
+ ;; Hooks is a keyword to allow it to be specified, without requiring
the
+ ;; docstring.
(`:hooks (setq hooks (pop body)))
(_ (pop body))))
`(progn
(defun ,function ,args
,docstring
,@body)
- (dolist (h ,hooks)
+ (dolist (h (quote ,hooks))
(add-hook h (function ,function))))))
;; Add font lock for both macros.
@@ -116,16 +125,11 @@ quoted. The keywords are:
'emacs-lisp-mode
'(("(\\(define-hook-helper\\)\\_>[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
(1 font-lock-keyword-face)
+ (2 font-lock-function-name-face nil t))
+ ("(\\(define-hook-function\\)\\_>[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
+ (1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))))
-(cl-defmacro remove-hook-helper (hook &key name (suffix "hook"))
- "Remove a hook helper from HOOK-hook.
-
-NAME and SUFFIX are exactly as in ‘define-hook-helper’, and can
-be used to find the exact helper to remove."
- (let ((func-sym (intern (format "%s--%s%s" hook-helper--helper-prefix
(symbol-name hook) (if name (concat "/" (symbol-name name)) "")))))
- `(remove-hook (quote ,(intern (concat (symbol-name hook) "-" suffix)))
(function ,func-sym))))
-
(provide 'hook-helpers)
;;; hook-helpers.el ends here
- [elpa] scratch/hook-helpers b373c79 08/19: Removed define-mode-hook-helpers, since it only moves the word "mode" around., (continued)
- [elpa] scratch/hook-helpers b373c79 08/19: Removed define-mode-hook-helpers, since it only moves the word "mode" around., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers f1409ec 05/19: Updated README to include new usage., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 73d0cb5 13/19: Added gitignore file, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers e253e03 11/19: Implemented new design for anonymous helpers, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 5e4a3a8 02/19: Added remove-hook-helper to README., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 706af98 15/19: Clean up describe-hook-helpers, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 3bb2282 09/19: Updated README, removing define-mode-hook-helper., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 7f1eccf 16/19: Fixed bug in hkhlp-normalize-hook-spec, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 0386e23 04/19: Modified define-hook-helper to more closely match defun., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 0fc0b3d 14/19: Fixed bug in define-hook-helper, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers dff9910 10/19: Added `define-hook-function' to allow defining a function to be added to multiple hooks.,
Ian Dunn <=
- [elpa] scratch/hook-helpers a46803b 17/19: Fixed failing tests, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 93ae501 12/19: Finished last commit., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 7970dcf 01/19: Initial commit., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers ff95f49 18/19: Preparations to push to ELPA, Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 365d8de 19/19: Add 'packages/hook-helpers/' from commit 'ff95f4944f3d6d1a43aca141cb7fa36a9043704d', Ian Dunn, 2017/04/23