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: Select completions from the minibuffer Date: Thu, 10 Mar 2022 20:58:39 +0200 Organization: LINKOV.NET Message-ID: <86v8wlprc0.fsf@mail.linkov.net> 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="32042"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 10 20:03:03 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 1nSO3z-0008B9-AW for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Mar 2022 20:03:03 +0100 Original-Received: from localhost ([::1]:60998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSO3y-0006tT-As for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Mar 2022 14:03:02 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSO3F-0005ty-V3 for emacs-devel@gnu.org; Thu, 10 Mar 2022 14:02:17 -0500 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:33047) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSO3E-0002fg-3O for emacs-devel@gnu.org; Thu, 10 Mar 2022 14:02:17 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 0CCE1200003 for ; Thu, 10 Mar 2022 19:02:12 +0000 (UTC) Received-SPF: pass client-ip=217.70.178.232; envelope-from=juri@linkov.net; helo=relay12.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, RCVD_IN_MSPIKE_H2=-0.001, 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:287001 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=minibuffer-completion-next-previous.patch diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 36b8d80841..e92bb0f885 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2681,7 +2766,10 @@ 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-" #'minibuffer-completion-previous + "M-" #'minibuffer-completion-next + "M-RET" #'minibuffer-completion-choose) (defvar-keymap minibuffer-local-must-match-map :doc "Local keymap for minibuffer input with completion, for exact match." @@ -4271,6 +4359,39 @@ minibuffer-scroll-other-window-down (with-minibuffer-selected-window (scroll-other-window-down arg))) +(defmacro with-minibuffer-scroll-window (&rest body) + "Execute the forms in BODY from the minibuffer in its scrolling window. +When used in a minibuffer window, select the window where scrolling command +should scroll, and execute the forms." + (declare (indent 0) (debug t)) + `(let ((window (or (get-buffer-window "*Completions*" 0) ; remove? + ;; 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-completion-previous (&optional arg) + "Run `previous-completion' from the minibuffer in its scrolling window." + (interactive "P") + (with-minibuffer-scroll-window + (previous-completion (or arg 1)) + (choose-completion nil t t))) + +(defun minibuffer-completion-next (&optional arg) + "Run `next-completion' from the minibuffer in its scrolling window." + (interactive "P") + (with-minibuffer-scroll-window + (next-completion (or arg 1)) + (choose-completion nil t t))) + +(defun minibuffer-completion-choose (&optional arg) + "Run `choose-completion' from the minibuffer in its scrolling window." + (interactive "P") + (with-minibuffer-scroll-window + (choose-completion nil arg))) + (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, --=-=-=--