emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master afdf679: Add a new hook: `quit-window-hook'


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master afdf679: Add a new hook: `quit-window-hook'
Date: Mon, 19 Aug 2019 22:22:26 -0400 (EDT)

branch: master
commit afdf679841ad31664d41e7debca7083632add0f8
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    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.
---
 doc/lispref/windows.texi |  4 ++++
 etc/NEWS                 |  4 ++++
 lisp/window.el           | 17 +++++++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 1035739..157f004 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 23bf2b8..1737f8f 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 723671e..80dbd64 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)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]