From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: dalanicolai Newsgroups: gmane.emacs.bugs Subject: bug#54438: 27.2; inconsistent-behavior-global-vs-local-hook Date: Fri, 18 Mar 2022 10:12:48 +0100 Message-ID: References: <871qz0m6qa.fsf@web.de> <161a1515-187d-18c2-f9f1-86f4ea29614c@gmx.at> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000916f6505da7a8d53" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32192"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Michael Heerdegen , 54438@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 18 10:14:27 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nV8gl-0008Ad-Os for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 18 Mar 2022 10:14:27 +0100 Original-Received: from localhost ([::1]:53474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nV8gk-00062x-Eh for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 18 Mar 2022 05:14:26 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nV8gM-00060k-KN for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2022 05:14:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nV8gM-0001BP-Bx for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2022 05:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nV8gM-0001mS-7g for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2022 05:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: dalanicolai Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 18 Mar 2022 09:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54438 X-GNU-PR-Package: emacs Original-Received: via spool by 54438-submit@debbugs.gnu.org id=B54438.16475947896773 (code B ref 54438); Fri, 18 Mar 2022 09:14:02 +0000 Original-Received: (at 54438) by debbugs.gnu.org; 18 Mar 2022 09:13:09 +0000 Original-Received: from localhost ([127.0.0.1]:56272 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nV8fU-0001lB-Tu for submit@debbugs.gnu.org; Fri, 18 Mar 2022 05:13:09 -0400 Original-Received: from mail-yb1-f170.google.com ([209.85.219.170]:40718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nV8fR-0001kb-1A for 54438@debbugs.gnu.org; Fri, 18 Mar 2022 05:13:06 -0400 Original-Received: by mail-yb1-f170.google.com with SMTP id z8so14769034ybh.7 for <54438@debbugs.gnu.org>; Fri, 18 Mar 2022 02:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bjOdS12XAMa+B86TYB9489D8DwlkKnJLzsXUSp+BlHA=; b=A2Svwk4oT3DBAYy36DJCESYGIloGyLqqiWk5QTbpfLRr3jhhFyoPNvNuDx66T/nCQO kyZKkXPSEeQ2nxr2oBArJU/6LzjoAgeNq2N2Qb8iu8miZNXfhPZB2//mj8akZV/Zb8ca rNbZ1UXGeu/1AEEJBcifb2V25fTEMDHrv4IGQ4ZPAqtRKiSJAcK0YhI/+oP04AqfmF80 81qxXeba2eR9b0sWQ9WhnPpQlgZPpOS4KrhmQShckCMe9HL3FQQLFe0kJcyqk6RXsZnF b3tj7QMDH/Cyo7c+0qrGvX3YkECqfKeypcT/35AH4UypSMiFvEkA06t4wa9EemiPiqAY +Ydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bjOdS12XAMa+B86TYB9489D8DwlkKnJLzsXUSp+BlHA=; b=X3N0oMmqz42hqGCyUPqkNcbyqDLXJpNOkwoD4n8EXLyq2ZAqtes/kA4GIkGIqiavPV kLU+wOHoMqXusWXKXu1VgDsW4V3jOPd+0HqoJwi16fX+i3ZocVnWxlRLxp1LCBt3946n EKr9wWEiUyM1mtmv1GjzU9oP0t2+6QjU8/IUbJUeU+6F7b2LDM5b5xoNmEBqBwwCyUlu fkW3VZLO7uSUJskx7rxvtyZs4XVjhDyIOtnSGKbw8EYYDD1Cnf5xranBDsoRzRgNoUag OP+EQenGgLl8L5ZOToKH0/SXGWVz4zlTe7v5NxmiVE2dMAw2o6TRv7SciiwKUopOtgQ2 Euog== X-Gm-Message-State: AOAM532bhJdQplEAuwAycGT0zLy0iW1S9HEqXzErUoa021vKom7+JUCE RrxblB5rcSMtjgfOJsnUf5jm2f0c3sZQg200cTo= X-Google-Smtp-Source: ABdhPJz0aH+wS2Xrc/CQYlWr/y6AS5YkUa0X3hZamAGxESqUrF4K8Pzl/oD0NIXnkM0wPh+ASzt3OQBo6HjD3wWRkSY= X-Received: by 2002:a25:3bd4:0:b0:633:6772:5ac1 with SMTP id i203-20020a253bd4000000b0063367725ac1mr8700319yba.431.1647594779536; Fri, 18 Mar 2022 02:12:59 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:228535 Archived-At: --000000000000916f6505da7a8d53 Content-Type: text/plain; charset="UTF-8" And, moreover, the behavior for the global vs local hook is inconsistent... On Fri, 18 Mar 2022 at 10:11, dalanicolai wrote: > Thank you for the reply. Ah, sorry I forgot to remove the parens to > include the `pop-to-buffer` within the defun. > > About the 'restoring mechanism'; the global hook seems not to restore the > window selected before running the hook. > > So here are the two separated test cases (they both use the 'pop-up' > function) > > (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) > (pop-to-buffer "test"))) > > ;; evaluate code to remove the (global) hook > (remove-hook 'window-configuration-change-hook #'pop-up) > > (defun test () > (interactive) > (with-current-buffer (get-buffer-create "test") > (add-hook 'window-configuration-change-hook #'pop-up nil t) > (pop-to-buffer "test"))) > > > So the 'restoring mechanism' works like you explained for the local hook > but not for the global hook > (where after calling 'test', the pop-up buffer will be selected). > > Also, I would expect that a hook just calls the hook function, and it > would not 'restore the window > selected before the hook'. I would say the restoring is undesired > behavior. > > > > On Fri, 18 Mar 2022 at 09:37, martin rudalics wrote: > >> > I think it's a bad idea to do something that changes the window >> > configuration in `window-configuration-change-hook'. It's not >> > unexpected to get an infinite recursion or any other unpredictable >> > behavior. >> >> People should avoid it in packages because they could easily step on >> each other's toes. Written carefully, it could be useful in private >> code. >> >> martin >> > --000000000000916f6505da7a8d53 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
And, moreover, the behavior for the global vs local hook i= s inconsistent...

On Fri, 18 Mar 2022 at 10:11, dalanicolai <dalanicolai@gmail.com> wrote:
<= /div>
Thank you for the reply. Ah, sorry I forgot to remove the parens to inclu= de the `pop-to-buffer` within the defun.

About the= 'restoring mechanism'; the global hook seems not to restore the wi= ndow selected before running the hook.

So here are= the two separated test cases (they both use the 'pop-up' function)=

(defun pop-up ()
=C2=A0 (pop-to-buffer "p= op-up"))

(defun test ()
=C2=A0 (interactive)
=C2=A0 (with= -current-buffer (get-buffer-create "test")
=C2=A0 =C2=A0 (add-= hook 'window-configuration-change-hook #'pop-up)
=C2=A0 =C2=A0 (= pop-to-buffer "test")))

;; evaluate code to remove the (gl= obal) hook
(remove-hook 'window-configuration-change-hook #'pop-= up)

(defun test ()
=C2=A0 (interactive)
=C2=A0 (with-current-b= uffer (get-buffer-create "test")
=C2=A0 =C2=A0 (add-hook '= window-configuration-change-hook #'pop-up nil t)
=C2=A0 =C2=A0 (pop-= to-buffer "test")))


So th= e 'restoring mechanism' works like you explained for the local hook= but not for the global hook
(where after calling 'test',= the pop-up buffer will be selected).

Also, I woul= d expect that a hook just calls the hook function, and it would not 're= store the window
=C2=A0selected before the hook'. I would say= the restoring is undesired behavior.



On Fri, 18 Mar 2022 at 09:37, martin rudalics <rudalics@gmx.at> wrote:
=C2=A0> I think it's a = bad idea to do something that changes the window
=C2=A0> configuration in `window-configuration-change-hook'.=C2=A0 I= t's not
=C2=A0> unexpected to get an infinite recursion or any other unpredictab= le
=C2=A0> behavior.

People should avoid it in packages because they could easily step on
each other's toes.=C2=A0 Written carefully, it could be useful in priva= te
code.

martin
--000000000000916f6505da7a8d53--