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, 30 Sep 2019 23:26:49 +0200 Message-ID: <874l0t8oh2.fsf@gmail.com> References: <87ef0r396q.fsf@gmail.com> <87tv995zlc.fsf@gmail.com> <87h858ryot.fsf@mail.linkov.net> <87ef0aajli.fsf@gmail.com> <875zle9akd.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="90617"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: 36981@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 30 23:27:13 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 1iF3CL-000NOt-A9 for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 Sep 2019 23:27:13 +0200 Original-Received: from localhost ([::1]:57532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iF3CK-00068J-5f for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 Sep 2019 17:27:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52804) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iF3CC-000687-8d for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 17:27:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iF3CA-0007yd-At for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 17:27:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51787) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iF3CA-0007yX-4x for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 17:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iF3C9-0000Vh-W5 for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 17:27:02 -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, 30 Sep 2019 21:27: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.15698788201954 (code B ref 36981); Mon, 30 Sep 2019 21:27:01 +0000 Original-Received: (at 36981) by debbugs.gnu.org; 30 Sep 2019 21:27:00 +0000 Original-Received: from localhost ([127.0.0.1]:60608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iF3C7-0000VR-ST for submit@debbugs.gnu.org; Mon, 30 Sep 2019 17:27:00 -0400 Original-Received: from mail-wr1-f49.google.com ([209.85.221.49]:35573) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iF3C5-0000V9-Gz for 36981@debbugs.gnu.org; Mon, 30 Sep 2019 17:26:58 -0400 Original-Received: by mail-wr1-f49.google.com with SMTP id v8so12992060wrt.2 for <36981@debbugs.gnu.org>; Mon, 30 Sep 2019 14:26:57 -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=HZEWbwvG7GhU57ah0XB2xvKc4td0naFZ7/yht4hhUVc=; b=ABEY9/H+pKJZQRAARWSkEoyDxGLtz0Ld6tKnUdifZRS93FM/Nz0RbpAkWCz0+d1+4q m3uNNeGWaDn8PtNQOxRYTTH4Klb06OqXZcmuJol8fGI6EFNSdcV+NlL0ygMt8ZQjHWv8 zQZgViLvKaCfnli6438ti9qLwx3fSjWl+uiCRlN02jIOzNi0QtfX+sIZfDiJgnnec5HS 4Ikn/4z2ELn6WC8Ev9daGanIhMEP9v9IT5ETq2YlxgaX93zHZt9zZwHHGmQT1Ko6SwtW Xntu4W6NEHN9MIcxPCpNc0++6rXTE3nAWv50RB8R+NlEyxCw1wVZNrtrSfDFE6A5sOj1 gMdw== 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=HZEWbwvG7GhU57ah0XB2xvKc4td0naFZ7/yht4hhUVc=; b=niYq89zyuj0Ph0Y9b7OJgAObZlm2hWeMk4tvuOY/MPcrZYfViD8sW2BpNsba39841O tkCN9YKDlVDaXrKpix5DKNaBPeiMv0L9T2O3qd8npjY+/awI/R9fOnYNr9zQHNT2GC9Q HDSHsLHIOoVrAeAqXAV8ZFLG/OwBPBrxKyHZ58yD0kPW8Rr9yRNBXfkbz5tf4jbaxS+L CO4eHzsHyM/EfJImFh9Wq5mkgGn9hr0r3KVZTfGPU9mGXfruyiDQzB/OqECvZgnWP7AA T9el0vZpRyLNyvrPVeUK9qrC8xHk478iG31k3G7y6snjbXUAM30a6/gLxlxPOCTux1gE fDdQ== X-Gm-Message-State: APjAAAUGgu9qpr55/XKOwqu9ir6HjN386Jn07kNiLyUmZXoclOcVg0Q7 V0VRvP1AOMPvUx0B51iheNzLPkTtAOo= X-Google-Smtp-Source: APXvYqw6frdPnqKdrIZnWMIu9vo/Yp0TgGRQM+maGtZVzGcdOgrgl3PTJhoWvCyDSVJC5M99ZPnaLQ== X-Received: by 2002:a5d:460b:: with SMTP id t11mr13828773wrq.377.1569878811289; Mon, 30 Sep 2019 14:26:51 -0700 (PDT) Original-Received: from lead (dslb-178-008-086-051.178.008.pools.vodafone-ip.de. [178.8.86.51]) by smtp.gmail.com with ESMTPSA id s10sm1281214wmf.48.2019.09.30.14.26.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2019 14:26:50 -0700 (PDT) In-Reply-To: (Stefan Kangas's message of "Fri, 27 Sep 2019 12:32:20 +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:167953 Archived-At: --=-=-= Content-Type: text/plain Hey Stefan, thanks again for the input. > Perhaps just: > > * test/lisp/emacs-lisp/package-tests.el (package-test-list-filter-by-name) > (package-test-list-clear-filter): New tests. > >> +@item / s >> +Filter the package list by name (@code{package-menu-filter-by-name}). > > That should be "/ n" as below. Good catch! >> ++++ >> +*** New function 'package-menu-filter-by-name'. >> +Allows users to filter packages by name on the packages list. By >> +default, it is bound to '/ n'. To clear the filter, use '/ /'. >> + >> ++++ >> +*** Function 'package-menu-fiter-by-keyword' has been renamed >> +from 'package-menu-filter'. Its keybinding has also been changed to >> +'/ k' (from 'f'). To clear the filter, '/ /' must now be used instead >> +of 'q'. >> + >> ++++ >> +*** New function 'package-menu-clear-filter' >> +Allows users to clear a filter applied with 'package-menu-filter-by-name' or >> +'package-menu-filter-by-keyword'. > > Perhaps this would be better as just one item where all changes are > explained together? > >> @@ -2699,7 +2701,9 @@ 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 Keyword" package-menu-filter-by-keyword :help "Filter packages by keyword"] >> + ["Filter Packages by Name" package-menu-filter-by-name :help "Filter packages by name"] >> + ["Clear Packages Filter" package-menu-clear-filter :help "Clear package list filter"] > > This is fine by me, but perhaps it would be better to add a submenu > for filtering? Good idea, I've changed the menu entries so that they're part of a submenu now. I'm attaching the new patch. Thanks! --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=search.patch Content-Description: patch >From a6cb17c6d99113d6f6a6b2a3164a9101c8fecb51 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Thu, 26 Sep 2019 19:18:58 +0200 Subject: [PATCH 1/1] Filter packages by name in list-packages. (Bug#36981) * lisp/emacs-lisp/package.el (package-menu-filter-by-name): New function to filter packages by name. (package-menu-clear-filter): New function to clear applied filters. (package-menu-filter-by-keyword): Rename function from package-menu-filter. (package-menu--generate): Don't change 'q' binding anymore. (package-menu-mode-map): Bind '/ n' to package-menu-filter-by-name, '/ k' to package-menu-filter-by-keyword and '/ /' to package-menu-clear-filter. (package-menu-mode-menu): Update menu entries for the three functions. * test/lisp/emacs-lisp/package-tests.el (package-test-list-filter-by-name) (package-test-list-clear-filter): New tests. * doc/emacs/package.texi: Document usage of package-menu-filter-by-name, package-menu-clear-filter and update reference to package-menu-filter-by-keyword. * etc/NEWS: Announce changes. --- doc/emacs/package.texi | 19 ++++++++--- etc/NEWS | 10 ++++++ lisp/emacs-lisp/package.el | 45 ++++++++++++++++++++------- test/lisp/emacs-lisp/package-tests.el | 24 +++++++++++++- 4 files changed, 81 insertions(+), 17 deletions(-) diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi index 2c09ca8902..d97648af1b 100644 --- a/doc/emacs/package.texi +++ b/doc/emacs/package.texi @@ -136,11 +136,20 @@ Package Menu the list of available packages from the package archive again, and recomputes the package list. -@item f -Filter the package list (@code{package-menu-filter}). This prompts -for a keyword (e.g., @samp{games}), then shows only the packages -that relate to that keyword. To restore the full package list, -type @kbd{q}. +@item / k +Filter the package list by keyword +(@code{package-menu-filter-by-keyword}). This prompts for a keyword +(e.g., @samp{games}), then shows only the packages that relate to that +keyword. + +@item / n +Filter the package list by name (@code{package-menu-filter-by-name}). +This prompts for a string, then shows only the packages whose names +match a regexp with that value. + +@item / / +Clear filter currently applied to the package list +(@code{package-menu-clear-filter}). @item H Permanently hide packages that match a regexp diff --git a/etc/NEWS b/etc/NEWS index cb8b6fcac1..015322c111 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -983,6 +983,16 @@ early init file. *** New function 'package-activate-all'. ++++ +*** New functions for filtering packages list +A new function has been added which allows users to filter the +packages list by name: 'package-menu-filter-by-name'. By default, it +is bound to '/ n'. Additionally, the function +'package-menu-fiter-by-keyword' has been renamed from +'package-menu-filter'. Its keybinding has also been changed to '/ k' +(from 'f'). To clear any of the two filters, the user can now call +the 'package-menu-clear-filter' function, bound to '/ /' by default. + --- *** Imenu support has been added to 'package-menu-mode'. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index ab1fb8b90f..28e971044e 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -2667,7 +2667,9 @@ package-menu-mode-map (define-key map "i" 'package-menu-mark-install) (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 (kbd "/ k") 'package-menu-filter-by-keyword) + (define-key map (kbd "/ n") 'package-menu-filter-by-name) + (define-key map (kbd "/ /") 'package-menu-clear-filter) (define-key map "~" 'package-menu-mark-obsolete-for-deletion) (define-key map "x" 'package-menu-execute) (define-key map "h" 'package-menu-quick-help) @@ -2699,7 +2701,11 @@ 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" + ["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"] + ["Clear Filter" package-menu-clear-filter :help "Clear package list filter"]) + ["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) @@ -3010,9 +3016,6 @@ package-menu--generate (let ((filters (mapconcat #'identity keywords ","))) (concat "Package[" filters "]")) "Package")) - (if keywords - (define-key package-menu-mode-map "q" 'package-show-package-list) - (define-key package-menu-mode-map "q" 'quit-window)) (tabulated-list-init-header) (tabulated-list-print remember-pos)) @@ -3640,9 +3643,7 @@ package-show-package-list (select-window win) (switch-to-buffer buf)))) -;; package-menu--generate rebinds "q" on the fly, so we have to -;; hard-code the binding in the doc-string here. -(defun package-menu-filter (keyword) +(defun package-menu-filter-by-keyword (keyword) "Filter the *Packages* buffer. Show only those items that relate to the specified KEYWORD. @@ -3653,9 +3654,7 @@ package-menu-filter KEYWORD can also be used to filter by status or archive name by using keywords like \"arc:gnu\" and \"status:available\". Statuses available include \"incompat\", \"available\", -\"built-in\" and \"installed\". - -To restore the full package list, type `q'." +\"built-in\" and \"installed\"." (interactive (list (completing-read-multiple "Keywords (comma separated): " (package-all-keywords)))) @@ -3663,6 +3662,30 @@ package-menu-filter (list keyword) keyword))) +(defun package-menu-filter-by-name (name) + "Filter the *Packages* buffer by NAME. +Show only those items whose name matches the regular expression +NAME. If NAME is nil or the empty string, show all packages." + (interactive (list (read-from-minibuffer "Filter by name (regexp): "))) + (if (or (not name) (string-empty-p name)) + (package-show-package-list t nil) + ;; Update `tabulated-list-entries' so that it contains all + ;; packages before searching. + (package-menu--refresh t nil) + (let (matched) + (dolist (entry tabulated-list-entries) + (let* ((pkg-name (package-desc-name (car entry)))) + (when (string-match name (symbol-name pkg-name)) + (push pkg-name matched)))) + (if matched + (package-show-package-list matched nil) + (user-error "No packages found"))))) + +(defun package-menu-clear-filter () + "Clear any filter currently applied to the *Packages* buffer." + (interactive) + (package-menu--generate t t)) + (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..a2ee9f06b1 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,28 @@ 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-filter-by-name () + "Ensure package list is filtered correctly by package name." + (with-package-test () + (let ((buf (package-list-packages))) + (package-menu-filter-by-name "tetris") + (goto-char (point-min)) + (should (re-search-forward "^\\s-+tetris" nil t)) + (should (= (count-lines (point-min) (point-max)) 1)) + (kill-buffer buf)))) + +(ert-deftest package-test-list-clear-filter () + "Ensure package list filter is cleared correctly." + (with-package-test () + (let ((buf (package-list-packages))) + (let ((num-packages (count-lines (point-min) (point-max)))) + (should (> num-packages 1)) + (package-menu-filter-by-name "tetris") + (should (= (count-lines (point-min) (point-max)) 1)) + (package-menu-clear-filter) + (should (= (count-lines (point-min) (point-max)) num-packages))) + (kill-buffer buf)))) + (ert-deftest package-test-update-archives () "Test updating package archives." (with-package-test () -- 2.17.1 --=-=-=--