refactor: deprecate appendq!, prependq!, & delq! macros

In the interest of slimming down Doom's core (as we near v3), I've
deprecated these macros. They doesn't really need to exist. Sure, the
alternatives aren't as ergonomic or elegant, but they're good enough
that we don't need these trivial wrappers. Their local uses have been
refactored out as well.
This commit is contained in:
Henrik Lissner
2025-03-25 00:31:41 -04:00
parent 2f7f37d49b
commit dac6e05b87
27 changed files with 85 additions and 131 deletions

View File

@ -351,8 +351,8 @@ in."
(print! "%s" (string-join (append doom-doctor--errors doom-doctor--warnings) "\n")))
(setq doom-local-errors doom-doctor--errors
doom-local-warnings doom-doctor--warnings)))
(appendq! doom-doctor--errors doom-local-errors)
(appendq! doom-doctor--warnings doom-local-warnings))))))
(cl-callf append doom-doctor--errors doom-local-errors)
(cl-callf append doom-doctor--warnings doom-local-warnings))))))
(error
(warn! "Attempt to load DOOM failed\n %s\n"
(or (cdr-safe ex) (car ex)))

View File

@ -82,30 +82,6 @@ are great, but this file exists to add demos for Doom's API and beyond.
(after! rustic ...)
(after! python ...)
#+end_src
* appendq!
:PROPERTIES:
:added: 3.0.0-pre
:END:
#+begin_src emacs-lisp
(let ((x '(a b c)))
(appendq! x '(c d e))
x)
#+end_src
#+RESULTS:
: (a b c c d e)
#+begin_src emacs-lisp
(let ((x '(a b c))
(y '(c d e))
(z '(f g)))
(appendq! x y z '(h))
x)
#+end_src
#+RESULTS:
: (a b c c d e f g h)
* cmd!
:PROPERTIES:
:added: 3.0.0-pre
@ -573,30 +549,6 @@ These are side-by-side comparisons, showing how to bind keys with and without
;; refresh to delete packages used only on one system, use :ignore
(package! evil :ignore (not (equal system-name "my-desktop")))
#+end_src
* prependq!
:PROPERTIES:
:added: 3.0.0-pre
:END:
#+begin_src emacs-lisp
(let ((x '(a b c)))
(prependq! x '(c d e))
x)
#+end_src
#+RESULTS:
: (c d e a b c)
#+begin_src emacs-lisp
(let ((x '(a b c))
(y '(c d e))
(z '(f g)))
(prependq! x y z '(h))
x)
#+end_src
#+RESULTS:
: (c d e f g h a b c)
* pushnew!
:PROPERTIES:
:added: 3.0.0-pre

View File

@ -644,16 +644,16 @@ on."
;; read-only, in `so-long-minor-mode', so we can have a basic editing
;; experience in them, at least. It will remain off in `so-long-mode',
;; however, because long files have a far bigger impact on Emacs performance.
(delq! 'font-lock-mode so-long-minor-modes)
(delq! 'display-line-numbers-mode so-long-minor-modes)
(delq! 'buffer-read-only so-long-variable-overrides 'assq)
(cl-callf2 delq 'font-lock-mode so-long-minor-modes)
(cl-callf2 delq 'display-line-numbers-mode so-long-minor-modes)
(setf (alist-get 'buffer-read-only so-long-variable-overrides nil t) nil)
;; ...but at least reduce the level of syntax highlighting
(add-to-list 'so-long-variable-overrides '(font-lock-maximum-decoration . 1))
;; ...and insist that save-place not operate in large/long files
(add-to-list 'so-long-variable-overrides '(save-place-alist . nil))
;; But disable everything else that may be unnecessary/expensive for large or
;; wide buffers.
(appendq! so-long-minor-modes
(cl-callf append so-long-minor-modes
'(spell-fu-mode
eldoc-mode
highlight-numbers-mode

View File

@ -160,13 +160,14 @@ all hooks after it are ignored.")
,bdef)
forms))
(when-let (desc (cadr (memq :which-key udef)))
(prependq!
wkforms `((which-key-add-key-based-replacements
(cl-callf2 append
`((which-key-add-key-based-replacements
(general--concat t doom-leader-alt-key ,key)
,desc)
(which-key-add-key-based-replacements
(general--concat t doom-leader-key ,key)
,desc))))))))
,desc))
wkforms))))))
(macroexp-progn
(append (and wkforms `((after! which-key ,@(nreverse wkforms))))
(nreverse forms)))))

View File

@ -708,8 +708,10 @@ See `general-key-dispatch' for what other arguments it accepts in BRANCHES."
;;; Mutation
;; DEPRECATED: Remove in v3.0
(defmacro appendq! (sym &rest lists)
"Append LISTS to SYM in place."
(declare (obsolete "Use `cl-callf2' instead" "3.0.0"))
`(setq ,sym (append ,sym ,@lists)))
(defmacro setq! (&rest settings)
@ -723,10 +725,12 @@ Unlike `setopt', this won't needlessly pull in dependencies."
collect `(funcall (or (get ',var 'custom-set) #'set-default-toplevel-value)
',var ,val))))
;; DEPRECATED: Remove in v3.0
(defmacro delq! (elt list &optional fetcher)
"`delq' ELT from LIST in-place.
If FETCHER is a function, ELT is used as the key in LIST (an alist)."
(declare (obsolete "Use `cl-callf2' or `alist-get' instead" "3.0.0"))
`(setq ,list (delq ,(if fetcher
`(funcall ,fetcher ,elt ,list)
elt)
@ -739,8 +743,10 @@ This is a variadic `cl-pushnew'."
`(dolist (,var (list ,@values) (with-no-warnings ,place))
(cl-pushnew ,var ,place :test #'equal))))
;; DEPRECATED: Remove in v3.0
(defmacro prependq! (sym &rest lists)
"Prepend LISTS to SYM in place."
(declare (obsolete "Use `cl-callf2' instead" "3.0.0"))
`(setq ,sym (append ,@lists ,sym)))
@ -839,7 +845,7 @@ to reverse this and trigger `after!' blocks at a more reasonable time."
(let ((advice-fn (intern (format "doom--defer-feature-%s-a" feature)))
(fns (or fns (list feature))))
`(progn
(delq! ',feature features)
(cl-callf2 delq ',feature features)
(defadvice! ,advice-fn (&rest _)
:before ',fns
;; Some plugins (like yasnippet) will invoke a fn early to parse

View File

@ -184,7 +184,7 @@ original state.")
(let ((doom-straight--auto-options doom-straight--auto-options))
;; We can't intercept C-g, so no point displaying any options for this key
;; when C-c is the proper way to abort batch Emacs.
(delq! "C-g" actions 'assoc)
(cl-callf2 delq 'assoc actions)
;; HACK: Remove actions that don't work in noninteractive Emacs (like
;; opening dired or magit).
(setq actions

View File

@ -410,7 +410,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
:preface (defvar winner-dont-bind-my-keys t) ; I'll bind keys myself
:hook (doom-first-buffer . winner-mode)
:config
(appendq! winner-boring-buffers
(cl-callf append winner-boring-buffers
'("*Compile-Log*" "*inferior-lisp*" "*Fuzzy Completions*"
"*Apropos*" "*Help*" "*cvs*" "*Buffer List*" "*Ibuffer*"
"*esh command on file*")))

View File

@ -701,11 +701,12 @@ to `doom-profile-cache-dir' instead, so it can be safely cleaned up as part of
(setq package-user-dir (file-name-concat doom-local-dir "elpa/")
package-gnupghome-dir (expand-file-name "gpg" package-user-dir))
(let ((s (if gnutls-verify-error "s" "")))
(prependq! package-archives
;; I omit Marmalade because its packages are manually submitted
;; rather than pulled, and so often out of date.
(cl-callf2 append
;; I omit Marmalade because its packages are manually submitted rather
;; than pulled, and so often out of date.
`(("melpa" . ,(format "http%s://melpa.org/packages/" s))
("org" . ,(format "http%s://orgmode.org/elpa/" s)))))
("org" . ,(format "http%s://orgmode.org/elpa/" s)))
package-archives))
;; Refresh package.el the first time you call `package-install', so it's still
;; trivially usable. Remember to run 'doom sync' to purge them; they can

View File

@ -113,8 +113,7 @@ MATCH is a string regexp. Only entries that match it will be included."
(let (result)
(dolist (file (mapcan (doom-rpartial #'doom-glob "*") (ensure-list paths)))
(cond ((file-directory-p file)
(appendq!
result
(cl-callf append result
(and (memq type '(t dirs))
(string-match-p match file)
(not (and filter (funcall filter file)))

View File

@ -151,13 +151,13 @@ properties:
(:cond
(cl-loop for (cond . mods) in (cdr m)
if (eval cond t)
return (prependq! mplist mods)))
return (cl-callf2 append mods mplist)))
(:if (if (eval (cadr m) t)
(push (caddr m) mplist)
(prependq! mplist (cdddr m))))
(cl-callf2 append (cdddr m) mplist)))
(test (if (xor (eval (cadr m) t)
(eq test :unless))
(prependq! mplist (cddr m))))))
(cl-callf2 append (cddr m) mplist)))))
((catch 'doom-modules
(let* ((module (if (listp m) (car m) m))
(flags (if (listp m) (cdr m))))

View File

@ -199,7 +199,7 @@ processed."
(cl-pushnew name doom-disabled-packages)
(when recipe
(straight-override-recipe (cons name recipe)))
(appendq! packages (cons name (straight--get-dependencies name)))))))
(cl-callf append packages (cons name (straight--get-dependencies name)))))))
(dolist (package (cl-delete-duplicates packages :test #'equal))
(straight-register-package package)
(let ((name (symbol-name package)))

View File

@ -45,8 +45,7 @@ name under `pcache-directory' (by default a subdirectory under
"Persist VARIABLES (list of symbols) in LOCATION (symbol).
This populates these variables with cached values, if one exists, and saves them
to file when Emacs quits. This cannot persist buffer-local variables."
(cl-check-type location string)
(dolist (var variables)
(dolist (var (ensure-list variables))
(when (doom-store-member-p var location)
(set var (doom-store-get var location))))
(setf (alist-get location doom-store-persist-alist)
@ -57,12 +56,10 @@ to file when Emacs quits. This cannot persist buffer-local variables."
"Unregisters VARIABLES (list of symbols) in LOCATION (symbol).
Variables to persist are recorded in `doom-store-persist-alist'. Does not affect
the actual variables themselves or their values."
(cl-check-type location string)
(setf (alist-get location doom-store-persist-alist nil t)
(if variables
(setf (alist-get location doom-store-persist-alist)
(cl-set-difference (cdr (assq location doom-store-persist-alist))
variables))
(delq! location doom-store-persist-alist 'assoc)))
variables))))
(defun doom--store-init (&optional location)
(cl-check-type location (or null string))

View File

@ -5,7 +5,7 @@
;; `elisp-mode' is loaded at startup. In order to lazy load its config we need
;; to pretend it isn't loaded
(delq! 'ispell features)
(cl-callf2 delq 'ispell features)
(global-set-key [remap ispell-word] #'+spell/correct)

View File

@ -149,7 +149,7 @@
;; Don't show documentation in echo area, because company-box displays its own
;; in a child frame.
(delq! 'company-echo-metadata-frontend company-frontends)
(cl-callf2 delq 'company-echo-metadata-frontend company-frontends)
(defun +company-box-icons--elisp-fn (candidate)
(when (derived-mode-p 'emacs-lisp-mode)

View File

@ -351,7 +351,7 @@ If ARG (universal argument), include all files, even hidden or compressed ones."
:require-match t
:action (lambda (cand)
(let ((mark (cdr cand)))
(delq! (marker-buffer mark) buffers)
(cl-callf2 delq (marker-buffer mark) buffers)
(mapc #'kill-buffer buffers)
(setq buffers nil)
(with-current-buffer (switch-to-buffer (marker-buffer mark))

View File

@ -109,7 +109,7 @@
(dolist (hook (cdr deferral-list))
(advice-remove hook #',fn)
(remove-hook hook #',fn))
(delq! deferral-list doom--deferred-packages-alist)
(cl-callf2 delq deferral-list doom--deferred-packages-alist)
(unintern ',fn nil)))))
(let (forms)
(dolist (hook hooks forms)

View File

@ -182,7 +182,7 @@ directives. By default, this only recognizes C directives.")
(advice-add #'evil-open-below :around #'+evil--insert-newline-below-and-respect-comments-a)
;; Lazy load evil ex commands
(delq! 'evil-ex features)
(cl-callf2 delq 'evil-ex features)
(add-transient-hook! 'evil-ex (provide 'evil-ex))
(after! evil-ex (load! "+commands")))

View File

@ -45,7 +45,7 @@
(advice-add #'yas-snippet-dirs :filter-return #'delete-dups)
;; Remove GUI dropdown prompt (prefer ivy/helm)
(delq! 'yas-dropdown-prompt yas-prompt-functions)
(cl-callf2 delq 'yas-dropdown-prompt yas-prompt-functions)
;; Prioritize private snippets in `+snippets-dir' over built-in ones if there
;; are multiple choices.
(add-to-list 'yas-prompt-functions #'+snippets-prompt-private)

View File

@ -115,7 +115,7 @@ Fixes #3939: unsortable dired entries on Windows."
(when (modulep! +icons)
(setq dirvish-subtree-always-show-state t)
(appendq! dirvish-attributes '(nerd-icons subtree-state)))
(cl-callf append dirvish-attributes '(nerd-icons subtree-state)))
(setq dirvish-hide-details '(dirvish dirvish-side)
dirvish-hide-cursor '(dirvish dirvish-side))

View File

@ -630,7 +630,6 @@ See `+mu4e-msg-gmail-p' and `mu4e-sent-messages-behavior'.")
(defvar +mu4e--last-invalid-gmail-action 0)
(delq! 'delete mu4e-marks #'assq)
(setf (alist-get 'delete mu4e-marks)
(list
:char '("D" . "")

View File

@ -217,9 +217,8 @@ Math faces should stay fixed by the mixed-pitch blacklist, this is mostly for
(defadvice! +latex--dont-indent-itemize-and-enumerate-and-description-a (fn &rest args)
:around #'LaTeX-fill-region-as-paragraph
(let ((LaTeX-indent-environment-list LaTeX-indent-environment-list))
(delq! "itemize" LaTeX-indent-environment-list 'assoc)
(delq! "enumerate" LaTeX-indent-environment-list 'assoc)
(delq! "description" LaTeX-indent-environment-list 'assoc)
(dolist (item '("itemize" "enumerate" "description"))
(setf (alist-get item LaTeX-indent-environment-list nil t #'equal) nil))
(apply fn args))))

View File

@ -760,7 +760,7 @@ mutating hooks on exported output, like formatters."
"Restart `org-mode', but only once."
(remove-hook 'doom-switch-buffer-hook #'+org--restart-mode-h 'local)
(quiet! (org-mode-restart))
(delq! (current-buffer) org-agenda-new-buffers)
(cl-callf2 delq (current-buffer) org-agenda-new-buffers)
(run-hooks 'find-file-hook))
(add-hook! 'org-agenda-finalize-hook

View File

@ -20,4 +20,4 @@
(use-package! company-solidity
:when (modulep! :completion company)
:config (delq! 'company-solidity company-backends)))
:config (cl-callf2 delq 'company-solidity company-backends)))

View File

@ -62,7 +62,7 @@
collect (cons (car pair)
(string-trim-right (cdr pair)
"\\(?:>\\|]\\|}\\)+\\'")))))
(delq! nil web-mode-engines-auto-pairs))
(cl-callf2 delq nil web-mode-engines-auto-pairs))
(add-to-list 'web-mode-engines-alist '("elixir" . "\\.eex\\'"))
(add-to-list 'web-mode-engines-alist '("phoenix" . "\\.[lh]eex\\'"))

View File

@ -54,7 +54,7 @@ QUERY must be a string, and PROVIDER must be a key of
(and (fboundp backend)
(funcall backend query))
(error
(delq! major-mode +lookup--last-provider 'assq)
(setf (alist-get major-mode +lookup--last-provider nil t) nil)
(signal (car e) (cdr e))))
(throw 'done t)))))))

View File

@ -35,7 +35,7 @@ Note that this will keep all ligatures in `+ligatures-prog-mode-list' active, as
(declare (indent defun))
(if (null (car-safe plist))
(dolist (mode (ensure-list modes))
(delq! mode +ligatures-extra-alist 'assq))
(setf (alist-get mode +ligatures-extra-alist nil t) nil))
(let ((results))
(while plist
(let ((key (pop plist)))

View File

@ -474,7 +474,7 @@ lines are selected, or the NxM dimensions of a block selection.")
(defun +modeline-add-selection-segment-h ()
(add-to-list '+modeline-format-left '+modeline-selection-info 'append))
(defun +modeline-remove-selection-segment-h ()
(delq! '+modeline-selection-info +modeline-format-left))
(cl-callf2 delq '+modeline-selection-info +modeline-format-left))
(if (featurep 'evil)
(progn