unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
@ 2023-05-12  1:06 Michael Heerdegen
  2023-05-12  7:39 ` martin rudalics
  2023-05-12 17:11 ` Juri Linkov
  0 siblings, 2 replies; 21+ messages in thread
From: Michael Heerdegen @ 2023-05-12  1:06 UTC (permalink / raw)
  To: 63455; +Cc: rudalics, juri, dgutov


X-Debbugs-CC: rudalics@gmx.at, juri@linkov.net, dgutov@yandex.ru

Hello,

(info "(elisp) Buffer Display Action Alists") says near the end:

|    If no ‘window-height’, ‘window-width’ or ‘window-size’ entry was
| specified, the window may still be resized automatically when the buffer
| is temporary and ‘temp-buffer-resize-mode’ has been enabled, *note
| Temporary Displays::.  In that case, the CDR of a ‘window-height’,
| ‘window-width’ or ‘window-size’ entry can be used to inhibit or override
| the default behavior of ‘temp-buffer-resize-mode’ for specific buffers
| or invocations of ‘display-buffer’.

OTOH, the action `display-buffer-in-direction' _always_ resizes the
window no matter what buffer is current.  Try e.g.

#+begin_src emacs-lisp
(display-buffer (current-buffer)
               '((display-buffer-in-direction) . ((direction . top))))
#+end_src

from any window or buffer.

This is handled by this part of the implementation of
`display-buffer-in-direction':

#+begin_src emacs-lisp
	(setq alist
	      (append alist
		      `(,(if temp-buffer-resize-mode
		             '(window-height . resize-temp-buffer-window)
	                   '(window-height . fit-window-to-buffer))
	                ,(when temp-buffer-resize-mode
	                   '(preserve-size . (nil . t))))))
#+end_src

Looking at that it doesn't seem to be intended as a general behavior,
and the behavior is not a good default IMO - even if it can be
suppressed by adding a (window-height . nil) entry to the
`display-buffer' call.

I guess that Bug#45945 could be a symptom of this problem.


TIA,

Michael.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-12  1:06 bug#63455: 30.0.50; display-buffer-in-direction is always resizing Michael Heerdegen
@ 2023-05-12  7:39 ` martin rudalics
  2023-05-12 17:16   ` Juri Linkov
  2023-05-17 16:56   ` Juri Linkov
  2023-05-12 17:11 ` Juri Linkov
  1 sibling, 2 replies; 21+ messages in thread
From: martin rudalics @ 2023-05-12  7:39 UTC (permalink / raw)
  To: Michael Heerdegen, 63455; +Cc: dgutov, juri

 > OTOH, the action `display-buffer-in-direction' _always_ resizes the
 > window no matter what buffer is current.  Try e.g.
 >
 > #+begin_src emacs-lisp
 > (display-buffer (current-buffer)
 >                 '((display-buffer-in-direction) . ((direction . top))))
 > #+end_src
 >
 > from any window or buffer.
 >
 > This is handled by this part of the implementation of
 > `display-buffer-in-direction':
 >
 > #+begin_src emacs-lisp
 > 	(setq alist
 > 	      (append alist
 > 		      `(,(if temp-buffer-resize-mode
 > 		             '(window-height . resize-temp-buffer-window)
 > 	                   '(window-height . fit-window-to-buffer))
 > 	                ,(when temp-buffer-resize-mode
 > 	                   '(preserve-size . (nil . t))))))
 > #+end_src
 >
 > Looking at that it doesn't seem to be intended as a general behavior,
 > and the behavior is not a good default IMO - even if it can be
 > suppressed by adding a (window-height . nil) entry to the
 > `display-buffer' call.
 >
 > I guess that Bug#45945 could be a symptom of this problem.

I think you're right.  In my local Emacs I removed both incarnations of
that code (the other one being in 'display-buffer--maybe-at-bottom')
long ago.  I can only shortly sketch how I manage things here: The end
of 'help--window-setup' has become

         (help-window-setup
          (setq window (temp-buffer-window-show (current-buffer) nil t)))
         (help-make-xrefs (current-buffer))
	(when (and window temp-buffer-resize-mode)
           (let (resize-temp-buffer-window-inhibit)
             (resize-temp-buffer-window window)))))))

'temp-buffer-window-show' has a third argument NO-RESIZE and its last
lines are rewritten as

	(with-selected-window window
	  (run-hooks 'temp-buffer-window-show-hook)
	  (when (and (not no-resize) temp-buffer-resize-mode)
	    (resize-temp-buffer-window window)))
	;; Return the window.
	window))))

Maybe Juri can make heads or tails of this.

martin





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-12  1:06 bug#63455: 30.0.50; display-buffer-in-direction is always resizing Michael Heerdegen
  2023-05-12  7:39 ` martin rudalics
@ 2023-05-12 17:11 ` Juri Linkov
  2023-05-13  5:29   ` Michael Heerdegen
  1 sibling, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-12 17:11 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: rudalics, 63455, dgutov

> #+begin_src emacs-lisp
> 	(setq alist
> 	      (append alist
> 		      `(,(if temp-buffer-resize-mode
> 		             '(window-height . resize-temp-buffer-window)
> 	                   '(window-height . fit-window-to-buffer))
> 	                ,(when temp-buffer-resize-mode
> 	                   '(preserve-size . (nil . t))))))
> #+end_src
>
> Looking at that it doesn't seem to be intended as a general behavior,
> and the behavior is not a good default IMO - even if it can be
> suppressed by adding a (window-height . nil) entry to the
> `display-buffer' call.
>
> I guess that Bug#45945 could be a symptom of this problem.

Indeed, an unusual default.  Is it possible to change this default now
given there is code that might rely on it already?

In the Emacs source tree most of calls already override the default:
're-builder', 'proced-with-processes-buffer', 'widget-choose',
'xref-show-definitions-buffer-at-bottom' (fixed in bug#45945 as you noted).

But 'ediff-setup-windows-plain-compare' uses the current default.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-12  7:39 ` martin rudalics
@ 2023-05-12 17:16   ` Juri Linkov
  2023-05-13  8:56     ` martin rudalics
  2023-05-17 16:56   ` Juri Linkov
  1 sibling, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-12 17:16 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

> I think you're right.  In my local Emacs I removed both incarnations of
> that code (the other one being in 'display-buffer--maybe-at-bottom')
> long ago.

There are 3 uses of 'display-buffer--maybe-at-bottom' in the Emacs
source tree: 'project-kill-buffers' and 'save-buffers-kill-emacs'
override the default.  But 'hack-local-variables-confirm'
depends on the current default value.

> I can only shortly sketch how I manage things here: The end
> of 'help--window-setup' has become
>
>         (help-window-setup
>          (setq window (temp-buffer-window-show (current-buffer) nil t)))
>         (help-make-xrefs (current-buffer))
> 	(when (and window temp-buffer-resize-mode)
>           (let (resize-temp-buffer-window-inhibit)
>             (resize-temp-buffer-window window)))))))
>
> 'temp-buffer-window-show' has a third argument NO-RESIZE and its last
> lines are rewritten as
>
> 	(with-selected-window window
> 	  (run-hooks 'temp-buffer-window-show-hook)
> 	  (when (and (not no-resize) temp-buffer-resize-mode)
> 	    (resize-temp-buffer-window window)))
> 	;; Return the window.
> 	window))))
>
> Maybe Juri can make heads or tails of this.

Are these changes intended to completely remove these lines from
'display-buffer-in-direction' and 'display-buffer--maybe-at-bottom'?

		      `(,(if temp-buffer-resize-mode
		             '(window-height . resize-temp-buffer-window)
	                   '(window-height . fit-window-to-buffer))
	                ,(when temp-buffer-resize-mode
	                   '(preserve-size . (nil . t))))

I expected that only 1 line should be removed to change this to:

		      `(,(when temp-buffer-resize-mode
		           '(window-height . resize-temp-buffer-window))
	                ,(when temp-buffer-resize-mode
	                   '(preserve-size . (nil . t))))

But if all lines should be removed, then how to use it?
I tried with your patch, but this doesn't resize the window:

(setq temp-buffer-resize-mode t)
(display-buffer (current-buffer)
		'((display-buffer-in-direction) . ((direction . top))))





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-12 17:11 ` Juri Linkov
@ 2023-05-13  5:29   ` Michael Heerdegen
  2023-05-15 17:02     ` Juri Linkov
  0 siblings, 1 reply; 21+ messages in thread
From: Michael Heerdegen @ 2023-05-13  5:29 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rudalics, 63455, dgutov

Juri Linkov <juri@linkov.net> writes:

> Indeed, an unusual default.  Is it possible to change this default now
> given there is code that might rely on it already?

I don't know, but the alternative is to live with a confusingly
inconsistent behavior.  Code relying on that behavior relies on
something undocumented.

The only other alternative I see is to provide the documented behavior
under a new name.  We could in addition rename the current defun to
something containing "--temp" and keep the old name as an obsolete
alias.

Michael.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-12 17:16   ` Juri Linkov
@ 2023-05-13  8:56     ` martin rudalics
  2023-05-15 17:01       ` Juri Linkov
  0 siblings, 1 reply; 21+ messages in thread
From: martin rudalics @ 2023-05-13  8:56 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Michael Heerdegen, 63455, dgutov

 > There are 3 uses of 'display-buffer--maybe-at-bottom' in the Emacs
 > source tree: 'project-kill-buffers' and 'save-buffers-kill-emacs'
 > override the default.  But 'hack-local-variables-confirm'
 > depends on the current default value.

In 'hack-local-variables-confirm' I'm using

	(pop-to-buffer
          buf '(display-buffer--maybe-at-bottom
                (window-height . (fit-window-to-buffer))))

 > Are these changes intended to completely remove these lines from
 > 'display-buffer-in-direction' and 'display-buffer--maybe-at-bottom'?
 >
 > 		      `(,(if temp-buffer-resize-mode
 > 		             '(window-height . resize-temp-buffer-window)
 > 	                   '(window-height . fit-window-to-buffer))
 > 	                ,(when temp-buffer-resize-mode
 > 	                   '(preserve-size . (nil . t))))

Yes.

 > I expected that only 1 line should be removed to change this to:
 >
 > 		      `(,(when temp-buffer-resize-mode
 > 		           '(window-height . resize-temp-buffer-window))
 > 	                ,(when temp-buffer-resize-mode
 > 	                   '(preserve-size . (nil . t))))

That wouldn't help.  Try with

(defun display-buffer--maybe-at-bottom (buffer alist)
   (let ((alist (append alist `(,(when temp-buffer-resize-mode
		                  '(window-height . resize-temp-buffer-window))
	                       ,(when temp-buffer-resize-mode
	                          '(preserve-size . (nil . t)))))))
     (or (display-buffer--maybe-same-window buffer alist)
         (display-buffer-reuse-window buffer alist)
         (display-buffer--maybe-pop-up-frame buffer alist)
         (display-buffer-at-bottom buffer alist))))

(setq temp-buffer-resize-mode t)

(pop-to-buffer (get-buffer-create "*foo*")
	       '(display-buffer--maybe-at-bottom))

'temp-buffer-resize-mode' is a global variable.  Once a user customized
it to t, _any_ buffer that passes through one of these functions will be
resized, regardless of whether it is a temporary buffer or an "ordinary"
one.

 > But if all lines should be removed, then how to use it?
 > I tried with your patch, but this doesn't resize the window:
 >
 > (setq temp-buffer-resize-mode t)
 > (display-buffer (current-buffer)
 > 		'((display-buffer-in-direction) . ((direction . top))))

Right.  You can use, for example,

(setq temp-buffer-resize-mode t)
(temp-buffer-window-show (current-buffer)
		 '((display-buffer-in-direction) . ((direction . top))))

which obviously makes the current buffer temporary with all its
consequences.  But 'temp-buffer-resize-mode' _is_ about temporary
buffers.

Note that when 'temp-buffer-resize-mode' is set, the way Emacs handles
this currently is wrong for _two_ reasons:

- When 'display-buffer' calls one of these functions it will resize the
   window regardless of whether it should be resized or not - that's the
   subject of the present bug.

- When the user customizes 'display-buffer-alist' to call another
   display action, say 'display-buffer-below-selected', the window will
   not be resized.   Try without and with the first form evaluated:

   (setq display-buffer-alist
	'(("*foo*" display-buffer-below-selected)))

   (pop-to-buffer (get-buffer-create "*foo*")
		 '(display-buffer--maybe-at-bottom))

We could add a buffer-local variable say 'temporary' which the temporary
buffer functions would set and 'display-buffer' would always obey in
conjunction with 'temp-buffer-resize-mode'.  Then a program or the user
could set or reset that variable to obtain the desired behavior with
plain 'display-buffer' calls as well.  Whether such an option is clean
is another question.

martin





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-13  8:56     ` martin rudalics
@ 2023-05-15 17:01       ` Juri Linkov
  2023-05-15 18:21         ` Eli Zaretskii
  2023-05-16  7:19         ` martin rudalics
  0 siblings, 2 replies; 21+ messages in thread
From: Juri Linkov @ 2023-05-15 17:01 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

> - When the user customizes 'display-buffer-alist' to call another
>   display action, say 'display-buffer-below-selected', the window will
>   not be resized.   Try without and with the first form evaluated:
>
>   (setq display-buffer-alist
> 	'(("*foo*" display-buffer-below-selected)))
>
>   (pop-to-buffer (get-buffer-create "*foo*")
> 		 '(display-buffer--maybe-at-bottom))

I tried with your patch, and it works correctly.  I guess
this change is for master, not the release branch?

> We could add a buffer-local variable say 'temporary' which the temporary
> buffer functions would set and 'display-buffer' would always obey in
> conjunction with 'temp-buffer-resize-mode'.  Then a program or the user
> could set or reset that variable to obtain the desired behavior with
> plain 'display-buffer' calls as well.  Whether such an option is clean
> is another question.

Maybe temporary buffers should resize windows by default?
Then such an option should be able to override the default behavior.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-13  5:29   ` Michael Heerdegen
@ 2023-05-15 17:02     ` Juri Linkov
  0 siblings, 0 replies; 21+ messages in thread
From: Juri Linkov @ 2023-05-15 17:02 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: rudalics, 63455, dgutov

>> Indeed, an unusual default.  Is it possible to change this default now
>> given there is code that might rely on it already?
>
> I don't know, but the alternative is to live with a confusingly
> inconsistent behavior.  Code relying on that behavior relies on
> something undocumented.

Agreed that better to make this consistent.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-15 17:01       ` Juri Linkov
@ 2023-05-15 18:21         ` Eli Zaretskii
  2023-05-16  7:19         ` martin rudalics
  1 sibling, 0 replies; 21+ messages in thread
From: Eli Zaretskii @ 2023-05-15 18:21 UTC (permalink / raw)
  To: Juri Linkov; +Cc: michael_heerdegen, rudalics, 63455, dgutov

> Cc: Michael Heerdegen <michael_heerdegen@web.de>, 63455@debbugs.gnu.org,
>  dgutov@yandex.ru
> From: Juri Linkov <juri@linkov.net>
> Date: Mon, 15 May 2023 20:01:49 +0300
> 
> > - When the user customizes 'display-buffer-alist' to call another
> >   display action, say 'display-buffer-below-selected', the window will
> >   not be resized.   Try without and with the first form evaluated:
> >
> >   (setq display-buffer-alist
> > 	'(("*foo*" display-buffer-below-selected)))
> >
> >   (pop-to-buffer (get-buffer-create "*foo*")
> > 		 '(display-buffer--maybe-at-bottom))
> 
> I tried with your patch, and it works correctly.  I guess
> this change is for master, not the release branch?

The release branch should now accept only very simple and safe fixes
or very urgent ones for grave problems.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-15 17:01       ` Juri Linkov
  2023-05-15 18:21         ` Eli Zaretskii
@ 2023-05-16  7:19         ` martin rudalics
  2023-05-16 16:35           ` Juri Linkov
  1 sibling, 1 reply; 21+ messages in thread
From: martin rudalics @ 2023-05-16  7:19 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Michael Heerdegen, 63455, dgutov

 > Maybe temporary buffers should resize windows by default?
 > Then such an option should be able to override the default behavior.

We could write a function similar to 'completions--fit-window-to-buffer'
(do you know what the &rest _ args there are used for?) like

(defun maybe-fit-window-to-buffer (&optional window)
   "Fit WINDOW to buffer if 'temp-buffer-resize-mode' is on."
   (when temp-buffer-resize-mode
     (resize-temp-buffer-window window)))

and use that in all occasions where we want to resize a window outside
the scope of 'with-temp-buffer-window' when 'temp-buffer-resize-mode'
was turned on by the user (leaving alone the behavior of the earlier
mentioned 're-builder' etc. which apparently work without complaints).

martin






^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-16  7:19         ` martin rudalics
@ 2023-05-16 16:35           ` Juri Linkov
  0 siblings, 0 replies; 21+ messages in thread
From: Juri Linkov @ 2023-05-16 16:35 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

> We could write a function similar to 'completions--fit-window-to-buffer'
> (do you know what the &rest _ args there are used for?) like

Looks like the &rest _ args is defensive programming.

> (defun maybe-fit-window-to-buffer (&optional window)
>   "Fit WINDOW to buffer if 'temp-buffer-resize-mode' is on."
>   (when temp-buffer-resize-mode
>     (resize-temp-buffer-window window)))
>
> and use that in all occasions where we want to resize a window outside
> the scope of 'with-temp-buffer-window' when 'temp-buffer-resize-mode'
> was turned on by the user (leaving alone the behavior of the earlier
> mentioned 're-builder' etc. which apparently work without complaints).

This helper could be useful.  Maybe it should be added
when such need arises.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-12  7:39 ` martin rudalics
  2023-05-12 17:16   ` Juri Linkov
@ 2023-05-17 16:56   ` Juri Linkov
  2023-05-18  8:29     ` martin rudalics
  1 sibling, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-17 16:56 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]

> 'temp-buffer-window-show' has a third argument NO-RESIZE and its last
> lines are rewritten as
>
> 	(with-selected-window window
> 	  (run-hooks 'temp-buffer-window-show-hook)
> 	  (when (and (not no-resize) temp-buffer-resize-mode)
> 	    (resize-temp-buffer-window window)))
> 	;; Return the window.
> 	window))))
>
> Maybe Juri can make heads or tails of this.

Does your complete patch look like this?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bug_63455.patch --]
[-- Type: text/x-diff, Size: 4422 bytes --]

diff --git a/lisp/files.el b/lisp/files.el
index 148f47cbc97..b3962145e79 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3772,7 +3772,8 @@ hack-local-variables-confirm
 
       ;; Display the buffer and read a choice.
       (save-window-excursion
-	(pop-to-buffer buf '(display-buffer--maybe-at-bottom))
+	(pop-to-buffer buf '(display-buffer--maybe-at-bottom
+			     (window-height . fit-window-to-buffer)))
 	(let* ((exit-chars '(?y ?n ?\s))
 	       (prompt (format "Please type %s%s: "
 			       (if offer-save
diff --git a/lisp/help.el b/lisp/help.el
index 6f55136049b..676c18f2411 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -2175,7 +2175,8 @@ help--window-setup
     (setq-local help-mode--current-data nil)
     (buffer-disable-undo)
     (let ((inhibit-read-only t)
-	  (inhibit-modification-hooks t))
+	  (inhibit-modification-hooks t)
+	  window)
       (erase-buffer)
       (delete-all-overlays)
       (prog1
@@ -2186,7 +2187,12 @@ help--window-setup
         (help-make-xrefs (current-buffer))
         ;; This must be done after the buffer has been completely
         ;; generated, since `temp-buffer-resize-mode' may be enabled.
-        (help-window-setup (temp-buffer-window-show (current-buffer)))))))
+        (help-window-setup
+         (setq window (temp-buffer-window-show (current-buffer) nil t)))
+        (help-make-xrefs (current-buffer))
+        (when (and window temp-buffer-resize-mode)
+          (let (resize-temp-buffer-window-inhibit)
+            (resize-temp-buffer-window window)))))))
 
 ;; Called from C, on encountering `help-char' when reading a char.
 ;; Don't print to *Help*; that would clobber Help history.
diff --git a/lisp/window.el b/lisp/window.el
index aa7520f30fa..b816d10298a 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -110,7 +110,7 @@ temp-buffer-window-setup
 ;; Defined in help.el.
 (defvar resize-temp-buffer-window-inhibit)
 
-(defun temp-buffer-window-show (buffer &optional action)
+(defun temp-buffer-window-show (buffer &optional action no-resize)
   "Show temporary buffer BUFFER in a window.
 Return the window showing BUFFER.  Pass ACTION as action argument
 to `display-buffer'."
@@ -139,7 +139,7 @@ temp-buffer-window-show
 	(set-window-hscroll window 0)
 	(with-selected-window window
 	  (run-hooks 'temp-buffer-window-show-hook)
-	  (when temp-buffer-resize-mode
+	  (when (and (not no-resize) temp-buffer-resize-mode)
 	    (resize-temp-buffer-window window)))
 	;; Return the window.
 	window))))
@@ -8300,14 +8305,6 @@ display-buffer-in-direction
 	 (t
 	  (setq direction 'below)))
 
-	(setq alist
-	      (append alist
-		      `(,(if temp-buffer-resize-mode
-		             '(window-height . resize-temp-buffer-window)
-	                   '(window-height . fit-window-to-buffer))
-	                ,(when temp-buffer-resize-mode
-	                   '(preserve-size . (nil . t))))))
-
 	(setq windows (windows-sharing-edge window direction within))
 	(dolist (other windows)
 	  (cond
@@ -8384,15 +8381,10 @@ display-buffer-below-selected
 	     (window--display-buffer buffer window 'reuse alist)))))
 
 (defun display-buffer--maybe-at-bottom (buffer alist)
-  (let ((alist (append alist `(,(if temp-buffer-resize-mode
-		                    '(window-height . resize-temp-buffer-window)
-	                          '(window-height . fit-window-to-buffer))
-	                       ,(when temp-buffer-resize-mode
-	                          '(preserve-size . (nil . t)))))))
-    (or (display-buffer--maybe-same-window buffer alist)
+  (or (display-buffer--maybe-same-window buffer alist)
         (display-buffer-reuse-window buffer alist)
         (display-buffer--maybe-pop-up-frame buffer alist)
-        (display-buffer-at-bottom buffer alist))))
+        (display-buffer-at-bottom buffer alist)))
 
 ;; This should be rewritten as
 ;; (display-buffer-in-direction buffer (cons '(direction . bottom) alist))
diff --git a/lisp/vc/ediff-wind.el b/lisp/vc/ediff-wind.el
index eb903f093f9..c6ce1b78e52 100644
--- a/lisp/vc/ediff-wind.el
+++ b/lisp/vc/ediff-wind.el
@@ -433,7 +433,8 @@ ediff-setup-windows-plain-compare
 
     (select-window (display-buffer-in-direction
                     control-buffer
-                    '((direction . bottom))))
+                    '((direction . bottom)
+                      (window-height . fit-window-to-buffer))))
     (ediff-setup-control-buffer control-buffer)
     ))
 

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-17 16:56   ` Juri Linkov
@ 2023-05-18  8:29     ` martin rudalics
  2023-05-18 15:54       ` Juri Linkov
  2023-05-19 17:54       ` Juri Linkov
  0 siblings, 2 replies; 21+ messages in thread
From: martin rudalics @ 2023-05-18  8:29 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Michael Heerdegen, 63455, dgutov

 > Does your complete patch look like this?

Almost (I had to make 'ediff-setup-windows-plain-compare' do what your
patch does).  But as I mentioned earlier, you might want to replace
'fit-window-to-buffer' with something conditioned on whether the user
has customized 'temp-buffer-resize-mode' - some users simply might not
want their windows to auto-resize.

martin





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-18  8:29     ` martin rudalics
@ 2023-05-18 15:54       ` Juri Linkov
  2023-05-19  7:31         ` martin rudalics
  2023-05-19 17:54       ` Juri Linkov
  1 sibling, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-18 15:54 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

>> Does your complete patch look like this?
>
> Almost (I had to make 'ediff-setup-windows-plain-compare' do what your
> patch does).  But as I mentioned earlier, you might want to replace
> 'fit-window-to-buffer' with something conditioned on whether the user
> has customized 'temp-buffer-resize-mode' - some users simply might not
> want their windows to auto-resize.

This function should be added instead of your changes in
help--window-setup and temp-buffer-window-show?





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-18 15:54       ` Juri Linkov
@ 2023-05-19  7:31         ` martin rudalics
  0 siblings, 0 replies; 21+ messages in thread
From: martin rudalics @ 2023-05-19  7:31 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Michael Heerdegen, 63455, dgutov

 > This function should be added instead of your changes in
 > help--window-setup and temp-buffer-window-show?

IIRC 'help--window-setup' wants us to (1) show the window via
'display-buffer' (2) call 'help-make-xrefs' which may change the buffer
size and (3) only then fit the window to the buffer, something "this
function" cannot accomplish.  BTW, this is a special case the NO-RESIZE
argument might not handle correctly in the queer case where a user has
'temp-buffer-resize-mode' enabled but does _not_ want to fit help
windows to their buffer and added a special rule for *Help* buffers.

So conceptually "this function" should be used only in functions like
'hack-local-variables-confirm' where we do something temporary buffer
likish without calling 'with-temp-buffer-window' explicitly.

martin





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-18  8:29     ` martin rudalics
  2023-05-18 15:54       ` Juri Linkov
@ 2023-05-19 17:54       ` Juri Linkov
  2023-05-20  8:27         ` martin rudalics
  1 sibling, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-19 17:54 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

>> Does your complete patch look like this?
>
> Almost (I had to make 'ediff-setup-windows-plain-compare' do what your
> patch does).  But as I mentioned earlier, you might want to replace
> 'fit-window-to-buffer' with something conditioned on whether the user
> has customized 'temp-buffer-resize-mode' - some users simply might not
> want their windows to auto-resize.

I still don't understand the need to add a new function.
When users don't want their windows to auto-resize,
then they can simply do:

(add-to-list 'display-buffer-alist
             '("*Help*" nil
               ;; Inhibit resizing Help buffers
               (window-height . nil)))





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-19 17:54       ` Juri Linkov
@ 2023-05-20  8:27         ` martin rudalics
  2023-05-22 18:03           ` Juri Linkov
  0 siblings, 1 reply; 21+ messages in thread
From: martin rudalics @ 2023-05-20  8:27 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Michael Heerdegen, 63455, dgutov

 >> Almost (I had to make 'ediff-setup-windows-plain-compare' do what your
 >> patch does).  But as I mentioned earlier, you might want to replace
 >> 'fit-window-to-buffer' with something conditioned on whether the user
 >> has customized 'temp-buffer-resize-mode' - some users simply might not
 >> want their windows to auto-resize.
 >
 > I still don't understand the need to add a new function.

The new function would serve, for example, in
'ediff-setup-windows-plain-compare'

     (select-window (display-buffer-in-direction
                     control-buffer
                     '((direction . bottom)
                       (window-height . fit-window-to-buffer))))

to make sure the window is fit iff 'temp-buffer-resize-mode' is enabled.

 > When users don't want their windows to auto-resize,
 > then they can simply do:
 >
 > (add-to-list 'display-buffer-alist
 >               '("*Help*" nil
 >                 ;; Inhibit resizing Help buffers
 >                 (window-height . nil)))

A user who has not set 'temp-buffer-resize-mode' does not want
auto-resizing to happen and probably does not want to deal with
'display-buffer-alist' either.

In either case, the new function is not relevant to your example.  That
setup doesn't work with 'temp-buffer-resize-mode' turned on because
'help--window-setup' ignores 'display-buffer-alist' when it does

         (when (and window temp-buffer-resize-mode)
           (let (resize-temp-buffer-window-inhibit)
             (resize-temp-buffer-window window)))))))

All this has become very contrived because of 'help-make-xrefs'.  I
suppose we have to (1) make 'temp-buffer-windo-show' return the function
'display-buffer' would have used to resize the window if NO-RESIZE had
allowed it to do so and (2) have 'help--window-setup' apply the return
value, if non-nil, to resize the window after calling 'help-make-xrefs'.
If worse comes to worst, 'help--window-setup' may have to investigate
the current value of 'resize-temp-buffer-window-inhibit' too ...

martin





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-20  8:27         ` martin rudalics
@ 2023-05-22 18:03           ` Juri Linkov
  2023-05-23  2:30             ` Michael Heerdegen
  0 siblings, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-22 18:03 UTC (permalink / raw)
  To: martin rudalics; +Cc: Michael Heerdegen, 63455, dgutov

>>> Almost (I had to make 'ediff-setup-windows-plain-compare' do what your
>>> patch does).  But as I mentioned earlier, you might want to replace
>>> 'fit-window-to-buffer' with something conditioned on whether the user
>>> has customized 'temp-buffer-resize-mode' - some users simply might not
>>> want their windows to auto-resize.
>>
>> I still don't understand the need to add a new function.
>
> The new function would serve, for example, in
> 'ediff-setup-windows-plain-compare'
>
>     (select-window (display-buffer-in-direction
>                     control-buffer
>                     '((direction . bottom)
>                       (window-height . fit-window-to-buffer))))
>
> to make sure the window is fit iff 'temp-buffer-resize-mode' is enabled.

Maybe a good name for the new function would be 'fit-window-to-temp-buffer'?





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-22 18:03           ` Juri Linkov
@ 2023-05-23  2:30             ` Michael Heerdegen
  2023-05-23 18:25               ` Juri Linkov
  0 siblings, 1 reply; 21+ messages in thread
From: Michael Heerdegen @ 2023-05-23  2:30 UTC (permalink / raw)
  To: Juri Linkov; +Cc: martin rudalics, 63455, dgutov

Juri Linkov <juri@linkov.net> writes:

> Maybe a good name for the new function would be
> 'fit-window-to-temp-buffer'?

Sorry to come up with this now, but: I think "temp-buffer" is a
misnomer here.  AFAIU it is used for *Help* buffers.  Those are not
more temporary than a lot of other buffers (doesn't the *Help* buffer
live more or less the whole session if you don't kill it?), and the way
Help buffers are displayed has not much or not only to do with how long
they live.

I always found that naming confusing.  It makes me think of
`with-temp-buffer', helper buffers, not of *Help*.  Do you find the
naming appropriate, having the use cases in mind?

Michael.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-23  2:30             ` Michael Heerdegen
@ 2023-05-23 18:25               ` Juri Linkov
  2023-05-24  2:48                 ` Michael Heerdegen
  0 siblings, 1 reply; 21+ messages in thread
From: Juri Linkov @ 2023-05-23 18:25 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: martin rudalics, 63455, dgutov

>> Maybe a good name for the new function would be
>> 'fit-window-to-temp-buffer'?
>
> Sorry to come up with this now, but: I think "temp-buffer" is a
> misnomer here.  AFAIU it is used for *Help* buffers.  Those are not
> more temporary than a lot of other buffers (doesn't the *Help* buffer
> live more or less the whole session if you don't kill it?), and the way
> Help buffers are displayed has not much or not only to do with how long
> they live.
>
> I always found that naming confusing.  It makes me think of
> `with-temp-buffer', helper buffers, not of *Help*.  Do you find the
> naming appropriate, having the use cases in mind?

According to (info "(emacs) Temporary Displays")
maybe a better name would be "view-buffer" because
it's intended for non-editable buffers.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#63455: 30.0.50; display-buffer-in-direction is always resizing
  2023-05-23 18:25               ` Juri Linkov
@ 2023-05-24  2:48                 ` Michael Heerdegen
  0 siblings, 0 replies; 21+ messages in thread
From: Michael Heerdegen @ 2023-05-24  2:48 UTC (permalink / raw)
  To: Juri Linkov; +Cc: martin rudalics, 63455, dgutov

Juri Linkov <juri@linkov.net> writes:

> > I always found that naming confusing.  It makes me think of
> > `with-temp-buffer', helper buffers, not of *Help*.  Do you find the
> > naming appropriate, having the use cases in mind?
>
> According to (info "(emacs) Temporary Displays")
> maybe a better name would be "view-buffer" because
> it's intended for non-editable buffers.

Hmm - I think that name sounds a bit too general to me.

I don't know - it's all a bit messy.

`with-output-to-temp-buffer' displays the buffer.  That's also a bit
surprising.

(info "(elisp) Temporary Displays") says:

 -- User Option: temp-buffer-show-function
     If this variable is non-‘nil’, ‘with-output-to-temp-buffer’ calls
     it as a function to do the job of displaying a help buffer.
                                                    ^^^^
The name "temp" is everywhere.  And it is, in the context of buffer
display (in the wider sense), more or less synonymous with "help
buffer" (in the wider sense again).

If it's too late to change all of the related names, maybe we should
describe the naming habits more explicitly so that it is less confusing
and more discoverable.

Michael.





^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-05-24  2:48 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12  1:06 bug#63455: 30.0.50; display-buffer-in-direction is always resizing Michael Heerdegen
2023-05-12  7:39 ` martin rudalics
2023-05-12 17:16   ` Juri Linkov
2023-05-13  8:56     ` martin rudalics
2023-05-15 17:01       ` Juri Linkov
2023-05-15 18:21         ` Eli Zaretskii
2023-05-16  7:19         ` martin rudalics
2023-05-16 16:35           ` Juri Linkov
2023-05-17 16:56   ` Juri Linkov
2023-05-18  8:29     ` martin rudalics
2023-05-18 15:54       ` Juri Linkov
2023-05-19  7:31         ` martin rudalics
2023-05-19 17:54       ` Juri Linkov
2023-05-20  8:27         ` martin rudalics
2023-05-22 18:03           ` Juri Linkov
2023-05-23  2:30             ` Michael Heerdegen
2023-05-23 18:25               ` Juri Linkov
2023-05-24  2:48                 ` Michael Heerdegen
2023-05-12 17:11 ` Juri Linkov
2023-05-13  5:29   ` Michael Heerdegen
2023-05-15 17:02     ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).