bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54438: 27.2; inconsistent-behavior-global-vs-local-hook


From: martin rudalics
Subject: 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]