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

From: Juri Linkov <[email-masked]>
Date: Wed, 31 Oct 2018 23:20:13 +0200

>> Ok, after a small change it handles also C-g:
>
> I forgot (or never learned) how to use it.  Can you please include an
> example so people can try it.

An example is this:

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

>> 			      ;; But don't remove immediately after
>> 			      ;; adding the hook by the same command.
>> 			      (eq this-command ',this-command))
>
> Can you give the rationale for the latter?  I don't grok it.

When display-buffer-directionally is called, it adds the hook
to post-command-hook, and when display-buffer-directionally finishes,
post-command-hook is called, and immediately removes itself from
post-command-hook.  This condition ensures that the hook is removed
only when post-command-hook is called after a next command finishes
(while the minibuffer is inactive).

>>                         (setq display-buffer-overriding-action
>>                               ',display-buffer-overriding-action)
>>                         (remove-hook 'post-command-hook ',hook))))
>>        (add-hook 'post-command-hook hook))
>>      (setq display-buffer-overriding-action
>>            `((lambda (buffer alist)
>>                (unless (> (minibuffer-depth) 0)
>> 		(window--display-buffer buffer ,win 'reuse alist)))))))
>
> 'reuse' holds only for the ?0 case.  When we split, the third argument
> should be 'window'.

I noticed that when replaced with

(window--display-buffer buffer ,win ',(if (eq dir ?0) 'reuse 'window) alist)

then 'window means that killing the buffer will delete its window.

Another observation is that switch-to-buffer is unaffected by this command.