unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Pieter van Oostrum <pieter-l@vanoostrum.org>
To: Stefan Kangas <stefan@marxist.se>
Cc: Pieter van Oostrum <pieter@vanoostrum.org>, 39903@debbugs.gnu.org
Subject: bug#39903: 28.0.50; Feature request: another filter for Package Menu
Date: Thu, 05 Mar 2020 23:24:45 +0100	[thread overview]
Message-ID: <lxlfoe7842.fsf@cochabamba.vanoostrum.org> (raw)
In-Reply-To: <lxwo7y7rsq.fsf@cochabamba.vanoostrum.org> (Pieter van Oostrum's message of "Thu, 05 Mar 2020 16:19:33 +0100")

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

Here is the patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-filter-command-to-Package-Menu-Bug-39903.patch --]
[-- Type: text/x-patch, Size: 5528 bytes --]

From 005c0d43c8fd97caaf58d0ed3362c11022aff292 Mon Sep 17 00:00:00 2001
From: Pieter van Oostrum <pieter@vanoostrum.org>
Date: Thu, 5 Mar 2020 20:20:04 +0100
Subject: [PATCH] Add new filter command to Package Menu (Bug#39903)

* lisp/emacs-lisp/package.el (package-menu-filter-marked):
New filter command.
* test/lisp/emacs-lisp/package-tests.el (package-test-list-filter-marked):
New test.
(package-menu-mode-menu):
(package-menu-mode-map): Update menu to include new filter command.

* doc/emacs/package.texi (Package Menu): Document the new command.
* etc/NEWS: Announce the new command.
---
 doc/emacs/package.texi                |  6 ++++++
 etc/NEWS                              |  1 +
 lisp/emacs-lisp/package.el            | 31 +++++++++++++++++++++++++++
 test/lisp/emacs-lisp/package-tests.el | 15 +++++++++++++
 4 files changed, 53 insertions(+)

diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi
index db3cf317ff..91e44b8eba 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -202,6 +202,12 @@ Package Menu
 @samp{=}, and then a package version, and shows packages that has a
 lower, equal or higher version than the one specified.
 
+@item / m
+@kindex / m @r{(Package Menu)}
+@findex package-menu-filter-marked
+Filter package list by non-empty mark (@code{package-menu-filter-marked}).
+This shows only the packages that have been marked to be installed or deleted.
+
 @item / /
 @kindex / / @r{(Package Menu)}
 @findex package-menu-filter-clear
diff --git a/etc/NEWS b/etc/NEWS
index fcdf6dbe24..01f46cc79d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -172,6 +172,7 @@ key             binding
 / n             package-menu-filter-by-name
 / s             package-menu-filter-by-status
 / v             package-menu-filter-by-version
+/ m             package-menu-filter-marked
 / /             package-menu-filter-clear
 
 \f
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 43eb038a86..efac7d888c 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2692,6 +2692,7 @@ package-menu-mode-map
     (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)
+    (define-key map (kbd "/ m") 'package-menu-filter-marked)
     map)
   "Local keymap for `package-menu-mode' buffers.")
 
@@ -2722,6 +2723,7 @@ package-menu-mode-menu
      ["Filter by Name" package-menu-filter-by-name :help "Filter packages by name"]
      ["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"]
      ["Clear Filter" package-menu-clear-filter :help "Clear package list filter"])
 
     ["Hide by Regexp" package-menu-hide-package :help "Hide all packages matching a regexp"]
@@ -3845,6 +3847,35 @@ package-menu-filter-by-version
            (funcall fun (package-desc-version pkg-desc) ver)))
        (format "versions:%s%s" predicate version)))))
 
+(defun package-menu-filter-marked ()
+  "Filter \"*Packages*\" buffer by non-empty upgrade mark.
+Unlike other filters, this leaves the marks intact."
+  (interactive)
+  (package--ensure-package-menu-mode)
+  (widen)
+  (let (found-entries mark pkg-id entry marks)
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (eobp))
+        (setq mark (char-after))
+        (unless (eq mark ?\s)
+	  (setq pkg-id (tabulated-list-get-id))
+          (setq entry (package-menu--print-info-simple pkg-id))
+	  (push entry found-entries)
+	  ;; remember the mark
+	  (push (cons pkg-id mark) marks))
+        (forward-line))
+      (if found-entries
+          (progn
+            (setq tabulated-list-entries found-entries)
+            (package-menu--display t nil)
+	    ;; redo the marks, but we must remember the marks!!
+	    (goto-char (point-min))
+	    (while (not (eobp))
+	      (setq mark (cdr (assq (tabulated-list-get-id) marks)))
+	      (tabulated-list-put-tag (char-to-string mark) t)))
+	(user-error "No packages found")))))
+
 (defun package-menu-clear-filter ()
   "Clear any filter currently applied to the \"*Packages*\" buffer."
   (interactive)
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index 05770d6b58..524c7f8f94 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -413,6 +413,21 @@ package-test-list-filter-by-status
     ;; No installed packages in default environment.
     (should-error (package-menu-filter-by-status "installed"))))
 
+(ert-deftest package-test-list-filter-marked ()
+  "Ensure package list is filtered correctly by non-empty mark."
+  (with-package-test ()
+    (let ((buf (package-list-packages)))
+      (revert-buffer)
+      (search-forward-regexp "^ +simple-single")
+      (package-menu-mark-install)
+      (package-menu-filter-marked)
+      (goto-char (point-min))
+      (should (re-search-forward "^I +simple-single" nil t))
+      (should (= (count-lines (point-min) (point-max)) 1))
+      (package-menu-mark-unmark)
+      ;; No marked packages in default environment.
+      (should-error (package-menu-filter-marked)))))
+
 (ert-deftest package-test-list-filter-by-version ()
   (with-package-menu-test
     (should-error (package-menu-filter-by-version "1.1" 'unknown-symbol)))  )
-- 
2.25.1


[-- Attachment #3: Type: text/plain, Size: 87 bytes --]


-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]

  reply	other threads:[~2020-03-05 22:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04 14:53 bug#39903: 28.0.50; Feature request: another filter for Package Menu Pieter van Oostrum
2020-03-05 14:24 ` Pieter van Oostrum
2020-03-05 14:51 ` Stefan Kangas
2020-03-05 15:19   ` Pieter van Oostrum
2020-03-05 22:24     ` Pieter van Oostrum [this message]
2020-05-09 15:38       ` Stefan Kangas
2020-05-09 15:51         ` Eli Zaretskii
2020-05-09 16:22           ` Stefan Kangas

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=lxlfoe7842.fsf@cochabamba.vanoostrum.org \
    --to=pieter-l@vanoostrum.org \
    --cc=39903@debbugs.gnu.org \
    --cc=pieter@vanoostrum.org \
    --cc=stefan@marxist.se \
    /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).