Subject: bug#70819: 29.3; clone-indirect-buffer-other-window is inconsistent with *-other-window commands

From: Eli Zaretskii <[email-masked]>
Date: Sat, 11 May 2024 12:29:26 +0300

> From: Richard Sent <[email-masked]>
> Date: Tue, 07 May 2024 12:19:27 -0400
> 
> clone-indirect-buffer-other-window does not match the behavior
> *-other-window commands (e.g. find-file-other-window).
> 
> find-file-other-window calls switch-to-buffer-other-window, which
> ensures that the new file /always/ appears in a different window than
> the current one.
> 
> clone-indirect-buffer-other-window insteads wraps clone-indirect-buffer
> in a (pop-up-windows t) binding, which (somehow) results in different
> behavior. Depending on the value of display-buffer-alist, the "other
> window" can in fact be the active window, making
> clone-indirect-buffer-other-window behave indentically to
> clone-indirect-buffer.
> 
> This can be reproduced with Emacs -Q and the minimal config:
> 
> --8<---------------cut here---------------start------------->8---
> (add-to-list 'display-buffer-alist
>                '(".*"
>                  (display-buffer-reuse-window display-buffer-same-window))
>                ;; Append so default behavior is lowest priority
>                t)
> --8<---------------cut here---------------end--------------->8---
> 
> The convention with *-other-window commands is to, well, run * and
> display in another window, regardless of the settings in
> display-buffer-alist. switch-to-buffer-other-window is another example
> of a command that follows the expected behavior, even though it follows
> a similar pattern to clone-indirect-buffer-other-window (wrap a command
> in (pop-up-windows t)).
> 
> As a possible solution I found that this replacement for
> clone-indirect-buffer-other-window behaves as expected:
> 
> --8<---------------cut here---------------start------------->8---
> (defun my-clone-indirect-buffer-other-window (newname display-flag &optional norecord)
>   "Like `clone-indirect-buffer' but display in another window."
>   (interactive
>    (progn
>      (if (get major-mode 'no-clone-indirect)
> 	 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
>      (list (if current-prefix-arg
> 	       (read-buffer "Name of indirect buffer: " (current-buffer)))
> 	   t)))
>   (switch-to-buffer-other-window
>    (clone-indirect-buffer newname display-flag norecord)))
> --8<---------------cut here---------------end--------------->8---

Martin, any comments?

Adding also Stefan, in case he wants to comment.