From df1204818a023bdde46e36c8cfd878cf0937fab7 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 4 Sep 2009 03:18:08 +0000 Subject: [PATCH] (locate-file-completion-table): Make it provide boundary information, so partial-completion works better. --- lisp/ChangeLog | 5 +++++ lisp/files.el | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7882d1b1b04..64af8363417 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2009-09-04 Stefan Monnier + + * files.el (locate-file-completion-table): Make it provide boundary + information, so partial-completion works better. + 2009-09-04 Leo (tiny change) * mail/footnote.el (Footnote-text-under-cursor): diff --git a/lisp/files.el b/lisp/files.el index 42eee8e609d..9f22a60dc00 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -716,24 +716,34 @@ one or more of those symbols." (defun locate-file-completion-table (dirs suffixes string pred action) "Do completion for file names passed to `locate-file'." - (if (file-name-absolute-p string) - (let ((read-file-name-predicate pred)) - (read-file-name-internal string nil action)) + (cond + ((file-name-absolute-p string) + (let ((read-file-name-predicate pred)) + (read-file-name-internal string nil action))) + ((eq (car-safe action) 'boundaries) + (let ((suffix (cdr action))) + (list* 'boundaries + (length (file-name-directory string)) + (let ((x (file-name-directory suffix))) + (if x (1- (length x)) (length suffix)))))) + (t (let ((names nil) (suffix (concat (regexp-opt suffixes t) "\\'")) - (string-dir (file-name-directory string))) + (string-dir (file-name-directory string)) + (string-file (file-name-nondirectory string))) (dolist (dir dirs) (unless dir (setq dir default-directory)) (if string-dir (setq dir (expand-file-name string-dir dir))) (when (file-directory-p dir) (dolist (file (file-name-all-completions - (file-name-nondirectory string) dir)) - (add-to-list 'names (if string-dir (concat string-dir file) file)) + string-file dir)) + (push file names) (when (string-match suffix file) (setq file (substring file 0 (match-beginning 0))) - (push (if string-dir (concat string-dir file) file) names))))) - (complete-with-action action names string pred)))) + (push file names))))) + (completion-table-with-context + string-dir names string-file pred action))))) (defun locate-file-completion (string path-and-suffixes action) "Do completion for file names passed to `locate-file'. -- 2.39.2