Improve doom/help-packages
+ Cache package list + Show "generating package list" message the first time (better ux) + Display location of package files in package information + Turn links/file paths into buttons + Add link to module readmes (if any) Mentioned in #4406
This commit is contained in:
parent
55e90f064f
commit
a3b8be52a8
1 changed files with 94 additions and 47 deletions
|
@ -381,25 +381,33 @@ current file is in, or d) the module associated with the current major mode (see
|
||||||
;;
|
;;
|
||||||
;;; `doom/help-packages'
|
;;; `doom/help-packages'
|
||||||
|
|
||||||
(defun doom--help-package-insert-button (label path &optional regexp)
|
(defun doom--help-insert-button (label &optional path)
|
||||||
(declare (indent defun))
|
(cl-destructuring-bind (uri . qs)
|
||||||
(insert-text-button
|
(let ((parts (split-string label "::" t)))
|
||||||
(string-trim label)
|
(cons (string-trim (car parts))
|
||||||
'face 'link
|
(string-join (cdr parts) "::")))
|
||||||
'follow-link t
|
(let ((path (or path label)))
|
||||||
'action
|
(insert-text-button
|
||||||
`(lambda (_)
|
uri
|
||||||
(unless (file-exists-p ,path)
|
'face 'link
|
||||||
(user-error "Module doesn't exist"))
|
'follow-link t
|
||||||
(when (window-dedicated-p)
|
'action
|
||||||
(other-window 1))
|
(lambda (_)
|
||||||
(let ((buffer (find-file ,path)))
|
(when (window-dedicated-p)
|
||||||
(when ,(stringp regexp)
|
(other-window 1))
|
||||||
(with-current-buffer buffer
|
(pcase (cond ((string-match-p "^https?://" qs) 'url)
|
||||||
(goto-char (point-min))
|
('file))
|
||||||
(if (re-search-forward ,regexp nil t)
|
((or `file `nil)
|
||||||
(recenter)
|
(unless (file-exists-p path)
|
||||||
(message "Couldn't find the config block"))))))))
|
(user-error "Path does not exist: %S" path))
|
||||||
|
(let ((buffer (or (get-file-buffer path)
|
||||||
|
(find-file path))))
|
||||||
|
(when qs
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(goto-char (point-min))
|
||||||
|
(re-search-forward qs)
|
||||||
|
(recenter)))))
|
||||||
|
(`url (browse-url uri))))))))
|
||||||
|
|
||||||
(defun doom--help-package-configs (package)
|
(defun doom--help-package-configs (package)
|
||||||
(let ((default-directory doom-emacs-dir))
|
(let ((default-directory doom-emacs-dir))
|
||||||
|
@ -413,6 +421,7 @@ current file is in, or d) the module associated with the current major mode (see
|
||||||
":(exclude)*.org"))
|
":(exclude)*.org"))
|
||||||
"\n" t)))
|
"\n" t)))
|
||||||
|
|
||||||
|
(defvar doom--help-packages-list nil)
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/help-packages (package)
|
(defun doom/help-packages (package)
|
||||||
"Like `describe-package', but for packages installed by Doom modules.
|
"Like `describe-package', but for packages installed by Doom modules.
|
||||||
|
@ -427,12 +436,18 @@ If prefix arg is present, refresh the cache."
|
||||||
(require 'finder-inf nil t)
|
(require 'finder-inf nil t)
|
||||||
(require 'package)
|
(require 'package)
|
||||||
(require 'straight)
|
(require 'straight)
|
||||||
(let ((packages (delete-dups
|
(let ((packages
|
||||||
(append (mapcar #'car package-alist)
|
(if (and doom--help-packages-list (null current-prefix-arg))
|
||||||
(mapcar #'car package--builtins)
|
doom--help-packages-list
|
||||||
(mapcar #'intern (hash-table-keys straight--build-cache))
|
(message "Generating packages list for the first time...")
|
||||||
(mapcar #'car (doom-package-list 'all))
|
(sit-for 0.1)
|
||||||
nil))))
|
(setq doom--help-packages-list
|
||||||
|
(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)
|
(unless (memq guess packages)
|
||||||
(setq guess nil))
|
(setq guess nil))
|
||||||
(list
|
(list
|
||||||
|
@ -440,9 +455,10 @@ If prefix arg is present, refresh the cache."
|
||||||
(completing-read (if guess
|
(completing-read (if guess
|
||||||
(format "Select Doom package to search for (default %s): "
|
(format "Select Doom package to search for (default %s): "
|
||||||
guess)
|
guess)
|
||||||
"Describe Doom package: ")
|
(format "Describe Doom package (%d): " (length packages)))
|
||||||
packages nil t nil nil
|
packages nil t nil nil
|
||||||
(if guess (symbol-name guess))))))))
|
(if guess (symbol-name guess))))))))
|
||||||
|
;; TODO Refactor me.
|
||||||
(require 'core-packages)
|
(require 'core-packages)
|
||||||
(doom-initialize-packages)
|
(doom-initialize-packages)
|
||||||
(if (or (package-desc-p package)
|
(if (or (package-desc-p package)
|
||||||
|
@ -477,20 +493,39 @@ If prefix arg is present, refresh the cache."
|
||||||
"unpinned")
|
"unpinned")
|
||||||
"\n")
|
"\n")
|
||||||
(package--print-help-section "Build")
|
(package--print-help-section "Build")
|
||||||
(insert (let ((default-directory (straight--repos-dir (symbol-name package))))
|
(let ((default-directory (straight--repos-dir (symbol-name package))))
|
||||||
(cdr
|
(insert (cdr (doom-call-process "git" "log" "-1" "--format=%D %h %ci"))
|
||||||
(doom-call-process "git" "log" "-1" "--format=%D %h %ci")))
|
"\n" indent))
|
||||||
"\n")
|
(package--print-help-section "Build location")
|
||||||
|
(let ((build-dir (straight--build-dir (symbol-name package))))
|
||||||
|
(if (file-exists-p build-dir)
|
||||||
|
(doom--help-insert-button (abbreviate-file-name build-dir))
|
||||||
|
(insert "n/a")))
|
||||||
|
(insert "\n" indent)
|
||||||
|
(package--print-help-section "Repo location")
|
||||||
|
(let ((repo-dir (straight--repos-dir (symbol-name package))))
|
||||||
|
(if (file-exists-p repo-dir)
|
||||||
|
(doom--help-insert-button (abbreviate-file-name repo-dir))
|
||||||
|
(insert "n/a"))
|
||||||
|
(insert "\n"))
|
||||||
(let ((recipe (doom-package-build-recipe package)))
|
(let ((recipe (doom-package-build-recipe package)))
|
||||||
(insert (format! "%s\n"
|
(package--print-help-section "Recipe")
|
||||||
(indent 13
|
(insert (format "%s\n" (string-trim (pp-to-string recipe))))
|
||||||
(string-trim (pp-to-string recipe)))))
|
|
||||||
|
|
||||||
(package--print-help-section "Homepage")
|
(package--print-help-section "Homepage")
|
||||||
(insert (doom--package-url package))))
|
(doom--help-insert-button (doom--package-url package)))
|
||||||
(`elpa (insert "[M]ELPA " (doom--package-url package)))
|
(insert "\n" indent))
|
||||||
(`builtin (insert "Built-in"))
|
(`elpa (insert "[M]ELPA ")
|
||||||
(`other (insert
|
(doom--help-insert-button (doom--package-url package))
|
||||||
|
(package--print-help-section "Location")
|
||||||
|
(doom--help-insert-button
|
||||||
|
(abbreviate-file-name
|
||||||
|
(file-name-directory (locate-library (symbol-name package))))))
|
||||||
|
(`builtin (insert "Built-in\n")
|
||||||
|
(package--print-help-section "Location")
|
||||||
|
(doom--help-insert-button
|
||||||
|
(abbreviate-file-name
|
||||||
|
(file-name-directory (locate-library (symbol-name package))))))
|
||||||
|
(`other (doom--help-insert-button
|
||||||
(abbreviate-file-name
|
(abbreviate-file-name
|
||||||
(or (symbol-file package)
|
(or (symbol-file package)
|
||||||
(locate-library (symbol-name package))))))
|
(locate-library (symbol-name package))))))
|
||||||
|
@ -506,14 +541,24 @@ If prefix arg is present, refresh the 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 modules)
|
(dolist (m modules)
|
||||||
(insert indent)
|
(let* ((module-path (pcase (car m)
|
||||||
(doom--help-package-insert-button
|
(:core doom-core-dir)
|
||||||
(format "%s %s" (car m) (or (cdr m) ""))
|
(:private doom-private-dir)
|
||||||
(pcase (car m)
|
(category (doom-module-path category (cdr m)))))
|
||||||
(:core doom-core-dir)
|
(readme-path (expand-file-name "README.org" module-path)))
|
||||||
(:private doom-private-dir)
|
(insert indent)
|
||||||
(category (doom-module-path category (cdr m)))))
|
(doom--help-insert-button
|
||||||
(insert "\n")))
|
(format "%s %s" (car m) (or (cdr m) ""))
|
||||||
|
module-path)
|
||||||
|
(insert " (")
|
||||||
|
(if (file-exists-p readme-path)
|
||||||
|
(doom--help-insert-button
|
||||||
|
"readme"
|
||||||
|
(expand-file-name
|
||||||
|
"README.org"
|
||||||
|
readme-path))
|
||||||
|
(insert "no readme"))
|
||||||
|
(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:")
|
||||||
|
@ -582,7 +627,9 @@ If prefix arg is present, refresh the cache."
|
||||||
(format "%s.el" package))))
|
(format "%s.el" package))))
|
||||||
(_ (plist-get plist :url))))))
|
(_ (plist-get plist :url))))))
|
||||||
((and (require 'package nil t)
|
((and (require 'package nil t)
|
||||||
(or package-archive-contents (doom-refresh-packages-maybe))
|
(or package-archive-contents
|
||||||
|
(progn (package-refresh-contents)
|
||||||
|
package-archive-contents))
|
||||||
(pcase (package-desc-archive (cadr (assq package package-archive-contents)))
|
(pcase (package-desc-archive (cadr (assq package package-archive-contents)))
|
||||||
("org" "https://orgmode.org")
|
("org" "https://orgmode.org")
|
||||||
((or "melpa" "melpa-mirror")
|
((or "melpa" "melpa-mirror")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue