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.

Full log


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




This bug report was last modified 5 years and 323 days ago.

Previous Next


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