Commit 567bf811 authored by Artur Malabarba's avatar Artur Malabarba
Browse files

* lisp/emacs-lisp/package.el: Exclude packages by name

(package-hidden-regexps): New variable.
(package-menu--refresh): Use it.
(package-menu-hide-package): New command.
parent a9d9b66e
......@@ -2554,10 +2554,11 @@ Installed obsolete packages are always displayed.")
(unless (derived-mode-p 'package-menu-mode)
(user-error "The current buffer is not a Package Menu"))
(message "%s available-obsolete packages" (if package-menu--hide-obsolete
"Hiding" "Displaying"))
(setq package-menu--hide-packages
(not package-menu--hide-packages))
(message "%s packages" (if package-menu--hide-packages
"Hiding obsolete or unwanted"
"Displaying all"))
(revert-buffer nil 'no-confirm))
(defun package--remove-hidden (pkg-list)
......@@ -2600,13 +2601,23 @@ to their archives."
(defcustom package-hidden-regexps nil
"List of regexps matching the name of packages to hide.
If the name of a package matches any of these regexps it is
omited from the package menu. To toggle this, type \\[package-menu-toggle-hiding].
Values can be interactively added to this list by typing
\\[package-menu-hide-package] on a package"
:type '(repeat (regexp :tag "Hide packages with name matching")))
(defun package-menu--refresh (&optional packages keywords)
"Re-populate the `tabulated-list-entries'.
PACKAGES should be nil or t, which means to display all known packages.
KEYWORDS should be nil or a list of keywords."
;; Construct list of (PKG-DESC . STATUS).
(unless packages (setq packages t))
(let (info-list)
(let ((hidden-names (mapconcat #'identity package-hidden-regexps "\\|"))
;; Installed packages:
(dolist (elt package-alist)
(let ((name (car elt)))
......@@ -2629,7 +2640,13 @@ KEYWORDS should be nil or a list of keywords."
;; Available and disabled packages:
(dolist (elt package-archive-contents)
(let ((name (car elt)))
(when (or (eq packages t) (memq name packages))
;; To be displayed it must be in PACKAGES;
(when (and (or (eq packages t) (memq name packages))
;; and we must either not be hiding anything,
(or (not package-menu--hide-packages)
(not package-hidden-regexps)
;; or just not hiding this specific package.
(not (string-match hidden-names (symbol-name name)))))
;; Hide available-obsolete or low-priority packages.
(dolist (pkg (package--remove-hidden (cdr elt)))
(when (package--has-keyword-p pkg keywords)
......@@ -2770,6 +2787,29 @@ This fetches the contents of each archive specified in
(setq package-menu--new-package-list nil)
(package-refresh-contents package-menu-async))
(defun package-menu-hide-package ()
"Hide a package under point.
If optional arg BUTTON is non-nil, describe its associated package."
(declare (interactive-only "change `package-hidden-regexps' instead."))
(let* ((name (when (derived-mode-p 'package-menu-mode)
(concat "\\`" (regexp-quote (symbol-name (package-desc-name
(re (read-string "Hide packages matching regexp: " name)))
;; Test if it is valid.
(string-match re "")
(push re package-hidden-regexps)
(customize-save-variable 'package-hidden-regexps package-hidden-regexps)
(let ((hidden
(cl-remove-if-not (lambda (e) (string-match re (symbol-name (car e))))
(message (substitute-command-keys
(concat "Hiding %s packages, type `\\[package-menu-toggle-hiding]'"
" to toggle or `\\[customize-variable] RET package-hidden-regexps'"
" to customize it"))
(length hidden)))))
(defun package-menu-describe-package (&optional button)
"Describe the current package.
If optional arg BUTTON is non-nil, describe its associated package."
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment