[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0a7ec10 2/2: Add command to filter package menu by name or descri
From: |
Stefan Kangas |
Subject: |
master 0a7ec10 2/2: Add command to filter package menu by name or description |
Date: |
Tue, 17 Nov 2020 06:18:55 -0500 (EST) |
branch: master
commit 0a7ec10ac621c210fbf87e4465cb05e378b79889
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>
Add command to filter package menu by name or description
* lisp/emacs-lisp/package.el (package-menu-filter-by-description):
(package-menu-filter-by-name-or-description): New commands to filter
the package menu. (Bug#44699)
(package-menu-mode-map): Bind the above new commands.
(package-menu-mode-menu): Add new commands to the menu.
* doc/emacs/package.texi (Package Menu): Document new commands.
---
doc/emacs/package.texi | 16 ++++++++++++++++
etc/NEWS | 4 +++-
lisp/emacs-lisp/package.el | 43 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi
index 56e8ee1..4981dd5 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -187,6 +187,14 @@ Filter package list by archive
(@code{package-menu-filter-by-archive}).
This prompts for a package archive (e.g., @samp{gnu}), then shows only
packages from that archive.
+@item / d
+@kindex / d @r{(Package Menu)}
+@findex package-menu-filter-by-description
+Filter package list by description
+(@code{package-menu-filter-by-description}). This prompts for a
+regular expression, then shows only packages with descriptions
+matching that regexp.
+
@item / k
@kindex / k @r{(Package Menu)}
@findex package-menu-filter-by-keyword
@@ -194,6 +202,14 @@ Filter package list by keyword
(@code{package-menu-filter-by-keyword}).
This prompts for a keyword (e.g., @samp{games}), then shows only
packages with that keyword.
+@item / N
+@kindex / N @r{(Package Menu)}
+@findex package-menu-filter-by-name-or-description
+Filter package list by name or description
+(@code{package-menu-filter-by-name-or-description}). This prompts for
+a regular expression, then shows only packages with a name or
+description matching that regexp.
+
@item / n
@kindex / n @r{(Package Menu)}
@findex package-menu-filter-by-name
diff --git a/etc/NEWS b/etc/NEWS
index 79c937b..9f39851 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -831,12 +831,14 @@ equivalent to '(map (:sym sym))'.
+++
*** New commands to filter the package list.
-The filter command key bindings are as follows:
+The filter commands are bound to the following keys:
key binding
--- -------
/ a package-menu-filter-by-archive
+/ d package-menu-filter-by-description
/ k package-menu-filter-by-keyword
+/ N package-menu-filter-by-name-or-description
/ n package-menu-filter-by-name
/ s package-menu-filter-by-status
/ v package-menu-filter-by-version
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index fbab6de..d78a1a2 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2704,7 +2704,9 @@ either a full name or nil, and EMAIL is a valid email
address."
(define-key map "(" #'package-menu-toggle-hiding)
(define-key map (kbd "/ /") 'package-menu-clear-filter)
(define-key map (kbd "/ a") 'package-menu-filter-by-archive)
+ (define-key map (kbd "/ d") 'package-menu-filter-by-description)
(define-key map (kbd "/ k") 'package-menu-filter-by-keyword)
+ (define-key map (kbd "/ N") 'package-menu-filter-by-name-or-description)
(define-key map (kbd "/ n") 'package-menu-filter-by-name)
(define-key map (kbd "/ s") 'package-menu-filter-by-status)
(define-key map (kbd "/ v") 'package-menu-filter-by-version)
@@ -2736,8 +2738,11 @@ either a full name or nil, and EMAIL is a valid email
address."
"--"
("Filter Packages"
["Filter by Archive" package-menu-filter-by-archive :help "Filter
packages by archive"]
+ ["Filter by Description" package-menu-filter-by-description :help "Filter
packages by description"]
["Filter by Keyword" package-menu-filter-by-keyword :help "Filter
packages by keyword"]
["Filter by Name" package-menu-filter-by-name :help "Filter packages by
name"]
+ ["Filter by Name or Description"
package-menu-filter-by-name-or-description
+ :help "Filter packages by name or description"]
["Filter by Status" package-menu-filter-by-status :help "Filter packages
by status"]
["Filter by Version" package-menu-filter-by-version :help "Filter
packages by version"]
["Filter Marked" package-menu-filter-marked :help "Filter packages marked
for upgrade"]
@@ -3765,6 +3770,23 @@ packages."
(string-join archive ",")
archive)))))
+(defun package-menu-filter-by-description (description)
+ "Filter the \"*Packages*\" buffer by DESCRIPTION regexp.
+Display only packages with a description that matches regexp
+DESCRIPTION.
+
+When called interactively, prompt for DESCRIPTION.
+
+If DESCRIPTION is nil or the empty string, show all packages."
+ (interactive (list (read-regexp "Filter by description (regexp)")))
+ (package--ensure-package-menu-mode)
+ (if (or (not description) (string-empty-p description))
+ (package-menu--generate t t)
+ (package-menu--filter-by (lambda (pkg-desc)
+ (string-match description
+ (package-desc-summary pkg-desc)))
+ (format "desc:%s" description))))
+
(defun package-menu-filter-by-keyword (keyword)
"Filter the \"*Packages*\" buffer by KEYWORD.
Display only packages with specified KEYWORD.
@@ -3790,6 +3812,27 @@ packages."
(define-obsolete-function-alias
'package-menu-filter #'package-menu-filter-by-keyword "27.1")
+(defun package-menu-filter-by-name-or-description (name-or-description)
+ "Filter the \"*Packages*\" buffer by NAME-OR-DESCRIPTION regexp.
+Display only packages with a name-or-description that matches regexp
+NAME-OR-DESCRIPTION.
+
+When called interactively, prompt for NAME-OR-DESCRIPTION.
+
+If NAME-OR-DESCRIPTION is nil or the empty string, show all
+packages."
+ (interactive (list (read-regexp "Filter by name or description (regexp)")))
+ (package--ensure-package-menu-mode)
+ (if (or (not name-or-description) (string-empty-p name-or-description))
+ (package-menu--generate t t)
+ (package-menu--filter-by (lambda (pkg-desc)
+ (or (string-match name-or-description
+ (package-desc-summary pkg-desc))
+ (string-match name-or-description
+ (symbol-name
+ (package-desc-name pkg-desc)))))
+ (format "name-or-desc:%s" name-or-description))))
+
(defun package-menu-filter-by-name (name)
"Filter the \"*Packages*\" buffer by NAME regexp.
Display only packages with name that matches regexp NAME.