diff options
| author | Spencer Baugh | 2024-02-27 15:42:38 -0500 |
|---|---|---|
| committer | Juri Linkov | 2024-03-15 09:40:48 +0200 |
| commit | 9dcb28d6014f72e5f52ad46d6141e9be4e11bfa5 (patch) | |
| tree | 80eb505300717f515989353e69e03625efdc2607 | |
| parent | 09ab66935154ea0cc4a351b8320bc0e9276b7780 (diff) | |
| download | emacs-9dcb28d6014f72e5f52ad46d6141e9be4e11bfa5.tar.gz emacs-9dcb28d6014f72e5f52ad46d6141e9be4e11bfa5.zip | |
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.
| -rw-r--r-- | lisp/minibuffer.el | 24 | ||||
| -rw-r--r-- | 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." | |||
| 3163 | :type 'boolean | 3163 | :type 'boolean |
| 3164 | :version "30.1") | 3164 | :version "30.1") |
| 3165 | 3165 | ||
| 3166 | (defvar minibuffer-visible-completions--always-bind nil | ||
| 3167 | "If non-nil, force the `minibuffer-visible-completions' bindings on.") | ||
| 3168 | |||
| 3169 | (defun minibuffer-visible-completions--filter (cmd) | ||
| 3170 | "Return CMD if `minibuffer-visible-completions' bindings should be active." | ||
| 3171 | (if minibuffer-visible-completions--always-bind | ||
| 3172 | cmd | ||
| 3173 | (when-let ((window (get-buffer-window "*Completions*" 0))) | ||
| 3174 | (when (and (eq (buffer-local-value 'completion-reference-buffer | ||
| 3175 | (window-buffer window)) | ||
| 3176 | (window-buffer (active-minibuffer-window))) | ||
| 3177 | (if (eq cmd #'minibuffer-choose-completion-or-exit) | ||
| 3178 | (with-current-buffer (window-buffer window) | ||
| 3179 | (get-text-property (point) 'completion--string)) | ||
| 3180 | t)) | ||
| 3181 | cmd)))) | ||
| 3182 | |||
| 3166 | (defun minibuffer-visible-completions-bind (binding) | 3183 | (defun minibuffer-visible-completions-bind (binding) |
| 3167 | "Use BINDING when completions are visible. | 3184 | "Use BINDING when completions are visible. |
| 3168 | Return an item that is enabled only when a window | 3185 | Return an item that is enabled only when a window |
| 3169 | displaying the *Completions* buffer exists." | 3186 | displaying the *Completions* buffer exists." |
| 3170 | `(menu-item | 3187 | `(menu-item |
| 3171 | "" ,binding | 3188 | "" ,binding |
| 3172 | :filter ,(lambda (cmd) | 3189 | :filter ,#'minibuffer-visible-completions--filter)) |
| 3173 | (when-let ((window (get-buffer-window "*Completions*" 0))) | ||
| 3174 | (when (eq (buffer-local-value 'completion-reference-buffer | ||
| 3175 | (window-buffer window)) | ||
| 3176 | (window-buffer (active-minibuffer-window))) | ||
| 3177 | cmd))))) | ||
| 3178 | 3190 | ||
| 3179 | (defvar-keymap minibuffer-visible-completions-map | 3191 | (defvar-keymap minibuffer-visible-completions-map |
| 3180 | :doc "Local keymap for minibuffer input with visible completions." | 3192 | :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'." | |||
| 10298 | :version "22.1" | 10298 | :version "22.1" |
| 10299 | :group 'completion) | 10299 | :group 'completion) |
| 10300 | 10300 | ||
| 10301 | (defvar minibuffer-visible-completions--always-bind) | ||
| 10302 | |||
| 10301 | ;; This function goes in completion-setup-hook, so that it is called | 10303 | ;; This function goes in completion-setup-hook, so that it is called |
| 10302 | ;; after the text of the completion list buffer is written. | 10304 | ;; after the text of the completion list buffer is written. |
| 10303 | (defun completion-setup-function () | 10305 | (defun completion-setup-function () |
| @@ -10338,15 +10340,16 @@ Called from `temp-buffer-show-hook'." | |||
| 10338 | (if minibuffer-visible-completions | 10340 | (if minibuffer-visible-completions |
| 10339 | (let ((helps | 10341 | (let ((helps |
| 10340 | (with-current-buffer (window-buffer (active-minibuffer-window)) | 10342 | (with-current-buffer (window-buffer (active-minibuffer-window)) |
| 10341 | (list | 10343 | (let ((minibuffer-visible-completions--always-bind t)) |
| 10342 | (substitute-command-keys | 10344 | (list |
| 10343 | (if (display-mouse-p) | 10345 | (substitute-command-keys |
| 10344 | "Click or type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n" | 10346 | (if (display-mouse-p) |
| 10345 | "Type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n")) | 10347 | "Click or type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n" |
| 10346 | (substitute-command-keys | 10348 | "Type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n")) |
| 10347 | "Type \\[minibuffer-next-completion], \\[minibuffer-previous-completion], \ | 10349 | (substitute-command-keys |
| 10350 | "Type \\[minibuffer-next-completion], \\[minibuffer-previous-completion], \ | ||
| 10348 | \\[minibuffer-next-line-completion], \\[minibuffer-previous-line-completion] \ | 10351 | \\[minibuffer-next-line-completion], \\[minibuffer-previous-line-completion] \ |
| 10349 | to move point between completions.\n\n"))))) | 10352 | to move point between completions.\n\n")))))) |
| 10350 | (dolist (help helps) | 10353 | (dolist (help helps) |
| 10351 | (insert help))) | 10354 | (insert help))) |
| 10352 | (insert (substitute-command-keys | 10355 | (insert (substitute-command-keys |