From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Federico Tedin Newsgroups: gmane.emacs.bugs Subject: bug#36981: 26.2; request: add searching by package name to list-packages Date: Mon, 09 Sep 2019 22:54:56 +0200 Message-ID: <87woeh197j.fsf@gmail.com> References: <87ef0r396q.fsf@gmail.com> <87tv9mke73.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="224837"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 36981@debbugs.gnu.org, ndame To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 09 22:56:11 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i7Qhn-000wLX-Fb for geb-bug-gnu-emacs@m.gmane.org; Mon, 09 Sep 2019 22:56:11 +0200 Original-Received: from localhost ([::1]:60660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7Qhm-0003lK-AT for geb-bug-gnu-emacs@m.gmane.org; Mon, 09 Sep 2019 16:56:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34028) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7Qhf-0003l2-SJ for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2019 16:56:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7Qhe-0001uY-8c for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2019 16:56:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60039) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7Qhe-0001uL-2B for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2019 16:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i7Qhd-0003uW-UT for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2019 16:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Federico Tedin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Sep 2019 20:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36981 X-GNU-PR-Package: emacs Original-Received: via spool by 36981-submit@debbugs.gnu.org id=B36981.156806250914933 (code B ref 36981); Mon, 09 Sep 2019 20:56:01 +0000 Original-Received: (at 36981) by debbugs.gnu.org; 9 Sep 2019 20:55:09 +0000 Original-Received: from localhost ([127.0.0.1]:40627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i7Qgm-0003sm-Qf for submit@debbugs.gnu.org; Mon, 09 Sep 2019 16:55:09 -0400 Original-Received: from mail-wr1-f47.google.com ([209.85.221.47]:37528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i7Qgj-0003sA-Rx for 36981@debbugs.gnu.org; Mon, 09 Sep 2019 16:55:06 -0400 Original-Received: by mail-wr1-f47.google.com with SMTP id i1so15268580wro.4 for <36981@debbugs.gnu.org>; Mon, 09 Sep 2019 13:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=muBWxDrxB5r1HaC8AL6DsVsFIkce6rSDgJ4/fJdb4MI=; b=I20oeffdoFD4eSr/zd2SdxD/HBRsXgt95JOynCfsBfxWapk0aFX9lhEzqktHHsGAO0 VoUpijjNC51zYM5wecY9oSyYrRKlGQmiUaBMo5yORvWVLpeBNBcyBCpGxP8sp51rXeqD FEtDNc2RbaYD/sgaZiJGYfLwHNfEQpGCADJlwSEbcRT+rRCRHDEztKPg61hNUx6+Gb69 R+o+Hws5wO+gaQwTzQp17HXnUlxfqFOYk0xC5BfZP8Vx1MOLQxw5qSq+tMJb5SkozizB JXOT+Oqg3lvePda5eGuh9NPI8MkacqO5ccyTYh3ygHTt7H2IsP1jUGRM2FxdsUEu2r0f XpWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=muBWxDrxB5r1HaC8AL6DsVsFIkce6rSDgJ4/fJdb4MI=; b=eeshbLmTlB+wqJdY1QJki+/rAeOM5KtHWn0Hxqg3OctP8269AV9YdVfTUxxXZIpoc3 tNRF/3ibpGD/Jnxv/MiB4tIea5IhzMTNrsQizUBycbdVW+mmm6OH1L8X0y76xgZHv5t4 aUOA5W7OnP2/2ugPOgty/jKqmsJUqcv1aTVHAeXl0YyD8AZMfRESQPpSDFdZt1J+CWRW l35O4OC4nruhFXG4EbJ8PaO5R5n7Y26QjK1QfSKYLQqv6T5WtFDvcR6UpA0Vzjz0vqEr 1pocCBIoPOiq5Gwz/NCwfcw9wV+Bpi7oPav9c1FvRhN7fJXba2ZYrlxPiifxPyT9sl7A QBHA== X-Gm-Message-State: APjAAAXBZ+yxof7UQTWVIHBquSLxnHS4UFfobJUvSKJxOCG8vJQjGtGB 6euXACMVFgB9jfpZ+rJGsi4= X-Google-Smtp-Source: APXvYqxEhumBrLa8UAU4XkleDB059ot31hSL/sFjooq6KPy9RYp777rC0ci6/G6/4IE/GrK6R/Xudg== X-Received: by 2002:a5d:6108:: with SMTP id v8mr16217464wrt.255.1568062499918; Mon, 09 Sep 2019 13:54:59 -0700 (PDT) Original-Received: from lead (dslb-188-103-126-075.188.103.pools.vodafone-ip.de. [188.103.126.75]) by smtp.gmail.com with ESMTPSA id 189sm1135452wma.6.2019.09.09.13.54.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Sep 2019 13:54:57 -0700 (PDT) In-Reply-To: <87tv9mke73.fsf@gmail.com> ("=?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?="'s message of "Sun, 08 Sep 2019 17:20:00 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:166340 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi =C5=A0t=C4=9Bp=C3=A1n, thanks for your very detailed feedback. >> + (if (or keywords (and packages (listp packages))) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > AKA "(consp packages)", though maybe you find your version more > descriptive. Thanks, didn't know they were equivalent. >> +(defun package-menu-search (name) >> + "Filter the *Packages* buffer. >> +Show only those items whose name matches NAME. If NAME is nil or an >> +empty string, show all packages. > > If I was reading it as a user, I would appreciate it if the doc string > was more specific regarding the NAME argument, e.g. said "matches the > regular expression NAME" or something to that effect. > Also, I think "empty string" is usually prefixed with "the", not "an", > as there is only one such thing, e.g. (eq "" "") =3D> t.=20 I've changed the docstring as you described, I think it's clearer now. >> +To restore the full package list, type `q'." >> + (interactive >> + (list (read-from-minibuffer "Package name: ") >> + current-prefix-arg)) > ^^^^^^^^^^^^^^^^^^ > > Is this a remnant of some previous WIP version? The function now takes a > single argument, right? Correct! I forgot to remove it. I was experimenting with making 'C-u s' search packages by name, but only considering packages that were already listed. This way it was possible to combine the keyword search and name search. I decided against it in the end because I'm not sure if it is a necessary addition. I'm attaching a new patch with some changes. - Fede --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=search.patch Content-Description: patch >From e1a8d4ab5b03d5800e5c42c61cd2471e45f2a9f5 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Mon, 9 Sep 2019 22:48:36 +0200 Subject: [PATCH 1/1] Search packages by name in list-packages (Bug#36981) * lisp/emacs-lisp/package.el (package-menu-search): Added a new function that allows filtering packages by name. (package-menu--generate): Show full packages list with 'q' if current list has been filtered. (package-menu-mode-map): Bind 's' to package-menu-search. * test/lisp/emacs-lisp/package-tests.el (package-test-list-search): Added a test for package-menu-search. * doc/emacs/package.texi: Document usage of 'package-menu-search'. * etc/NEWS: Announce changes. --- doc/emacs/package.texi | 5 +++++ etc/NEWS | 4 ++++ lisp/emacs-lisp/package.el | 28 +++++++++++++++++++++++++-- test/lisp/emacs-lisp/package-tests.el | 11 ++++++++++- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi index 4b33f250c4..84de3a5103 100644 --- a/doc/emacs/package.texi +++ b/doc/emacs/package.texi @@ -142,6 +142,11 @@ Package Menu that relate to that keyword. To restore the full package list, type @kbd{q}. +@item s +Search packages by name (@code{package-menu-search}). This prompts +for a string, then shows only the packages whose names match a regexp +with that value. To restore the full package list, type @kbd{q}. + @item H Permanently hide packages that match a regexp (@code{package-menu-hide-package}). diff --git a/etc/NEWS b/etc/NEWS index 87666740df..6554dc1f79 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -968,6 +968,10 @@ early init file. *** New function 'package-activate-all'. +*** New function 'package-menu-search'. +Allows users to search packages by name on the packages list. By +default, it is bound to 's'. + --- *** Imenu support has been added to 'package-menu-mode'. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index ef0c5171de..d1ff7b964d 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -2621,6 +2621,7 @@ package-menu-mode-map (define-key map "U" 'package-menu-mark-upgrades) (define-key map "r" 'package-menu-refresh) (define-key map "f" 'package-menu-filter) + (define-key map "s" 'package-menu-search) (define-key map "~" 'package-menu-mark-obsolete-for-deletion) (define-key map "x" 'package-menu-execute) (define-key map "h" 'package-menu-quick-help) @@ -2652,7 +2653,8 @@ package-menu-mode-map ["Unmark" package-menu-mark-unmark :help "Clear any marks on a package and move to the next line"] "--" - ["Filter Package List" package-menu-filter :help "Filter package selection (q to go back)"] + ["Filter Packages by Keywords" package-menu-filter :help "Filter packages by keywords (q to go back)"] + ["Filter Packages by Name" package-menu-search :help "Filter packages by name (q to go back)"] ["Hide by Regexp" package-menu-hide-package :help "Permanently hide all packages matching a regexp"] ["Display Older Versions" package-menu-toggle-hiding :style toggle :selected (not package-menu--hide-packages) @@ -2963,7 +2965,7 @@ package-menu--generate (let ((filters (mapconcat #'identity keywords ","))) (concat "Package[" filters "]")) "Package")) - (if keywords + (if (or keywords (consp packages)) (define-key package-menu-mode-map "q" 'package-show-package-list) (define-key package-menu-mode-map "q" 'quit-window)) (tabulated-list-init-header) @@ -3598,6 +3600,28 @@ package-menu-filter (list keyword) keyword))) +(defun package-menu-search (name) + "Filter the *Packages* buffer. +Show only those items whose name matches the regular expression +NAME. If NAME is nil or the empty string, show all packages. + +To restore the full package list, type `q'." + (interactive (list (read-from-minibuffer "Package name: "))) + (if (or (not name) (string-empty-p name)) + (package-show-package-list t nil) + ;; Update `tabulated-list-entries' so that in contains all + ;; packages before searching. + (package-menu--refresh t nil) + (let (matched) + (dolist (entry tabulated-list-entries) + (let* ((pkg-name-sym (package-desc-name (car entry))) + (pkg-name (symbol-name pkg-name-sym))) + (when (string-match name pkg-name) + (push pkg-name-sym matched)))) + (if matched + (package-show-package-list matched nil) + (user-error "No packages found"))))) + (defun package-list-packages-no-fetch () "Display a list of packages. Does not fetch the updated list of packages before displaying. diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el index c757bccf67..ea28db83ce 100644 --- a/test/lisp/emacs-lisp/package-tests.el +++ b/test/lisp/emacs-lisp/package-tests.el @@ -28,7 +28,7 @@ ;; Run this in a clean Emacs session using: ;; -;; $ emacs -Q --batch -L . -l package-test.el -l ert -f ert-run-tests-batch-and-exit +;; $ emacs -Q --batch -L . -l package-tests.el -l ert -f ert-run-tests-batch-and-exit ;;; Code: @@ -360,6 +360,15 @@ package-test--compatible-p (should-not (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+\\(available\\|new\\)" nil t)) (kill-buffer buf)))) +(ert-deftest package-test-list-search () + "Ensure package list is filtered correctly by package name." + (with-package-test () + (let ((buf (package-list-packages))) + (package-menu-search "tetris") + (should (= (length tabulated-list-entries) 1)) + (should (eq (package-desc-name (caar tabulated-list-entries)) 'tetris)) + (kill-buffer buf)))) + (ert-deftest package-test-update-archives () "Test updating package archives." (with-package-test () -- 2.17.1 --=-=-=--