Fix doom/help-packages

This commit is contained in:
Henrik Lissner 2019-09-03 16:53:41 -04:00
parent 92c839be02
commit 44ef61a7f7
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -366,15 +366,6 @@ current file is in, or d) the module associated with the current major mode (see
(recenter) (recenter)
(message "Couldn't find the config block")))))))) (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) (defun doom--help-package-configs (package)
;; TODO Add git checks, in case ~/.emacs.d isn't a git repo ;; TODO Add git checks, in case ~/.emacs.d isn't a git repo
(let ((default-directory doom-emacs-dir)) (let ((default-directory doom-emacs-dir))
@ -394,16 +385,16 @@ defined and configured.
If prefix arg is present, refresh the cache." If prefix arg is present, refresh the cache."
(interactive (interactive
(let* ((guess (or (function-called-at-point) (let ((guess (or (function-called-at-point)
(symbol-at-point)))) (symbol-at-point))))
(require 'finder-inf nil t) (require 'finder-inf nil t)
(require 'package) (require 'core-packages)
(unless package--initialized (doom-initialize-packages)
(package-initialize t)) (let ((packages (delete-dups
(let ((packages (cl-delete-duplicates (append (mapcar #'car package-alist)
(append (mapcar 'car package-alist) (mapcar #'car package--builtins)
(mapcar 'car package--builtins) (mapcar #'intern (hash-table-keys straight--build-cache))
(mapcar 'car (doom--help-packages-list)) (mapcar #'car (doom-package-list 'all))
nil)))) nil))))
(unless (memq guess packages) (unless (memq guess packages)
(setq guess nil)) (setq guess nil))
@ -415,75 +406,80 @@ If prefix arg is present, refresh the cache."
"Describe package: ") "Describe package: ")
packages nil t nil nil packages nil t nil nil
(if guess (symbol-name guess)))))))) (if guess (symbol-name guess))))))))
(if (or (package-desc-p package) (require 'core-packages)
(and (symbolp package) (doom-initialize-packages)
(or (assq package package-alist) (let ((straight-packages (mapcar #'intern (hash-table-keys straight--build-cache))))
(assq package package--builtins)))) (if (or (package-desc-p package)
(describe-package package) (and (symbolp package)
(help-setup-xref (list #'doom/help-packages package) (or (assq package package-alist)
(called-interactively-p 'interactive)) (assq package package--builtins))))
(with-help-window (help-buffer))) (describe-package package)
(save-excursion (help-setup-xref (list #'doom/help-packages package)
(with-current-buffer (help-buffer) (called-interactively-p 'interactive))
(let ((doom-packages (doom--help-packages-list)) (with-help-window (help-buffer)))
(inhibit-read-only t) (save-excursion
(indent (make-string 13 ? ))) (with-current-buffer (help-buffer)
(goto-char (point-max)) (let ((inhibit-read-only t)
(if (re-search-forward "^ *Status: " nil t) (indent (make-string 13 ? )))
(progn (goto-char (point-max))
(end-of-line) (if (re-search-forward "^ *Status: " nil t)
(insert "\n")) (progn
(re-search-forward "\n\n" nil t)) (end-of-line)
(insert "\n"))
(re-search-forward "\n\n" nil t))
(package--print-help-section "Package") (package--print-help-section "Package")
(insert (symbol-name package) "\n") (insert (symbol-name package) "\n")
(package--print-help-section "Source") (package--print-help-section "Source")
(insert (or (pcase (doom-package-backend package) (insert (or (pcase (doom-package-backend package)
(`straight (`straight
(format! "Straight\n%s" (format! "Straight (%s)\n%s"
(indent (let ((default-directory (straight--build-dir (symbol-name package))))
13 (string-trim (string-trim
(pp-to-string (shell-command-to-string "git log -1 --format=\"%D %h %ci\"")))
(doom-package-build-recipe package)))))) (indent
(`elpa 13 (string-trim
(format "[M]ELPA %s" (doom--package-url package))) (pp-to-string
(`builtin "Built-in") (doom-package-build-recipe package))))))
(_ (abbreviate-file-name (symbol-file package)))) (`elpa
"unknown") (format "[M]ELPA %s" (doom--package-url package)))
"\n") (`builtin "Built-in")
(_ (abbreviate-file-name (symbol-file package))))
"unknown")
"\n")
(when (assq package doom-packages) (when (gethash (symbol-name package) straight--build-cache)
(package--print-help-section "Modules") (package--print-help-section "Modules")
(insert "Declared by the following Doom modules:\n") (insert "Declared by the following Doom modules:\n")
(dolist (m (doom-package-get package :modules)) (dolist (m (doom-package-get package :modules))
(insert indent) (insert indent)
(doom--help-package-insert-button (doom--help-package-insert-button
(format "%s %s" (car m) (or (cdr m) "")) (format "%s %s" (car m) (or (cdr m) ""))
(pcase (car m) (pcase (car m)
(:core doom-core-dir) (:core doom-core-dir)
(:private doom-private-dir) (:private doom-private-dir)
(category (doom-module-path category (cdr m))))) (category (doom-module-path category (cdr m)))))
(insert "\n"))) (insert "\n")))
(package--print-help-section "Configs") (package--print-help-section "Configs")
(insert "This package is configured in the following locations:") (insert "This package is configured in the following locations:")
(dolist (location (doom--help-package-configs package)) (dolist (location (doom--help-package-configs package))
(insert "\n" indent) (insert "\n" indent)
(insert-text-button (insert-text-button
location location
'face 'link 'face 'link
'follow-link t 'follow-link t
'action 'action
`(lambda (_) `(lambda (_)
(cl-destructuring-bind (file line _match) (cl-destructuring-bind (file line _match)
,(split-string location ":") ,(split-string location ":")
(find-file (expand-file-name file doom-emacs-dir)) (find-file (expand-file-name file doom-emacs-dir))
(goto-char (point-min)) (goto-char (point-min))
(forward-line (1- line)) (forward-line (1- line))
(recenter))))) (recenter)))))
(insert "\n\n"))))) (insert "\n\n"))))))
(defvar doom--package-cache nil) (defvar doom--package-cache nil)
(defun doom--package-list () (defun doom--package-list ()