Subject: bug#35504: 26.2; Key `g' should run `package-menu-refresh' in the *Packages* buffer

From: Stefan Kangas <[email-masked]>
Date: Thu, 3 Oct 2019 01:59:25 +0200

Stefan Monnier <[email-masked]> writes:

> > I also agree.  How about the attached patch?
>
> Fine by me.  I wonder, tho: why not set revert-buffer-function and then
> redefine `package-menu-refresh` as an obsolete alias for `revert-buffer`?

Sure, I've tried to do that in the attached patch.  WDYT?

Best regards,
Stefan Kangas
From e5bd2232220a25c8c977ab2009ad0f96fca29cac Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Fri, 26 Jul 2019 12:49:35 +0200
Subject: [PATCH] Make 'g' refresh package data in package menu

* lisp/emacs-lisp/package.el (package-menu-revert): Rename from
'package-menu-refresh'.
(package-menu-refresh): Define obsolete fuction alias for the above.
(package-menu-mode): Set 'package-menu-refresh' to use the new name.
(package-menu-mode-map): Update binding to use the new
name.  (Bug#35504)

* doc/emacs/package.texi (Package Menu): Document it.
* etc/NEWS: Announce it.
---
 doc/emacs/package.texi     | 14 +++++++++++++-
 etc/NEWS                   |  8 ++++++++
 lisp/emacs-lisp/package.el | 12 +++++++++---
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi
index 2c09ca8902..8a2dca9193 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -85,16 +85,19 @@ Package Menu
 
 @table @kbd
 @item h
+@findex package-menu-quick-help
 Print a short message summarizing how to use the package menu
 (@code{package-menu-quick-help}).
 
 @item ?
 @itemx @key{RET}
+@findex package-menu-describe-package
 Display a help buffer for the package on the current line
 (@code{package-menu-describe-package}), similar to the help window
 displayed by the @kbd{C-h P} command (@pxref{Packages}).
 
 @item i
+@findex package-menu-mark-install
 Mark the package on the current line for installation
 (@code{package-menu-mark-install}).  If the package status is
 @samp{available}, this adds an @samp{I} character to the start of the
@@ -102,6 +105,7 @@ Package Menu
 package.
 
 @item d
+@findex package-menu-mark-delete
 Mark the package on the current line for deletion
 (@code{package-menu-mark-delete}).  If the package status is
 @samp{installed}, this adds a @samp{D} character to the start of the
@@ -110,6 +114,7 @@ Package Menu
 entails.
 
 @item ~
+@findex package-menu-mark-obsolete-for-deletion
 Mark all obsolete packages for deletion
 (@code{package-menu-mark-obsolete-for-deletion}).  This marks for
 deletion all the packages whose status is @samp{obsolete}.
@@ -120,6 +125,7 @@ Package Menu
 current line by an @kbd{i} or @kbd{d} command.
 
 @item U
+@findex package-menu-mark-upgrades
 Mark all package with a newer available version for upgrading
 (@code{package-menu-mark-upgrades}).  This places an installation mark
 on the new available versions, and a deletion mark on the old
@@ -127,26 +133,32 @@ Package Menu
 
 @item x
 @vindex package-menu-async
+@findex package-menu-execute
 Download and install all packages marked with @kbd{i}, and their
 dependencies; also, delete all packages marked with @kbd{d}
 (@code{package-menu-execute}).  This also removes the marks.
 
+@item g
 @item r
-Refresh the package list (@code{package-menu-refresh}).  This fetches
+@findex package-menu-revert
+Refresh the package list (@code{package-menu-revert}).  This fetches
 the list of available packages from the package archive again, and
 recomputes the package list.
 
 @item f
+@findex package-menu-filter
 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 H
+@findex package-menu-hide-package
 Permanently hide packages that match a regexp
 (@code{package-menu-hide-package}).
 
 @item (
+@findex package-menu-toggle-hiding
 Toggle visibility of old versions of packages and also of versions
 from lower-priority archives (@code{package-menu-toggle-hiding}).
 @end table
diff --git a/etc/NEWS b/etc/NEWS
index cb8b6fcac1..2dc22ba89f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -989,6 +989,14 @@ early init file.
 ---
 *** The package list can now be sorted by version or description.
 
++++
+*** 'package-menu-refresh' is an obsolete alias for 'package-menu-revert'.
+
++++
+*** 'g' will now update packages from archives in Package Menu.
+Previously, 'g' invoked 'tabulated-list-revert' which did not refresh
+the cached archive data.
+
 ** Info
 
 +++
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index ab1fb8b90f..d72e983c39 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2666,7 +2666,7 @@ package-menu-mode-map
     (define-key map "d" 'package-menu-mark-delete)
     (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 "r" 'package-menu-revert)
     (define-key map "f" 'package-menu-filter)
     (define-key map "~" 'package-menu-mark-obsolete-for-deletion)
     (define-key map "x" 'package-menu-execute)
@@ -2734,6 +2734,7 @@ package-menu-mode
   (setq tabulated-list-sort-key (cons "Status" nil))
   (add-hook 'tabulated-list-revert-hook #'package-menu--refresh nil t)
   (tabulated-list-init-header)
+  (setq revert-buffer-function 'package-menu-revert)
   (setf imenu-prev-index-position-function
         #'package--imenu-prev-index-position-function)
   (setf imenu-extract-index-name-function
@@ -3132,11 +3133,15 @@ package-menu--print-info-simple
 (defvar package-menu--old-archive-contents nil
   "`package-archive-contents' before the latest refresh.")
 
-(defun package-menu-refresh ()
+(defun package-menu-revert (&optional arg noconfirm)
   "In Package Menu, download the Emacs Lisp package archive.
 Fetch the contents of each archive specified in
 `package-archives', and then refresh the package menu.  Signal a
-user-error if there is already a refresh running asynchronously."
+user-error if there is already a refresh running asynchronously.
+
+`package-menu-mode' sets ‘revert-buffer-function’ to this
+function.  The args ARG and NOCONFIRM, passed from
+‘revert-buffer’, are ignored."
   (interactive)
   (unless (derived-mode-p 'package-menu-mode)
     (user-error "The current buffer is not a Package Menu"))
@@ -3145,6 +3150,7 @@ package-menu-refresh
   (setq package-menu--old-archive-contents package-archive-contents)
   (setq package-menu--new-package-list nil)
   (package-refresh-contents package-menu-async))
+(define-obsolete-function-alias 'package-menu-refresh 'package-menu-revert "27.1")
 
 (defun package-menu-hide-package ()
   "Hide a package under point in Package Menu.
-- 
2.20.1