From: Spencer Baugh <sbaugh@janestreet.com>
To: sbaugh@catern.com
Cc: 68801@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#68801: 30.0.50; minibuffer-visible-completions=t makes RET in completion-in-region a no-op with nothing selected
Date: Tue, 27 Feb 2024 15:45:23 -0500 [thread overview]
Message-ID: <iermsrly6u4.fsf@janestreet.com> (raw)
In-Reply-To: <ierplwjxlck.fsf@janestreet.com> (Spencer Baugh's message of "Mon, 26 Feb 2024 11:04:59 -0500")
[-- Attachment #1: Type: text/plain, Size: 666 bytes --]
Spencer Baugh <sbaugh@janestreet.com> writes:
> I'm thinking the right thing to do is just to go with my original patch
> which only binds RET when there's a selected completion. That's simple
> and straightforward.
>
> But I'm not sure how to adapt my completion-show-help change for that: I
> want to hint to the user that they should hit RET, but RET is only bound
> when a completion is selected, which isn't the case when *Completions*
> is first displayed. Any ideas? Could we just hardcode "RET" in the
> help text?
The solution is obvious in retrospect, just add a defvar to force the
bindings on.
Complete patch attached, I think this closes the bug.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-With-visible-completions-only-bind-RET-when-completi.patch --]
[-- Type: text/x-patch, Size: 5249 bytes --]
From e81a3dccacd1ba701361d84f6d61fb244e8b81d6 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Tue, 27 Feb 2024 15:42:38 -0500
Subject: [PATCH] With visible-completions, only bind RET when completion is
selected
Previously, if minibuffer-visible-completions was non-nil, we bound RET
whenever the *Completions* buffer was visible. This meant that RET in
completion-in-region would not enter a newline, which is a somewhat
annoying behavior change from minibuffer-visible-completions=nil.
Now, we only bind RET when a completion is selected. This means
RET will newline in completion-in-region.
So that completion help continues to suggest the correct keys,
we also add minibuffer-visible-completions--always-bind. When
let-bound to a non-nil value, it makes the
minibuffer-visible-completions binds always active. We let-bind
it around substitute-command-keys.
* lisp/minibuffer.el (minibuffer-visible-completions--always-bind)
(minibuffer-visible-completions--filter): Add.
(minibuffer-visible-completions-bind): Use
minibuffer-visible-completions--filter. (bug#68801)
* lisp/simple.el (minibuffer-visible-completions--always-bind)
(completion-setup-function): Let-bind
minibuffer-visible-completions--always-bind so the completion
help is correct.
---
lisp/minibuffer.el | 24 ++++++++++++++++++------
lisp/simple.el | 19 +++++++++++--------
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 708f3684d11..3a06baddeae 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3163,18 +3163,30 @@ minibuffer-visible-completions
:type 'boolean
:version "30.1")
+(defvar minibuffer-visible-completions--always-bind nil
+ "If non-nil, force the `minibuffer-visible-completions' bindings on.")
+
+(defun minibuffer-visible-completions--filter (cmd)
+ "Return CMD if `minibuffer-visible-completions' bindings should be active."
+ (if minibuffer-visible-completions--always-bind
+ cmd
+ (when-let ((window (get-buffer-window "*Completions*" 0)))
+ (when (and (eq (buffer-local-value 'completion-reference-buffer
+ (window-buffer window))
+ (window-buffer (active-minibuffer-window)))
+ (if (eq cmd #'minibuffer-choose-completion-or-exit)
+ (with-current-buffer (window-buffer window)
+ (get-text-property (point) 'completion--string))
+ t))
+ cmd))))
+
(defun minibuffer-visible-completions-bind (binding)
"Use BINDING when completions are visible.
Return an item that is enabled only when a window
displaying the *Completions* buffer exists."
`(menu-item
"" ,binding
- :filter ,(lambda (cmd)
- (when-let ((window (get-buffer-window "*Completions*" 0)))
- (when (eq (buffer-local-value 'completion-reference-buffer
- (window-buffer window))
- (window-buffer (active-minibuffer-window)))
- cmd)))))
+ :filter ,#'minibuffer-visible-completions--filter))
(defvar-keymap minibuffer-visible-completions-map
:doc "Local keymap for minibuffer input with visible completions."
diff --git a/lisp/simple.el b/lisp/simple.el
index 9a33049f4ca..ac2e1f9f1c9 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10298,6 +10298,8 @@ completion-show-help
:version "22.1"
:group 'completion)
+(defvar minibuffer-visible-completions--always-bind)
+
;; This function goes in completion-setup-hook, so that it is called
;; after the text of the completion list buffer is written.
(defun completion-setup-function ()
@@ -10338,15 +10340,16 @@ completion-setup-function
(if minibuffer-visible-completions
(let ((helps
(with-current-buffer (window-buffer (active-minibuffer-window))
- (list
- (substitute-command-keys
- (if (display-mouse-p)
- "Click or type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n"
- "Type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n"))
- (substitute-command-keys
- "Type \\[minibuffer-next-completion], \\[minibuffer-previous-completion], \
+ (let ((minibuffer-visible-completions--always-bind t))
+ (list
+ (substitute-command-keys
+ (if (display-mouse-p)
+ "Click or type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n"
+ "Type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n"))
+ (substitute-command-keys
+ "Type \\[minibuffer-next-completion], \\[minibuffer-previous-completion], \
\\[minibuffer-next-line-completion], \\[minibuffer-previous-line-completion] \
-to move point between completions.\n\n")))))
+to move point between completions.\n\n"))))))
(dolist (help helps)
(insert help)))
(insert (substitute-command-keys
--
2.39.3
next prev parent reply other threads:[~2024-02-27 20:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-29 18:49 bug#68801: 30.0.50; minibuffer-visible-completions=t makes RET in completion-in-region a no-op with nothing selected Spencer Baugh
2024-01-30 17:28 ` Juri Linkov
2024-01-30 20:21 ` Spencer Baugh
2024-01-31 7:58 ` Juri Linkov
2024-02-09 7:17 ` Juri Linkov
2024-02-10 18:14 ` sbaugh
2024-02-11 17:59 ` Juri Linkov
2024-02-11 21:02 ` sbaugh
2024-02-16 14:34 ` Spencer Baugh
2024-02-18 7:46 ` Juri Linkov
2024-02-26 16:04 ` Spencer Baugh
2024-02-27 20:45 ` Spencer Baugh [this message]
2024-02-29 17:56 ` Juri Linkov
2024-03-15 7:41 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=iermsrly6u4.fsf@janestreet.com \
--to=sbaugh@janestreet.com \
--cc=68801@debbugs.gnu.org \
--cc=juri@linkov.net \
--cc=sbaugh@catern.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).