GNU bug report logs - #61102
28.1; with-selected-window/save-window-excursion calls buffer-list-update-hook only once

Previous Next

Package: emacs;

Reported by: Al Haji-Ali <abdo.haji.ali <at> gmail.com>

Date: Fri, 27 Jan 2023 18:41:02 UTC

Severity: normal

Found in version 28.1

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: martin rudalics <rudalics <at> gmx.at>
To: Eli Zaretskii <eliz <at> gnu.org>, Al Haji-Ali <abdo.haji.ali <at> gmail.com>
Cc: 61102 <at> debbugs.gnu.org
Subject: bug#61102: 28.1; with-selected-window/save-window-excursion calls buffer-list-update-hook only once
Date: Thu, 2 Feb 2023 16:04:52 +0100
>> The following code:
>>
>> --8<---------------cut here---------------start------------->8---
>>
>> (let ((fn (lambda () (message "Buffer changed: %S" (current-buffer)))))
>>    (add-hook 'buffer-list-update-hook fn)
>>    (with-selected-window (minibuffer-window)
>>      (save-window-excursion nil) nil)
>>    (remove-hook 'buffer-list-update-hook fn)
>>    nil)
>>
>> --8<---------------cut here---------------end--------------->8---
>>
>> Prints "Buffer changed: #<buffer  *Minibuf-0*>" once, even though the selection should return to the currently selected buffer (which is different from the mini-buffer).
>>
>> I would expect either that the hook 'buffer-list-update-hook is not called at all, or that it is called twice (one time for every change of the selected buffer).

"for every change of the selected buffer" is ambiguous.  I suppose the
OP means "for every change of the selected window" here.

> Martin, any comments on this?  FWIW, I'm not sure this is a bug, but
> maybe I'm missing something.

The doc-string of 'with-selected-window' says that:

  "It does not alter the buffer list ordering."

and the Elisp manual is more explicit by saying that

  "The ordering of recently selected windows and the buffer list remain
   unchanged unless you deliberately change them within FORMS; for
   example, by calling ‘select-window’ with argument NORECORD ‘nil’.
   Hence, this macro is the preferred way to temporarily work with
   WINDOW as the selected window without needlessly running
   ‘buffer-list-update-hook’."

The one message the OP sees comes from this call in
'set-window-configuration'

	select_window (data->current_window, Qnil, false);

'set-window-configuration' itself is called by 'save-window-excursion'.

martin

This bug report was last modified 2 years and 106 days ago.

Previous Next


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