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.
This commit is contained in:
Case Duckworth 2021-05-21 10:48:05 -05:00
parent 727ab389b9
commit a5fe45e8db
4 changed files with 60 additions and 51 deletions

View File

@ -34,11 +34,12 @@
inhibit-x-resources t)
(acdw/gc-disable)
(hook-defun post-init-reset after-init-hook
(acdw/gc-enable)
(dolist (handler file-name-handler-alist)
(add-to-list 'orig-file-name-handler-alist handler))
(setq file-name-handler-alist orig-file-name-handler-alist))
(add-hook 'after-init-hook
(defun after-init@reset ()
(acdw/gc-enable)
(dolist (handler file-name-handler-alist)
(add-to-list 'orig-file-name-handler-alist handler))
(setq file-name-handler-alist orig-file-name-handler-alist)))
;;; Frame settings
(setq default-frame-alist ; Remove most UI
@ -60,18 +61,6 @@
inhibit-x-resources t ; Don't load ~/.Xresources
)
(hook-defun disable-ui-modes after-init-hook
(dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
'((tool-bar-mode . tool-bar-lines)
(menu-bar-mode . menu-bar-lines)
(scroll-bar-mode . vertical-scroll-bars)
(horizontal-scroll-bar-mode . horizontal-scroll-bars)
))
(let ((setting (alist-get (cdr mode) default-frame-alist)))
(when (or (not setting)
(= 0 setting))
(funcall (car mode) -1)))))
(add-function :after after-focus-change-function
(defun acdw/first-frame-setup ()
;; fonts
@ -96,6 +85,19 @@
;; only run this once
(remove-function after-focus-change-function
'acdw/first-frame-setup)))
(add-hook 'after-init-hook
(defun after-init@disable-ui-modes ()
(dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
'((tool-bar-mode . tool-bar-lines)
(menu-bar-mode . menu-bar-lines)
(scroll-bar-mode . vertical-scroll-bars)
(horizontal-scroll-bar-mode . horizontal-scroll-bars)
))
(let ((setting (alist-get (cdr mode) default-frame-alist)))
(when (or (not setting)
(= 0 setting))
(funcall (car mode) -1))))))
;;; Bootstrap package manager (`straight.el')

View File

@ -109,9 +109,10 @@
(t (mailcap-parse-mailcaps))))
;;; Composing mail
(hook-defun setup-message-mode message-mode-hook
(flyspell-mode +1)
(local-set-key (kbd "TAB") #'bbdb-complete-mail))
(add-hook 'message-mode-hook
(defun message-mode@setup ()
(flyspell-mode +1)
(local-set-key (kbd "TAB") #'bbdb-complete-mail)))
;;; Sending mail
(setq send-mail-function #'smtpmail-send-it

46
init.el
View File

@ -274,10 +274,12 @@
(:leader "s" eshell-pop-or-quit)
(hook-defun eshell-setup 'eshell-mode-hook
(define-key eshell-mode-map (kbd "C-d") #'eshell-quit-or-delete-char)
(when (boundp 'simple-modeline--mode-line)
(setq mode-line-format '(:eval simple-modeline--mode-line)))))
(add-hook 'eshell-mode-hook
(defun eshell-mode@setup ()
(define-key eshell-mode-map (kbd "C-d")
#'eshell-quit-or-delete-char)
(when (boundp 'simple-modeline--mode-line)
(setq mode-line-format '(:eval simple-modeline--mode-line))))))
(setup eww
(:option eww-search-prefix "https://duckduckgo.com/html?q="
@ -418,9 +420,10 @@
(setup prog
(:option smie-indent-basic tab-width)
(hook-defun auto-fill-prog-mode prog-mode-hook
(setq-local comment-auto-fill-only-comments t)
(turn-on-auto-fill))
(add-hook 'prog-mode-hook
(defun prog-mode@auto-fill ()
(setq-local comment-auto-fill-only-comments t)
(turn-on-auto-fill)))
(:option show-paren-delay 0
show-paren-style 'mixed
@ -526,11 +529,12 @@
"Welcome to GNU Emacs.\n\n")
initial-major-mode 'emacs-lisp-mode)
(hook-defun immortal-scratch kill-buffer-query-functions
(if (eq (current-buffer) (get-buffer "*scratch*"))
(progn (bury-buffer)
nil)
t)))
(add-hook 'kill-buffer-query-functions
(defun kill-buffer-query@immortal-scratch ()
(if (eq (current-buffer) (get-buffer "*scratch*"))
(progn (bury-buffer)
nil)
t))))
(setup scrolling
(:option auto-window-vscroll nil
@ -673,14 +677,16 @@
(apheleia-global-mode +1)
;; Use a dumb formatter on modes that `apheleia' doesn't work for.
(hook-defun dumb-auto-format before-save-hook
(setq stupid-modes '(makefile-mode
org-mode))
;; If there's no apheleia formatter for the mode, just indent the buffer.
(unless (or (apply #'derived-mode-p stupid-modes)
(and (fboundp 'apheleia--get-formatter-command)
(apheleia--get-formatter-command)))
(indent-region (point-min) (point-max)))))
(add-hook 'before-save-hook
(defun before-save@dumb-auto-format ()
(setq stupid-modes '(makefile-mode
org-mode))
;; If there's no apheleia formatter for the mode, just indent the
;; buffer.
(unless (or (apply #'derived-mode-p stupid-modes)
(and (fboundp 'apheleia--get-formatter-command)
(apheleia--get-formatter-command)))
(indent-region (point-min) (point-max))))))
(setup (:straight async)
(autoload 'dired-async-mode "dired-async.el" nil t)

View File

@ -65,17 +65,17 @@ ARG). When called with multiple arguments or a list, it returns
file
nil)))
(defmacro hook-defun (name hooks &rest forms)
"Define a function NAME that executes FORMS, and add it to
each hook in HOOKS."
(declare (indent 2))
(let ((func-name (intern (concat "hook-defun-" (symbol-name name))))
(hook-list (if (consp hooks) hooks (list hooks)))
(hook-defun-add-hook-list))
`(progn
(defun ,func-name () "Defined by `hook-defun'." ,@forms)
,@(dolist (hook hook-list hook-defun-add-hook-list)
(push `(add-hook ',hook #',func-name) hook-defun-add-hook-list)))))
;; (defmacro hook-defun (name hooks &rest forms)
;; "Define a function NAME that executes FORMS, and add it to
;; each hook in HOOKS."
;; (declare (indent 2))
;; (let ((func-name (intern (concat "hook-defun-" (symbol-name name))))
;; (hook-list (if (consp hooks) hooks (list hooks)))
;; (hook-defun-add-hook-list))
;; `(progn
;; (defun ,func-name () "Defined by `hook-defun'." ,@forms)
;; ,@(dolist (hook hook-list hook-defun-add-hook-list)
;; (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list)))))
(defun kill-region-or-backward-word (arg)
"Kill region if active, or backward word if not."