                 (recenter)
               (message "Couldn't find the config block"))))))))
 
-(defvar doom--help-packages-list nil)
-(defun doom--help-packages-list (&optional refresh)
-  (or (unless refresh
-        doom--help-packages-list)
-      (setq doom--help-packages-list
-            (append (cl-loop for package in doom-core-packages
-                             collect (list package :modules '((:core internal))))
-                    (doom-package-list 'all)))))
-
 (defun doom--help-package-configs (package)
   ;; TODO Add git checks, in case ~/.emacs.d isn't a git repo
   (let ((default-directory doom-emacs-dir))

                            "Describe package: ")
                          packages nil t nil nil
                          (if guess (symbol-name guess))))))))
  (if (or (package-desc-p package)
          (and (symbolp package)
               (or (assq package package-alist)
                   (assq package package--builtins))))
      (describe-package package)
    (help-setup-xref (list #'doom/help-packages package)
                     (called-interactively-p 'interactive))
    (with-help-window (help-buffer)))
  (save-excursion
    (with-current-buffer (help-buffer)
      (let ((doom-packages (doom--help-packages-list))
            (inhibit-read-only t)
            (indent (make-string 13 ? )))
        (goto-char (point-max))
        (if (re-search-forward "^ *Status: " nil t)
            (progn
              (end-of-line)
              (insert "\n"))
          (re-search-forward "\n\n" nil t))

        (package--print-help-section "Package")
        (insert (symbol-name package) "\n")

        (package--print-help-section "Source")
        (insert (or (pcase (doom-package-backend package)
                      (`straight
                       (format! "Straight\n%s"
                                (indent
                                 13 (string-trim
                                     (pp-to-string
                                      (doom-package-build-recipe package))))))
                      (`elpa
                       (format "[M]ELPA %s" (doom--package-url package)))
                      (`builtin "Built-in")
                      (_ (abbreviate-file-name (symbol-file package))))
                    "unknown")
                "\n")

        (when (assq package doom-packages)
          (package--print-help-section "Modules")
          (insert "Declared by the following Doom modules:\n")
          (dolist (m (doom-package-get package :modules))
            (insert indent)
            (doom--help-package-insert-button
              (format "%s %s" (car m) (or (cdr m) ""))
              (pcase (car m)
                (:core doom-core-dir)
                (:private doom-private-dir)
                (category (doom-module-path category (cdr m)))))
            (insert "\n")))

        (package--print-help-section "Configs")
        (insert "This package is configured in the following locations:")
        (dolist (location (doom--help-package-configs package))
          (insert "\n" indent)
          (insert-text-button
           location
           'face 'link
           'follow-link t
           'action
           `(lambda (_)
              (cl-destructuring-bind (file line _match)
                  ,(split-string location ":")
                (find-file (expand-file-name file doom-emacs-dir))
                (goto-char (point-min))
                (forward-line (1- line))
                (recenter)))))

        (insert "\n\n")))))

(defvar doom--package-cache nil)
(defun doom--package-list ()


If prefix arg is present, refresh the cache."
  (interactive
   (let ((guess (or (function-called-at-point)
                    (symbol-at-point))))
     (require 'finder-inf nil t)
     (require 'core-packages)
     (doom-initialize-packages)
     (let ((packages (delete-dups
                      (append (mapcar #'car package-alist)
                              (mapcar #'car package--builtins)
                              (mapcar #'intern (hash-table-keys straight--build-cache))
                              (mapcar #'car (doom-package-list 'all))
                              nil))))
       (unless (memq guess packages)
         (setq guess nil))
