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,29 +644,29 @@ 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
'(spell-fu-mode
eldoc-mode
highlight-numbers-mode
better-jumper-local-mode
ws-butler-mode
auto-composition-mode
undo-tree-mode
highlight-indent-guides-mode
hl-fill-column-mode
;; These are redundant on Emacs 29+
flycheck-mode
smartparens-mode
smartparens-strict-mode)))
(cl-callf append so-long-minor-modes
'(spell-fu-mode
eldoc-mode
highlight-numbers-mode
better-jumper-local-mode
ws-butler-mode
auto-composition-mode
undo-tree-mode
highlight-indent-guides-mode
hl-fill-column-mode
;; These are redundant on Emacs 29+
flycheck-mode
smartparens-mode
smartparens-strict-mode)))
(use-package! ws-butler

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
(general--concat t doom-leader-alt-key ,key)
,desc)
(which-key-add-key-based-replacements
(general--concat t doom-leader-key ,key)
,desc))))))))
(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))
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,10 +410,10 @@ 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
'("*Compile-Log*" "*inferior-lisp*" "*Fuzzy Completions*"
"*Apropos*" "*Help*" "*cvs*" "*Buffer List*" "*Ibuffer*"
"*esh command on file*")))
(cl-callf append winner-boring-buffers
'("*Compile-Log*" "*inferior-lisp*" "*Fuzzy Completions*"
"*Apropos*" "*Help*" "*cvs*" "*Buffer List*" "*Ibuffer*"
"*esh command on file*")))
(use-package! paren

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.
`(("melpa" . ,(format "http%s://melpa.org/packages/" s))
("org" . ,(format "http%s://orgmode.org/elpa/" s)))))
(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)))
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,24 +113,23 @@ 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
(and (memq type '(t dirs))
(string-match-p match file)
(not (and filter (funcall filter file)))
(not (and (file-symlink-p file)
(not follow-symlinks)))
(<= mindepth 0)
(list (if relative-to
(file-relative-name file relative-to)
file)))
(and (>= depth 1)
(apply #'doom-files-in file
(append (list :mindepth (1- mindepth)
:depth (1- depth)
:relative-to relative-to
:map nil)
rest)))))
(cl-callf append result
(and (memq type '(t dirs))
(string-match-p match file)
(not (and filter (funcall filter file)))
(not (and (file-symlink-p file)
(not follow-symlinks)))
(<= mindepth 0)
(list (if relative-to
(file-relative-name file relative-to)
file)))
(and (>= depth 1)
(apply #'doom-files-in file
(append (list :mindepth (1- mindepth)
:depth (1- depth)
:relative-to relative-to
:map nil)
rest)))))
((and (memq type '(t files))
(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)
(if variables
(setf (alist-get location doom-store-persist-alist)
(setf (alist-get location doom-store-persist-alist nil t)
(if variables
(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))