Function: package--suggestion-applies-p

package--suggestion-applies-p is a byte-compiled function defined in package-activate.el.gz.

Signature

(package--suggestion-applies-p SUG)

Documentation

Check if a suggestion SUG is applicable to the current buffer.

Each suggestion has the form (PACKAGE TYPE DATA [MAJOR-MODE]), where PACKAGE is a symbol denoting the package and major-mode to which the suggestion applies, TYPE is one of auto-mode-alist, magic-mode-alist or interpreter-mode-alist, indicating the type of check to be made, and DATA is the value to check against TYPE in the intuitive way (e.g., for auto-mode-alist DATA is a regular expression matching a file name for which PACKAGE should be suggested). If the package name and the major mode name differ, then an optional fourth element MAJOR-MODE can be used to indicate what command to invoke to enable the package.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/package-activate.el.gz
(defun package--suggestion-applies-p (sug)
  "Check if a suggestion SUG is applicable to the current buffer.
Each suggestion has the form (PACKAGE TYPE DATA [MAJOR-MODE]), where
PACKAGE is a symbol denoting the package and major-mode to which the
suggestion applies, TYPE is one of `auto-mode-alist', `magic-mode-alist'
or `interpreter-mode-alist', indicating the type of check to be made,
and DATA is the value to check against TYPE in the intuitive way (e.g.,
for `auto-mode-alist' DATA is a regular expression matching a file name
for which PACKAGE should be suggested).  If the package name and the
major mode name differ, then an optional fourth element MAJOR-MODE can
be used to indicate what command to invoke to enable the package."
  (pcase sug
    ((or (guard (not (eq major-mode 'fundamental-mode)))
         (guard (and package-autosuggest-once
                     (not (memq (car sug) package--autosuggest-suggested))))
         `(,(pred package-installed-p) . ,_))
     nil)
    (`(,_ auto-mode-alist ,ext . ,_)
     (and (buffer-file-name) (string-match-p ext (buffer-file-name)) t))
    (`(,_ magic-mode-alist ,mag . ,_)
     (without-restriction
       (save-excursion
         (goto-char (point-min))
         (looking-at-p mag))))
    (`(,_ interpreter-mode-alist ,intr . ,_)
     (without-restriction
       (save-excursion
         (goto-char (point-min))
         (and (looking-at auto-mode-interpreter-regexp)
              (string-match-p
               (concat "\\`" (file-name-nondirectory (match-string 2)) "\\'")
               intr)))))))