unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: dalanicolai <dalanicolai@gmail.com>, 54438@debbugs.gnu.org
Subject: bug#54438: 27.2; inconsistent-behavior-global-vs-local-hook
Date: Fri, 18 Mar 2022 09:36:51 +0100	[thread overview]
Message-ID: <f64e32c0-53ca-96ad-c8bf-579519daadc9@gmx.at> (raw)
In-Reply-To: <CACJP=3kQw8aOVnTEiBLvMF-kEVdP7TYNbMCWYjZSDz22bDv+6A@mail.gmail.com>

 > 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





      parent reply	other threads:[~2022-03-18  8:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 17:52 bug#54438: 27.2; inconsistent-behavior-global-vs-local-hook dalanicolai
2022-03-18  0:42 ` Michael Heerdegen
2022-03-18  8:37   ` martin rudalics
2022-03-18  9:11     ` dalanicolai
2022-03-18  9:12       ` dalanicolai
2022-03-18  9:58       ` martin rudalics
2022-03-18 12:14         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-03-18 17:03           ` dalanicolai
2022-03-18  8:36 ` martin rudalics [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f64e32c0-53ca-96ad-c8bf-579519daadc9@gmx.at \
    --to=rudalics@gmx.at \
    --cc=54438@debbugs.gnu.org \
    --cc=dalanicolai@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).