Subject: bug#32790: 27.0.50; point jumps unexpectedly after delete-window

From: Juri Linkov <[email-masked]>
Date: Wed, 28 Nov 2018 01:28:40 +0200

>> I realized now that maybe a new prefix arg could be useful to also
>> kill the buffer that was displayed in the deleted window.  Not sure,
>> if better to do this using the arg KILL of quit-window, or call
>> kill-buffer explicitly after deleting the window in the given direction.
>>
>> The prefix arg could be 'C-u C-u', e.g. 'C-u C-u C-x S-down' to delete
>> the window below and kill the buffer that it displayed.
>
> I can't give you any suggestions here because I can't memorize such
> combinations in the first place.

There are commands that use triple C-u, so this sequence is not too long.
I can't find a function that deletes the window together with killing its
buffer ('quit-window' with the arg KILL kills the buffer, but doesn't
always delete the window):

diff --git a/lisp/windmove.el b/lisp/windmove.el
index 6d61806a83..de3507d2d6 100644
--- a/lisp/windmove.el
+++ b/lisp/windmove.el
@@ -588,7 +588,9 @@ windmove-display-in-direction
 If prefix ARG is `C-u', reselect a previously selected window.
 If `windmove-display-no-select' is non-nil, this command doesn't
 select the window with a displayed buffer, and the meaning of
-the prefix argument is reversed."
+the prefix argument is reversed.
+When `switch-to-buffer-obey-display-actions' is non-nil,
+`switch-to-buffer' commands are also supported."
   (let* ((no-select (not (eq (consp arg) windmove-display-no-select))) ; xor
          (old-window (or (minibuffer-selected-window) (selected-window)))
          (new-window)
@@ -684,6 +686,7 @@ windmove-delete-in-direction
   "Delete the window at direction DIR.
 If prefix ARG is `C-u', delete the selected window and
 select the window at direction DIR.
+With two \\[universal-argument] prefixes, also kill the buffer in that window.
 When `windmove-wrap-around' is non-nil, takes the window
 from the opposite side of the frame."
   (let ((other-window (window-in-direction dir nil nil arg
@@ -691,7 +694,9 @@ windmove-delete-in-direction
     (cond ((null other-window)
            (user-error "No window %s from selected window" dir))
           (t
-           (if (not (consp arg))
+           (when (equal arg '(16))
+             (kill-buffer (window-buffer other-window)))
+           (if (not (equal arg '(4)))
                (delete-window other-window)
              (delete-window (selected-window))
              (select-window other-window))))))