[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9dcb28d6014: With visible-completions, only bind RET when complet
From: |
Juri Linkov |
Subject: |
master 9dcb28d6014: With visible-completions, only bind RET when completion is selected |
Date: |
Fri, 15 Mar 2024 03:43:25 -0400 (EDT) |
branch: master
commit 9dcb28d6014f72e5f52ad46d6141e9be4e11bfa5
Author: Spencer Baugh <sbaugh@janestreet.com>
Commit: Juri Linkov <juri@linkov.net>
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 099fa1599d5..0a844c538b4 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3163,18 +3163,30 @@ and `RET' accepts the input typed into the minibuffer."
: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 f127290231b..0645f18cc78 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10298,6 +10298,8 @@ Called from `temp-buffer-show-hook'."
: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 @@ Called from `temp-buffer-show-hook'."
(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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 9dcb28d6014: With visible-completions, only bind RET when completion is selected,
Juri Linkov <=