emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 77cbde6d09: minibuffer.el: Try and fix bug#53053


From: Stefan Monnier
Subject: master 77cbde6d09: minibuffer.el: Try and fix bug#53053
Date: Mon, 7 Feb 2022 16:51:48 -0500 (EST)

branch: master
commit 77cbde6d09bbca0070bfc7765fb07b8a69f7c6f2
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    minibuffer.el: Try and fix bug#53053
    
    * lisp/minibuffer.el (completion--sifn-requote): Special case for when
    `upos` is at the very end.
---
 lisp/minibuffer.el | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index c9f5823940..36b8d80841 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2932,26 +2932,30 @@ same as `substitute-in-file-name'."
   (let* ((ustr (substitute-in-file-name qstr))
          (uprefix (substring ustr 0 upos))
          qprefix)
-    ;; Main assumption: nothing after qpos should affect the text before upos,
-    ;; so we can work our way backward from the end of qstr, one character
-    ;; at a time.
-    ;; Second assumptions: If qpos is far from the end this can be a bit slow,
-    ;; so we speed it up by doing a first loop that skips a word at a time.
-    ;; This word-sized loop is careful not to cut in the middle of env-vars.
-    (while (let ((boundary (string-match "\\(\\$+{?\\)?\\w+\\W*\\'" qstr)))
-             (and boundary
-                  (progn
-                    (setq qprefix (substring qstr 0 boundary))
+    (if (eq upos (length ustr))
+        ;; Easy and common case.  This not only speed things up in a very
+        ;; common case but it also avoids problems in some cases (bug#53053).
+        (cons (length qstr) #'minibuffer-maybe-quote-filename)
+      ;; Main assumption: nothing after qpos should affect the text before 
upos,
+      ;; so we can work our way backward from the end of qstr, one character
+      ;; at a time.
+      ;; Second assumptions: If qpos is far from the end this can be a bit 
slow,
+      ;; so we speed it up by doing a first loop that skips a word at a time.
+      ;; This word-sized loop is careful not to cut in the middle of env-vars.
+      (while (let ((boundary (string-match "\\(\\$+{?\\)?\\w+\\W*\\'" qstr)))
+               (and boundary
+                    (progn
+                      (setq qprefix (substring qstr 0 boundary))
+                      (string-prefix-p uprefix
+                                       (substitute-in-file-name qprefix)))))
+        (setq qstr qprefix))
+      (let ((qpos (length qstr)))
+        (while (and (> qpos 0)
                     (string-prefix-p uprefix
-                                   (substitute-in-file-name qprefix)))))
-      (setq qstr qprefix))
-    (let ((qpos (length qstr)))
-      (while (and (> qpos 0)
-                  (string-prefix-p uprefix
-                                   (substitute-in-file-name
-                                    (substring qstr 0 (1- qpos)))))
-        (setq qpos (1- qpos)))
-      (cons qpos #'minibuffer-maybe-quote-filename))))
+                                     (substitute-in-file-name
+                                      (substring qstr 0 (1- qpos)))))
+          (setq qpos (1- qpos)))
+        (cons qpos #'minibuffer-maybe-quote-filename)))))
 
 (defalias 'completion--file-name-table
   (completion-table-with-quoting #'completion-file-name-table



reply via email to

[Prev in Thread] Current Thread [Next in Thread]