Implement new user option 'quit-window-kill-buffer' (Bug#76248)
* lisp/window.el (quit-window-kill-buffer): New option. (quit-window): Handle it. * doc/lispref/windows.texi (Quitting Windows): Describe new option 'quit-window-kill-buffer'. * etc/NEWS: Announce new option 'quit-window-kill-buffer'.
This commit is contained in:
parent
f12fbed4c1
commit
99410ba902
3 changed files with 50 additions and 7 deletions
|
@ -4953,11 +4953,26 @@ instead of burying it.
|
|||
|
||||
@vindex quit-window-hook
|
||||
The function @code{quit-window} first runs @code{quit-window-hook}.
|
||||
Then it calls the function @code{quit-restore-window}, described next,
|
||||
Then it calls the function @code{quit-restore-window}, described below,
|
||||
which does the hard work.
|
||||
@end deffn
|
||||
|
||||
You can get more control by calling @code{quit-restore-window} instead.
|
||||
The following option tells @code{quit-window} whether it should
|
||||
preferably kill or bury @var{window}'s buffer.
|
||||
|
||||
@defopt quit-window-kill-buffer
|
||||
If this is @code{nil} and @var{kill} is @code{nil}, @code{quit-window}
|
||||
will bury @var{window}'s buffer. If this is @code{t},
|
||||
@code{quit-window} will try to kill @var{window}'s buffer. Otherwise,
|
||||
this should be a list of major modes. @code{quit-window} will kill the
|
||||
buffer of @var{window} regardless of the value of @var{kill} if that
|
||||
buffer's major mode is either a member of this list or is derived from a
|
||||
member of this list. In any other case, @code{quit-window} will kill
|
||||
the buffer only if @var{kill} is non-@code{nil} and bury it otherwise.
|
||||
@end defopt
|
||||
|
||||
You can get more control by calling @code{quit-restore-window} instead
|
||||
of @code{quit-window}.
|
||||
|
||||
@defun quit-restore-window &optional window bury-or-kill
|
||||
This function handles @var{window} and its buffer after quitting. The
|
||||
|
|
5
etc/NEWS
5
etc/NEWS
|
@ -199,6 +199,11 @@ This abnormal hook gives its client a way to save a window from getting
|
|||
deleted implicitly by functions like 'kill-buffer', 'bury-buffer' and
|
||||
'quit-restore-window'.
|
||||
|
||||
+++
|
||||
*** New user option 'quit-window-kill-buffer'.
|
||||
This option specifies whether 'quit-window' should preferably kill or
|
||||
bury the buffer shown by the window to quit.
|
||||
|
||||
+++
|
||||
*** New user option 'kill-buffer-quit-windows'.
|
||||
This option has 'kill-buffer' call 'quit-restore-window' to handle the
|
||||
|
|
|
@ -5447,6 +5447,21 @@ elsewhere. This value is used by `quit-windows-on'."
|
|||
((eq bury-or-kill 'bury)
|
||||
(bury-buffer-internal buffer)))))
|
||||
|
||||
(defcustom quit-window-kill-buffer nil
|
||||
"Non-nil means `quit-window' will try to kill WINDOW's buffer.
|
||||
If this is nil and the KILL argument is nil, `quit-window' will bury
|
||||
WINDOW's buffer. If this is t, `quit-window' will always try to kill
|
||||
WINDOW's buffer. Otherwise, this should be a list of major modes.
|
||||
`quit-window' will kill the buffer of its WINDOW argument regardless of
|
||||
the value of KILL if that buffer's major mode is either a member of this
|
||||
list or is derived from a member of this list. In any other case,
|
||||
`quit-window' will kill the buffer only if KILL is non-nil and bury it
|
||||
otherwise."
|
||||
:type '(choice (boolean :tag "All major modes")
|
||||
(repeat (symbol :tag "Major mode")))
|
||||
:version "31.1"
|
||||
:group 'windows)
|
||||
|
||||
(defun quit-window (&optional kill window)
|
||||
"Quit WINDOW and bury its buffer.
|
||||
WINDOW must be a live window and defaults to the selected one.
|
||||
|
@ -5460,11 +5475,19 @@ Windows' for more details.
|
|||
The functions in `quit-window-hook' will be run before doing
|
||||
anything else."
|
||||
(interactive "P")
|
||||
;; Run the hook from the buffer implied to get any buffer-local
|
||||
;; values.
|
||||
(with-current-buffer (window-buffer (window-normalize-window window))
|
||||
(run-hooks 'quit-window-hook))
|
||||
(quit-restore-window window (if kill 'kill 'bury)))
|
||||
(let (kill-from-mode)
|
||||
(with-current-buffer (window-buffer (window-normalize-window window))
|
||||
;; Run the hook from the buffer implied to get any buffer-local
|
||||
;; values.
|
||||
(run-hooks 'quit-window-hook)
|
||||
|
||||
(setq kill-from-mode
|
||||
(or (eq quit-window-kill-buffer t)
|
||||
(and (listp quit-window-kill-buffer)
|
||||
(derived-mode-p quit-window-kill-buffer)))))
|
||||
|
||||
(quit-restore-window
|
||||
window (if (or kill kill-from-mode) 'kill 'bury))))
|
||||
|
||||
(defun quit-windows-on (&optional buffer-or-name kill frame)
|
||||
"Quit all windows showing BUFFER-OR-NAME.
|
||||
|
|
Loading…
Add table
Reference in a new issue