GNU bug report logs - #71616
switch-to-buffer behaves inconsistently when switch-to-buffer-obey-display-actions is t and nil .

Previous Next

Package: emacs;

Reported by: Siyuan Chen <chansey97 <at> gmail.com>

Date: Mon, 17 Jun 2024 18:18:01 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Siyuan Chen <chansey97 <at> gmail.com>
Subject: bug#71616: closed (Re: bug#71616: switch-to-buffer behaves
 inconsistently when switch-to-buffer-obey-display-actions is t and nil .)
Date: Sat, 06 Jul 2024 07:42:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#71616: switch-to-buffer behaves inconsistently when switch-to-buffer-obey-display-actions is t and nil .

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 71616 <at> debbugs.gnu.org.

-- 
71616: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71616
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 71616-done <at> debbugs.gnu.org, chansey97 <at> gmail.com, juri <at> linkov.net
Subject: Re: bug#71616: switch-to-buffer behaves inconsistently when
 switch-to-buffer-obey-display-actions is t and nil .
Date: Sat, 06 Jul 2024 10:41:26 +0300
> Cc: 71616 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>
> Date: Sun, 23 Jun 2024 10:39:37 +0200
> From:  martin rudalics via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
>  > This patch fixed my original use case, which did not touch
>  > 'set-window-buffer'.
> 
> Pushed to master.  The 'set-window-buffer' scenario is not likely to
> cause any harm unless someone uses it in combination with
> 'set-window-start-and-point' from a previous buffer entry of that window
> in which case the author will have to do the same thing I did.
> 
> Please consider closing this bug if you see no further problems.

No further comments in 2 weeks, so I'm now closing this bug.

Thanks.

[Message part 3 (message/rfc822, inline)]
From: Siyuan Chen <chansey97 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: switch-to-buffer behaves inconsistently when
 switch-to-buffer-obey-display-actions is t and nil .
Date: Tue, 18 Jun 2024 02:14:52 +0800
[Message part 4 (text/plain, inline)]
Hi,

Recently I found a strange behavior about `switch-to-buffer' when
`switch-to-buffer-obey-display-actions' is t.

At the moment, by default, `switch-to-buffer-obey-display-actions' is set
as nil, so `switch-to-buffer' does not be affected by some display-buffer
options, such as `display-buffer-overriding-action',
`display-buffer-alist', etc.

However, if `switch-to-buffer-obey-display-actions' is t,
 `switch-to-buffer' can adapt these display-buffer options. This feature
was introduced by the commit 3f36651c6470bab951f12f486eb4928235f1ba50 and
the implementation is to call `pop-to-buffer-same-window' inside
`switch-to-buffer'.

More details, see
bug#32790
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=3f36651c6470bab951f12f486eb4928235f1ba50
https://mail.gnu.org/archive/html/bug-gnu-emacs/2018-11/msg00962.html

The problem is that the `switch-to-buffer' also obeys
`switch-to-buffer-preserve-window-point' while `pop-to-buffer-same-window'
doesn't. Therefore this new feature has to be compatible with
`switch-to-buffer-preserve-window-point' too. This has been implemented in
that commit but not quite right IMHO.

Let's examine the different behaviors when
`switch-to-buffer-obey-display-actions' is nil and t in `switch-to-buffer':

- When `switch-to-buffer-obey-display-actions' is nil,
`switch-to-buffer-preserve-window-point' is t (or nil, no matter actually)
and `(eq buffer (window-buffer))`, the `switch-to-buffer' will do nothing.

- When `switch-to-buffer-obey-display-actions' is t and
`switch-to-buffer-preserve-window-point' is t, `switch-to-buffer' will set
window-point if the target window is the same as the current window (yep,
that is the switch semantics). However, it does not consider what happens
when the target buffer is the same as the current buffer, just like `(eq
buffer (window-buffer))` in the 1st situation!

BTW the `switch-to-buffer-preserve-window-point' docs is a bit confusion:

> This variable is ignored if the buffer is already displayed in
> the selected window or never appeared in it before, or if
> ‘switch-to-buffer’ calls ‘pop-to-buffer’ to display the buffer,
> or non-nil ‘switch-to-buffer-obey-display-actions’ displays it
> in another window.

It doesn't mention what happens if non-nil
‘switch-to-buffer-obey-display-actions’ displays it in the same window with
the buffer that is already displayed. I also don't know whether the
sentence i.e. "if the buffer is already displayed in the selected window"
includes ‘switch-to-buffer-obey-display-actions’ is t.

The following are the minimal steps to reproduce.

## Test with default settings:

1. Emacs -Q

2. Open a .el file, e.g. window.el, and keep the cursor location at 1

3. Click buffers menu -> *scratch* to switch buffer

4. Click buffers menu -> window.el to switch buffer back

5. Move the current location to L24

6. M-x switch-to-buffer window.el

The result is that the buffer and window state keeps original, everything
is fine.

## Test with switch-to-buffer-obey-display-actions = t

1. Emacs -Q

2. M-x eval-expression (setq switch-to-buffer-obey-display-actions t)

2. Open a .el file, e.g. window.el, and keep the cursor location at 1

3. Click buffers menu -> *scratch* to switch buffer

4. Click buffers menu -> window.el to switch buffer back

5. Move the current location to L24

6. M-x switch-to-buffer window.el

The result is that the current cursor location jumps to location at 1!

This inconsistent behavior convinced me that this is a bug.

Emacs 29.3 on Window.

Thanks.

Best regards,

Siyuan Chen
[Message part 5 (text/html, inline)]

This bug report was last modified 323 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.