From: Lars Ingebrigtsen Date: Tue, 20 Aug 2019 02:21:53 +0000 (-0700) Subject: Add a new hook: `quit-window-hook' X-Git-Tag: emacs-27.0.90~1564 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=afdf679841ad31664d41e7debca7083632add0f8;p=emacs.git Add a new hook: `quit-window-hook' * doc/lispref/windows.texi (Quitting Windows): Mention in. * lisp/window.el (quit-restore-window): Run the new `quit-window-hook' before doing anything else (bug#9867). (quit-window): Note that the hook will be run in the doc string. * lisp/window.el (quit-window-hook): New variable. --- diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 1035739e2b0..157f004cf3f 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -4043,6 +4043,10 @@ the selected one. The function's behavior is determined by the four elements of the list specified by @var{window}'s @code{quit-restore} parameter (@pxref{Window Parameters}). +@vindex quit-window-hook +The functions in @code{quit-window-hook} are run before doing anything +else. + The first element of the @code{quit-restore} parameter is one of the symbols @code{window}, meaning that the window has been specially created by @code{display-buffer}; @code{frame}, a separate frame has diff --git a/etc/NEWS b/etc/NEWS index 23bf2b898a9..1737f8f18fe 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2024,6 +2024,10 @@ valid event type. * Lisp Changes in Emacs 27.1 ++++ +** The new 'quit-window-hook' is now run first when executing the +'quit-window' command. + ** The variables 'help-enable-completion-auto-load', 'help-enable-auto-load' and 'vhdl-project-auto-load', as well as the 'vhdl-auto-load-project' have been renamed to have "autoload" without diff --git a/lisp/window.el b/lisp/window.el index 723671efa57..80dbd64f18a 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4848,6 +4848,12 @@ all window-local buffer lists." ;; Unrecord BUFFER in WINDOW. (unrecord-window-buffer window buffer))))) +(defcustom quit-window-hook nil + "Hook run before performing any other actions in the `quit-buffer' command." + :type 'hook + :version "27.1" + :group 'windows) + (defun quit-restore-window (&optional window bury-or-kill) "Quit WINDOW and deal with its buffer. WINDOW must be a live window and defaults to the selected one. @@ -4876,7 +4882,11 @@ nil means to not handle the buffer in a particular way. This most reliable remedy to not have `switch-to-prev-buffer' switch to this buffer again without killing the buffer. -`kill' means to kill WINDOW's buffer." +`kill' means to kill WINDOW's buffer. + +The functions in `quit-window-hook' will be run before doing +anything else." + (run-hooks 'quit-window-hook) (setq window (window-normalize-window window t)) (let* ((buffer (window-buffer window)) (quit-restore (window-parameter window 'quit-restore)) @@ -4971,7 +4981,10 @@ According to information stored in WINDOW's `quit-restore' window parameter either (1) delete WINDOW and its frame, (2) delete WINDOW, (3) restore the buffer previously displayed in WINDOW, or (4) make WINDOW display some other buffer than the present -one. If non-nil, reset `quit-restore' parameter to nil." +one. If non-nil, reset `quit-restore' parameter to nil. + +The functions in `quit-window-hook' will be run before doing +anything else." (interactive "P") (quit-restore-window window (if kill 'kill 'bury)))