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: [PATCH] Re: Other details about completion. Date: Wed, 06 Apr 2022 19:48:40 +0300 Organization: LINKOV.NET Message-ID: <86sfqqduon.fsf@mail.linkov.net> References: <20220401153839.idrzrbfl2yfzga3y.ref@Ergus> <20220401153839.idrzrbfl2yfzga3y@Ergus> <86r16g92v5.fsf@mail.linkov.net> <20220401202425.jfrwqmkm3ffmcm5h@Ergus> <20220404193501.adojhz7uvvaoq4sj@Ergus> <86czhw4oqr.fsf@mail.linkov.net> <4E8D9AEF-4D7A-4B11-822F-8D0911964A05@aol.com> <86bkxfibdo.fsf@mail.linkov.net> <20220405232013.5y5jnr4ykzqgxqla@Ergus> <86a6cyiqlt.fsf@mail.linkov.net> <20220406132108.evlofp5l3krsl5h7@Ergus> 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="6498"; 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: Philip Kaludercic , emacs-devel@gnu.org To: Ergus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 06 18:53:01 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 1nc8tw-0001X5-RH for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Apr 2022 18:53:00 +0200 Original-Received: from localhost ([::1]:43732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nc8tv-0008Ia-Hb for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Apr 2022 12:52:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nc8sr-0006xt-RQ for emacs-devel@gnu.org; Wed, 06 Apr 2022 12:51:53 -0400 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:40251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nc8sp-0007t9-Oh for emacs-devel@gnu.org; Wed, 06 Apr 2022 12:51:53 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id E6AF2100007; Wed, 6 Apr 2022 16:51:46 +0000 (UTC) In-Reply-To: <20220406132108.evlofp5l3krsl5h7@Ergus> (Ergus's message of "Wed, 6 Apr 2022 15:21:08 +0200") Received-SPF: pass client-ip=217.70.178.231; envelope-from=juri@linkov.net; helo=relay11.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:287844 Archived-At: --=-=-= Content-Type: text/plain >>> 1) I think it is more intuitive to invert and use the M-S- >>> minibuffer-choose-** and M- for >>> minibuffer-{previous|next}-completion for not insert commands... >> >> Easier to type M- were intended as the primary way to use this feature. > I know, but such primary behavior is too intrusive IMO. > >> Whereas more hard to type M-S-/M-RET as a rarely used alternative. > Mi proposal (the suffix one) is basically to avoid the need of M-RET. So your proposal is something in between. Then maybe instead of two sets of commands (that either insert the current completion or not) we could have one set of commands bound to M-/M-, and a customizable option with three values: insert, don't insert, use transient suffix. > I took the idea basically from some configs around for fish and zsh.. > ... > But OTOH I will strongly recommend the C-g and arrow navigation > behavior... That could be maybe implemented with a set-transient-map... What is also interesting to note is that even every web browser uses own completion logic: 1. in Firefox: the suffix of the first completion is inserted to the address bar as the selected region, but / inserts the completion without selecting its suffix, like M-/M- currently does in Emacs. One ESC closes the completions window, another ESC clears the address bar. 2. in Chromium: / inserts the completion without any selection, like M-/M- currently does in Emacs. One ESC clears the inserted string, another ESC closes the completions window and clears the address bar. >> But what about M-/M- for not one-column format? > > This just confirms me that the initial approach implemented with a minor > mode (or using a set-transient-map) may be a solution. We started with non-intrusive keybindings. But indeed, more intrusive keys should be enabled only depending on a new customizable option. Here is the next patch that does this and allows using all arrow keys only when the completions window is visible: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=completion-arrows.patch diff --git a/lisp/simple.el b/lisp/simple.el index ef52006501..bfc268b828 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -9151,6 +9151,15 @@ delete-completion-window (if (get-buffer-window buf) (select-window (get-buffer-window buf)))))) +(defcustom completion-arrows nil + "Non-nil means to use arrows to browse completions from the minibuffer." + :type '(choice (const :tag "Don't use arrows" nil) + (const :tag "Use arrows" t) + (const :tag "Use arrows when completions window is visible" + visible)) + :version "29.1" + :group 'completion) + (defcustom completion-wrap-movement t "Non-nil means to wrap around when selecting completion options. This affects the commands `next-completion' and diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index c79c5a7a5d..ff124e18e9 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2736,6 +2821,15 @@ completion-help-at-point (define-key map "\n" 'exit-minibuffer) (define-key map "\r" 'exit-minibuffer)) +(defun completion-arrows (binding) + `(menu-item + "" ,binding + :filter ,(lambda (cmd) + (when (or (eq completion-arrows t) + (and (eq completion-arrows 'visible) + (get-buffer-window "*Completions*" 0))) + cmd)))) + (defvar-keymap minibuffer-local-completion-map :doc "Local keymap for minibuffer input with completion." :parent minibuffer-local-map @@ -2749,6 +2843,12 @@ minibuffer-local-completion-map "" #'switch-to-completions "M-v" #'switch-to-completions "M-g M-c" #'switch-to-completions + + "" (completion-arrows 'minibuffer-previous-completion) + "" (completion-arrows 'minibuffer-next-completion) + "" (completion-arrows 'minibuffer-previous-line-completion) + "" (completion-arrows 'minibuffer-next-line-completion) + "M-" #'minibuffer-choose-previous-completion "M-" #'minibuffer-choose-next-completion "M-S-" #'minibuffer-previous-completion @@ -4372,6 +4472,22 @@ minibuffer-next-completion (setq-local cursor-face-highlight-nonselected-window t)) (next-completion n))) +(defun minibuffer-previous-line-completion (&optional n) + "Run `previous-line' from the minibuffer in its completions window." + (interactive "p") + (with-minibuffer-completions-window + (when completions-highlight-face + (setq-local cursor-face-highlight-nonselected-window t)) + (forward-line (- n)))) + +(defun minibuffer-next-line-completion (&optional n) + "Run `next-line' from the minibuffer in its completions window." + (interactive "p") + (with-minibuffer-completions-window + (when completions-highlight-face + (setq-local cursor-face-highlight-nonselected-window t)) + (forward-line 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." --=-=-=--