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: Select completions from the minibuffer Date: Thu, 10 Mar 2022 21:51:46 +0200 Organization: LINKOV.NET Message-ID: <86ilslmvql.fsf@mail.linkov.net> References: <86v8wlprc0.fsf@mail.linkov.net> <874k454n84.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24463"; 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: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 10 20:56:58 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 1nSOu9-0006Ef-UH for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Mar 2022 20:56:57 +0100 Original-Received: from localhost ([::1]:58262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSOu8-0002Wj-Bt for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Mar 2022 14:56:56 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:35298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSOt0-0001IC-TZ for emacs-devel@gnu.org; Thu, 10 Mar 2022 14:55:46 -0500 Original-Received: from [2001:4b98:dc4:8::221] (port=48999 helo=relay1-d.mail.gandi.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSOsz-0002WO-0L for emacs-devel@gnu.org; Thu, 10 Mar 2022 14:55:46 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id DB489240003; Thu, 10 Mar 2022 19:55:41 +0000 (UTC) In-Reply-To: <874k454n84.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 10 Mar 2022 20:32:59 +0100") X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:4b98:dc4:8::221 (failed) Received-SPF: pass client-ip=2001:4b98:dc4:8::221; envelope-from=juri@linkov.net; helo=relay1-d.mail.gandi.net X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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:287003 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit >> Here is a non-intrusive patch that doesn't change the default behavior >> while provides navigation of completions from the minibuffer >> like web browsers do on their address bar. > > [...] > >> + "M-" #'minibuffer-completion-previous >> + "M-" #'minibuffer-completion-next >> + "M-RET" #'minibuffer-completion-choose) > > If I'm reading this patch correctly, then this looks like just what I've > wanted for decades. 😀 > > [...] > >> + (choose-completion nil t t))) > > But this doesn't seem quite correct? The function only takes a single > parameter... Or is that part of the patch missing? Oops, it depends on another patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=choose-completion-no-auto-exit.patch diff --git a/lisp/simple.el b/lisp/simple.el index accc119e2b..65fc2c94a3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -9039,6 +9039,7 @@ completion-list-mode-map (define-key map [follow-link] 'mouse-face) (define-key map [down-mouse-2] nil) (define-key map "\C-m" 'choose-completion) + (define-key map [C-return] 'choose-completion-no-auto-exit) (define-key map "\e\e\e" 'delete-completion-window) (define-key map [remap keyboard-quit] #'delete-completion-window) (define-key map [left] 'previous-completion) @@ -9151,10 +9152,12 @@ next-completion (when (/= 0 n) (switch-to-minibuffer)))) -(defun choose-completion (&optional event) +(defun choose-completion (&optional event no-exit no-quit) "Choose the completion at point. -If EVENT, use EVENT's position to determine the starting position." - (interactive (list last-nonmenu-event)) +If EVENT, use EVENT's position to determine the starting position. +With the prefix NO-EXIT, insert the completion at point to the minibuffer +and quit the completion window without exiting the minibuffer." + (interactive (list last-nonmenu-event current-prefix-arg)) ;; In case this is run via the mouse, give temporary modes such as ;; isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) @@ -9162,6 +9165,7 @@ choose-completion (let ((buffer completion-reference-buffer) (base-position completion-base-position) (insert-function completion-list-insert-choice-function) + (completion-no-auto-exit (if no-exit t completion-no-auto-exit)) (choice (save-excursion (goto-char (posn-point (event-start event))) @@ -9179,7 +9184,8 @@ choose-completion (unless (buffer-live-p buffer) (error "Destination buffer is dead")) - (quit-window nil (posn-window (event-start event))) + (unless no-quit + (quit-window nil (posn-window (event-start event)))) (with-current-buffer buffer (choose-completion-string @@ -9189,6 +9195,14 @@ choose-completion (list (choose-completion-guess-base-position choice))) insert-function))))) +(defun choose-completion-no-auto-exit (&optional event) + "Insert the completion at point to the minibuffer without exiting it. +Like `choose-completion', it chooses the completion at point, +inserts it to the minibuffer, but doesn't exit the minibuffer." + (interactive (list last-nonmenu-event)) + (let ((completion-no-auto-exit t)) + (choose-completion event))) + ;; Delete the longest partial match for STRING ;; that can be found before POINT. (defun choose-completion-guess-base-position (string) --=-=-=--