From ea9fad47ece69cba9b30be8ec57a51f4f9421851 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 12 Mar 2021 17:29:26 -0600 Subject: Change `acdw/hooks' form Instead of only allowing (list-of-hooks) (list-of-functions), `acdw/hooks' now accepts a (list-of-hook-specs), each of which is of the above form, allowing the user to set multiple unrelated hooks at once. --- lisp/acdw.el | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index 201db1f..6641e9b 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -101,35 +101,34 @@ SPEC is as for `defface'." ,@face-list))) ;;; Hooks +(defmacro acdw/hooks (hook-specs &rest args) + "Add functions to hooks, according to HOOK-SPECS. -(defmacro acdw/hooks (hooks funcs &optional depth local) - "Add FUNCS to HOOKS. - -Either HOOKS or FUNCS can be a list, in which case they're mapped -over to add all FUNCS to all HOOKS. They can also be singletons, -in which case `acdw/hooks' acts pretty much like `add-hook'. - -DEPTH and LOCAL apply to all HOOKS defined here. If you need -more fine-grained control, just use `add-hook'." - (let ((hooks (if (listp hooks) hooks (list hooks))) - (funcs (if (listp funcs) funcs (list funcs))) - (depth (if depth depth 0)) - (hook-list)) - (dolist (hook hooks) - (dolist (func funcs) - (push `(add-hook ',hook #',func ,depth ,local) hook-list))) - `(progn - ,@hook-list))) - -(defmacro acdw/hooks-after (file hooks funcs &optional depth local) - "Add FUNCS, from FILE, to HOOKS." - (let ((funcs (if (listp funcs) funcs (list funcs))) - (autoload-list)) - (dolist (func funcs) - (add-to-list 'autoload-list `(autoload #',func ,file))) +Each HOOK-SPEC is of the following format: (HOOKS FUNCS [DEPTH] [LOCAL]). +Either HOOKS or FUNCS can also be a list, in which case `add-hook' is called +over the Cartesian product of HOOKS and FUNCS. In each HOOK-SPEC, DEPTH and +LOCAL apply to all hooks defined; if finer control is needed, either pass the +same hooks and functions in different HOOK-SPECs, or just use `add-hook'. + +ARGS accept the following keywords: + +:after FEATURE .. `autoload' all functions after FEATURE." + (let ((after (plist-get args :after)) + (command-list)) + (dolist (spec hook-specs) + (let* ((hooks (car spec)) + (funcs (cadr spec)) + (depth (or (caddr spec) 0)) + (local (cadddr spec))) + (when (not (listp hooks)) (setq hooks (list hooks))) + (when (not (listp funcs)) (setq funcs (list funcs))) + (dolist (hook hooks) + (dolist (func funcs) + (push `(add-hook ',hook #',func ,depth ,local) command-list) + (when after + (push `(autoload #',func ,after) command-list)))))) `(progn - ,@autoload-list - (acdw/hooks ,hooks ,funcs ,depth ,local)))) + ,@command-list))) ;;; Keybindings @@ -209,7 +208,7 @@ ARGS can include the following keywords: (when then-forms (push `(with-eval-after-load ',requirement ,@then-forms) final-form)) (when hooks - (push `(acdw/hooks-after ,(symbol-name requirement) ,@hooks) final-form)) + (push `(acdw/hooks ,hooks :after ,(symbol-name requirement)) final-form)) (when binds (push `(acdw/bind-after-map ,(symbol-name requirement) nil ,binds) final-form)) -- cgit 1.4.1-21-gabe81