Merge pull request #4600 from MageJohn/refactor/help-packages
Refactor doom/help-packages
This commit is contained in:
commit
ad16d85e99
1 changed files with 78 additions and 76 deletions
|
@ -404,33 +404,31 @@ variables, this only lists variables that exist to be customized (defined with
|
||||||
;;
|
;;
|
||||||
;;; `doom/help-packages'
|
;;; `doom/help-packages'
|
||||||
|
|
||||||
(defun doom--help-insert-button (label &optional path)
|
(defun doom--help-insert-button (label &optional uri line)
|
||||||
(cl-destructuring-bind (uri . qs)
|
"Helper function to insert a button at point.
|
||||||
(let ((parts (split-string label "::" t)))
|
|
||||||
(cons (string-trim (car parts))
|
The button will have the text LABEL. If URI is given, the button will open it,
|
||||||
(string-join (cdr parts) "::")))
|
otherwise the LABEL will be used. If the uri to open is a url it will be opened
|
||||||
(let ((path (or path label)))
|
in a browser. If LINE is given (and the uri to open is not a url), then the file
|
||||||
|
will open with point on that line."
|
||||||
|
(let ((uri (or uri label)))
|
||||||
(insert-text-button
|
(insert-text-button
|
||||||
uri
|
label
|
||||||
'face 'link
|
'face 'link
|
||||||
'follow-link t
|
'follow-link t
|
||||||
'action
|
'action
|
||||||
|
(if (string-match-p "^https?://" uri)
|
||||||
|
(lambda (_) (browse-url uri))
|
||||||
|
(unless (file-exists-p uri)
|
||||||
|
(error "Path does not exist: %S" uri))
|
||||||
(lambda (_)
|
(lambda (_)
|
||||||
(when (window-dedicated-p)
|
(when (window-dedicated-p)
|
||||||
(other-window 1))
|
(other-window 1))
|
||||||
(pcase (cond ((string-match-p "^https?://" qs) 'url)
|
(find-file uri)
|
||||||
('file))
|
(when line
|
||||||
((or `file `nil)
|
|
||||||
(unless (file-exists-p path)
|
|
||||||
(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))
|
(goto-char (point-min))
|
||||||
(re-search-forward qs)
|
(forward-line (1- line))
|
||||||
(recenter)))))
|
(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))
|
||||||
|
@ -463,44 +461,41 @@ If prefix arg is present, refresh the cache."
|
||||||
(if (and doom--help-packages-list (null current-prefix-arg))
|
(if (and doom--help-packages-list (null current-prefix-arg))
|
||||||
doom--help-packages-list
|
doom--help-packages-list
|
||||||
(message "Generating packages list for the first time...")
|
(message "Generating packages list for the first time...")
|
||||||
(sit-for 0.1)
|
(redisplay)
|
||||||
(setq doom--help-packages-list
|
(setq doom--help-packages-list
|
||||||
(delete-dups
|
(delete-dups
|
||||||
(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 #'intern
|
||||||
|
(hash-table-keys straight--build-cache))
|
||||||
(mapcar #'car (doom-package-list 'all))
|
(mapcar #'car (doom-package-list 'all))
|
||||||
nil))))))
|
nil))))))
|
||||||
(unless (memq guess packages)
|
(unless (memq guess packages)
|
||||||
(setq guess nil))
|
(setq guess nil))
|
||||||
(list
|
(list
|
||||||
(intern
|
(intern
|
||||||
(completing-read (if guess
|
(completing-read (format "Describe Doom package (%s): "
|
||||||
(format "Select Doom package to search for (default %s): "
|
(concat (when guess
|
||||||
guess)
|
(format "default '%s', " guess))
|
||||||
(format "Describe Doom package (%d): " (length packages)))
|
(format "total %d" (length packages))))
|
||||||
packages nil t nil nil
|
packages nil t nil nil
|
||||||
(if guess (symbol-name guess))))))))
|
(when guess (symbol-name guess))))))))
|
||||||
;; TODO Refactor me.
|
;; TODO Refactor me.
|
||||||
(require 'core-packages)
|
(require 'core-packages)
|
||||||
(doom-initialize-packages)
|
(doom-initialize-packages)
|
||||||
(if (or (package-desc-p package)
|
(help-setup-xref (list #'doom/help-packages package)
|
||||||
|
(called-interactively-p 'interactive))
|
||||||
|
(with-help-window (help-buffer)
|
||||||
|
(with-current-buffer standard-output
|
||||||
|
(when (or (package-desc-p package)
|
||||||
(and (symbolp package)
|
(and (symbolp package)
|
||||||
(or (assq package package-alist)
|
(or (assq package package-alist)
|
||||||
(assq package package--builtins))))
|
(assq package package--builtins))))
|
||||||
(describe-package package)
|
(describe-package-1 package))
|
||||||
(help-setup-xref (list #'doom/help-packages package)
|
(let ((indent (make-string 13 ? )))
|
||||||
(called-interactively-p 'interactive))
|
(goto-char (point-min))
|
||||||
(with-help-window (help-buffer)))
|
(if (re-search-forward " Status: .*$" nil t)
|
||||||
(save-excursion
|
(insert "\n")
|
||||||
(with-current-buffer (help-buffer)
|
|
||||||
(let ((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"))
|
|
||||||
(search-forward "\n\n" nil t))
|
(search-forward "\n\n" nil t))
|
||||||
|
|
||||||
(package--print-help-section "Package")
|
(package--print-help-section "Package")
|
||||||
|
@ -515,38 +510,50 @@ If prefix arg is present, refresh the cache."
|
||||||
pin
|
pin
|
||||||
"unpinned")
|
"unpinned")
|
||||||
"\n")
|
"\n")
|
||||||
|
|
||||||
(package--print-help-section "Build")
|
(package--print-help-section "Build")
|
||||||
(let ((default-directory (straight--repos-dir (symbol-name package))))
|
(let ((default-directory (straight--repos-dir (symbol-name package))))
|
||||||
(insert (cdr (doom-call-process "git" "log" "-1" "--format=%D %h %ci"))
|
(if (file-exists-p default-directory)
|
||||||
"\n" indent))
|
(insert (cdr (doom-call-process "git" "log" "-1" "--format=%D %h %ci")))
|
||||||
|
(insert "n/a")))
|
||||||
|
(insert "\n" indent)
|
||||||
|
|
||||||
(package--print-help-section "Build location")
|
(package--print-help-section "Build location")
|
||||||
(let ((build-dir (straight--build-dir (symbol-name package))))
|
(let ((build-dir (straight--build-dir (symbol-name package))))
|
||||||
(if (file-exists-p build-dir)
|
(if (file-exists-p build-dir)
|
||||||
(doom--help-insert-button (abbreviate-file-name build-dir))
|
(doom--help-insert-button (abbreviate-file-name build-dir))
|
||||||
(insert "n/a")))
|
(insert "n/a")))
|
||||||
(insert "\n" indent)
|
(insert "\n" indent)
|
||||||
|
|
||||||
(package--print-help-section "Repo location")
|
(package--print-help-section "Repo location")
|
||||||
(let ((repo-dir (straight--repos-dir (symbol-name package))))
|
(let ((repo-dir (straight--repos-dir (symbol-name package))))
|
||||||
(if (file-exists-p repo-dir)
|
(if (file-exists-p repo-dir)
|
||||||
(doom--help-insert-button (abbreviate-file-name repo-dir))
|
(doom--help-insert-button (abbreviate-file-name repo-dir))
|
||||||
(insert "n/a"))
|
(insert "n/a"))
|
||||||
(insert "\n"))
|
(insert "\n"))
|
||||||
|
|
||||||
(let ((recipe (doom-package-build-recipe package)))
|
(let ((recipe (doom-package-build-recipe package)))
|
||||||
(package--print-help-section "Recipe")
|
(package--print-help-section "Recipe")
|
||||||
(insert (format "%s\n" (string-trim (pp-to-string recipe))))
|
(insert
|
||||||
|
(replace-regexp-in-string "\n" (concat "\n" indent)
|
||||||
|
(pp-to-string recipe))))
|
||||||
|
|
||||||
(package--print-help-section "Homepage")
|
(package--print-help-section "Homepage")
|
||||||
(doom--help-insert-button (doom--package-url package))))
|
(doom--help-insert-button (doom--package-url package)))
|
||||||
|
|
||||||
(`elpa (insert "[M]ELPA ")
|
(`elpa (insert "[M]ELPA ")
|
||||||
(doom--help-insert-button (doom--package-url package))
|
(doom--help-insert-button (doom--package-url package))
|
||||||
(package--print-help-section "Location")
|
(package--print-help-section "Location")
|
||||||
(doom--help-insert-button
|
(doom--help-insert-button
|
||||||
(abbreviate-file-name
|
(abbreviate-file-name
|
||||||
(file-name-directory (locate-library (symbol-name package))))))
|
(file-name-directory
|
||||||
|
(locate-library (symbol-name package))))))
|
||||||
(`builtin (insert "Built-in\n")
|
(`builtin (insert "Built-in\n")
|
||||||
(package--print-help-section "Location")
|
(package--print-help-section "Location")
|
||||||
(doom--help-insert-button
|
(doom--help-insert-button
|
||||||
(abbreviate-file-name
|
(abbreviate-file-name
|
||||||
(file-name-directory (locate-library (symbol-name package))))))
|
(file-name-directory
|
||||||
|
(locate-library (symbol-name package))))))
|
||||||
(`other (doom--help-insert-button
|
(`other (doom--help-insert-button
|
||||||
(abbreviate-file-name
|
(abbreviate-file-name
|
||||||
(or (symbol-file package)
|
(or (symbol-file package)
|
||||||
|
@ -566,7 +573,9 @@ If prefix arg is present, refresh the cache."
|
||||||
(let* ((module-path (pcase (car m)
|
(let* ((module-path (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-locate-path category
|
||||||
|
(cdr m)))))
|
||||||
(readme-path (expand-file-name "README.org" module-path)))
|
(readme-path (expand-file-name "README.org" module-path)))
|
||||||
(insert indent)
|
(insert indent)
|
||||||
(doom--help-insert-button
|
(doom--help-insert-button
|
||||||
|
@ -574,30 +583,23 @@ If prefix arg is present, refresh the cache."
|
||||||
module-path)
|
module-path)
|
||||||
(insert " (")
|
(insert " (")
|
||||||
(if (file-exists-p readme-path)
|
(if (file-exists-p readme-path)
|
||||||
(doom--help-insert-button
|
(doom--help-insert-button "readme" readme-path)
|
||||||
"readme"
|
|
||||||
readme-path)
|
|
||||||
(insert "no readme"))
|
(insert "no readme"))
|
||||||
(insert ")\n"))))
|
(insert ")\n"))))
|
||||||
|
|
||||||
(package--print-help-section "Configs")
|
(package--print-help-section "Configs")
|
||||||
|
(if-let ((configs (doom--help-package-configs package)))
|
||||||
|
(progn
|
||||||
(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 configs)
|
||||||
(insert "\n" indent)
|
(insert "\n" indent)
|
||||||
(insert-text-button
|
|
||||||
location
|
|
||||||
'face 'link
|
|
||||||
'follow-link t
|
|
||||||
'action
|
|
||||||
`(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))
|
(doom--help-insert-button location
|
||||||
(goto-char (point-min))
|
(expand-file-name file doom-emacs-dir)
|
||||||
(forward-line (1- (string-to-number line)))
|
(string-to-number line)))))
|
||||||
(recenter)))))
|
(insert "This package is not configured anywhere"))
|
||||||
|
(goto-char (point-min))))))
|
||||||
(insert "\n\n")))))
|
|
||||||
|
|
||||||
(defvar doom--package-cache nil)
|
(defvar doom--package-cache nil)
|
||||||
(defun doom--package-list (&optional prompt)
|
(defun doom--package-list (&optional prompt)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue