[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/minibuffer-completion-enhancements 8ecd4371b9a 22/35: ; Avoid at
From: |
Eshel Yaron |
Subject: |
feature/minibuffer-completion-enhancements 8ecd4371b9a 22/35: ; Avoid attempting to restore stale previous completion input |
Date: |
Sun, 21 Jan 2024 03:54:31 -0500 (EST) |
branch: feature/minibuffer-completion-enhancements
commit 8ecd4371b9a6666b969606601bb1aab98d572cb4
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
; Avoid attempting to restore stale previous completion input
* lisp/minibuffer.el (minibuffer--cache-completion-input): Accept the
minibuffer base contents, not just its length.
(minibuffer-restore-completion-input): Ensure cached minibuffer base
is up to date before restoring.
(completion--do-completion, completion-all-sorted-completions)
(minibuffer-completion-help): Adapt.
---
lisp/minibuffer.el | 50 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 15 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index fc6fe1553e0..c0d656d5771 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1600,11 +1600,17 @@ when the buffer's text is already an exact match."
('always t))
(minibuffer-completion-help beg end))
(t (minibuffer-hide-completions)
- (minibuffer--cache-completion-input
- string (car (completion-boundaries
- string
- minibuffer-completion-table
- minibuffer-completion-predicate "")))
+ (when (minibufferp)
+ (let ((base-size
+ (car (completion-boundaries
+ string
+ minibuffer-completion-table
+ minibuffer-completion-predicate ""))))
+ (minibuffer--cache-completion-input
+ (substring string base-size)
+ (buffer-substring-no-properties
+ (minibuffer-prompt-end)
+ (+ (minibuffer-prompt-end) base-size)))))
(when exact
;; If completion did not put point at end of field,
;; it's a sign that completion is not finished.
@@ -1875,8 +1881,14 @@ include as `display-sort-function' in completion
metadata."
;; Cache input for `minibuffer-restore-completion-input',
;; unless STRING is an exact and sole completion.
- (unless (and (not (consp (cdr all))) (equal (car all) string))
- (minibuffer--cache-completion-input string base-size))
+ (and (minibufferp)
+ (or (consp (cdr all)) ; not sole
+ (not (equal (car all) string))) ; not exact
+ (minibuffer--cache-completion-input
+ (substring string base-size)
+ (buffer-substring-no-properties (minibuffer-prompt-end)
+ (+ (minibuffer-prompt-end)
+ base-size))))
;; Cache the result. This is not just for speed, but also so that
;; repeated calls to minibuffer-force-complete can cycle through
@@ -1934,10 +1946,17 @@ Interactively, ARG is the prefix argument, and it
defaults to 1."
(defun minibuffer-restore-completion-input ()
"Restore minibuffer contents to last input used for completion."
(interactive "" minibuffer-mode)
- (when completion--input
- (completion--replace (+ (minibuffer-prompt-end) (cdr completion--input))
- (point-max)
- (car completion--input))))
+ (let* ((string (car completion--input))
+ (base (cdr completion--input))
+ (base-size (length base))
+ (prompt-end (minibuffer-prompt-end)))
+ (setq completion--input nil)
+ (if (and string (<= (+ prompt-end base-size (length string)) (point-max))
+ ;; Don't restore if the base has changed.
+ (equal base (buffer-substring-no-properties
+ prompt-end (+ prompt-end base-size))))
+ (completion--replace (+ prompt-end base-size) (point-max) string)
+ (user-error "No partial completion input to restore"))))
(defun minibuffer-force-complete (&optional start end dont-cycle)
"Complete the minibuffer to an exact match.
@@ -2832,9 +2851,9 @@ completions list."
(ngettext "" "s" (length styles))
(mapconcat #'symbol-name styles "', `"))))
-(defun minibuffer--cache-completion-input (string base-size)
- "Record STRING and BASE-SIZE for `minibuffer-restore-completion-input'."
- (setq completion--input (cons (substring string base-size) base-size)))
+(defun minibuffer--cache-completion-input (string base)
+ "Record STRING and BASE for `minibuffer-restore-completion-input'."
+ (setq completion--input (cons string base)))
(defun minibuffer-completion-help (&optional start end)
"Display a list of possible completions of the current minibuffer contents."
@@ -2852,7 +2871,6 @@ completions list."
md))
(last (last completions))
(base-size (or (cdr last) 0)))
- (minibuffer--cache-completion-input string base-size)
(message nil)
(if (or (null completions)
(and (not (consp (cdr completions)))
@@ -2896,6 +2914,8 @@ completions list."
;; minibuffer-hide-completions will know whether to
;; delete the window or not.
(display-buffer-mark-dedicated 'soft))
+ (minibuffer--cache-completion-input (substring string base-size)
+ minibuffer-completion-base)
(with-current-buffer-window
"*Completions*"
;; This is a copy of `display-buffer-fallback-action'
- feature/minibuffer-completion-enhancements ca72ed2f7a7 15/35: New command 'minibuffer-set-completion-styles', (continued)
- feature/minibuffer-completion-enhancements ca72ed2f7a7 15/35: New command 'minibuffer-set-completion-styles', Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 68d33f872e9 24/35: Show completions category in heading line, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements a8434d8b285 26/35: ; * etc/NEWS: (re-)announce 'completions-auto-update-mode'., Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 4f85e6f58a4 06/35: ; Respect 'completion-boundaries' in 'completions-auto-update', Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements f9c59caa378 13/35: Improve handling of file name completion predicate, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 26bca940e12 17/35: ; Fix typos in recent documentation additions, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements c80749e4bee 18/35: ; Adapt some recent changes around completion categories, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements dc4ce1052ba 32/35: New command 'crm-complete-and-insert-separator', Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements bc5c729d69f 33/35: ; (crm-change-separator): Enable recursive minibuffers., Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 5fae8cef46d 35/35: ; * doc/emacs/mini.texi (Completion Multi): Fix typo., Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 8ecd4371b9a 22/35: ; Avoid attempting to restore stale previous completion input,
Eshel Yaron <=
- feature/minibuffer-completion-enhancements 370936bef90 23/35: New helper function for creating completion tables with metadata, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements cea254f1483 27/35: Add completion annotations for file name completion, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 4f1e41bc064 29/35: ; Elaborate minibuffer file name reading documentation, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 5725301b016 02/35: * doc/lispref/minibuf.texi (Completion Commands): Fix typos., Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements fd705bffffa 04/35: Add Completions Auto Update minor mode, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements c896c757a9d 05/35: ; Respect 'completion-boundaries' in narrow-completions commands, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 0d82d262b65 12/35: ; Fix completions restriction descriptions with boundaries, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements c00e059c368 30/35: Avoid slow remote file name completion annotations, Eshel Yaron, 2024/01/21
- feature/minibuffer-completion-enhancements 1b22e4b3e11 34/35: Highlight input separators in 'c-r-m' minibuffers, Eshel Yaron, 2024/01/21