GNU bug report logs - #54438
27.2; inconsistent-behavior-global-vs-local-hook

Previous Next

Package: emacs;

Reported by: dalanicolai <dalanicolai <at> gmail.com>

Date: Thu, 17 Mar 2022 18:00:02 UTC

Severity: normal

Found in version 27.2

Full log


Message #11 received at 54438 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: dalanicolai <dalanicolai <at> gmail.com>, 54438 <at> debbugs.gnu.org
Subject: Re: bug#54438: 27.2; inconsistent-behavior-global-vs-local-hook
Date: Fri, 18 Mar 2022 09:36:51 +0100
> I have used the following test code:
>
> (defun pop-up ()
>    (pop-to-buffer "pop-up"))
>
> (defun test ()
>    (interactive)
>    (with-current-buffer (get-buffer-create "test")
>      (add-hook 'window-configuration-change-hook #'pop-up)))
>      ;; (add-hook 'window-configuration-change-hook #'pop-up nil t)
>
>      ;; the following line triggers the `pop-up` hook function
>      (pop-to-buffer "test")))

What is the last paren here supposed to close?  Please provide two
separate test sequences - one for the local and one for the global hook
case.

> ;; evaluate code to remove the (global) hook
> (remove-hook 'window-configuration-change-hook #'pop-up)
>
> So you can start from emacs -Q, evaluate the above code, and do `M-x
> test`, as expected the 'pop-up' buffer will be selected.
>
> Now remove the hook (by evaluating the last line), then comment out the
> global hook and uncomment the local hook. Again do `M-x test`, this
> time, the 'test' buffer, wrongly and inconsistently, will be selected.
> To me this behavior looks like a bug.

I'd recommend to use 'window-configuration-change-hook' only when you
want the window/buffer of concern to be selected/made current while
running the hook.  Otherwise, you will inevitably run into problems when

- OT1H you want to select another window (that for "pop-up") while
  running the hook, and

- OTOH the mechanism at the end of run_window_configuration_change_hook
  (in window.c) restores the window selected before running the hook
  (apparently that for "test" in your case) which is certainly not a new
  window that popped up while running the hook.

martin




This bug report was last modified 3 years and 87 days ago.

Previous Next


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