Fix doom/help-packages

Also adds doom-package-backend function.

TODO: Report more information about straight packages.
This commit is contained in:
Henrik Lissner 2019-07-28 23:27:17 +02:00
parent 00a4701b16
commit e3d6d13be5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 47 additions and 25 deletions

View file

@ -397,17 +397,19 @@ If prefix arg is present, refresh the cache."
(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)
(unless package--initialized (unless package--initialized
(package-initialize t)) (package-initialize t))
(let* ((doom--packages (doom--help-packages-list)) (let ((packages (cl-delete-duplicates
(packages (cl-delete-duplicates
(append (mapcar 'car package-alist) (append (mapcar 'car package-alist)
(mapcar 'car package--builtins) (mapcar 'car package--builtins)
(mapcar 'car doom--packages) (mapcar 'car (doom--help-packages-list))
nil)))) nil))))
(unless (memq guess packages) (unless (memq guess packages)
(setq guess nil)) (setq guess nil))
(list (intern (completing-read (if guess (list
(intern
(completing-read (if guess
(format "Select package to search for (default %s): " (format "Select package to search for (default %s): "
guess) guess)
"Describe package: ") "Describe package: ")
@ -416,40 +418,45 @@ If prefix arg is present, refresh the cache."
(if (or (package-desc-p package) (if (or (package-desc-p package)
(and (symbolp package) (and (symbolp package)
(or (assq package package-alist) (or (assq package package-alist)
(assq package package-archive-contents)
(assq package package--builtins)))) (assq package package--builtins))))
(describe-package package) (describe-package package)
(help-setup-xref (list #'doom/help-packages package) (help-setup-xref (list #'doom/help-packages package)
(called-interactively-p 'interactive)) (called-interactively-p 'interactive))
(with-help-window (help-buffer) (with-help-window (help-buffer)))
(with-current-buffer standard-output
(prin1 package)
(princ " is a site package.\n\n"))))
(save-excursion (save-excursion
(with-current-buffer (help-buffer) (with-current-buffer (help-buffer)
(let ((doom-packages (doom--help-packages-list)) (let ((doom-packages (doom--help-packages-list))
(inhibit-read-only t) (inhibit-read-only t)
(indent (make-string 13 ? ))) (indent (make-string 13 ? )))
(goto-char (point-min)) (goto-char (point-max))
(if (re-search-forward "^ *Status: " nil t) (if (re-search-forward "^ *Status: " nil t)
(progn (progn
(end-of-line) (end-of-line)
(insert "\n")) (insert "\n"))
(re-search-forward "\n\n" nil t)) (re-search-forward "\n\n" nil t))
(package--print-help-section "Package")
(insert (symbol-name package) "\n")
(package--print-help-section "Source") (package--print-help-section "Source")
(insert (or (pcase (ignore-errors (doom-package-backend package)) (insert (or (pcase (doom-package-backend package)
(`elpa (concat "[M]ELPA " (doom--package-url package))) (`straight
(`quelpa (format "QUELPA %s" (prin1-to-string (doom-package-prop package :recipe)))) (format! "Straight\n%s"
(`emacs "Built-in") (indent
(_ (symbol-file package))) 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") "unknown")
"\n") "\n")
(when (assq package doom-packages) (when (assq package doom-packages)
(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-prop 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) ""))
@ -474,7 +481,9 @@ If prefix arg is present, refresh the cache."
(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")))))
(defvar doom--package-cache nil) (defvar doom--package-cache nil)
(defun doom--package-list () (defun doom--package-list ()

View file

@ -101,6 +101,19 @@ A protected package cannot be deleted and will be auto-installed if missing."
(or (doom-package-protected-p package) (or (doom-package-protected-p package)
(assq :core (doom-package-get package :modules)))) (assq :core (doom-package-get package :modules))))
;;;###autoload
(defun doom-package-backend (package)
"Return 'straight, 'builtin, 'elpa or 'other, depending on how PACKAGE is
installed."
(cond ((gethash (symbol-name package) straight--build-cache)
'straight)
((or (doom-package-built-in-p package)
(assq package package--builtins))
'builtin)
((assq package package-alist)
'elpa)
('other)))
;;;###autoload ;;;###autoload
(defun doom-package-different-recipe-p (name) (defun doom-package-different-recipe-p (name)
"Return t if a package named NAME (a symbol) has a different recipe than it "Return t if a package named NAME (a symbol) has a different recipe than it