changeset 108831:c8b4b7099b45

* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary past the end of `string'. (completion--file-name-table): Delegate to completion-file-name-table for the `boundaries' case.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 30 May 2010 10:17:31 -0400
parents 0d7ed8742a5f
children d901ae131f55
files lisp/ChangeLog lisp/minibuffer.el
diffstat 2 files changed, 31 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sun May 30 06:44:46 2010 +0200
+++ b/lisp/ChangeLog	Sun May 30 10:17:31 2010 -0400
@@ -1,3 +1,10 @@
+2010-05-30  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* minibuffer.el (completion-file-name-table): Don't return a boundary
+	past the end of `string' (bug#6299).
+	(completion--file-name-table): Delegate to completion-file-name-table
+	for the `boundaries' case.
+
 2010-05-30  Juanma Barranquero  <lekktu@gmail.com>
 
 	* emulation/cua-base.el: Recognize `right-char' and `left-char' as
--- a/lisp/minibuffer.el	Sun May 30 06:44:46 2010 +0200
+++ b/lisp/minibuffer.el	Sun May 30 10:17:31 2010 -0400
@@ -1342,12 +1342,19 @@
    ((eq (car-safe action) 'boundaries)
     (let ((start (length (file-name-directory string)))
           (end (string-match-p "/" (cdr action))))
-      (list* 'boundaries start end)))
+      (list* 'boundaries
+             ;; if `string' is "C:" in w32, (file-name-directory string)
+             ;; returns "C:/", so `start' is 3 rather than 2.
+             ;; Not quite sure what is The Right Fix, but clipping it
+             ;; back to 2 will work for this particular case.  We'll
+             ;; see if we can come up with a better fix when we bump
+             ;; into more such problematic cases.
+             (min start (length string)) end)))
 
-     ((eq action 'lambda)
-      (if (zerop (length string))
-          nil    ;Not sure why it's here, but it probably doesn't harm.
-        (funcall (or pred 'file-exists-p) string)))
+   ((eq action 'lambda)
+    (if (zerop (length string))
+        nil    ;Not sure why it's here, but it probably doesn't harm.
+      (funcall (or pred 'file-exists-p) string)))
 
    (t
       (let* ((name (file-name-nondirectory string))
@@ -1395,19 +1402,20 @@
   (cond
    ((eq (car-safe action) 'boundaries)
     ;; For the boundaries, we can't really delegate to
-    ;; completion-file-name-table and then fix them up, because it
-    ;; would require us to track the relationship between `str' and
+    ;; substitute-in-file-name+completion-file-name-table and then fix
+    ;; them up (as we do for the other actions), because it would
+    ;; require us to track the relationship between `str' and
     ;; `string', which is difficult.  And in any case, if
-    ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba", there's
-    ;; no way for us to return proper boundaries info, because the
-    ;; boundary is not (yet) in `string'.
-    ;; FIXME: Actually there is a way to return correct boundaries info,
-    ;; at the condition of modifying the all-completions return accordingly.
-    (let ((start (length (file-name-directory string)))
-          (end (string-match-p "/" (cdr action))))
-      (list* 'boundaries start end)))
+    ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba",
+    ;; there's no way for us to return proper boundaries info, because
+    ;; the boundary is not (yet) in `string'.
+    ;;
+    ;; FIXME: Actually there is a way to return correct boundaries
+    ;; info, at the condition of modifying the all-completions
+    ;; return accordingly. But for now, let's not bother.
+    (completion-file-name-table string pred action))
 
-       (t
+   (t
     (let* ((default-directory
              (if (stringp pred)
                  ;; It used to be that `pred' was abused to pass `dir'