@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
((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.
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.