Subject: 27.0.50; gnus-summary-widget-forward error with other frame

From: "Basil L. Contovounesios" <[email-masked]>
Date: Sat, 04 May 2019 19:05:47 +0100

Tags: patch

>From 4190fec56ebd413e0e398d23edb55b89772ae1d0 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Sat, 4 May 2019 16:29:39 +0100
Subject: [PATCH] Fix Gnus summary widget navigation across frames

* lisp/gnus/gnus-sum.el (gnus-summary-widget-forward)
(gnus-summary-widget-backward): Signal more informative error if
article window is not found.  Consider other frames displaying
article buffer, and raise its frame before navigating its widgets.
* lisp/gnus/gnus-win.el (gnus-get-buffer-window): Simplify and add
docstring.
---
 lisp/gnus/gnus-sum.el | 18 ++++++++++++------
 lisp/gnus/gnus-win.el | 19 ++++++++++---------
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index b8aa302f11..ac222acfd2 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -9423,8 +9423,11 @@ gnus-summary-widget-forward
   (interactive "p")
   (gnus-summary-select-article)
   (gnus-configure-windows 'article)
-  (select-window (gnus-get-buffer-window gnus-article-buffer))
-  (widget-forward arg))
+  (let ((win (or (gnus-get-buffer-window gnus-article-buffer t)
+                 (error "No article window found"))))
+    (select-window win)
+    (select-frame-set-input-focus (window-frame win))
+    (widget-forward arg)))
 
 (defun gnus-summary-widget-backward (arg)
   "Move point to the previous field or button in the article.
@@ -9432,10 +9435,13 @@ gnus-summary-widget-backward
   (interactive "p")
   (gnus-summary-select-article)
   (gnus-configure-windows 'article)
-  (select-window (gnus-get-buffer-window gnus-article-buffer))
-  (unless (widget-at (point))
-    (goto-char (point-max)))
-  (widget-backward arg))
+  (let ((win (or (gnus-get-buffer-window gnus-article-buffer t)
+                 (error "No article window found"))))
+    (select-window win)
+    (select-frame-set-input-focus (window-frame win))
+    (unless (widget-at (point))
+      (goto-char (point-max)))
+    (widget-backward arg)))
 
 (defun gnus-summary-isearch-article (&optional regexp-p)
   "Do incremental search forward on the current article.
diff --git a/lisp/gnus/gnus-win.el b/lisp/gnus/gnus-win.el
index 5f7154c545..a992fe731c 100644
--- a/lisp/gnus/gnus-win.el
+++ b/lisp/gnus/gnus-win.el
@@ -28,6 +28,7 @@
 
 (require 'gnus)
 (require 'gnus-util)
+(require 'seq)
 
 (defgroup gnus-windows nil
   "Window configuration."
@@ -509,15 +510,15 @@ gnus-remove-some-windows
 	      (delq lowest-buf bufs)))))
 
 (defun gnus-get-buffer-window (buffer &optional frame)
-  (cond ((and (null gnus-use-frames-on-any-display)
-	      (memq frame '(t 0 visible)))
-	 (car
-	  (let ((frames (frames-on-display-list)))
-	    (seq-remove (lambda (win) (not (memq (window-frame win)
-						     frames)))
-			    (get-buffer-window-list buffer nil frame)))))
-	(t
-	 (get-buffer-window buffer frame))))
+  "Return a window currently displaying BUFFER, or nil if none.
+Like `get-buffer-window', but respecting
+`gnus-use-frames-on-any-display'."
+  (if (and (not gnus-use-frames-on-any-display)
+           (memq frame '(t 0 visible)))
+      (let ((frames (frames-on-display-list)))
+        (seq-find (lambda (win) (memq (window-frame win) frames))
+                  (get-buffer-window-list buffer nil frame)))
+    (get-buffer-window buffer frame)))
 
 (provide 'gnus-win)
 
-- 
2.20.1

Since at least Emacs 24.4, the commands gnus-summary-widget-forward and
gnus-summary-widget-backward have been signalling an error in multiframe
configurations:

0. HOME=$(mktemp -d) emacs -Q
1. (progn (setq debug-on-error t
                gnus-select-method '(nntp "news.gwene.org"))
          (gnus-add-configuration
           '(article (frame 1.0
                            (summary 1.0 point frame-focus)
                            (article 1.0)))))
2. C-j
3. M-x gnus RET
4. s          [session only]
5. ^          [gnus-group-enter-server-mode]
6. n          [goto nntp:news.gwene.org]
7. RET        [gnus-server-read-server]
8. C-s gmane.emacs.devel RET
9. u          [gnus-browse-unsubscribe-current-group]
10. q         [gnus-browse-exit]
11. q         [gnus-server-exit]
12. RET 1 RET [gnus-group-select-group]
13. TAB       [gnus-summary-widget-forward]

Debugger entered--Lisp error: (wrong-type-argument window-live-p nil)
  select-window(nil)
  gnus-summary-widget-forward(1)
  funcall-interactively(gnus-summary-widget-forward 1)
  call-interactively(gnus-summary-widget-forward nil nil)
  command-execute(gnus-summary-widget-forward)

Is it okay to push the attached fix, which additionally simplifies the
subroutine gnus-get-buffer-window used by the two commands?

Thanks,

-- 
Basil

Gnus v5.13
In GNU Emacs 27.0.50 (build 14, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2019-05-04 built on thunk
Repository revision: b5376e0ebd7b62f00c1b64aef87cd8d96cfbc71a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description: Debian GNU/Linux buster/sid