From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Exiting completion-in-region-mode Date: Thu, 19 May 2022 21:52:36 +0300 Organization: LINKOV.NET Message-ID: <86sfp5qrrf.fsf@mail.linkov.net> References: <87k0b84tfr.fsf@occasionallycogent.com> <87h76c4ruf.fsf@occasionallycogent.com> <86sfpwwerz.fsf@mail.linkov.net> <87czh03xa9.fsf@occasionallycogent.com> <867d6zq1c5.fsf_-_@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12640"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: James N. V. Cash , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 19 20:55:51 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nrlJO-00037v-Po for ged-emacs-devel@m.gmane-mx.org; Thu, 19 May 2022 20:55:50 +0200 Original-Received: from localhost ([::1]:45714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nrlJN-0001Zf-8j for ged-emacs-devel@m.gmane-mx.org; Thu, 19 May 2022 14:55:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrlHw-0000qp-Go for emacs-devel@gnu.org; Thu, 19 May 2022 14:54:20 -0400 Original-Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]:52729) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrlHu-0003YT-GY for emacs-devel@gnu.org; Thu, 19 May 2022 14:54:19 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 79621E0002; Thu, 19 May 2022 18:54:13 +0000 (UTC) In-Reply-To: <867d6zq1c5.fsf_-_@mail.linkov.net> (Juri Linkov's message of "Thu, 05 May 2022 21:30:18 +0300") Received-SPF: pass client-ip=2001:4b98:dc4:8::224; envelope-from=juri@linkov.net; helo=relay4-d.mail.gandi.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:289987 Archived-At: > 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-" #'minibuffer-previous-completion + "M-" #'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)))