Subject: bug#70213: Info-mode side window fit-window-to-buffer issue

From: Joseph Turner <[email-masked]>
Date: Fri, 05 Apr 2024 18:34:11 -0700

Stephen Berman <[email-masked]> writes:

> On Fri, 05 Apr 2024 14:58:27 -0700 Joseph Turner <[email-masked]> wrote:
>
>> Stephen Berman <[email-masked]> writes:
>>> FWIW, I get the expected result with your recipe on master (GNU/Linux,
>>> Gtk3; I don't have emacs-29 at hand to test).
>>
>> According to the issue that Juri linked to (bug#68081), this issue was
>> resolved on master.
>
> Yes, I saw Juri's post after I sent mine; I had missed that bug report.
>
>>                      Was your Emacs build since January 6 (since
>> d3a4fe5694f7bd1a09546d67d2cddc0f444d41ca )?
>
> Yep, I'm currently at
> 09f381d70d8..: Michael Albinus 2024-03-31 Fix wildcard signals in dbusbind.c

The attached patch fixes this issue, but more would need to be done for
fit-window-to-buffer to be a meaningful value in display-buffer-alist,
since navigating between info nodes doesn't cause the window to resize.

>From f8a2584e3927c149eb2b008de5cb27fb148f08e1 Mon Sep 17 00:00:00 2001
From: Joseph Turner <[email-masked]>
Date: Fri, 5 Apr 2024 18:32:36 -0700
Subject: [PATCH] Display buffer after ensuring it contains text

* lisp/info.el (info-pop-to-buffer):

bug#70213
---
 lisp/info.el | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/lisp/info.el b/lisp/info.el
index 1e478cdbee9..fe134161af4 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -807,30 +807,28 @@ info-pop-to-buffer
 		  (get-buffer-create "*info*")))))
     (with-current-buffer buffer
       (unless (derived-mode-p 'Info-mode)
-	(Info-mode)))
+	(Info-mode))
+
+      (if file-or-node
+	  ;; If argument already contains parentheses, don't add another set
+	  ;; since the argument will then be parsed improperly.  This also
+	  ;; has the added benefit of allowing node names to be included
+	  ;; following the parenthesized filename.
+	  (Info-goto-node
+	   (if (and (stringp file-or-node) (string-match "(.*)" file-or-node))
+	       file-or-node
+             (concat "(" file-or-node ")")))
+	(if (and (zerop (buffer-size))
+		 (null Info-history))
+	    ;; If we just created the Info buffer, go to the directory.
+	    (Info-directory))))
+
+    (when-let ((window (display-buffer buffer
+			               (if other-window
+				           '(nil (inhibit-same-window . t))
+			                 '(display-buffer-same-window)))))
+      (select-window window))))
 
-    (let* ((window
-	    (display-buffer buffer
-			    (if other-window
-				'(nil (inhibit-same-window . t))
-			      '(display-buffer-same-window)))))
-      (with-current-buffer buffer
-	(if file-or-node
-	    ;; If argument already contains parentheses, don't add another set
-	    ;; since the argument will then be parsed improperly.  This also
-	    ;; has the added benefit of allowing node names to be included
-	    ;; following the parenthesized filename.
-	    (Info-goto-node
-	     (if (and (stringp file-or-node) (string-match "(.*)" file-or-node))
-		 file-or-node
-               (concat "(" file-or-node ")")))
-	  (if (and (zerop (buffer-size))
-		   (null Info-history))
-	      ;; If we just created the Info buffer, go to the directory.
-	      (Info-directory))))
-
-      (when window
-	(select-window window)))))
 
 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
 ;;;###autoload
-- 
2.41.0