aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-08-19 19:21:53 -0700
committerLars Ingebrigtsen2019-08-19 19:21:53 -0700
commitafdf679841ad31664d41e7debca7083632add0f8 (patch)
treeb48578fd132805405977b812c0b17fd09044c1ac
parent221a3272ad4a1befb41dda2990d672782bc0257f (diff)
downloademacs-afdf679841ad31664d41e7debca7083632add0f8.tar.gz
emacs-afdf679841ad31664d41e7debca7083632add0f8.zip
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.
-rw-r--r--doc/lispref/windows.texi4
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/window.el17
3 files changed, 23 insertions, 2 deletions
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
4043elements of the list specified by @var{window}'s @code{quit-restore} 4043elements of the list specified by @var{window}'s @code{quit-restore}
4044parameter (@pxref{Window Parameters}). 4044parameter (@pxref{Window Parameters}).
4045 4045
4046@vindex quit-window-hook
4047The functions in @code{quit-window-hook} are run before doing anything
4048else.
4049
4046The first element of the @code{quit-restore} parameter is one of the 4050The first element of the @code{quit-restore} parameter is one of the
4047symbols @code{window}, meaning that the window has been specially 4051symbols @code{window}, meaning that the window has been specially
4048created by @code{display-buffer}; @code{frame}, a separate frame has 4052created 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.
2024 2024
2025* Lisp Changes in Emacs 27.1 2025* Lisp Changes in Emacs 27.1
2026 2026
2027+++
2028** The new 'quit-window-hook' is now run first when executing the
2029'quit-window' command.
2030
2027** The variables 'help-enable-completion-auto-load', 2031** The variables 'help-enable-completion-auto-load',
2028'help-enable-auto-load' and 'vhdl-project-auto-load', as well as the 2032'help-enable-auto-load' and 'vhdl-project-auto-load', as well as the
2029'vhdl-auto-load-project' have been renamed to have "autoload" without 2033'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."
4848 ;; Unrecord BUFFER in WINDOW. 4848 ;; Unrecord BUFFER in WINDOW.
4849 (unrecord-window-buffer window buffer))))) 4849 (unrecord-window-buffer window buffer)))))
4850 4850
4851(defcustom quit-window-hook nil
4852 "Hook run before performing any other actions in the `quit-buffer' command."
4853 :type 'hook
4854 :version "27.1"
4855 :group 'windows)
4856
4851(defun quit-restore-window (&optional window bury-or-kill) 4857(defun quit-restore-window (&optional window bury-or-kill)
4852 "Quit WINDOW and deal with its buffer. 4858 "Quit WINDOW and deal with its buffer.
4853WINDOW must be a live window and defaults to the selected one. 4859WINDOW 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
4876 most reliable remedy to not have `switch-to-prev-buffer' switch 4882 most reliable remedy to not have `switch-to-prev-buffer' switch
4877 to this buffer again without killing the buffer. 4883 to this buffer again without killing the buffer.
4878 4884
4879`kill' means to kill WINDOW's buffer." 4885`kill' means to kill WINDOW's buffer.
4886
4887The functions in `quit-window-hook' will be run before doing
4888anything else."
4889 (run-hooks 'quit-window-hook)
4880 (setq window (window-normalize-window window t)) 4890 (setq window (window-normalize-window window t))
4881 (let* ((buffer (window-buffer window)) 4891 (let* ((buffer (window-buffer window))
4882 (quit-restore (window-parameter window 'quit-restore)) 4892 (quit-restore (window-parameter window 'quit-restore))
@@ -4971,7 +4981,10 @@ According to information stored in WINDOW's `quit-restore' window
4971parameter either (1) delete WINDOW and its frame, (2) delete 4981parameter either (1) delete WINDOW and its frame, (2) delete
4972WINDOW, (3) restore the buffer previously displayed in WINDOW, 4982WINDOW, (3) restore the buffer previously displayed in WINDOW,
4973or (4) make WINDOW display some other buffer than the present 4983or (4) make WINDOW display some other buffer than the present
4974one. If non-nil, reset `quit-restore' parameter to nil." 4984one. If non-nil, reset `quit-restore' parameter to nil.
4985
4986The functions in `quit-window-hook' will be run before doing
4987anything else."
4975 (interactive "P") 4988 (interactive "P")
4976 (quit-restore-window window (if kill 'kill 'bury))) 4989 (quit-restore-window window (if kill 'kill 'bury)))
4977 4990