aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Kaludercic2024-11-06 19:41:12 +0100
committerPhilip Kaludercic2024-11-06 19:41:12 +0100
commit73c76caa1a5871a81500b3e2df8da38f48cc5d1e (patch)
tree76acf7f55f42015ddc9f2caf0da27fe5a9b94f6a
parent90d6044e23b65c76ba529a7b20c7d8e27634b6f0 (diff)
downloademacs-73c76caa1a5871a81500b3e2df8da38f48cc5d1e.tar.gz
emacs-73c76caa1a5871a81500b3e2df8da38f48cc5d1e.zip
Improve package-autosuggest documentation
* lisp/emacs-lisp/package.el (package-autosuggest-database) (package-autosuggest-mode, package--autosuggest-suggested) (package--suggestion-applies-p) (package--autosuggest-find-candidates) (package--autosuggest-install-and-enable) (package--autosuggest-after-change-mode, package-autosuggest): Elaborate docstrings.
-rw-r--r--lisp/emacs-lisp/package.el65
1 files changed, 42 insertions, 23 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 50095d92ae3..bead32bdaf8 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -4545,10 +4545,24 @@ the `Version:' header."
4545 (insert-file-contents 4545 (insert-file-contents
4546 (expand-file-name "package-autosuggest.eld" data-directory)"/home/phi/Source/emacs/etc/package-autosuggest.eld") 4546 (expand-file-name "package-autosuggest.eld" data-directory)"/home/phi/Source/emacs/etc/package-autosuggest.eld")
4547 (read (current-buffer)))) 4547 (read (current-buffer))))
4548 "Database of hints for packages to suggest installing.") 4548 "List of hints for packages to suggest installing.
4549Each hint has the form (PACKAGE TYPE DATA), where PACKAGE is a symbol
4550denoting the package the hint applies to, TYPE is one of
4551`auto-mode-alist', `magic-mode-alist' or `interpreter-mode-alist'
4552indicating the type of check to be made and DATA is the value to check
4553against TYPE in the intuitive way (e.g. for `auto-mode-alist' DATA is a
4554regular expression matching a file name that PACKAGE should be suggested
4555for).")
4549 4556
4550(define-minor-mode package-autosuggest-mode 4557(define-minor-mode package-autosuggest-mode
4551 "Enable the automatic suggestion and installation of packages." 4558 "Enable the automatic suggestion and installation of packages.
4559As a user option, you can set this value to `mode-line' (default) to
4560indicate the availability of a package suggestion in the minor mode,
4561`always' to prompt the user in the minibuffer every time a suggestion is
4562available in a `fundamenta-mode' buffer, `once' to do only prompt the
4563user once for each suggestion or `message' to just display a message
4564hinting at the existence of a suggestion. If `package-autosuggest-mode'
4565is set to nil, the minor mode will be disabled and no suggestions occur."
4552 :init-value 'mode-line :global t 4566 :init-value 'mode-line :global t
4553 :type '(choice (const :tag "Indicate in mode line" mode-line) 4567 :type '(choice (const :tag "Indicate in mode line" mode-line)
4554 (const :tag "Always prompt" always) 4568 (const :tag "Always prompt" always)
@@ -4560,27 +4574,30 @@ the `Version:' header."
4560 #'package--autosuggest-after-change-mode)) 4574 #'package--autosuggest-after-change-mode))
4561 4575
4562(defvar package--autosuggest-suggested '() 4576(defvar package--autosuggest-suggested '()
4563 "List of packages that have already been suggested.") 4577 "List of packages that have already been suggested.
4564 4578The elements of this list should be a subset of elements from
4565(defun package--suggestion-applies-p (pkg-sug) 4579`package-autosuggest-database'. Suggestions found in this list will not
4566 "Check if a suggestion PKG-SUG is applicable to the current buffer." 4580count as suggestions (e.g. if `package-autosuggest-mode' is set to
4567 (pcase pkg-sug 4581`mode-line', a suggestion found in here will inhibit
4582`package-autosuggest-mode' from displaying a hint in the mode line).")
4583
4584(defun package--suggestion-applies-p (sug)
4585 "Check if a suggestion SUG is applicable to the current buffer.
4586SUG should be an element of `package-autosuggest-database'."
4587 (pcase sug
4568 (`(,(or (pred (assq _ package--autosuggest-suggested)) 4588 (`(,(or (pred (assq _ package--autosuggest-suggested))
4569 (pred package-installed-p)) 4589 (pred package-installed-p))
4570 . ,_) 4590 . ,_)
4571 nil) 4591 nil)
4572 ((or `(,_ auto-mode-alist ,ext _) 4592 (`(,_ auto-mode-alist ,ext)
4573 `(,_ auto-mode-alist ,ext))
4574 (and (string-match-p ext (buffer-name)) t)) 4593 (and (string-match-p ext (buffer-name)) t))
4575 ((or `(,_ magic-mode-alist ,mag _) 4594 (`(,_ magic-mode-alist ,mag)
4576 `(,_ magic-mode-alist ,mag))
4577 (save-restriction 4595 (save-restriction
4578 (widen) 4596 (widen)
4579 (save-excursion 4597 (save-excursion
4580 (goto-char (point-min)) 4598 (goto-char (point-min))
4581 (looking-at-p mag)))) 4599 (looking-at-p mag))))
4582 ((or `(,_ interpreter-mode-alist ,magic _) 4600 (`(,_ interpreter-mode-alist ,magic)
4583 `(,_ interpreter-mode-alist ,magic))
4584 (save-restriction 4601 (save-restriction
4585 (widen) 4602 (widen)
4586 (save-excursion 4603 (save-excursion
@@ -4591,7 +4608,9 @@ the `Version:' header."
4591 magic))))))) 4608 magic)))))))
4592 4609
4593(defun package--autosuggest-find-candidates () 4610(defun package--autosuggest-find-candidates ()
4594 "Return a list of packages that might be interesting the current buffer." 4611 "Return a list of suggestions that might be interesting the current buffer.
4612The elements of the returned list will be a subset of the elements of
4613`package--autosuggest-suggested'."
4595 (and package-autosuggest-mode 4614 (and package-autosuggest-mode
4596 (let (suggetions) 4615 (let (suggetions)
4597 (dolist (sug package-autosuggest-database) 4616 (dolist (sug package-autosuggest-database)
@@ -4599,21 +4618,20 @@ the `Version:' header."
4599 (push sug suggetions))) 4618 (push sug suggetions)))
4600 suggetions))) 4619 suggetions)))
4601 4620
4602(defun package--autosuggest-install-and-enable (pkg-sug) 4621(defun package--autosuggest-install-and-enable (sug)
4603 "Install and enable a package suggestion PKG-ENT. 4622 "Install and enable a package suggestion PKG-ENT.
4604PKG-SUG has the same form as an element of 4623SUG should be an element of `package-autosuggest-database'."
4605`package-autosuggest-database'."
4606 (let ((buffers-to-update '())) 4624 (let ((buffers-to-update '()))
4607 (dolist (buf (buffer-list)) 4625 (dolist (buf (buffer-list))
4608 (with-current-buffer buf 4626 (with-current-buffer buf
4609 (when (and (eq major-mode 'fundamental-mode) (buffer-file-name) 4627 (when (and (eq major-mode 'fundamental-mode) (buffer-file-name)
4610 (package--suggestion-applies-p pkg-sug)) 4628 (package--suggestion-applies-p sug))
4611 (push buf buffers-to-update)))) 4629 (push buf buffers-to-update))))
4612 (package-install (car pkg-sug)) 4630 (package-install (car sug))
4613 (dolist (buf buffers-to-update) 4631 (dolist (buf buffers-to-update)
4614 (with-demoted-errors "Failed to enable major mode: %S" 4632 (with-demoted-errors "Failed to enable major mode: %S"
4615 (with-current-buffer buf 4633 (with-current-buffer buf
4616 (funcall-interactively (or (cadddr pkg-sug) (car pkg-sug)))))))) 4634 (funcall-interactively (or (cadddr sug) (car sug))))))))
4617 4635
4618(defvar package--autosugest-line-format 4636(defvar package--autosugest-line-format
4619 '(:eval (package--autosugest-line-format))) 4637 '(:eval (package--autosugest-line-format)))
@@ -4646,7 +4664,8 @@ PKG-SUG has the same form as an element of
4646 '(package-autosuggest-mode ("" package--autosugest-line-format))) 4664 '(package-autosuggest-mode ("" package--autosugest-line-format)))
4647 4665
4648(defun package--autosuggest-after-change-mode () 4666(defun package--autosuggest-after-change-mode ()
4649 "Hook function to suggest packages for installation." 4667 "Display package suggestions for the current buffer.
4668This function should be added to `after-change-major-mode-hook'."
4650 (when-let* ((avail (package--autosuggest-find-candidates)) 4669 (when-let* ((avail (package--autosuggest-find-candidates))
4651 (pkgs (mapconcat #'symbol-name 4670 (pkgs (mapconcat #'symbol-name
4652 (delete-dups (mapcar #'car avail)) 4671 (delete-dups (mapcar #'car avail))
@@ -4665,10 +4684,10 @@ PKG-SUG has the same form as an element of
4665 (message 4684 (message
4666 (substitute-command-keys 4685 (substitute-command-keys
4667 (format "Found suggested packages: %s. Install using \\[package-autosuggest]" 4686 (format "Found suggested packages: %s. Install using \\[package-autosuggest]"
4668 pkgs))))))) 4687 pkgs)))p))))
4669 4688
4670(defun package-autosuggest () 4689(defun package-autosuggest ()
4671 "Prompt the user for suggested packages." 4690 "Prompt the user to install the suggested packages."
4672 (interactive) 4691 (interactive)
4673 (let* ((avail (or (package--autosuggest-find-candidates) 4692 (let* ((avail (or (package--autosuggest-find-candidates)
4674 (user-error "No suggestions found"))) 4693 (user-error "No suggestions found")))