diff options
author | Stephen Leake <stephen_leake@stephe-leake.org> | 2019-04-25 16:29:36 -0700 |
---|---|---|
committer | Stephen Leake <stephen_leake@stephe-leake.org> | 2019-04-25 16:29:36 -0700 |
commit | d2a5283a065fd03d6dc606cc7ec29822e544dffb (patch) | |
tree | 275e0ea3a813d77fd9319832b3b87d66b14ca6d4 /lisp/files.el | |
parent | 1486eadf7c9469f873fcd04beafd03f21564d580 (diff) | |
download | emacs-scratch/project-uniquify-files.tar.gz |
Add new file completion tables, change project.el to allow using themscratch/project-uniquify-files
* lisp/file-complete-root-relative.el: New file.
* lisp/uniquify-files.el: New file.
* test/lisp/progmodes/uniquify-files-resources/: New directory
containing files for testing uniquify-files.
* test/lisp/progmodes/uniquify-files-test.el: New file; test
uniquify-files.
* lisp/files.el (path-files): New function; useful with new completion
tables.
* lisp/progmodes/project.el (project-file-completion-table): Use
file-complete-root-relative completion table.
(project-find-file): Add optional FILENAME parameter.
(project--completing-read-strict): Rewrite to just use the given
completion table; extracting the common directory is now done by
file-complete-root-relative. This also allows using the new
uniquify-files completion table.
* lisp/minibuffer.el (completion-category-defaults): Add
uniquify-file.
(completing-read-default): Add final step to call completion table
with 'alist action if supported.
Diffstat (limited to 'lisp/files.el')
-rw-r--r-- | lisp/files.el | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/files.el b/lisp/files.el index c05d70a00ec..47ee197536e 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -842,6 +842,32 @@ output directories whose names match REGEXP." (push (expand-file-name file dir) files))))) (nconc result (nreverse files)))) +(defun path-files (path &optional pred) + "Return a list of all files matching PRED in PATH. +PATH is flat; no subdirectories of entries in PATH are +visited (unless they are also in PATH). PRED is a function +taking one argument; an absolute file name." + (let (visited ;; list of already visited directories, to avoid duplication + result) + (dolist (dir path) + (while (member dir visited) + (setq dir (pop path))) + (when (and dir + (file-directory-p dir)) + (push dir visited) + (mapc + (lambda (rel-file) + (let ((absfile (concat (file-name-as-directory dir) rel-file))) + (when (and (not (string-equal "." (substring absfile -1))) + (not (string-equal ".." (substring absfile -2))) + (not (file-directory-p absfile)) + (or (null pred) + (funcall pred absfile))) + (push absfile result)))) + (file-name-all-completions "" dir));; uses completion-regexp-list + )) + result)) + (defvar module-file-suffix) (defun load-file (file) |