Subject: Re: bug#63455: 30.0.50; display-buffer-in-direction is always resizing

From: martin rudalics <[email-masked]>
Date: Sat, 13 May 2023 10:56:16 +0200

> 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