* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element
@ 2013-04-12 12:34 Joost Kremers
2013-04-12 17:32 ` Stefan Monnier
2013-04-12 18:59 ` bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element Andreas Schwab
0 siblings, 2 replies; 8+ messages in thread
From: Joost Kremers @ 2013-04-12 12:34 UTC (permalink / raw)
To: 14191
(buffer-list) returns a list of buffers, but the first buffer in the
list is not the current buffer.
Recipe to reproduce:
- start Emacs with `emacs -Q'
- M-x ielm RET
- at the prompt, type (buffer-list)
Output (list of buffers wrapped for better readability):
,----
| *** Welcome to IELM *** Type (describe-mode) for help.
| ELISP> (buffer-list)
| (#<buffer *scratch*> #<buffer *Minibuf-1*> #<buffer *Minibuf-0*>
| #<buffer *Messages*> #<buffer *code-conversion-work*>
| #<buffer *Echo Area 0*> #<buffer *Echo Area 1*> #<buffer *ielm*>)
`----
Although the *ielm* buffer is current, the first buffer in the list is
the *scratch* buffer.
Doing the same thing in an Emacs Debian (Ubuntu) snapshot from a few
weeks ago:
,----
| *** Welcome to IELM *** Type (describe-mode) for help.
| ELISP> (buffer-list)
| (#<buffer *ielm*> #<buffer *scratch*> #<buffer *Minibuf-1*>
| #<buffer *Minibuf-0*> #<buffer *Messages*>
| #<buffer *code-conversion-work*> #<buffer *Echo Area 0*>
| #<buffer *Echo Area 1*>)
|
| ELISP> (emacs-version)
| "GNU Emacs 24.3.50.1 (i686-pc-linux-gnu)\n of 2013-03-19 on gold, modified by Debian"
`----
Here, the output of buffer-list has the *ielm* buffer as its first
element. (Note, I've included the output of (emacs-version) here: this
is obviously *not* the version in which the bug occurs. That version is
given below.)
Note that I'm just using the *ielm* buffer to show the output of
(buffer-list). It has nothing to do with the bug itself. Using `M-x eval
RET (buffer-list) RET' gives the same result, as does using
(buffer-list) in Elisp. (Which is how I ran into the bug: swbuff.el from
http://emhacks.sourceforge.net/ stopped working properly. I traced the
problem to this changed behaviour of buffer-list.)
HTH
Joost Kremers
In GNU Emacs 24.3.50.1 (i686-pc-linux-gnu, GTK+ Version 3.6.0)
of 2013-04-11 on fermium, modified by Debian
(emacs-snapshot package, version 2:20130410-1~ppa1~quantal1)
Windowing system distributor `The X.Org Foundation', version 11.0.11300000
System Description: Ubuntu 12.10
Configured using:
`configure --build i686-linux-gnu --host i686-linux-gnu --prefix=/usr
--sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var
--infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/24.3.50/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3.50/site-lisp:/usr/share/emacs/site-lisp
--without-compress-info --with-crt-dir=/usr/lib/i386-linux-gnu/
--with-x=yes --with-x-toolkit=gtk3 --with-imagemagick=yes
CFLAGS='-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2'
CPPFLAGS='-D_FORTIFY_SOURCE=2' LDFLAGS='-g -Wl,--as-needed
-znocombreloc''
Important settings:
value of $LC_MONETARY: en_US.UTF-8
value of $LC_NUMERIC: en_US.UTF-8
value of $LC_TIME: en_US.UTF-8
value of $LANG: en_GB.UTF-8
locale-coding-system: utf-8-unix
default enable-multibyte-characters: t
Major mode: IELM
Minor modes in effect:
tooltip-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Recent input:
M-x i e l m <return> ( b u f f e r - l i s t ) <return>
<help-echo> <help-echo> <help-echo> <up> <up> <up>
<up> C-a a <backspace> <up> <left> <left> <left> <left>
<left> <left> <left> C-SPC <down> <down> <down> <down>
<down> <down> M-w ( e m a c s - v e r s i o n ) <return>
<help-echo> <help-echo> <up> <up> <up> <right> C-SPC
<down> <down> M-w C-x C-g M-x e m a c <tab> b u <tab>
<M-backspace> <M-backspace> r e p <tab> o r <tab>
<return>
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
End of buffer
Mark set
Making completion list...
Load-path shadows:
None found.
Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils help-mode easymenu ielm pp comint ansi-color ring
time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer loaddefs button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind inotify
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element
2013-04-12 12:34 bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element Joost Kremers
@ 2013-04-12 17:32 ` Stefan Monnier
2013-04-12 17:51 ` bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement Drew Adams
2013-04-12 18:59 ` bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element Andreas Schwab
1 sibling, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2013-04-12 17:32 UTC (permalink / raw)
To: Joost Kremers; +Cc: 14191-done
> - start Emacs with `emacs -Q'
> - M-x ielm RET
> - at the prompt, type (buffer-list)
[...]
> Although the *ielm* buffer is current, the first buffer in the list is
> the *scratch* buffer.
I've installed the patch below which should restore the old behavior.
Thanks for the nice test case.
Stefan
=== modified file 'src/window.c'
--- src/window.c 2013-04-11 16:06:47 +0000
+++ src/window.c 2013-04-12 17:30:35 +0000
@@ -489,7 +489,10 @@
Fset_buffer (w->contents);
if (EQ (window, selected_window) && !inhibit_point_swap)
- return window;
+ /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
+ way to call record_buffer from Elisp, so it's important that we call
+ record_buffer before returning here. */
+ goto record_and_return;
sf = SELECTED_FRAME ();
if (XFRAME (WINDOW_FRAME (w)) != sf)
@@ -508,7 +511,10 @@
fset_selected_window (sf, window);
select_window_1 (window, inhibit_point_swap);
+ bset_last_selected_window (XBUFFER (w->contents), window);
+ windows_or_buffers_changed++;
+ record_and_return:
/* record_buffer can run QUIT, so make sure it is run only after we have
re-established the invariant between selected_window and selected_frame,
otherwise the temporary broken invariant might "escape" (bug#14161). */
@@ -518,8 +524,6 @@
record_buffer (w->contents);
}
- bset_last_selected_window (XBUFFER (w->contents), window);
- windows_or_buffers_changed++;
return window;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement
2013-04-12 17:32 ` Stefan Monnier
@ 2013-04-12 17:51 ` Drew Adams
2013-04-13 8:02 ` martin rudalics
0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2013-04-12 17:51 UTC (permalink / raw)
To: 'Stefan Monnier', 'Joost Kremers'; +Cc: 14191-done
> + /* `switch-to-buffer' uses (select-window
> + (selected-window)) as a "clever"
> + way to call record_buffer from Elisp
As your quote-marks are no doubt meant to suggest here, there's really nothing
clever about code that relies on behavior that is somewhat obscure.
Why not take away some of the mystery and make the behavior here more
transparent by creating a function whose name suggests it?
(defun record-selected-window-buffer () ; Or `defsubst', if you prefer.
"Move the buffer of the selected window to the front of `buffer-list'."
(select-window (selected-window)))
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement
2013-04-12 17:51 ` bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement Drew Adams
@ 2013-04-13 8:02 ` martin rudalics
2013-04-13 15:08 ` Drew Adams
0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2013-04-13 8:02 UTC (permalink / raw)
To: Drew Adams; +Cc: 'Joost Kremers', 14191-done
> Why not take away some of the mystery and make the behavior here more
> transparent by creating a function whose name suggests it?
`record-window-buffer' ?
martin
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement
2013-04-13 8:02 ` martin rudalics
@ 2013-04-13 15:08 ` Drew Adams
2013-04-15 7:10 ` martin rudalics
0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2013-04-13 15:08 UTC (permalink / raw)
To: 'martin rudalics'; +Cc: 'Joost Kremers', 14191-done
> > Why not take away some of the mystery and make the behavior
> > here more transparent by creating a function whose name
> > suggests it?
>
> `record-window-buffer' ?
;-)
I wasn't aware of it. I was just basing my off-the-cuff suggestion on what the
code was apparently trying to do here.
But `record-window-buffer' is apparently quite a bit more than just
(select-window (selected-window)).
Should `record-window-buffer' be used in its place at this occurrence? If not,
should another function be defined to do only (select-window (selected-window))
- essentially an alias to better communicate the intention?
You're the expert here, not I. My feeling is just that using (select-window
(selected-window)) to take advantage of a less-than-obvious side effect is
obfuscating, not clever or wise.
Without an informative alias for this action, the code really needs to be
commented to indicate the unobvious intention/effect, at the least. But is
probably better to have a function name & doc string communicate this than code
comments and bug reports.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement
2013-04-13 15:08 ` Drew Adams
@ 2013-04-15 7:10 ` martin rudalics
0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2013-04-15 7:10 UTC (permalink / raw)
To: Drew Adams; +Cc: 'Joost Kremers', 14191-done
> But `record-window-buffer' is apparently quite a bit more than just
> (select-window (selected-window)).
More and less, I think.
> Should `record-window-buffer' be used in its place at this occurrence? If not,
> should another function be defined to do only (select-window (selected-window))
> - essentially an alias to better communicate the intention?
>
> You're the expert here, not I. My feeling is just that using (select-window
> (selected-window)) to take advantage of a less-than-obvious side effect is
> obfuscating, not clever or wise.
>
> Without an informative alias for this action, the code really needs to be
> commented to indicate the unobvious intention/effect, at the least. But is
> probably better to have a function name & doc string communicate this than code
> comments and bug reports.
As Andreas already remarked, the behavior of Emacs in this regard was
never clearly documented. Unfortunately, I don't know more about its
"unobvious intention/effect" than you.
martin
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element
2013-04-12 12:34 bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element Joost Kremers
2013-04-12 17:32 ` Stefan Monnier
@ 2013-04-12 18:59 ` Andreas Schwab
2013-04-14 12:46 ` Joost Kremers
1 sibling, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2013-04-12 18:59 UTC (permalink / raw)
To: Joost Kremers; +Cc: 14191
Joost Kremers <joostkremers@fastmail.fm> writes:
> (buffer-list) returns a list of buffers, but the first buffer in the
> list is not the current buffer.
Nor is it documented to do so.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-04-15 7:10 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-12 12:34 bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element Joost Kremers
2013-04-12 17:32 ` Stefan Monnier
2013-04-12 17:51 ` bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its firstelement Drew Adams
2013-04-13 8:02 ` martin rudalics
2013-04-13 15:08 ` Drew Adams
2013-04-15 7:10 ` martin rudalics
2013-04-12 18:59 ` bug#14191: 24.3.50; (buffer-list) returns list with non-current buffer as its first element Andreas Schwab
2013-04-14 12:46 ` Joost Kremers
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).