summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-05-21 10:48:05 -0500
committerCase Duckworth2021-05-21 10:57:58 -0500
commita5fe45e8db98f2405b6ec3d325d9d4366434faa7 (patch)
treea10665b4197b1417eb5cc2af865460f3ad025b84
parentFix `acdw/system' argument parsing (diff)
downloademacs-a5fe45e8db98f2405b6ec3d325d9d4366434faa7.tar.gz
emacs-a5fe45e8db98f2405b6ec3d325d9d4366434faa7.zip
Comment out `hook-defun'
The only plus `hook-defun' has over (add-hook 'hook (defun name ... )) is the
ability to add the same function to multiple hooks at once.  My init files
don't use that functionality, so I've retired this macro for now.

I'm thinking, honestly, that if a function is used in more than one hook, it
should be defined separately and added to each hook in turn ... you know, like
Emacs does it by default.
-rw-r--r--early-init.el36
-rw-r--r--gnus.el7
-rw-r--r--init.el46
-rw-r--r--lisp/acdw.el22
4 files changed, 60 insertions, 51 deletions
diff --git a/early-init.el b/early-init.el index 622d220..bb717d6 100644 --- a/early-init.el +++ b/early-init.el
@@ -34,11 +34,12 @@
34 inhibit-x-resources t) 34 inhibit-x-resources t)
35(acdw/gc-disable) 35(acdw/gc-disable)
36 36
37(hook-defun post-init-reset after-init-hook 37(add-hook 'after-init-hook
38 (acdw/gc-enable) 38 (defun after-init@reset ()
39 (dolist (handler file-name-handler-alist) 39 (acdw/gc-enable)
40 (add-to-list 'orig-file-name-handler-alist handler)) 40 (dolist (handler file-name-handler-alist)
41 (setq file-name-handler-alist orig-file-name-handler-alist)) 41 (add-to-list 'orig-file-name-handler-alist handler))
42 (setq file-name-handler-alist orig-file-name-handler-alist)))
42 43
43;;; Frame settings 44;;; Frame settings
44(setq default-frame-alist ; Remove most UI 45(setq default-frame-alist ; Remove most UI
@@ -60,18 +61,6 @@
60 inhibit-x-resources t ; Don't load ~/.Xresources 61 inhibit-x-resources t ; Don't load ~/.Xresources
61 ) 62 )
62 63
63(hook-defun disable-ui-modes after-init-hook
64 (dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
65 '((tool-bar-mode . tool-bar-lines)
66 (menu-bar-mode . menu-bar-lines)
67 (scroll-bar-mode . vertical-scroll-bars)
68 (horizontal-scroll-bar-mode . horizontal-scroll-bars)
69 ))
70 (let ((setting (alist-get (cdr mode) default-frame-alist)))
71 (when (or (not setting)
72 (= 0 setting))
73 (funcall (car mode) -1)))))
74
75(add-function :after after-focus-change-function 64(add-function :after after-focus-change-function
76 (defun acdw/first-frame-setup () 65 (defun acdw/first-frame-setup ()
77 ;; fonts 66 ;; fonts
@@ -96,6 +85,19 @@
96 ;; only run this once 85 ;; only run this once
97 (remove-function after-focus-change-function 86 (remove-function after-focus-change-function
98 'acdw/first-frame-setup))) 87 'acdw/first-frame-setup)))
88(add-hook 'after-init-hook
89 (defun after-init@disable-ui-modes ()
90 (dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
91 '((tool-bar-mode . tool-bar-lines)
92 (menu-bar-mode . menu-bar-lines)
93 (scroll-bar-mode . vertical-scroll-bars)
94 (horizontal-scroll-bar-mode . horizontal-scroll-bars)
95 ))
96 (let ((setting (alist-get (cdr mode) default-frame-alist)))
97 (when (or (not setting)
98 (= 0 setting))
99 (funcall (car mode) -1))))))
100
99 101
100 102
101;;; Bootstrap package manager (`straight.el') 103;;; Bootstrap package manager (`straight.el')
diff --git a/gnus.el b/gnus.el index 5fdb08f..6c244d7 100644 --- a/gnus.el +++ b/gnus.el
@@ -109,9 +109,10 @@
109 (t (mailcap-parse-mailcaps)))) 109 (t (mailcap-parse-mailcaps))))
110 110
111;;; Composing mail 111;;; Composing mail
112(hook-defun setup-message-mode message-mode-hook 112(add-hook 'message-mode-hook
113 (flyspell-mode +1) 113 (defun message-mode@setup ()
114 (local-set-key (kbd "TAB") #'bbdb-complete-mail)) 114 (flyspell-mode +1)
115 (local-set-key (kbd "TAB") #'bbdb-complete-mail)))
115 116
116;;; Sending mail 117;;; Sending mail
117(setq send-mail-function #'smtpmail-send-it 118(setq send-mail-function #'smtpmail-send-it
diff --git a/init.el b/init.el index cf69c1b..a114c94 100644 --- a/init.el +++ b/init.el
@@ -274,10 +274,12 @@
274 274
275 (:leader "s" eshell-pop-or-quit) 275 (:leader "s" eshell-pop-or-quit)
276 276
277 (hook-defun eshell-setup 'eshell-mode-hook 277 (add-hook 'eshell-mode-hook
278 (define-key eshell-mode-map (kbd "C-d") #'eshell-quit-or-delete-char) 278 (defun eshell-mode@setup ()
279 (when (boundp 'simple-modeline--mode-line) 279 (define-key eshell-mode-map (kbd "C-d")
280 (setq mode-line-format '(:eval simple-modeline--mode-line))))) 280 #'eshell-quit-or-delete-char)
281 (when (boundp 'simple-modeline--mode-line)
282 (setq mode-line-format '(:eval simple-modeline--mode-line))))))
281 283
282(setup eww 284(setup eww
283 (:option eww-search-prefix "https://duckduckgo.com/html?q=" 285 (:option eww-search-prefix "https://duckduckgo.com/html?q="
@@ -418,9 +420,10 @@
418(setup prog 420(setup prog
419 (:option smie-indent-basic tab-width) 421 (:option smie-indent-basic tab-width)
420 422
421 (hook-defun auto-fill-prog-mode prog-mode-hook 423 (add-hook 'prog-mode-hook
422 (setq-local comment-auto-fill-only-comments t) 424 (defun prog-mode@auto-fill ()
423 (turn-on-auto-fill)) 425 (setq-local comment-auto-fill-only-comments t)
426 (turn-on-auto-fill)))
424 427
425 (:option show-paren-delay 0 428 (:option show-paren-delay 0
426 show-paren-style 'mixed 429 show-paren-style 'mixed
@@ -526,11 +529,12 @@
526 "Welcome to GNU Emacs.\n\n") 529 "Welcome to GNU Emacs.\n\n")
527 initial-major-mode 'emacs-lisp-mode) 530 initial-major-mode 'emacs-lisp-mode)
528 531
529 (hook-defun immortal-scratch kill-buffer-query-functions 532 (add-hook 'kill-buffer-query-functions
530 (if (eq (current-buffer) (get-buffer "*scratch*")) 533 (defun kill-buffer-query@immortal-scratch ()
531 (progn (bury-buffer) 534 (if (eq (current-buffer) (get-buffer "*scratch*"))
532 nil) 535 (progn (bury-buffer)
533 t))) 536 nil)
537 t))))
534 538
535(setup scrolling 539(setup scrolling
536 (:option auto-window-vscroll nil 540 (:option auto-window-vscroll nil
@@ -673,14 +677,16 @@
673 (apheleia-global-mode +1) 677 (apheleia-global-mode +1)
674 678
675 ;; Use a dumb formatter on modes that `apheleia' doesn't work for. 679 ;; Use a dumb formatter on modes that `apheleia' doesn't work for.
676 (hook-defun dumb-auto-format before-save-hook 680 (add-hook 'before-save-hook
677 (setq stupid-modes '(makefile-mode 681 (defun before-save@dumb-auto-format ()
678 org-mode)) 682 (setq stupid-modes '(makefile-mode
679 ;; If there's no apheleia formatter for the mode, just indent the buffer. 683 org-mode))
680 (unless (or (apply #'derived-mode-p stupid-modes) 684 ;; If there's no apheleia formatter for the mode, just indent the
681 (and (fboundp 'apheleia--get-formatter-command) 685 ;; buffer.
682 (apheleia--get-formatter-command))) 686 (unless (or (apply #'derived-mode-p stupid-modes)
683 (indent-region (point-min) (point-max))))) 687 (and (fboundp 'apheleia--get-formatter-command)
688 (apheleia--get-formatter-command)))
689 (indent-region (point-min) (point-max))))))
684 690
685(setup (:straight async) 691(setup (:straight async)
686 (autoload 'dired-async-mode "dired-async.el" nil t) 692 (autoload 'dired-async-mode "dired-async.el" nil t)
diff --git a/lisp/acdw.el b/lisp/acdw.el index 4a7d4b3..c48c4e3 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -65,17 +65,17 @@ ARG). When called with multiple arguments or a list, it returns
65 file 65 file
66 nil))) 66 nil)))
67 67
68(defmacro hook-defun (name hooks &rest forms) 68;; (defmacro hook-defun (name hooks &rest forms)
69 "Define a function NAME that executes FORMS, and add it to 69;; "Define a function NAME that executes FORMS, and add it to
70each hook in HOOKS." 70;; each hook in HOOKS."
71 (declare (indent 2)) 71;; (declare (indent 2))
72 (let ((func-name (intern (concat "hook-defun-" (symbol-name name)))) 72;; (let ((func-name (intern (concat "hook-defun-" (symbol-name name))))
73 (hook-list (if (consp hooks) hooks (list hooks))) 73;; (hook-list (if (consp hooks) hooks (list hooks)))
74 (hook-defun-add-hook-list)) 74;; (hook-defun-add-hook-list))
75 `(progn 75;; `(progn
76 (defun ,func-name () "Defined by `hook-defun'." ,@forms) 76;; (defun ,func-name () "Defined by `hook-defun'." ,@forms)
77 ,@(dolist (hook hook-list hook-defun-add-hook-list) 77;; ,@(dolist (hook hook-list hook-defun-add-hook-list)
78 (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list))))) 78;; (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list)))))
79 79
80(defun kill-region-or-backward-word (arg) 80(defun kill-region-or-backward-word (arg)
81 "Kill region if active, or backward word if not." 81 "Kill region if active, or backward word if not."