unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: James N. V. Cash <james.nvc@gmail.com>,  emacs-devel@gnu.org
Subject: Re: Exiting completion-in-region-mode
Date: Thu, 19 May 2022 21:52:36 +0300	[thread overview]
Message-ID: <86sfp5qrrf.fsf@mail.linkov.net> (raw)
In-Reply-To: <867d6zq1c5.fsf_-_@mail.linkov.net> (Juri Linkov's message of "Thu, 05 May 2022 21:30:18 +0300")

> 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)))



      reply	other threads:[~2022-05-19 18:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29  0:36 [PATCH] Handle case where `beg` and `end` are strings instead of markers James N. V. Cash
2022-04-29  1:10 ` James N. V. Cash
2022-04-29  7:05   ` Juri Linkov
2022-04-29 12:10     ` James N. V. Cash
2022-04-29 12:55       ` Stefan Monnier
2022-04-29 14:07         ` James N. V. Cash
2022-04-29 16:18           ` Stefan Monnier
2022-04-29 17:20             ` James N. V. Cash
2022-04-29 17:29             ` Juri Linkov
2022-04-29 21:05         ` Stefan Monnier
2022-04-30 12:41           ` James N. V. Cash
2022-04-30 13:44             ` Stefan Monnier
2022-04-30 15:48               ` James N. V. Cash
2022-05-01 18:06                 ` Juri Linkov
2022-05-02 15:32                   ` James N. V. Cash
2022-05-02 19:11                     ` Juri Linkov
2022-05-04 12:08                       ` James N. V. Cash
2022-05-04 19:27                         ` Juri Linkov
2022-05-04 21:09                           ` James N. V. Cash
2022-05-05 18:16                             ` Juri Linkov
2022-05-01 18:03               ` Juri Linkov
2022-05-01 18:37                 ` Stefan Monnier
2022-05-05 18:19                   ` Juri Linkov
2022-05-05 18:30         ` Exiting completion-in-region-mode (was: Handle case where `beg` and `end` are strings instead of markers) Juri Linkov
2022-05-19 18:52           ` Juri Linkov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86sfp5qrrf.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=emacs-devel@gnu.org \
    --cc=james.nvc@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).