unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39903: 28.0.50; Feature request: another filter for Package Menu
@ 2020-03-04 14:53 Pieter van Oostrum
  2020-03-05 14:24 ` Pieter van Oostrum
  2020-03-05 14:51 ` Stefan Kangas
  0 siblings, 2 replies; 8+ messages in thread
From: Pieter van Oostrum @ 2020-03-04 14:53 UTC (permalink / raw)
  To: 39903

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 1424 bytes --]

This is a request for a new filter in Package Menu.

Motivation: The command `package-menu-mark-upgrades' in the "*Packages*"
buffer marks all packages that have new versions. Both the new versions
are marked for installation (I) and the old versions for deletion (D).

However, it is not so easy to inspect which packages will be
affected. Currently the only simple ways are to do an `isearch' in the
"*Packages*" buffer for "^[^ ]", or to do an `occur' for the same
regexp. The latter gives an overview of all packages involved, but
requires an indirection step to get into the "*Packages*" buffer, for
example to unmark a package.

The attached file adds a new command to filter the "*Packages*"
buffer to show only the packages with a non-empty mark, i.e. the same as
the above `occur' command would show, but then without the extra
indirection.

My proposal is to bind it to "/m", and to add a menu entry.

This function is dependent on commit aea12d4903 (Bug#38424), which
introduces other filters. Contrary to the other filters, this filter
keeps the marks intact. Otherwise it would not be useful.
(Other filters clear the marks, because the marks are not part of the
data structure that builds the package list, but only of the
representation in the buffer.)

If this filter is accepted, I will make it into a full-blown patch with
documentation, etc.) The current format is fit to be included in the `init' file.


[-- Attachment #2: package-filter.el --]
[-- Type: application/octet-stream, Size: 1312 bytes --]

(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")))))

(eval-after-load 'package
  (progn
    (define-key package-menu-mode-map "/m" 'package-menu--filter-marked)
    (easy-menu-add-item
     package-menu-mode-menu
     '("Filter Packages")
     ["Filter Marked" package-menu--filter-marked :help "Filter packages marked for upgrade"])))


[-- Attachment #3: .signature --]
[-- Type: text/plain, Size: 223 bytes --]


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


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  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
  1 sibling, 0 replies; 8+ messages in thread
From: Pieter van Oostrum @ 2020-03-05 14:24 UTC (permalink / raw)
  To: Pieter van Oostrum; +Cc: 39903

I saw that I had inadvertently used a -- in the function name.
package-menu--filter-marked should be replaced with package-menu-filter-marked.
-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-03-05 14:51 UTC (permalink / raw)
  To: Pieter van Oostrum; +Cc: 39903

Pieter van Oostrum <pieter@vanoostrum.org> writes:

> This is a request for a new filter in Package Menu.
>
> Motivation: The command `package-menu-mark-upgrades' in the "*Packages*"
> buffer marks all packages that have new versions. Both the new versions
> are marked for installation (I) and the old versions for deletion (D).
>
> However, it is not so easy to inspect which packages will be
> affected. Currently the only simple ways are to do an `isearch' in the
> "*Packages*" buffer for "^[^ ]", or to do an `occur' for the same
> regexp. The latter gives an overview of all packages involved, but
> requires an indirection step to get into the "*Packages*" buffer, for
> example to unmark a package.
>
> The attached file adds a new command to filter the "*Packages*"
> buffer to show only the packages with a non-empty mark, i.e. the same as
> the above `occur' command would show, but then without the extra
> indirection.
>
> My proposal is to bind it to "/m", and to add a menu entry.

This looks useful.  Could you write this up as a patch instead?
Preferably also with a Changelog entry as described in the CONTRIBUTE
file.  We should also add this new command to the relevant NEWS entry,
and the user manual.

Thanks in advance.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  2020-03-05 14:51 ` Stefan Kangas
@ 2020-03-05 15:19   ` Pieter van Oostrum
  2020-03-05 22:24     ` Pieter van Oostrum
  0 siblings, 1 reply; 8+ messages in thread
From: Pieter van Oostrum @ 2020-03-05 15:19 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Pieter van Oostrum, 39903

Stefan Kangas <stefan@marxist.se> writes:
>
> This looks useful.  Could you write this up as a patch instead?
> Preferably also with a Changelog entry as described in the CONTRIBUTE
> file.  We should also add this new command to the relevant NEWS entry,
> and the user manual.

Yes, I'll do.
-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  2020-03-05 15:19   ` Pieter van Oostrum
@ 2020-03-05 22:24     ` Pieter van Oostrum
  2020-05-09 15:38       ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Pieter van Oostrum @ 2020-03-05 22:24 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Pieter van Oostrum, 39903

[-- 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]

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  2020-03-05 22:24     ` Pieter van Oostrum
@ 2020-05-09 15:38       ` Stefan Kangas
  2020-05-09 15:51         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-05-09 15:38 UTC (permalink / raw)
  To: Pieter van Oostrum; +Cc: Pieter van Oostrum, 39903

Pieter van Oostrum <pieter-l@vanoostrum.org> writes:

> Here is the patch:

Sorry for the late reply here.  The patch looks good to me.

Have you signed the copyright assignment papers?

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  2020-05-09 15:38       ` Stefan Kangas
@ 2020-05-09 15:51         ` Eli Zaretskii
  2020-05-09 16:22           ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2020-05-09 15:51 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: pieter-l, 39903

> From: Stefan Kangas <stefan@marxist.se>
> Date: Sat, 9 May 2020 11:38:24 -0400
> Cc: Pieter van Oostrum <pieter@vanoostrum.org>, 39903@debbugs.gnu.org
> 
> Have you signed the copyright assignment papers?

Yes, he has.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#39903: 28.0.50; Feature request: another filter for Package Menu
  2020-05-09 15:51         ` Eli Zaretskii
@ 2020-05-09 16:22           ` Stefan Kangas
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Kangas @ 2020-05-09 16:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: pieter-l, 39903

close 39903 28.1
thanks

Eli Zaretskii <eliz@gnu.org> writes:

>> Have you signed the copyright assignment papers?
>
> Yes, he has.

Thanks.  This patch is now pushed to master as commit 196bc13b7b.
I'm closing the bug with this message.

Thank you, Pieter, for your contribution.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-05-09 16:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-05-09 15:38       ` Stefan Kangas
2020-05-09 15:51         ` Eli Zaretskii
2020-05-09 16:22           ` Stefan Kangas

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).