unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Juri Linkov <juri@linkov.net>, 44699@debbugs.gnu.org
Subject: bug#44699: Add package filter by description
Date: Mon, 16 Nov 2020 19:15:20 -0800	[thread overview]
Message-ID: <CADwFkmnqZ6qSWcTWPj8eSesWiF6xxEAqN1AQHpB+FJM5UrUjzg@mail.gmail.com> (raw)
In-Reply-To: <87ft592fcz.fsf_-_@mail.linkov.net>

[-- Attachment #1: Type: text/plain, Size: 522 bytes --]

tags 44699 + patch
thanks

Juri Linkov <juri@linkov.net> writes:

> Severity: wishlist
>
>>> BTW, what I still miss in package filtering is a key to match
>>> package descriptions (in addition to package names).  For example,
>>> Ubuntu package manager allows filtering by these fields:
>>> "Name", "Description and Name".
>>
>> Good idea, that would be useful (and straightforward to add).  Could you
>> please open a new bug report for that?
>
> Opened a new bug report here.

Thanks.  How does the attached patch look?

[-- Attachment #2: 0001-Add-command-to-filter-package-menu-by-name-or-descri.patch --]
[-- Type: text/x-diff, Size: 6791 bytes --]

From b149068c0c046c40d0814213088caf7a42f872f2 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Tue, 17 Nov 2020 03:41:04 +0100
Subject: [PATCH] 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.
(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 56e8ee1363..4981dd50c7 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -187,6 +187,14 @@ Package Menu
 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 @@ Package Menu
 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 79c937b9ae..9f39851b4a 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 fbab6debd5..d78a1a2856 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2704,7 +2704,9 @@ package-menu-mode-map
     (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 @@ package-menu-mode-menu
     "--"
     ("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 @@ package-menu-filter-by-archive
                                              (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 @@ package-menu-filter-by-keyword
 (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.
-- 
2.29.2


  reply	other threads:[~2020-11-17  3:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10 10:36 bug#44550: 28.0.50; proposal for tabulated-list-mode to provide narrowing incremental search Jean Louis
2020-11-10 15:57 ` Eli Zaretskii
2020-11-10 19:57   ` Jean Louis
2020-11-11 15:35     ` Eli Zaretskii
2020-11-11 17:22       ` Jean Louis
2020-11-15 20:03     ` Juri Linkov
2020-11-15 22:04       ` Jean Louis
2020-11-15 23:26         ` Drew Adams
2020-11-15 22:51       ` Stefan Kangas
2020-11-16  9:05         ` Juri Linkov
2020-11-16 13:04           ` Stefan Kangas
2020-11-16 20:53             ` bug#44699: Add package filter by description Juri Linkov
2020-11-17  3:15               ` Stefan Kangas [this message]
2020-11-17  8:30                 ` Juri Linkov
2020-11-17 11:27                   ` Stefan Kangas
2020-11-16 16:22           ` bug#44550: 28.0.50; proposal for tabulated-list-mode to provide narrowing incremental search Drew Adams
2020-11-16 17:49             ` Jean Louis
2020-11-17  7:05           ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADwFkmnqZ6qSWcTWPj8eSesWiF6xxEAqN1AQHpB+FJM5UrUjzg@mail.gmail.com \
    --to=stefan@marxist.se \
    --cc=44699@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).