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: Sun, 13 Mar 2022 20:05:47 +0200 Organization: LINKOV.NET Message-ID: <86h7817mj4.fsf@mail.linkov.net> References: <86v8wlprc0.fsf@mail.linkov.net> <874k454n84.fsf@gnus.org> <86ilslmvql.fsf@mail.linkov.net> <87v8wl35wg.fsf@gnus.org> <86k0d06dik.fsf@mail.linkov.net> <87ee3714li.fsf@gnus.org> <86r1773sb4.fsf@mail.linkov.net> <87pmmquew4.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="29296"; 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 Sun Mar 13 19:17:09 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 1nTSmB-0007Qi-G9 for ged-emacs-devel@m.gmane-mx.org; Sun, 13 Mar 2022 19:17:07 +0100 Original-Received: from localhost ([::1]:47430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTSmA-0003UG-3x for ged-emacs-devel@m.gmane-mx.org; Sun, 13 Mar 2022 14:17:06 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTSiz-0007rB-En for emacs-devel@gnu.org; Sun, 13 Mar 2022 14:13:49 -0400 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:53737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTSix-0001G5-L2 for emacs-devel@gnu.org; Sun, 13 Mar 2022 14:13:49 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 8374020004; Sun, 13 Mar 2022 18:13:45 +0000 (UTC) In-Reply-To: <87pmmquew4.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 13 Mar 2022 15:05:15 +0100") Received-SPF: pass client-ip=217.70.183.200; envelope-from=juri@linkov.net; helo=relay7-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, 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:287081 Archived-At: --=-=-= Content-Type: text/plain >> I posted a patch to bug#49931 that adds a new user option. >> Maybe it could be enabled by default? > > Skimming the patch, I think that might make sense. But perhaps push it > disabled first, and then we can gain some experience with it, and then > enable it by default if there's no unforeseen side effects? Yep, this would be the best course of action. The new variable completion-use-base-affixes will be also enabled for the M-up/down feature. Here is an updated patch that also requires other two patches from bug#47417 (merged with bug#49931) and bug#48356: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=minibuffer-choose-completion.patch diff --git a/lisp/simple.el b/lisp/simple.el index accc119e2b..52cf54c563 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3891,6 +3891,9 @@ minibuffer-local-shell-command-map (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map "\t" 'completion-at-point) + (define-key map (kbd "M-") 'minibuffer-previous-completion) + (define-key map (kbd "M-") 'minibuffer-next-completion) + (define-key map (kbd "M-RET") 'minibuffer-choose-completion) map) "Keymap used for completing shell commands in minibuffer.") diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 36b8d80841..5685f078ad 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2681,7 +2775,12 @@ minibuffer-local-completion-map "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions - "M-g M-c" #'switch-to-completions) + "M-g M-c" #'switch-to-completions + "M-S-" #'minibuffer-previous-completion + "M-S-" #'minibuffer-next-completion + "M-" #'minibuffer-choose-previous-completion + "M-" #'minibuffer-choose-next-completion + "M-RET" #'minibuffer-choose-completion) (defvar-keymap minibuffer-local-must-match-map :doc "Local keymap for minibuffer input with completion, for exact match." @@ -4271,6 +4370,52 @@ minibuffer-scroll-other-window-down (with-minibuffer-selected-window (scroll-other-window-down arg))) +(defmacro with-minibuffer-completions-window (&rest body) + "Execute the forms in BODY from the minibuffer in its completions window. +When used in a minibuffer window, select the window with completions, +and execute the forms." + (declare (indent 0) (debug t)) + `(let ((window (or (get-buffer-window "*Completions*" 0) + ;; Make sure we have a completions window. + (progn (minibuffer-completion-help) + (get-buffer-window "*Completions*" 0))))) + (when window + (with-selected-window window + ,@body)))) + +(defun minibuffer-previous-completion (&optional n) + "Run `previous-completion' from the minibuffer in its completions window." + (interactive "p") + (with-minibuffer-completions-window + (previous-completion n))) + +(defun minibuffer-next-completion (&optional n) + "Run `next-completion' from the minibuffer in its completions window." + (interactive "p") + (with-minibuffer-completions-window + (next-completion n))) + +(defun minibuffer-choose-previous-completion (&optional n) + "Run `previous-completion' from the minibuffer in its completions window. +Also insert the selected completion to the minibuffer." + (interactive "p") + (minibuffer-previous-completion n) + (minibuffer-choose-completion t t)) + +(defun minibuffer-choose-next-completion (&optional n) + "Run `next-completion' from the minibuffer in its completions window. +Also insert the selected completion to the minibuffer." + (interactive "p") + (minibuffer-next-completion n) + (minibuffer-choose-completion t t)) + +(defun minibuffer-choose-completion (&optional no-exit no-quit) + "Run `choose-completion' from the minibuffer in its completions window." + (interactive "p") + (with-minibuffer-completions-window + (let ((completion-use-base-affixes t)) + (choose-completion nil no-exit no-quit)))) + (defcustom minibuffer-default-prompt-format " (default %s)" "Format string used to output \"default\" values. When prompting for input, there will often be a default value, --=-=-=--