[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/hook-helpers b373c79 08/19: Removed define-mode-hook-help
From: |
Ian Dunn |
Subject: |
[elpa] scratch/hook-helpers b373c79 08/19: Removed define-mode-hook-helpers, since it only moves the word "mode" around. |
Date: |
Sun, 23 Apr 2017 12:50:39 -0400 (EDT) |
branch: scratch/hook-helpers
commit b373c79203e31d61f2bf1869742d50119c13b30c
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Removed define-mode-hook-helpers, since it only moves the word "mode"
around.
* hook-helpers.el (define-mode-hook-helpers): Removed.
---
hook-helpers.el | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/hook-helpers.el b/hook-helpers.el
index 85df095..1e27d4b 100644
--- a/hook-helpers.el
+++ b/hook-helpers.el
@@ -88,26 +88,35 @@ quoted. The keywords are:
,append)))))
;;;###autoload
-(defmacro define-mode-hook-helper (mode args &rest body)
- "Define hook helper for MODE.
-
-The suffix \"-mode\" is added to MODE before passing it to
-‘define-hook-helper’.
-
-ARGS and BODY are passed verbatim to ‘define-hook-helper’, so all allowed
-keys for that macro are allowed here."
- (declare (indent defun))
- `(define-hook-helper ,(intern (format "%s-mode" mode)) ,args ,@body))
+(defmacro define-hook-function (function args &optional docstring &rest body)
+ "Define FUNCTION to be a function, then add it to hooks."
+ (declare (indent defun) (doc-string 3))
+ ;; From `define-derived-mode'
+ (when (and docstring (not (stringp docstring)))
+ ;; Some trickiness, since what appears to be the docstring may really be
+ ;; the first element of the body.
+ (push docstring body)
+ (setq docstring nil))
+ ;; Process the key words
+ (let ((hooks nil))
+ (while (keywordp (car body))
+ (pcase (pop body)
+ ;; Why is hooks a keyword? It's required.
+ (`:hooks (setq hooks (pop body)))
+ (_ (pop body))))
+ `(progn
+ (defun ,function ,args
+ ,docstring
+ ,@body)
+ (dolist (h ,hooks)
+ (add-hook h (function ,function))))))
;; Add font lock for both macros.
(font-lock-add-keywords
'emacs-lisp-mode
'(("(\\(define-hook-helper\\)\\_>[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
(1 font-lock-keyword-face)
- (2 font-lock-function-name-face))
- ("(\\(define-mode-hook-helper\\)\\_>[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
- (1 font-lock-keyword-face)
- (2 font-lock-function-name-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.
- [elpa] branch scratch/hook-helpers created (now 365d8de), Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 597fce1 03/19: Updated README to include savannah project link., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 7981caf 06/19: Removed docstring argument from `hook-helpers'., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers 17f7d5d 07/19: Restored docstring argument in `define-hook-helper'., Ian Dunn, 2017/04/23
- [elpa] scratch/hook-helpers b373c79 08/19: Removed define-mode-hook-helpers, since it only moves the word "mode" around.,
Ian Dunn <=
- [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, 2017/04/23