GNU bug report logs -
#71616
switch-to-buffer behaves inconsistently when switch-to-buffer-obey-display-actions is t and nil .
Previous Next
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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 71616 in the body.
You can then email your comments to 71616 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71616
; Package
emacs
.
(Mon, 17 Jun 2024 18:18:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Siyuan Chen <chansey97 <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 17 Jun 2024 18:18:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (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 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71616
; Package
emacs
.
(Mon, 17 Jun 2024 18:37:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 71616 <at> debbugs.gnu.org (full text, mbox):
> 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.
I confirm this in Emacs 30. Maybe Martin could suggest how to fix this.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71616
; Package
emacs
.
(Wed, 19 Jun 2024 09:38:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 71616 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> ## 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.
>
> I confirm this in Emacs 30. Maybe Martin could suggest how to fix
>> this.
A recipe without involving a file is
1. M-: (setq switch-to-buffer-obey-display-actions t)
2. C-x b *Messages*
3. C-x b *scratch*
4. Move point
5. C-x b *scratch*
In step 2 we record the point of *scratch*. In 5 we go there because
the 'set-window-buffer' called by C-x b decides that the window already
shows buffer and does not record its current position. I attach a patch
that should fix this and the original scenario. It does _not_ fix the
case where instead of C-x b plain 'set-window-buffer' is used. If we
wanted to fix that, we'd have to call 'record-window-buffer' from there
even when the old and the new buffer are the same. I'm not sure whether
we want to do that.
martin
[switch-to-buffer-obey-display-actions.diff (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71616
; Package
emacs
.
(Sun, 23 Jun 2024 05:46:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 71616 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This patch fixed my original use case, which did not touch
'set-window-buffer'.
Thanks.
Best regards,
Siyuan Chen
On Wed, Jun 19, 2024 at 5:37 PM martin rudalics <rudalics <at> gmx.at> wrote:
> >> ## 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.
> >
> > I confirm this in Emacs 30. Maybe Martin could suggest how to fix
> >> this.
>
> A recipe without involving a file is
>
> 1. M-: (setq switch-to-buffer-obey-display-actions t)
> 2. C-x b *Messages*
> 3. C-x b *scratch*
> 4. Move point
> 5. C-x b *scratch*
>
> In step 2 we record the point of *scratch*. In 5 we go there because
> the 'set-window-buffer' called by C-x b decides that the window already
> shows buffer and does not record its current position. I attach a patch
> that should fix this and the original scenario. It does _not_ fix the
> case where instead of C-x b plain 'set-window-buffer' is used. If we
> wanted to fix that, we'd have to call 'record-window-buffer' from there
> even when the old and the new buffer are the same. I'm not sure whether
> we want to do that.
>
> martin
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71616
; Package
emacs
.
(Sun, 23 Jun 2024 08:40:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 71616 <at> debbugs.gnu.org (full text, mbox):
> 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.
Thanks, martin
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sat, 06 Jul 2024 07:42:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Siyuan Chen <chansey97 <at> gmail.com>
:
bug acknowledged by developer.
(Sat, 06 Jul 2024 07:42:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 71616-done <at> debbugs.gnu.org (full text, mbox):
> 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.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 03 Aug 2024 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 222 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.