refactor: replace doom-enlist with ensure-list

doom-enlist is now a deprecated alias for ensure-list, which is built
into Emacs 28.1+ and is its drop-in replacement. We've already
backported it for 27.x users in doom-lib (in 4bf4978).

Ref: 4bf49785fd
This commit is contained in:
Henrik Lissner 2022-08-07 12:24:14 +02:00
parent 1abcf913aa
commit 057e6c531c
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
28 changed files with 41 additions and 46 deletions

View file

@ -118,7 +118,7 @@ list remains lean."
(dolist (,recipe-var ,recipes-var (nreverse built)) (dolist (,recipe-var ,recipes-var (nreverse built))
(cl-block nil (cl-block nil
(straight--with-plist (append (list :recipe ,recipe-var) ,recipe-var) (straight--with-plist (append (list :recipe ,recipe-var) ,recipe-var)
,(doom-enlist binds) ,(ensure-list binds)
,@body)))))) ,@body))))))
(defvar doom-packages--cli-updated-recipes nil) (defvar doom-packages--cli-updated-recipes nil)

View file

@ -216,7 +216,7 @@ execution. Can be generated from a `doom-cli-context' with
This means that all non-keywords are strings, any prefixes provided by PLIST are This means that all non-keywords are strings, any prefixes provided by PLIST are
prepended, and the keyword is in front." prepended, and the keyword is in front."
(let* ((command (doom-enlist command)) (let* ((command (ensure-list command))
(prefix (plist-get plist :prefix)) (prefix (plist-get plist :prefix))
(prefix (if prefix (doom-cli-command-normalize (prefix (if prefix (doom-cli-command-normalize
prefix (append `(:prefix nil) plist)))) prefix (append `(:prefix nil) plist))))
@ -435,14 +435,14 @@ If RECURSIVE, includes breadcrumbs leading up to COMMANDSPEC."
collect command))) collect command)))
(seq-reduce (lambda (init next) (seq-reduce (lambda (init next)
(nconc (cl-loop with firstlen = (length (car init)) (nconc (cl-loop with firstlen = (length (car init))
for seg in (doom-enlist next) for seg in (ensure-list next)
nconc nconc
(cl-loop for command in init (cl-loop for command in init
while (= (length command) firstlen) while (= (length command) firstlen)
collect (append command (list seg)))) collect (append command (list seg))))
init)) init))
(cdr commandspec) (cdr commandspec)
`(,@(mapcar #'list (doom-enlist (car commandspec))))))) `(,@(mapcar #'list (ensure-list (car commandspec)))))))
(defun doom-cli--parse-docs (docs) (defun doom-cli--parse-docs (docs)
(when (and (stringp docs) (when (and (stringp docs)
@ -1639,7 +1639,7 @@ yet. They won't be included in command listings (by help documentation)."
(push `(cl-callf plist-put doom-cli--plist (push `(cl-callf plist-put doom-cli--plist
,key ,(if (eq key :prefix) ,key ,(if (eq key :prefix)
`(append (plist-get doom-cli--plist ,key) `(append (plist-get doom-cli--plist ,key)
(doom-enlist ,val)) (ensure-list ,val))
val)) val))
forms))) forms)))
(nreverse forms)) (nreverse forms))

View file

@ -290,9 +290,9 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
(:desc (:desc
(setq desc (pop rest))) (setq desc (pop rest)))
(:map (:map
(doom--map-set :keymaps `(quote ,(doom-enlist (pop rest))))) (doom--map-set :keymaps `(quote ,(ensure-list (pop rest)))))
(:mode (:mode
(push (cl-loop for m in (doom-enlist (pop rest)) (push (cl-loop for m in (ensure-list (pop rest))
collect (intern (concat (symbol-name m) "-map"))) collect (intern (concat (symbol-name m) "-map")))
rest) rest)
(push :map rest)) (push :map rest))

View file

@ -12,7 +12,7 @@
If a mode is quoted, it is left as is. If the entire HOOKS list is quoted, the If a mode is quoted, it is left as is. If the entire HOOKS list is quoted, the
list is returned as-is." list is returned as-is."
(declare (pure t) (side-effect-free t)) (declare (pure t) (side-effect-free t))
(let ((hook-list (doom-enlist (doom-unquote hooks)))) (let ((hook-list (ensure-list (doom-unquote hooks))))
(if (eq (car-safe hooks) 'quote) (if (eq (car-safe hooks) 'quote)
hook-list hook-list
(cl-loop for hook in hook-list (cl-loop for hook in hook-list
@ -53,11 +53,6 @@ list is returned as-is."
(setq exp (cadr exp))) (setq exp (cadr exp)))
exp) exp)
(defun doom-enlist (exp)
"Return EXP wrapped in a list, or as-is if already a list."
(declare (pure t) (side-effect-free t))
(if (proper-list-p exp) exp (list exp)))
(defun doom-keyword-intern (str) (defun doom-keyword-intern (str)
"Converts STR (a string) into a keyword (`keywordp')." "Converts STR (a string) into a keyword (`keywordp')."
(declare (pure t) (side-effect-free t)) (declare (pure t) (side-effect-free t))
@ -760,7 +755,7 @@ DOCSTRING and BODY are as in `defun'.
(setq docstring nil)) (setq docstring nil))
(let (where-alist) (let (where-alist)
(while (keywordp (car body)) (while (keywordp (car body))
(push `(cons ,(pop body) (doom-enlist ,(pop body))) (push `(cons ,(pop body) (ensure-list ,(pop body)))
where-alist)) where-alist))
`(progn `(progn
(defun ,symbol ,arglist ,docstring ,@body) (defun ,symbol ,arglist ,docstring ,@body)
@ -780,7 +775,7 @@ testing advice (when combined with `rotate-text').
(unless (stringp docstring) (unless (stringp docstring)
(push docstring body)) (push docstring body))
(while (keywordp (car body)) (while (keywordp (car body))
(push `(cons ,(pop body) (doom-enlist ,(pop body))) (push `(cons ,(pop body) (ensure-list ,(pop body)))
where-alist)) where-alist))
`(dolist (targets (list ,@(nreverse where-alist))) `(dolist (targets (list ,@(nreverse where-alist)))
(dolist (target (cdr targets)) (dolist (target (cdr targets))

View file

@ -140,7 +140,7 @@ uses a straight or package.el command directly).")
(print! (start "Installing straight...")) (print! (start "Installing straight..."))
(print-group! (print-group!
(cl-destructuring-bind (depth . options) (cl-destructuring-bind (depth . options)
(doom-enlist straight-vc-git-default-clone-depth) (ensure-list straight-vc-git-default-clone-depth)
(let ((branch-switch (if (memq 'single-branch options) (let ((branch-switch (if (memq 'single-branch options)
"--single-branch" "--single-branch"
"--no-single-branch"))) "--no-single-branch")))
@ -341,7 +341,7 @@ non-nil."
(defun doom-package-is-type-p (package type) (defun doom-package-is-type-p (package type)
"TODO" "TODO"
(memq type (doom-enlist (doom-package-get package :type)))) (memq type (ensure-list (doom-package-get package :type))))
(defun doom-package-in-module-p (package category &optional module) (defun doom-package-in-module-p (package category &optional module)
"Return non-nil if PACKAGE was installed by the user's private config." "Return non-nil if PACKAGE was installed by the user's private config."
@ -585,7 +585,7 @@ should use it!"
(cl-loop for target in targets (cl-loop for target in targets
if (or (keywordp target) (listp target)) if (or (keywordp target) (listp target))
append append
(cl-loop with (category . modules) = (doom-enlist target) (cl-loop with (category . modules) = (ensure-list target)
for (name . plist) in doom-packages for (name . plist) in doom-packages
for pkg-modules = (plist-get plist :modules) for pkg-modules = (plist-get plist :modules)
if (and (assq category pkg-modules) if (and (assq category pkg-modules)

View file

@ -160,7 +160,7 @@ See `doom-real-buffer-p' for details on what that means."
"Return a list of buffers whose `major-mode' is `eq' to MODE(S). "Return a list of buffers whose `major-mode' is `eq' to MODE(S).
If DERIVED-P, test with `derived-mode-p', otherwise use `eq'." If DERIVED-P, test with `derived-mode-p', otherwise use `eq'."
(let ((modes (doom-enlist modes))) (let ((modes (ensure-list modes)))
(cl-remove-if-not (if derived-p (cl-remove-if-not (if derived-p
(lambda (buf) (lambda (buf)
(apply #'provided-mode-derived-p (apply #'provided-mode-derived-p

View file

@ -101,7 +101,7 @@ The search recurses up to DEPTH and no further. DEPTH is an integer.
MATCH is a string regexp. Only entries that match it will be included." MATCH is a string regexp. Only entries that match it will be included."
(let (result) (let (result)
(dolist (file (mapcan (doom-rpartial #'doom-glob "*") (doom-enlist paths))) (dolist (file (mapcan (doom-rpartial #'doom-glob "*") (ensure-list paths)))
(cond ((file-directory-p file) (cond ((file-directory-p file)
(appendq! (appendq!
result result

View file

@ -111,7 +111,7 @@ selection of all minor-modes, active or not."
"TODO" "TODO"
(require 'org) (require 'org)
(let* ((default-directory doom-docs-dir) (let* ((default-directory doom-docs-dir)
(org-agenda-files (mapcar #'expand-file-name (doom-enlist files))) (org-agenda-files (mapcar #'expand-file-name (ensure-list files)))
(depth (if (integerp depth) depth)) (depth (if (integerp depth) depth))
(mindepth (if (integerp mindepth) mindepth)) (mindepth (if (integerp mindepth) mindepth))
(org-inhibit-startup t)) (org-inhibit-startup t))

View file

@ -316,7 +316,7 @@ editorconfig or dtrt-indent installed."
(editorconfig-set-indentation nil width))) (editorconfig-set-indentation nil width)))
((require 'dtrt-indent nil t) ((require 'dtrt-indent nil t)
(when-let (vars (nth 2 (assq major-mode dtrt-indent-hook-mapping-list))) (when-let (vars (nth 2 (assq major-mode dtrt-indent-hook-mapping-list)))
(dolist (var (doom-enlist vars)) (dolist (var (ensure-list vars))
(doom-log "Updated %s = %d" var width) (doom-log "Updated %s = %d" var width)
(set var width))))) (set var width)))))
(message "Changed indentation to %d" width)) (message "Changed indentation to %d" width))

View file

@ -28,7 +28,7 @@ all themes. It will apply to all themes once they are loaded."
`(progn `(progn
(defun ,fn () (defun ,fn ()
(let (custom--inhibit-theme-enable) (let (custom--inhibit-theme-enable)
(dolist (theme (doom-enlist (or ,theme 'user))) (dolist (theme (ensure-list (or ,theme 'user)))
(when (or (eq theme 'user) (when (or (eq theme 'user)
(custom-theme-enabled-p theme)) (custom-theme-enabled-p theme))
(apply #'custom-theme-set-faces theme (apply #'custom-theme-set-faces theme

View file

@ -174,7 +174,7 @@ the word at point should be spell checked. For example:
"Return t if point is on a word that should be spell checked. "Return t if point is on a word that should be spell checked.
Return nil if on a link url, markup, html, or references." Return nil if on a link url, markup, html, or references."
(let ((faces (doom-enlist (get-text-property (point) 'face)))) (let ((faces (ensure-list (get-text-property (point) 'face))))
(or (and (memq 'font-lock-comment-face faces) (or (and (memq 'font-lock-comment-face faces)
(memq 'markdown-code-face faces)) (memq 'markdown-code-face faces))
(not (cl-loop with unsafe-faces = '(markdown-reference-face (not (cl-loop with unsafe-faces = '(markdown-reference-face

View file

@ -11,7 +11,7 @@
(defun set-flyspell-predicate! (modes predicate) (defun set-flyspell-predicate! (modes predicate)
"TODO" "TODO"
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes) +spell--flyspell-predicate-alist) (dolist (mode (ensure-list modes) +spell--flyspell-predicate-alist)
(add-to-list '+spell--flyspell-predicate-alist (cons mode predicate)))) (add-to-list '+spell--flyspell-predicate-alist (cons mode predicate))))
;;;###autoload ;;;###autoload

View file

@ -30,7 +30,7 @@ Examples:
(set-company-backend! 'sh-mode nil) ; unsets backends for sh-mode" (set-company-backend! 'sh-mode nil) ; unsets backends for sh-mode"
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(if (null (car backends)) (if (null (car backends))
(setq +company-backend-alist (setq +company-backend-alist
(delq (assq mode +company-backend-alist) (delq (assq mode +company-backend-alist)

View file

@ -6,7 +6,7 @@
(declare (indent defun)) (declare (indent defun))
(after! evil (after! evil
(if (listp modes) (if (listp modes)
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(evil-set-initial-state mode state)) (evil-set-initial-state mode state))
(evil-set-initial-state modes state)))) (evil-set-initial-state modes state))))

View file

@ -76,9 +76,9 @@
(when (and unset (not (gethash name format-all--format-table))) (when (and unset (not (gethash name format-all--format-table)))
(error "'%s' formatter does not exist to be unset" name)) (error "'%s' formatter does not exist to be unset" name))
(puthash name function format-all--format-table) (puthash name function format-all--format-table)
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(cl-destructuring-bind (m &optional probe) (cl-destructuring-bind (m &optional probe)
(doom-enlist mode) (ensure-list mode)
(if unset (if unset
(puthash m (assq-delete-all name (gethash key format-all-mode-table)) (puthash m (assq-delete-all name (gethash key format-all-mode-table))
format-all-mode-table) format-all-mode-table)

View file

@ -11,7 +11,7 @@
"Declare :symbols, :words or :patterns (all lists of strings) that "Declare :symbols, :words or :patterns (all lists of strings) that
`rotate-text' will cycle through." `rotate-text' will cycle through."
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(let ((fn-name (intern (format "+rotate-text-init-%s-h" mode)))) (let ((fn-name (intern (format "+rotate-text-init-%s-h" mode))))
(fset fn-name (fset fn-name
(lambda () (lambda ()

View file

@ -4,7 +4,7 @@
(defun set-yas-minor-mode! (modes) (defun set-yas-minor-mode! (modes)
"Register minor MODES (one mode symbol or a list of them) with yasnippet so it "Register minor MODES (one mode symbol or a list of them) with yasnippet so it
can have its own snippets category, if the folder exists." can have its own snippets category, if the folder exists."
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(let ((fn (intern (format "+snippets-register-%s-h" mode)))) (let ((fn (intern (format "+snippets-register-%s-h" mode))))
(fset fn (lambda () (yas-activate-extra-mode mode))) (fset fn (lambda () (yas-activate-extra-mode mode)))
(add-hook (intern (format "%s-hook" mode)) fn)))) (add-hook (intern (format "%s-hook" mode)) fn))))

View file

@ -9,7 +9,7 @@ Enables `electric-indent-local-mode' in MODES.
\(fn MODES &key WORDS CHARS)" \(fn MODES &key WORDS CHARS)"
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(let ((hook (intern (format "%s-hook" mode))) (let ((hook (intern (format "%s-hook" mode)))
(fn (intern (format "+electric--init-%s-h" mode)))) (fn (intern (format "+electric--init-%s-h" mode))))
(cond ((null (car-safe plist)) (cond ((null (car-safe plist))

View file

@ -26,7 +26,7 @@ exist, and `org-link' otherwise."
(apply #'org-link-set-parameters (apply #'org-link-set-parameters
key key
:complete (lambda () :complete (lambda ()
(if requires (mapc #'require (doom-enlist requires))) (if requires (mapc #'require (ensure-list requires)))
(+org--relative-path (+org--read-link-path key (funcall dir-fn)) (+org--relative-path (+org--read-link-path key (funcall dir-fn))
(funcall dir-fn))) (funcall dir-fn)))
:follow (lambda (link) :follow (lambda (link)

View file

@ -7,7 +7,7 @@
:defer t :defer t
:config :config
(setq org-cite-global-bibliography (setq org-cite-global-bibliography
(doom-enlist (ensure-list
(or (bound-and-true-p citar-bibliography) (or (bound-and-true-p citar-bibliography)
(bound-and-true-p bibtex-completion-bibliography))) (bound-and-true-p bibtex-completion-bibliography)))
;; Setup export processor; default csl/citeproc-el, with biblatex for ;; Setup export processor; default csl/citeproc-el, with biblatex for

View file

@ -119,9 +119,9 @@
(pcase-dolist (`((,category . ,modules) :after ,after :require ,libs) (pcase-dolist (`((,category . ,modules) :after ,after :require ,libs)
+debugger--dap-alist) +debugger--dap-alist)
(when (doom-module-p category (car modules) (cadr modules)) (when (doom-module-p category (car modules) (cadr modules))
(dolist (lib (doom-enlist after)) (dolist (lib (ensure-list after))
(with-eval-after-load lib (with-eval-after-load lib
(mapc #'require (doom-enlist libs)))))) (mapc #'require (ensure-list libs))))))
(dap-mode 1) (dap-mode 1)

View file

@ -31,7 +31,7 @@ recognized:
Defaults to `+eval/region', which will run the :send-region specified function Defaults to `+eval/region', which will run the :send-region specified function
or `+eval/send-region-to-repl'." or `+eval/send-region-to-repl'."
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(setf (alist-get mode +eval-repls) (setf (alist-get mode +eval-repls)
(cons command plist)))) (cons command plist))))
@ -59,7 +59,7 @@ MODES can be list of major mode symbols, or a single one.
4. If MODE is not a string and COMMANd is a symbol, add it to 4. If MODE is not a string and COMMANd is a symbol, add it to
`+eval-runners', which is used by `+eval/region'." `+eval-runners', which is used by `+eval/region'."
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(cond ((symbolp command) (cond ((symbolp command)
(push (cons mode command) +eval-runners)) (push (cons mode command) +eval-runners))
((stringp command) ((stringp command)

View file

@ -27,7 +27,7 @@ Example:
Used by `+lookup/in-docsets' and `+lookup/documentation'." Used by `+lookup/in-docsets' and `+lookup/documentation'."
(declare (indent defun)) (declare (indent defun))
(let ((action (if (keywordp (car docsets)) (pop docsets)))) (let ((action (if (keywordp (car docsets)) (pop docsets))))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(let ((hook (intern (format "%s-hook" mode))) (let ((hook (intern (format "%s-hook" mode)))
(fn (intern (format "+lookup-init--%s-%s" (or action "set") mode)))) (fn (intern (format "+lookup-init--%s-%s" (or action "set") mode))))
(if (null docsets) (if (null docsets)

View file

@ -66,7 +66,7 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
\(fn MODES &key DEFINITION IMPLEMENTATIONS TYPE-DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)" \(fn MODES &key DEFINITION IMPLEMENTATIONS TYPE-DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)"
(declare (indent defun)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(let ((hook (intern (format "%s-hook" mode))) (let ((hook (intern (format "%s-hook" mode)))
(fn (intern (format "+lookup--init-%s-handlers-h" mode)))) (fn (intern (format "+lookup--init-%s-handlers-h" mode))))
(if (null (car plist)) (if (null (car plist))
@ -106,7 +106,7 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
(defun +lookup--set-handler (spec functions-var &optional async enable) (defun +lookup--set-handler (spec functions-var &optional async enable)
(when spec (when spec
(cl-destructuring-bind (fn . plist) (cl-destructuring-bind (fn . plist)
(doom-enlist spec) (ensure-list spec)
(if (not enable) (if (not enable)
(remove-hook functions-var fn 'local) (remove-hook functions-var fn 'local)
(put fn '+lookup-async (or (plist-get plist :async) async)) (put fn '+lookup-async (or (plist-get plist :async) async))

View file

@ -21,7 +21,7 @@
single one. If a list, the first field found will be returned. Will error out single one. If a list, the first field found will be returned. Will error out
otherwise, unless NOERROR is non-nill." otherwise, unless NOERROR is non-nill."
(if-let* ((data (if (listp entry) entry (+pass-get-entry entry)))) (if-let* ((data (if (listp entry) entry (+pass-get-entry entry))))
(cl-loop for key in (doom-enlist fields) (cl-loop for key in (ensure-list fields)
when (assoc key data) when (assoc key data)
return (cdr it)) return (cdr it))
(unless noerror (unless noerror

View file

@ -42,7 +42,7 @@
'(((lambda (limit) '(((lambda (limit)
(let (case-fold-search) (let (case-fold-search)
(and (re-search-forward hl-todo-regexp limit t) (and (re-search-forward hl-todo-regexp limit t)
(memq 'font-lock-comment-face (doom-enlist (get-text-property (point) 'face)))))) (memq 'font-lock-comment-face (ensure-list (get-text-property (point) 'face))))))
(1 (hl-todo-get-face) t t)))) (1 (hl-todo-get-face) t t))))
(when hl-todo-mode (when hl-todo-mode
(hl-todo-mode -1) (hl-todo-mode -1)

View file

@ -33,7 +33,7 @@ Pretty symbols can be unset for emacs-lisp-mode with:
(set-ligatures! 'emacs-lisp-mode nil)" (set-ligatures! 'emacs-lisp-mode nil)"
(declare (indent defun)) (declare (indent defun))
(if (null (car-safe plist)) (if (null (car-safe plist))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(delq! mode +ligatures-extra-alist 'assq)) (delq! mode +ligatures-extra-alist 'assq))
(let (results) (let (results)
(while plist (while plist
@ -42,7 +42,7 @@ Pretty symbols can be unset for emacs-lisp-mode with:
(prependq! results (pop plist)) (prependq! results (pop plist))
(when-let (char (plist-get +ligatures-extra-symbols key)) (when-let (char (plist-get +ligatures-extra-symbols key))
(push (cons (pop plist) char) results))))) (push (cons (pop plist) char) results)))))
(dolist (mode (doom-enlist modes)) (dolist (mode (ensure-list modes))
(setf (alist-get mode +ligatures-extra-alist) (setf (alist-get mode +ligatures-extra-alist)
(if-let (old-results (alist-get mode +ligatures-extra-alist)) (if-let (old-results (alist-get mode +ligatures-extra-alist))
(dolist (cell results old-results) (dolist (cell results old-results)

View file

@ -143,7 +143,7 @@ If DEFAULT is non-nil, apply to all future buffers. Modelines are defined with
"Set the modeline to NAME on HOOKS. "Set the modeline to NAME on HOOKS.
See `def-modeline!' on how modelines are defined." See `def-modeline!' on how modelines are defined."
(let ((fn (intern (format "+modeline-set-%s-format-h" name)))) (let ((fn (intern (format "+modeline-set-%s-format-h" name))))
(dolist (hook (doom-enlist hooks)) (dolist (hook (ensure-list hooks))
(when after-init-time (when after-init-time
(dolist (name (mapcar #'car +modeline-format-alist)) (dolist (name (mapcar #'car +modeline-format-alist))
(remove-hook hook (intern (format "+modeline-set-%s-format-h" name))))) (remove-hook hook (intern (format "+modeline-set-%s-format-h" name)))))