comparison lisp/minibuffer.el @ 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 9f927f4deab4
children f0d32dbd0fcf
comparison
equal deleted inserted replaced
108830:0d7ed8742a5f 108831:c8b4b7099b45
1340 (ignore-errors 1340 (ignore-errors
1341 (cond 1341 (cond
1342 ((eq (car-safe action) 'boundaries) 1342 ((eq (car-safe action) 'boundaries)
1343 (let ((start (length (file-name-directory string))) 1343 (let ((start (length (file-name-directory string)))
1344 (end (string-match-p "/" (cdr action)))) 1344 (end (string-match-p "/" (cdr action))))
1345 (list* 'boundaries start end))) 1345 (list* 'boundaries
1346 1346 ;; if `string' is "C:" in w32, (file-name-directory string)
1347 ((eq action 'lambda) 1347 ;; returns "C:/", so `start' is 3 rather than 2.
1348 (if (zerop (length string)) 1348 ;; Not quite sure what is The Right Fix, but clipping it
1349 nil ;Not sure why it's here, but it probably doesn't harm. 1349 ;; back to 2 will work for this particular case. We'll
1350 (funcall (or pred 'file-exists-p) string))) 1350 ;; see if we can come up with a better fix when we bump
1351 ;; into more such problematic cases.
1352 (min start (length string)) end)))
1353
1354 ((eq action 'lambda)
1355 (if (zerop (length string))
1356 nil ;Not sure why it's here, but it probably doesn't harm.
1357 (funcall (or pred 'file-exists-p) string)))
1351 1358
1352 (t 1359 (t
1353 (let* ((name (file-name-nondirectory string)) 1360 (let* ((name (file-name-nondirectory string))
1354 (specdir (file-name-directory string)) 1361 (specdir (file-name-directory string))
1355 (realdir (or specdir default-directory))) 1362 (realdir (or specdir default-directory)))
1393 This is a completion table for file names, like `completion-file-name-table' 1400 This is a completion table for file names, like `completion-file-name-table'
1394 except that it passes the file name through `substitute-in-file-name'." 1401 except that it passes the file name through `substitute-in-file-name'."
1395 (cond 1402 (cond
1396 ((eq (car-safe action) 'boundaries) 1403 ((eq (car-safe action) 'boundaries)
1397 ;; For the boundaries, we can't really delegate to 1404 ;; For the boundaries, we can't really delegate to
1398 ;; completion-file-name-table and then fix them up, because it 1405 ;; substitute-in-file-name+completion-file-name-table and then fix
1399 ;; would require us to track the relationship between `str' and 1406 ;; them up (as we do for the other actions), because it would
1407 ;; require us to track the relationship between `str' and
1400 ;; `string', which is difficult. And in any case, if 1408 ;; `string', which is difficult. And in any case, if
1401 ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba", there's 1409 ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba",
1402 ;; no way for us to return proper boundaries info, because the 1410 ;; there's no way for us to return proper boundaries info, because
1403 ;; boundary is not (yet) in `string'. 1411 ;; the boundary is not (yet) in `string'.
1404 ;; FIXME: Actually there is a way to return correct boundaries info, 1412 ;;
1405 ;; at the condition of modifying the all-completions return accordingly. 1413 ;; FIXME: Actually there is a way to return correct boundaries
1406 (let ((start (length (file-name-directory string))) 1414 ;; info, at the condition of modifying the all-completions
1407 (end (string-match-p "/" (cdr action)))) 1415 ;; return accordingly. But for now, let's not bother.
1408 (list* 'boundaries start end))) 1416 (completion-file-name-table string pred action))
1409 1417
1410 (t 1418 (t
1411 (let* ((default-directory 1419 (let* ((default-directory
1412 (if (stringp pred) 1420 (if (stringp pred)
1413 ;; It used to be that `pred' was abused to pass `dir' 1421 ;; It used to be that `pred' was abused to pass `dir'
1414 ;; as an argument. 1422 ;; as an argument.
1415 (prog1 (file-name-as-directory (expand-file-name pred)) 1423 (prog1 (file-name-as-directory (expand-file-name pred))