 ;;
 ;;; `doom/help-packages'
 
-(defun doom--describe-package-insert-button (label path &optional regexp)
+(defun doom--help-package-insert-button (label path &optional regexp)
   (declare (indent defun))
   (insert-text-button
    (string-trim label)


If prefix arg is present, refresh the cache."
  (interactive
   (list (doom--completing-package nil current-prefix-arg)))
  (if (or (package-desc-p package)
          (and (symbolp package)
               (or (assq package package-alist)
                   (assq package package-archive-contents)
                   (assq package package--builtins))))
      (describe-package package)
    (doom--describe-package package))
  (save-excursion
    (with-current-buffer (help-buffer)
      (let ((inhibit-read-only t))
        (goto-char (point-min))
        (when (and (doom-package-installed-p package)
                   (re-search-forward "^ *Status: " nil t))
          (end-of-line)
          (let ((indent (make-string (length (match-string 0)) ? )))
            (insert "\n" indent "Installed by the following Doom modules:\n")
            (dolist (m (doom-package-prop package :modules))
              (insert indent)
              (doom--describe-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 "Source")
            (pcase (doom-package-backend package)
              (`elpa (insert "[M]ELPA"))
              (`quelpa (insert (format "QUELPA %s" (prin1-to-string (doom-package-prop package :recipe)))))
              (`emacs (insert "Built-in")))
            (insert "\n")

            (package--print-help-section "Configs")
            (insert-text-button
             "See where this package is configured"
             'face 'link
             'follow-link t
             'action
             `(lambda (_) (doom/help-package-config ',package)))))))))

;;;###autoload
(defun doom/help-package-config (package)
  "Jump to any `def-package!', `after!' or ;;;###package block for PACKAGE."
  (interactive
   (list (doom--completing-package "Select package to search for: " current-prefix-arg)))
  (let* ((default-directory doom-emacs-dir)
         (results (shell-command-to-string
                   (format "git grep --no-break --no-heading --line-number '%s %s\\($\\| \\)'"
                           "\\(^;;;###package\\|(after!\\|(def-package!\\)"
                           package)))
         (select (completing-read "Jump to config: " (split-string results "\n" t))))
    (cl-destructuring-bind (file line _match)
        (split-string select ":")
      (find-file (expand-file-name file doom-emacs-dir))
      (goto-line (string-to-number line))
      (recenter))))

                (recenter)
              (message "Couldn't find the config block"))))))))

(defun doom--help-packages-list (&optional refresh)
  (or (unless refresh
        (doom-cache-get 'help-packages))
      (doom-cache-set 'help-packages (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))
    (split-string
     (shell-command-to-string
      (format "git grep --no-break --no-heading --line-number '%s %s\\($\\| \\)'"
              "\\(^;;;###package\\|(after!\\|(def-package!\\)"
              package))
     "\n" t)))

;;;###autoload
(defun doom/help-packages (package)
