Subject: bug#67993: Selecting buffer automatically

From: Juri Linkov <[email-masked]>
Date: Wed, 10 Jan 2024 19:12:50 +0200

>>> That's why any such 'select-window' call (or its avoidance) you
>>> propose would be better handled within 'display-buffer' and not later
>>> in a 'post-command-hook'.
>>
>> No way to call 'select-window' immediately, because this will
>> break too many functions that expect a window to be selected
>> from the previous call of pop-to-buffer until the command
>> is finished.
>
> Do you mean that if I have two 'pop-to-buffer' calls within one and the
> same command, the first one has a (select-window . nil) entry and the
> second one no such entry, then the entry from the first call will cause
> the window from the second call to get deselected?  If so, then this
> deserves a special explanation in the manual.

This is what I see with the current patch:

1.
(let ((display-buffer-alist '(("1" nil (select-window . nil)))))
  (delete-other-windows) (split-window) (split-window) (balance-windows)
  (pop-to-buffer (get-buffer-create "1"))
  (pop-to-buffer (get-buffer-create "2")))

then the original window remains selected.

2.
(let ((display-buffer-alist '(("2" nil (select-window . nil)))))
  (delete-other-windows) (split-window) (split-window) (balance-windows)
  (pop-to-buffer (get-buffer-create "1"))
  (pop-to-buffer (get-buffer-create "2")))

then the window with "1" is selected after the command finishes.