fix: doom-package-list: failures to resolve module context

doom-module-from-path fails to deduce the module from some paths (it
seems to struggle with doom-user-dir in some cases), causing a (aref nil
2) error (see #6845).

Fix: #6845
This commit is contained in:
Henrik Lissner 2022-09-26 02:05:09 +02:00
parent 07c1534ea3
commit b8038e93cf
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -410,36 +410,34 @@ installed."
;;; Package getters ;;; Package getters
(defun doom-packages--read (file &optional noeval noerror) (defun doom-packages--read (file &optional noeval noerror)
(doom-context-with 'packages (condition-case-unless-debug e
(doom-module-context-with (doom-module-from-path file) (with-temp-buffer ; prevent buffer-local state from propagating
(condition-case-unless-debug e (if (not noeval)
(with-temp-buffer ; prevent buffer-local state from propagating (load file noerror 'nomessage 'nosuffix)
(if (not noeval) (when (file-exists-p file)
(load file noerror 'nomessage 'nosuffix) (insert-file-contents file)
(when (file-exists-p file) (with-syntax-table emacs-lisp-mode-syntax-table
(insert-file-contents file) ;; Scrape `package!' blocks from FILE for a comprehensive listing of
(let (emacs-lisp-mode) (emacs-lisp-mode)) ;; packages used by this module.
;; Scrape `package!' blocks from FILE for a comprehensive listing of (while (search-forward "(package!" nil t)
;; packages used by this module. (let ((ppss (save-excursion (syntax-ppss))))
(while (search-forward "(package!" nil t) ;; Don't collect packages in comments or strings
(let ((ppss (save-excursion (syntax-ppss)))) (unless (or (nth 3 ppss)
;; Don't collect packages in comments or strings (nth 4 ppss))
(unless (or (nth 3 ppss) (goto-char (match-beginning 0))
(nth 4 ppss)) (cl-destructuring-bind (_ name . plist)
(goto-char (match-beginning 0)) (read (current-buffer))
(cl-destructuring-bind (_ name . plist) (push (cons
(read (current-buffer)) name (plist-put
(push (cons plist :modules
name (plist-put (list (doom-module-context-key))))
plist :modules doom-packages)))))))))
(list (doom-module-context-key)))) (user-error
doom-packages)))))))) (user-error (error-message-string e)))
(user-error (error
(user-error (error-message-string e))) (signal 'doom-package-error
(error (list (doom-module-context-key)
(signal 'doom-package-error file e)))))
(list (doom-module-context-key)
file e)))))))
(defun doom-package-list (&optional module-list) (defun doom-package-list (&optional module-list)
"Retrieve a list of explicitly declared packages from MODULE-LIST. "Retrieve a list of explicitly declared packages from MODULE-LIST.
@ -448,25 +446,27 @@ If MODULE-LIST is omitted, read enabled module list in configdepth order (see
`doom-module-set'). Otherwise, MODULE-LIST may be any symbol (or t) to mean read `doom-module-set'). Otherwise, MODULE-LIST may be any symbol (or t) to mean read
all modules in `doom-modules-dir', including :core and :user. MODULE-LIST may all modules in `doom-modules-dir', including :core and :user. MODULE-LIST may
also be a list of module keys." also be a list of module keys."
(let ((module-list (cond ((null module-list) (doom-module-list)) (let ((module-list (cond ((null module-list) (doom-module-list))
((symbolp module-list) (doom-module-list 'all)) ((symbolp module-list) (doom-module-list 'all))
(module-list))) (module-list)))
;; TODO: doom-module-context (packages-file doom-module-packages-file)
(packages-file doom-module-packages-file) doom-disabled-packages
doom-disabled-packages doom-packages)
doom-packages) (letf! (defun read-packages (key)
(when (assq :user module-list) (doom-module-context-with key
;; We load the private packages file twice to populate (when-let (file (doom-module-locate-path
;; `doom-disabled-packages' disabled packages are seen ASAP, and a (car key) (cdr key) doom-module-packages-file))
;; second time to ensure privately overridden packages are properly (doom-packages--read file nil 'noerror))))
;; overwritten. (doom-context-with 'packages
(let (doom-packages) (when (assq :user module-list)
(doom-packages--read (doom-module-expand-path :user nil packages-file) ;; We load the private packages file twice to populate
nil 'noerror))) ;; `doom-disabled-packages' disabled packages are seen ASAP, and a
(cl-loop for (cat . mod) in module-list ;; second time to ensure privately overridden packages are properly
if (doom-module-locate-path cat mod packages-file) ;; overwritten.
do (doom-packages--read it nil 'noerror)) (let (doom-packages)
(nreverse doom-packages))) (read-packages (cons :user nil))))
(mapc #'read-packages module-list)
(nreverse doom-packages)))))
(defun doom-package-pinned-list () (defun doom-package-pinned-list ()
"Return an alist mapping package names (strings) to pinned commits (strings)." "Return an alist mapping package names (strings) to pinned commits (strings)."