Subject: bug#41436: 26.1; How to list upgradable packages only

From: Stefan Kangas <[email-masked]>
Date: Tue, 8 Sep 2020 12:53:20 +0000

tags 41436 + patch
thanks

Stefan Kangas <[email-masked]> writes:

>> I wonder whether it would not be nice to be able to list all upgradable
>> packages and then give the user an option of marking them one by one.
>
> I think it sounds useful.

Could you please try the attached patch and see if it works for you?
It should be applied to the master branch.

Best regards,
Stefan Kangas
From 89d0a1d7f1b6f3e243edfd2df7ac720540535f66 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Tue, 8 Sep 2020 14:50:29 +0200
Subject: [PATCH] Add command package-menu-filter-upgradable

* lisp/emacs-lisp/package.el (package-menu-filter-upgradable):
New command.  (Bug#41436)
(package-menu-mode-map): Bind the new command.
* doc/emacs/package.texi (Package Menu): Document the new command.
---
 doc/emacs/package.texi     |  6 ++++++
 etc/NEWS                   |  1 +
 lisp/emacs-lisp/package.el | 10 ++++++++++
 3 files changed, 17 insertions(+)

diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi
index 453d9eb401..56e8ee1363 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -222,6 +222,12 @@ Package Menu
 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 / u
+@kindex / u @r{(Package Menu)}
+@findex package-menu-filter-upgradable
+Filter package list to show only packages for which there are
+available upgrades (@code{package-menu-filter-upgradable}).
+
 @item / /
 @kindex / / @r{(Package Menu)}
 @findex package-menu-filter-clear
diff --git a/etc/NEWS b/etc/NEWS
index aa3acc26b3..de57e559ba 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -554,6 +554,7 @@ key             binding
 / s             package-menu-filter-by-status
 / v             package-menu-filter-by-version
 / m             package-menu-filter-marked
+/ u             package-menu-filter-upgradable
 / /             package-menu-filter-clear
 
 ---
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index a173fc060a..803bae2ece 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2710,6 +2710,7 @@ package-menu-mode-map
     (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)
+    (define-key map (kbd "/ u") 'package-menu-filter-upgradable)
     map)
   "Local keymap for `package-menu-mode' buffers.")
 
@@ -3906,6 +3907,15 @@ package-menu-filter-marked
 	      (tabulated-list-put-tag (char-to-string mark) t)))
 	(user-error "No packages found")))))
 
+(defun package-menu-filter-upgradable ()
+  "Filter \"*Packages*\" buffer to show only upgradable packages."
+  (interactive)
+  (let ((pkgs (mapcar #'car (package-menu--find-upgrades))))
+    (package-menu--filter-by
+     (lambda (pkg)
+       (memql (package-desc-name pkg) pkgs))
+     "upgradable")))
+
 (defun package-menu-clear-filter ()
   "Clear any filter currently applied to the \"*Packages*\" buffer."
   (interactive)
-- 
2.28.0