Subject: bug#51173: 28.0.60; gnus-article-describe-key doesn't work

From: Katsumi Yamaoka <[email-masked]>
Date: Wed, 13 Oct 2021 10:05:48 +0900

Hi,

The following example program returns `sh-case' on Emacs 27 and
olders, however to make it work on Emacs 28 and 29 the third
line has to be uncommented.  So does `describe-key' case.

(with-temp-buffer
  (sh-mode)
  ;;(set-window-buffer nil (current-buffer))
  (describe-key-briefly "\C-c\C-c"))

I don't know when/why those commands were changed to require the
buffer (where the keymap is) to be visited in the selected window,
but now `gnus-article-describe-key\(-briefly\)?' doesn't work
because of this.  A patch to gnus-art.el is attached, though the
one that should be fixed might be help.el.

Thanks.
--- gnus-art.el~	2021-10-06 01:11:50.777999500 +0000
+++ gnus-art.el	2021-10-13 01:04:18.073219200 +0000
@@ -6854,19 +6854,24 @@
 		       (read-key-sequence "Describe key: ")))
 	       gnus-article-mode)
   (gnus-article-check-buffer)
-  (if (memq (key-binding key t) '(gnus-article-read-summary-keys
-				  gnus-article-read-summary-send-keys))
-      (with-current-buffer gnus-article-current-summary
-	(setq unread-command-events
-	      (nconc
-	       (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
-				       (list 'meta (- x 128))
-				     x))
-		       key)
-	       unread-command-events))
-	(let ((cursor-in-echo-area t)
-	      gnus-pick-mode)
-	  (describe-key (read-key-sequence nil t))))
+  (if (and (memq (key-binding key t) '(gnus-article-read-summary-keys
+				       gnus-article-read-summary-send-keys))
+	   (buffer-live-p gnus-article-current-summary))
+      (let ((artbuf (current-buffer)))
+	(unwind-protect
+	    (progn
+	      (set-window-buffer nil gnus-article-current-summary)
+	      (setq unread-command-events
+		    (nconc
+		     (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
+					     (list 'meta (- x 128))
+					   x))
+			     key)
+		     unread-command-events))
+	      (let ((cursor-in-echo-area t)
+		    gnus-pick-mode)
+		(describe-key (read-key-sequence nil t))))
+	  (set-window-buffer nil artbuf)))
     (describe-key key)))
 
 (defun gnus-article-describe-key-briefly (key &optional insert)
@@ -6877,19 +6882,24 @@
 		     current-prefix-arg)
 	       gnus-article-mode)
   (gnus-article-check-buffer)
-  (if (memq (key-binding key t) '(gnus-article-read-summary-keys
-				  gnus-article-read-summary-send-keys))
-      (with-current-buffer gnus-article-current-summary
-	(setq unread-command-events
-	      (nconc
-	       (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
-				       (list 'meta (- x 128))
-				     x))
-		       key)
-	       unread-command-events))
-	(let ((cursor-in-echo-area t)
-	      gnus-pick-mode)
-	  (describe-key-briefly (read-key-sequence nil t) insert)))
+  (if (and (memq (key-binding key t) '(gnus-article-read-summary-keys
+				       gnus-article-read-summary-send-keys))
+	   (buffer-live-p gnus-article-current-summary))
+      (let ((artbuf (current-buffer)))
+	(unwind-protect
+	    (progn
+	      (set-window-buffer nil gnus-article-current-summary)
+	      (setq unread-command-events
+		    (nconc
+		     (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
+					     (list 'meta (- x 128))
+					   x))
+			     key)
+		     unread-command-events))
+	      (let ((cursor-in-echo-area t)
+		    gnus-pick-mode)
+		(describe-key-briefly (read-key-sequence nil t) insert)))
+	  (set-window-buffer nil artbuf)))
     (describe-key-briefly key insert)))
 
 ;;`gnus-agent-mode' in gnus-agent.el will define it.