Commit afdf6798 authored by Lars Ingebrigtsen's avatar Lars Ingebrigtsen
Browse files

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.
parent 221a3272
Pipeline #2896 failed with stage
in 90 minutes and 1 second
......@@ -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
......
......@@ -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
......
......@@ -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)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment