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

From: Juri Linkov <[email-masked]>
Date: Sun, 21 Oct 2018 21:17:28 +0300

>> Using arrow keys as a prefix will allow to tell Emacs explicitly
>> where do you want to display the buffer, e.g.
>>
>> H-up RET will display grep results in the above window after creating it
>>
>> H-left C-h f will display the *Help* buffer in the left window
>>
>> H-right C-x v d will display the vc-dir buffer in the right window
>>
>> H-down C-x C-b will display the buffer list in the bottom window
>>
>> The possibilities are limitless.
>
> I fail to see the connection between hyper key bindings and the way to
> display a buffer.  If at all, isn't that something Stephen Leake's
> 'other-frame-window' package is supposed to provide?

other-frame-window is limited to the coarse choice, i.e. to display the
buffer in a random window on the same frame, or in another frame.

Whereas the needed feature is to allow the user to point out exactly
in which window the buffer should be displayed.  This can be achieved
with something like this:

(let ((modifiers '(hyper)))
  (dolist (key '(left right up down))
    (define-key global-map (vector (append modifiers (list key)))
                'display-buffer-directionally)))

(defun display-buffer-directionally ()
  "Specify in which direction the buffer should be displayed."
  (interactive "P")
  (let* ((dir (event-basic-type (aref (this-command-keys) 0)))
	 (win (window-in-direction dir)))
    (unless win
      (setq win (split-window nil nil dir)))
    (let ((hook (list 'lambda)))
      (setcdr hook `((window)
		     (when (eq window ,win)
		       ;; When a new buffer was displayed in that window,
		       ;; we can restore a previous value.
		       (setq display-buffer-overriding-action
			     ',display-buffer-overriding-action)
		       (remove-hook 'window-state-change-functions ',hook))))
      (add-hook 'window-state-change-functions hook))
    (setq display-buffer-overriding-action
	  `((lambda (buffer alist)
	      (window--display-buffer buffer ,win 'reuse alist))))))

Do you think conceptually this is the right direction of development?