]> git.eshelyaron.com Git - emacs.git/commitdiff
lisp/minibuffer.el (completion--sifn-requote): Fix bug#72176
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 25 Jul 2024 12:39:38 +0000 (08:39 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sat, 27 Jul 2024 12:03:04 +0000 (14:03 +0200)
(cherry picked from commit 7170282a59a1981cd44f46d69a28f2c47a46884b)

lisp/minibuffer.el

index f6b0ca5bd109641f89ac9ebf0ad3bd51669303e9..8d3d41d33f77de9f6a598c7328d7c700471cecc5 100644 (file)
@@ -3824,7 +3824,7 @@ strings in `completion-ignored-extensions'."
     (file-error nil)))               ;PCM often calls with invalid directories.
 
 (defun completion--sifn-requote (upos qstr)
-  ;; We're looking for `qpos' such that:
+  ;; We're looking for (the largest) `qpos' such that:
   ;; (equal (substring (substitute-in-file-name qstr) 0 upos)
   ;;        (substitute-in-file-name (substring qstr 0 qpos)))
   ;; Big problem here: we have to reverse engineer substitute-in-file-name to
@@ -3854,11 +3854,13 @@ strings in `completion-ignored-extensions'."
       ;; 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,
+      ;; Second assumption: 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
+                    ;; Try and make sure we keep the largest `qpos' (bug#72176).
+                    (not (string-match-p "/[/~]" qstr boundary))
                     (progn
                       (setq qprefix (substring qstr 0 boundary))
                       (string-prefix-p uprefix