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

From: Juri Linkov <[email-masked]>
Date: Thu, 18 Oct 2018 00:30:40 +0300

>> For window selection I use (windmove-default-keybindings 'hyper),
>> so e.g. '<H-left>' selects the left window.  Could you recommend
>> a command to bind to e.g. 'C-x <H-left>' that will delete the left
>> window?
>
> Here <H-left> drags the character under the cursor by one character to
> the left and <H-up> drags the current line up by one line.  I use
> <M-S-left> for selecting the window on the left.  <C-M-S-left> either
> deletes the window on the left of the selected window provided there
> is one or makes a new window on the left of the selected window
> provided the selected window is already on the left of the frame.  The
> code for that command is below.

Thanks for sharing the code.  Now I have a good configuration:

  (defun my-windmove (&optional arg)
    (interactive "P")
    (let ((dir (event-basic-type (aref (this-command-keys) 0))))
      (condition-case nil
          (windmove-do-window-select dir arg)
        (error (select-window (split-window nil nil dir))))))

  (defun my-windelete (&optional arg)
    (interactive "P")
    (let ((dir (event-basic-type (aref (this-command-keys) 1))))
      (delete-window (window-in-direction dir))))

  (let ((modifiers '(hyper)))
    (dolist (key '(left right up down))
      (define-key global-map (vector (append modifiers (list key))) 'my-windmove)
      (define-key ctl-x-map  (vector (append modifiers (list key))) 'my-windelete)))

The only problem is the mismatch between key names and direction names.

Could you add aliases for 'up' and 'down' in window-in-direction?
Then we won't need such special handling in windmove.el:

  (window-in-direction
   (cond
    ((eq dir 'up) 'above)
    ((eq dir 'down) 'below)
    (t dir))
   window nil arg windmove-wrap-around t)