summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-03-12 17:29:26 -0600
committerCase Duckworth2021-03-12 17:29:26 -0600
commitea9fad47ece69cba9b30be8ec57a51f4f9421851 (patch)
treecb579808689645768424d020a51f0eef4ba7ec18
parentMove `acdw/modeline' functions into `acdw/pkg' forms (diff)
downloademacs-ea9fad47ece69cba9b30be8ec57a51f4f9421851.tar.gz
emacs-ea9fad47ece69cba9b30be8ec57a51f4f9421851.zip
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.
-rw-r--r--init.el8
-rw-r--r--lisp/acdw.el55
2 files changed, 31 insertions, 32 deletions
diff --git a/init.el b/init.el index 2f8760f..6940b6c 100644 --- a/init.el +++ b/init.el
@@ -51,7 +51,7 @@
51 (empty indentation space-before-tab space-after-tab)) 51 (empty indentation space-before-tab space-after-tab))
52 (indent-tabs-mode t) 52 (indent-tabs-mode t)
53 (tab-width 8))) 53 (tab-width 8)))
54(acdw/hooks before-save-hook whitespace-cleanup) 54(add-hook 'before-save-hook #'whitespace-cleanup)
55 55
56;; Pairs 56;; Pairs
57(add-hook 'prog-mode-hook #'electric-pair-local-mode) 57(add-hook 'prog-mode-hook #'electric-pair-local-mode)
@@ -377,8 +377,8 @@ indicator in the mode-line."
377(when (eq acdw/system :work) 377(when (eq acdw/system :work)
378 (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox")) 378 (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox"))
379 379
380(acdw/hooks text-mode-hook goto-address-mode) 380(acdw/hooks ((text-mode-hook goto-address-mode)
381(acdw/hooks prog-mode-hook goto-address-prog-mode) 381 (prog-mode-hook goto-address-prog-mode)))
382 382
383;;; Dired 383;;; Dired
384 384
@@ -403,7 +403,7 @@ indicator in the mode-line."
403 :binds (("i" dired-subtree-toggle :map dired-mode-map)))) 403 :binds (("i" dired-subtree-toggle :map dired-mode-map))))
404 404
405(acdw/pkg dired-collapse 405(acdw/pkg dired-collapse
406 :hooks (dired-mode-hook dired-collapse-mode)) 406 :hooks ((dired-mode-hook dired-collapse-mode)))
407 407
408;;; Eshell 408;;; Eshell
409 409
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'."
101 ,@face-list))) 101 ,@face-list)))
102 102
103;;; Hooks 103;;; Hooks
104(defmacro acdw/hooks (hook-specs &rest args)
105 "Add functions to hooks, according to HOOK-SPECS.
104 106
105(defmacro acdw/hooks (hooks funcs &optional depth local) 107Each HOOK-SPEC is of the following format: (HOOKS FUNCS [DEPTH] [LOCAL]).
106 "Add FUNCS to HOOKS. 108Either HOOKS or FUNCS can also be a list, in which case `add-hook' is called
107 109over the Cartesian product of HOOKS and FUNCS. In each HOOK-SPEC, DEPTH and
108Either HOOKS or FUNCS can be a list, in which case they're mapped 110LOCAL apply to all hooks defined; if finer control is needed, either pass the
109over to add all FUNCS to all HOOKS. They can also be singletons, 111same hooks and functions in different HOOK-SPECs, or just use `add-hook'.
110in which case `acdw/hooks' acts pretty much like `add-hook'. 112
111 113ARGS accept the following keywords:
112DEPTH and LOCAL apply to all HOOKS defined here. If you need 114
113more fine-grained control, just use `add-hook'." 115:after FEATURE .. `autoload' all functions after FEATURE."
114 (let ((hooks (if (listp hooks) hooks (list hooks))) 116 (let ((after (plist-get args :after))
115 (funcs (if (listp funcs) funcs (list funcs))) 117 (command-list))
116 (depth (if depth depth 0)) 118 (dolist (spec hook-specs)
117 (hook-list)) 119 (let* ((hooks (car spec))
118 (dolist (hook hooks) 120 (funcs (cadr spec))
119 (dolist (func funcs) 121 (depth (or (caddr spec) 0))
120 (push `(add-hook ',hook #',func ,depth ,local) hook-list))) 122 (local (cadddr spec)))
121 `(progn 123 (when (not (listp hooks)) (setq hooks (list hooks)))
122 ,@hook-list))) 124 (when (not (listp funcs)) (setq funcs (list funcs)))
123 125 (dolist (hook hooks)
124(defmacro acdw/hooks-after (file hooks funcs &optional depth local) 126 (dolist (func funcs)
125 "Add FUNCS, from FILE, to HOOKS." 127 (push `(add-hook ',hook #',func ,depth ,local) command-list)
126 (let ((funcs (if (listp funcs) funcs (list funcs))) 128 (when after
127 (autoload-list)) 129 (push `(autoload #',func ,after) command-list))))))
128 (dolist (func funcs)
129 (add-to-list 'autoload-list `(autoload #',func ,file)))
130 `(progn 130 `(progn
131 ,@autoload-list 131 ,@command-list)))
132 (acdw/hooks ,hooks ,funcs ,depth ,local))))
133 132
134;;; Keybindings 133;;; Keybindings
135 134
@@ -209,7 +208,7 @@ ARGS can include the following keywords:
209 (when then-forms 208 (when then-forms
210 (push `(with-eval-after-load ',requirement ,@then-forms) final-form)) 209 (push `(with-eval-after-load ',requirement ,@then-forms) final-form))
211 (when hooks 210 (when hooks
212 (push `(acdw/hooks-after ,(symbol-name requirement) ,@hooks) final-form)) 211 (push `(acdw/hooks ,hooks :after ,(symbol-name requirement)) final-form))
213 (when binds 212 (when binds
214 (push `(acdw/bind-after-map ,(symbol-name requirement) nil ,binds) 213 (push `(acdw/bind-after-map ,(symbol-name requirement) nil ,binds)
215 final-form)) 214 final-form))