GNU bug report logs -
#73545
30.0.91; Strange behaviour on switch-to-next-buffer
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 73545 in the body.
You can then email your comments to 73545 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#73545
; Package
emacs
.
(Sun, 29 Sep 2024 04:27:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Rahul Martim Juliato <rahuljuliato <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 29 Sep 2024 04:27:02 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)]
Hello there!
I just wanted to report something I found a bit strange.
I would like some keybindings to jump to the next/previous *non-special*
buffer.
With these settings:
(setq switch-to-prev-buffer-skip-regexp "\*[^*]+\*")
(setq switch-to-next-buffer-skip-regexp "\*[^*]+\*")
I have the init.el file open, along with the Messages and scratch
buffers.
When I run (switch-to-next-buffer) or (switch-to-previous-buffer), I get
a special buffer. If I run it again, I return to the file, and running
it once more takes me to another special buffer.
If I open another file, like .bashrc, it works as I initially expected.
Now, (switch-to-next-buffer) switches to init.el, and running it again
returns me to init.el back and forth, without switching to any more
special buffers.
It seems that I need to have at least two non-special buffers open. With
only one, the switch function probably (I haven't checked) reaches the
end of the buffer list without finding a match and returns the last
buffer.
Should it work this way? If there are no matches, shouldn't it stay on
the current buffer and/or display a message like "no next/prev buffer"
in the echo area?
Thanks!
--
Rahul Martim Juliato
https://www.rahuljuliato.com
PGP Fingerprint: 6B68 4353 84E2 2C7E 5A26 B79A C666 FC94 BD7E A483
PGP Public Key : https://www.rahuljuliato.com/rahul_pub_key.asc
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73545
; Package
emacs
.
(Sun, 29 Sep 2024 06:25:03 GMT)
Full text and
rfc822 format available.
Message #8 received at 73545 <at> debbugs.gnu.org (full text, mbox):
> From: Rahul Martim Juliato <rahuljuliato <at> gmail.com>
> Date: Sun, 29 Sep 2024 01:25:21 -0300
>
> I just wanted to report something I found a bit strange.
>
> I would like some keybindings to jump to the next/previous *non-special*
> buffer.
>
> With these settings:
>
> (setq switch-to-prev-buffer-skip-regexp "\*[^*]+\*")
> (setq switch-to-next-buffer-skip-regexp "\*[^*]+\*")
>
> I have the init.el file open, along with the Messages and scratch
> buffers.
Did you forget to double the backslashes?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73545
; Package
emacs
.
(Sun, 29 Sep 2024 12:32:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 73545 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Sun, Sep 29, 2024 at 08:39:03AM +0300, Eli Zaretskii wrote:
> > From: Rahul Martim Juliato <rahuljuliato <at> gmail.com>
> > Date: Sun, 29 Sep 2024 01:25:21 -0300
> >
> > I just wanted to report something I found a bit strange.
> >
> > I would like some keybindings to jump to the next/previous *non-special*
> > buffer.
> >
> > With these settings:
> >
> > (setq switch-to-prev-buffer-skip-regexp "\*[^*]+\*")
> > (setq switch-to-next-buffer-skip-regexp "\*[^*]+\*")
> >
> > I have the init.el file open, along with the Messages and scratch
> > buffers.
>
> Did you forget to double the backslashes?
Yep, I forgot it. Strange thing is, it worked without it :/
Let me correct it, what I now have is:
(setq switch-to-prev-buffer-skip-regexp "\\*[^*]+\\*")
And I wrongly added a switch-to-next-buffer-skip-regexp, which does not
exist, the switch-to-prev-buffer-skip-regexp variable does it for both
prev/next functions.
That said, the behaviour is the same as I first described.
--
Rahul Martim Juliato
https://www.rahuljuliato.com
PGP Fingerprint: 6B68 4353 84E2 2C7E 5A26 B79A C666 FC94 BD7E A483
PGP Public Key : https://www.rahuljuliato.com/rahul_pub_key.asc
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73545
; Package
emacs
.
(Sun, 29 Sep 2024 12:52:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 73545 <at> debbugs.gnu.org (full text, mbox):
> From: Rahul Martim Juliato <rahuljuliato <at> gmail.com>
> Date: Sun, 29 Sep 2024 09:29:56 -0300
> Cc: 73545 <at> debbugs.gnu.org
>
> That said, the behaviour is the same as I first described.
If you mean that Emacs switches to a buffer whose name matches
switch-to-prev-buffer-skip-regexp when there are no other buffers to
show, then this is the intended behavior, I think. Martin, am I
right?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73545
; Package
emacs
.
(Sun, 29 Sep 2024 14:18:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 73545 <at> debbugs.gnu.org (full text, mbox):
> If you mean that Emacs switches to a buffer whose name matches
> switch-to-prev-buffer-skip-regexp when there are no other buffers to
> show, then this is the intended behavior, I think. Martin, am I
> right?
I don't know about 'switch-to-prev-buffer-skip-regexp'. Here I have
set 'switch-to-prev-buffer-skip' to the function
(defun skip-undisplayed-buffers (_window buffer _bury-or-kill)
"Function for `switch-to-prev-buffer-skip'.
Skip BUFFER if it has never been displayed before."
(zerop (buffer-local-value 'buffer-display-count buffer)))
(setq switch-to-prev-buffer-skip 'skip-undisplayed-buffers)
Now with emacs -Q evaluate that in *scratch* and do C-x <left>. Gets me
"No previous buffer" and *scratch* stays. I think the same should
happen if 'switch-to-prev-buffer-skip-regexp' matches *Messages*. What
is the value of that variable?
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73545
; Package
emacs
.
(Thu, 03 Oct 2024 21:21:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 73545 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Sun, Sep 29, 2024 at 05:49:35PM +0200, martin rudalics wrote:
> > What
> > is the value of that variable?
>
> Found as:
>
> (setq switch-to-prev-buffer-skip-regexp "\\*[^*]+\\*")
>
> And the explanation is this snippet from 'switch-to-prev-buffer':
>
> (when (and skipped (not (functionp switch-to-prev-buffer-skip)))
> ;; Show first skipped buffer, unless skip was a function.
> (setq new-buffer skipped)
> (set-window-buffer-start-and-point window new-buffer)))
>
> That is, if the regexp excludes a specific buffer but
> 'switch-to-prev-buffer' didn't find another suitable buffer, it switches
> to the first excluded buffer. The Elisp manual is clear about this:
>
> This user option should be either a regular expression or a list of
> regular expressions. Buffers whose names match one of those
> regular expressions will be ignored by ‘switch-to-prev-buffer’ and
> ‘switch-to-next-buffer’ (except when there’s no other buffer to
> switch to).
>
> So if you want to make sure that *Messages* gets always excluded, you
> have to specify a function based on that regexp like
>
> (defun skip-these-buffers (_window buffer _bury-or-kill)
> "Function for `switch-to-prev-buffer-skip'."
> (string-match "\\*[^*]+\\*" (buffer-name buffer)))
>
> (setq switch-to-prev-buffer-skip 'skip-these-buffers)
>
> martin
Thanks a lot for the clarification!
I just found a bit strange the default behaviour (I guess I am biased by
my use case) being this way.
The snippet you provided is exactly what I was looking for.
I think this is all for this thread :)
--
Rahul Martim Juliato
https://www.rahuljuliato.com
PGP Fingerprint: 6B68 4353 84E2 2C7E 5A26 B79A C666 FC94 BD7E A483
PGP Public Key : https://www.rahuljuliato.com/rahul_pub_key.asc
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73545
; Package
emacs
.
(Fri, 04 Oct 2024 08:09:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 73545 <at> debbugs.gnu.org (full text, mbox):
> I just found a bit strange the default behaviour (I guess I am biased by
> my use case) being this way.
Historical reasons. 'switch-to-prev-buffer-skip' appeared in Emacs 27.1
and at that time I decided that if and only if it is a function it will
make sure that the buffer is never switched to. More or less to avoid
that peoples shoot themselves in their feet.
'switch-to-prev-buffer-skip-regexp' was added in Emacs 29.1 introducing
the following design error (which I wouldn't propose to exploit). With
emacs -Q do:
(setq switch-to-prev-buffer-skip-regexp "\\*[^*]+\\*")
(setq switch-to-prev-buffer-skip 'ignore)
C-x <left>
The fact that 'switch-to-prev-buffer-skip' was set to a function that
does nothing makes 'switch-to-prev-buffer-skip-regexp' miraculously
work when there are no other buffers left ...
'switch-to-prev-buffer-skip-regexp' should never have been added in the
first place. Rather 'switch-to-prev-buffer-skip' should have been given
an optional regexp value. But now it's too late to change that.
martin
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sat, 05 Oct 2024 10:33:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Rahul Martim Juliato <rahuljuliato <at> gmail.com>
:
bug acknowledged by developer.
(Sat, 05 Oct 2024 10:33:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 73545-done <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 29 Sep 2024 17:49:35 +0200
> From: martin rudalics <rudalics <at> gmx.at>
> Cc: 73545 <at> debbugs.gnu.org
>
> > What
> > is the value of that variable?
>
> Found as:
>
> (setq switch-to-prev-buffer-skip-regexp "\\*[^*]+\\*")
>
> And the explanation is this snippet from 'switch-to-prev-buffer':
>
> (when (and skipped (not (functionp switch-to-prev-buffer-skip)))
> ;; Show first skipped buffer, unless skip was a function.
> (setq new-buffer skipped)
> (set-window-buffer-start-and-point window new-buffer)))
>
> That is, if the regexp excludes a specific buffer but
> 'switch-to-prev-buffer' didn't find another suitable buffer, it switches
> to the first excluded buffer. The Elisp manual is clear about this:
>
> This user option should be either a regular expression or a list of
> regular expressions. Buffers whose names match one of those
> regular expressions will be ignored by ‘switch-to-prev-buffer’ and
> ‘switch-to-next-buffer’ (except when there’s no other buffer to
> switch to).
Thanks, I've now added this caveat to the variable's doc string, and
I'm therefore closing this bug.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 02 Nov 2024 11:24:12 GMT)
Full text and
rfc822 format available.
This bug report was last modified 225 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.