[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Exiting completion-in-region-mode
From: |
Juri Linkov |
Subject: |
Re: Exiting completion-in-region-mode |
Date: |
Thu, 19 May 2022 21:52:36 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) |
> BTW, there is a related problem: while using `M-down` in the minibuffer,
> it unexpectedly closes the *Completions* window when using
> completion-in-region mode in the minibuffer, such as with
> `M-: (c TAB M-down` or `M-! c TAB M-down`.
>
> The code responsible for automatic closing the *Completions* window
> is found in `completion-at-point`:
>
> (completion-in-region-mode-predicate
> (lambda ()
> ;; We're still in the same completion field.
> (let ((newstart (car-safe (funcall hookfun))))
> (and newstart (= newstart start)))))
>
> And I'm completely lost how to adjust it to not exit
> completion-in-region-mode.
I realized now that inserting each candidate to the ordinary buffer
while navigating the list of in-buffer completions not only difficult to
implement, but also causes a lot of usability problems such as adding
a new entry to the undo list for every M-down/M-up.
OTOH, when forcing the value minibuffer-completion-auto-choose to nil
for in-buffer completions, it works surprisingly well: it navigates
the completions list without inserting candidates to the buffer,
then M-RET inserts the selected completion.
All this is achievable with a small patch:
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index f3003505f1..dfa7640ebe 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2624,7 +2624,10 @@ completion-in-region-mode-map
;; FIXME: Only works if completion-in-region-mode was activated via
;; completion-at-point called directly.
"M-?" #'completion-help-at-point
- "TAB" #'completion-at-point)
+ "TAB" #'completion-at-point
+ "M-<up>" #'minibuffer-previous-completion
+ "M-<down>" #'minibuffer-next-completion
+ "M-RET" #'minibuffer-choose-completion)
;; It is difficult to know when to exit completion-in-region-mode (i.e. hide
;; the *Completions*). Here's how previous packages did it:
@@ -2671,6 +2674,7 @@ completion-in-region-mode
(cl-assert completion-in-region-mode-predicate)
(setq completion-in-region-mode--predicate
completion-in-region-mode-predicate)
+ (setq-local minibuffer-completion-auto-choose nil)
(add-hook 'post-command-hook #'completion-in-region--postch)
(push `(completion-in-region-mode . ,completion-in-region-mode-map)
minor-mode-overriding-map-alist)))