GNU bug report logs - #9867
24.0.90; quit-window should provide quit-window-hook

Previous Next

Package: emacs;

Reported by: Christoph Scholtes <cschol2112 <at> googlemail.com>

Date: Tue, 25 Oct 2011 04:07:01 UTC

Severity: minor

Tags: fixed

Found in version 24.0.90

Fixed in version 27.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9867 in the body.
You can then email your comments to 9867 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Tue, 25 Oct 2011 04:07:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christoph Scholtes <cschol2112 <at> googlemail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 25 Oct 2011 04:07:02 GMT) Full text and rfc822 format available.

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

From: Christoph Scholtes <cschol2112 <at> googlemail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.0.90; quit-window should provide quit-window-hook
Date: Mon, 24 Oct 2011 22:04:17 -0600
A `quit-window-hook' should be provided for the `quit-window' function.

See discussion here:
http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00919.html




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Tue, 20 Aug 2019 02:23:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Christoph Scholtes <cschol2112 <at> googlemail.com>
Cc: 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Mon, 19 Aug 2019 19:22:00 -0700
Christoph Scholtes <cschol2112 <at> googlemail.com> writes:

> A `quit-window-hook' should be provided for the `quit-window' function.
>
> See discussion here:
> http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00919.html

(I'm going through old bug reports that have unfortunately gotten no
attention yet.)

It seems like Chong OK'd this hook at the time, but it was never added
to Emacs.  I've now added it to Emacs 27, because it seems like a useful
addition to have -- now modes that need to do some clean-up thing before
doing whatever `quit-window' does can just add that to the hook
(buffer-locally).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 20 Aug 2019 02:23:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 9867 <at> debbugs.gnu.org and Christoph Scholtes <cschol2112 <at> googlemail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 20 Aug 2019 02:23:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Tue, 20 Aug 2019 08:20:02 GMT) Full text and rfc822 format available.

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

From: martin rudalics <rudalics <at> gmx.at>
To: Lars Ingebrigtsen <larsi <at> gnus.org>,
 Christoph Scholtes <cschol2112 <at> googlemail.com>
Cc: 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Tue, 20 Aug 2019 10:19:29 +0200
> It seems like Chong OK'd this hook at the time, but it was never added
> to Emacs.  I've now added it to Emacs 27, because it seems like a useful
> addition to have -- now modes that need to do some clean-up thing before
> doing whatever `quit-window' does can just add that to the hook
> (buffer-locally).

'quit-restore-window' can quit _any_ window not just the selected one.
This means that if a user puts something on a normal hook run by that
function, that something can only guess at which window is really quit
by that function.  Also, running a buffer-local value of that hook is
meaningless given the current implementation.  See the tribulations
run_window_configuration_change_hook runs into when trying to overcome
a similar problem (and note the unwind-protection overhead it incurs).

If people really need such a hook at all, please

- Make it either an abnormal hook run with the window quit as argument
  or run it from 'quit-window' but then only if it quits the selected
  window.

- Make sure to call any buffer-local value of that hook for the buffer
  of the window that is quit.

- Prefix it with 'quit-restore-' if you intend to run it from
  'quit-restore-window' (that function may be called by other
  functions as well).

- Fix the reference to the non-existent function 'quit-buffer'.

Thanks, martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Tue, 20 Aug 2019 14:26:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: cschol2112 <at> googlemail.com, larsi <at> gnus.org, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Tue, 20 Aug 2019 17:25:20 +0300
> From: martin rudalics <rudalics <at> gmx.at>
> Date: Tue, 20 Aug 2019 10:19:29 +0200
> Cc: 9867 <at> debbugs.gnu.org
> 
> If people really need such a hook at all, please
> 
> - Make it either an abnormal hook run with the window quit as argument
>    or run it from 'quit-window' but then only if it quits the selected
>    window.
> 
> - Make sure to call any buffer-local value of that hook for the buffer
>    of the window that is quit.
> 
> - Prefix it with 'quit-restore-' if you intend to run it from
>    'quit-restore-window' (that function may be called by other
>    functions as well).
> 
> - Fix the reference to the non-existent function 'quit-buffer'.

And also:

  - Add the new hook to the list in the node "Standard Hooks" in the
    ELisp manual.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Wed, 21 Aug 2019 20:20:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Wed, 21 Aug 2019 13:18:59 -0700
martin rudalics <rudalics <at> gmx.at> writes:

> If people really need such a hook at all, please
>
> - Make it either an abnormal hook run with the window quit as argument
>   or run it from 'quit-window' but then only if it quits the selected
>   window.

I was going back and forth on whether to call the hook from
`quit-window' or `quit-restore-window', so I ended up with invalid vode
in the latter.  Thinking about it a bit more, I think it makes more
sense to just run it from the former command -- other callers that call
`quit-restore-window' should perhaps call that hook manually (or not) at
all.

I'll move the hook over.

> - Fix the reference to the non-existent function 'quit-buffer'.

OK; done.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Wed, 21 Aug 2019 20:24:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: cschol2112 <at> googlemail.com, martin rudalics <rudalics <at> gmx.at>,
 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Wed, 21 Aug 2019 13:23:09 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

> And also:
>
>   - Add the new hook to the list in the node "Standard Hooks" in the
>     ELisp manual.

OK; done.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Thu, 22 Aug 2019 08:09:02 GMT) Full text and rfc822 format available.

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

From: martin rudalics <rudalics <at> gmx.at>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Thu, 22 Aug 2019 10:08:23 +0200
>> - Make it either an abnormal hook run with the window quit as argument
>>    or run it from 'quit-window' but then only if it quits the selected
>>    window.
>
> I was going back and forth on whether to call the hook from
> `quit-window' or `quit-restore-window', so I ended up with invalid vode
> in the latter.  Thinking about it a bit more, I think it makes more
> sense to just run it from the former command -- other callers that call
> `quit-restore-window' should perhaps call that hook manually (or not) at
> all.
>
> I'll move the hook over.

But it's still misconfigured when WINDOW is not the selected window:
The function run by the hook would not know which window is quit and
which is its buffer.

>> - Fix the reference to the non-existent function 'quit-buffer'.
>
> OK; done.

Thanks.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Fri, 23 Aug 2019 00:09:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Fri, 23 Aug 2019 02:08:17 +0200
martin rudalics <rudalics <at> gmx.at> writes:

> But it's still misconfigured when WINDOW is not the selected window:
> The function run by the hook would not know which window is quit and
> which is its buffer.

Yup; should be fixed now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Fri, 23 Aug 2019 07:47:02 GMT) Full text and rfc822 format available.

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

From: martin rudalics <rudalics <at> gmx.at>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Fri, 23 Aug 2019 09:46:48 +0200
>> But it's still misconfigured when WINDOW is not the selected window:
>> The function run by the hook would not know which window is quit and
>> which is its buffer.
>
> Yup; should be fixed now.

The function on the hook still wouldn't reliably know which window was
quit, for example, when its buffer is displayed in two windows at the
same time.  Consider:

(let ((window (split-window)))
  (quit-window nil window))

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Fri, 23 Aug 2019 08:06:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Fri, 23 Aug 2019 10:05:37 +0200
martin rudalics <rudalics <at> gmx.at> writes:

> The function on the hook still wouldn't reliably know which window was
> quit, for example, when its buffer is displayed in two windows at the
> same time.  Consider:
>
> (let ((window (split-window)))
>   (quit-window nil window))

That's true, but is there a use case for the hook function having to
know what window it's quitting?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Fri, 23 Aug 2019 08:43:02 GMT) Full text and rfc822 format available.

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

From: martin rudalics <rudalics <at> gmx.at>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Fri, 23 Aug 2019 10:42:32 +0200
> That's true, but is there a use case for the hook function having to
> know what window it's quitting?

I don't know.  But you could replace 'with-current-buffer' with
'with-selected-window' to avoid worrying about that (and better check
if WINDOW is not already selected before doing that internal state
saving rigmarole).  Or, as I suggested earlier, run the hook only when
quitting the selected window.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Sun, 25 Aug 2019 05:25:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Sun, 25 Aug 2019 07:24:39 +0200
martin rudalics <rudalics <at> gmx.at> writes:

>> That's true, but is there a use case for the hook function having to
>> know what window it's quitting?
>
> I don't know.  But you could replace 'with-current-buffer' with
> 'with-selected-window' to avoid worrying about that (and better check
> if WINDOW is not already selected before doing that internal state
> saving rigmarole).

I wasn't aware of `with-selected-window' -- it sounds a bit dramatic.
Does it have any side effects?

> Or, as I suggested earlier, run the hook only when
> quitting the selected window.

That's possible, but the semantics become perhaps a bit complicated?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Sun, 25 Aug 2019 08:12:02 GMT) Full text and rfc822 format available.

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

From: martin rudalics <rudalics <at> gmx.at>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Sun, 25 Aug 2019 10:11:16 +0200
> I wasn't aware of `with-selected-window' -- it sounds a bit dramatic.
> Does it have any side effects?

Not normally.  It's wrapped in an unwind protection form like
'with-current-buffer'.  The following untested snippet should be (1)
fairly optimal for the normal case where the selected window is quit
and (2) guard against the case where the function run on the hook does
soemthing unexpected with the window configuration:

(let ((window (window-normalize-window window))
      (buffer (window-buffer window)))
  (if (and (eq window (selected-window))
	   (eq buffer (current-buffer)))
      (run-hooks 'quit-window-hook)
    ;; Select WINDOW for `quit-window-hook'.
    (with-selected-window window
      (run-hooks 'quit-window-hook)))
  ;; Run 'quit-restore-window' only if 'quit-window-hook' has left
  ;; WINDOW alone.
  (when (and (window-live-p window)
	     (eq (window-buffer window) buffer))
    (quit-restore-window window (if kill 'kill 'bury))))

Something like (2) is needed, for example, when a function run by the
hook kills WINDOW's buffer and 'kill-buffer' cleans up WINDOW by
deleting it which in its turn would cause 'quit-restore-window' act on
the window selected after 'replace-buffer-in-windows'.  For an amusing
example of why such a thing is necessary have a look at how often
'kill-buffer' checks whetheer the buffer it's supposed to kill is
still alive.

>> Or, as I suggested earlier, run the hook only when
>> quitting the selected window.
>
> That's possible, but the semantics become perhaps a bit complicated?

You would have to provide a somewhat disputable doc-string, indeed.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9867; Package emacs. (Fri, 30 Aug 2019 09:41:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Christoph Scholtes <cschol2112 <at> googlemail.com>, 9867 <at> debbugs.gnu.org
Subject: Re: bug#9867: 24.0.90; quit-window should provide quit-window-hook
Date: Fri, 30 Aug 2019 11:40:46 +0200
martin rudalics <rudalics <at> gmx.at> writes:

> Not normally.  It's wrapped in an unwind protection form like
> 'with-current-buffer'.  The following untested snippet should be (1)
> fairly optimal for the normal case where the selected window is quit
> and (2) guard against the case where the function run on the hook does
> soemthing unexpected with the window configuration:
>
> (let ((window (window-normalize-window window))
>       (buffer (window-buffer window)))
>   (if (and (eq window (selected-window))
> 	   (eq buffer (current-buffer)))
>       (run-hooks 'quit-window-hook)
>     ;; Select WINDOW for `quit-window-hook'.
>     (with-selected-window window
>       (run-hooks 'quit-window-hook)))
>   ;; Run 'quit-restore-window' only if 'quit-window-hook' has left
>   ;; WINDOW alone.
>   (when (and (window-live-p window)
> 	     (eq (window-buffer window) buffer))
>     (quit-restore-window window (if kill 'kill 'bury))))

I think the semantics of the command becomes rather muddled with this
change.  We currently provide no guarantees for what or how the hook
function should do, or whether it basically disables the command if it
changes the window and so on (which is what this change will do).

If you think this should be what the semantics are, then I won't argue,
so please feel free to go ahead and make whatever changes you want here.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 27 Sep 2019 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 206 days ago.

Previous Next


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