diff options
| author | Stefan Monnier | 2002-04-30 01:56:23 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-04-30 01:56:23 +0000 |
| commit | 38eea7c76fab12adf2754fa109ead0d7c2ace04e (patch) | |
| tree | 026476145378c2b8df5f79758bf6228746e9c24e | |
| parent | de2413e9d9265a81128bae814472f9c4e7d09109 (diff) | |
| download | emacs-38eea7c76fab12adf2754fa109ead0d7c2ace04e.tar.gz emacs-38eea7c76fab12adf2754fa109ead0d7c2ace04e.zip | |
(locate-file): New fun.
(locate-file-completion): Rename from load-completion and generalize.
(load-library): Use it.
(make-auto-save-file-name): Expand caddr.
| -rw-r--r-- | lisp/files.el | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lisp/files.el b/lisp/files.el index 51eeaa73a71..4733a47df5f 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -546,13 +546,34 @@ colon-separated list of directories when resolving a relative directory name." | |||
| 546 | (read-file-name "Load file: ")))) | 546 | (read-file-name "Load file: ")))) |
| 547 | (load (expand-file-name file) nil nil t)) | 547 | (load (expand-file-name file) nil nil t)) |
| 548 | 548 | ||
| 549 | (defun load-completion (string predicate action) | 549 | (defun locate-file (filename path &optional suffixes predicate) |
| 550 | "Search for FILENAME through PATH. | ||
| 551 | If SUFFIXES is non-nil, it should be a list of suffixes to append to | ||
| 552 | file name when searching. If SUFFIXES is nil, it is equivalent to '(\"\"). | ||
| 553 | If non-nil, PREDICATE is used instead of `file-readable-p'. | ||
| 554 | PREDICATE can also be an integer to pass to the access(2) function, | ||
| 555 | in which case file-name-handlers are ignored. | ||
| 556 | For compatibility with XEmacs, PREDICATE can also be a symbol among | ||
| 557 | `executable', `readable', `writable', or `exists' or a list of one | ||
| 558 | of those symbols." | ||
| 559 | (if (and predicate (symbolp predicate) (not (functionp predicate))) | ||
| 560 | (setq predicate (list predicate))) | ||
| 561 | (when (and (consp predicate) (not (functionp predicate))) | ||
| 562 | (setq predicate | ||
| 563 | (logior (if (memq 'executable predicate) 1 0) | ||
| 564 | (if (memq 'writable predicate) 2 0) | ||
| 565 | (if (memq 'readable predicate) 4 0)))) | ||
| 566 | (locate-file-internal filename path suffixes predicate)) | ||
| 567 | |||
| 568 | (defun locate-file-completion (string path-and-suffixes action) | ||
| 569 | "Do completion for file names passed to `locate-file'. | ||
| 570 | PATH-AND-SUFFIXES is a pair of lists (DIRECTORIES . SUFFIXES)." | ||
| 550 | (if (file-name-absolute-p string) | 571 | (if (file-name-absolute-p string) |
| 551 | (read-file-name-internal string predicate action) | 572 | (read-file-name-internal string nil action) |
| 552 | (let ((names nil) | 573 | (let ((names nil) |
| 553 | (suffix (concat (regexp-opt load-suffixes t) "\\'")) | 574 | (suffix (concat (regexp-opt (cdr path-and-suffixes) t) "\\'")) |
| 554 | (string-dir (file-name-directory string))) | 575 | (string-dir (file-name-directory string))) |
| 555 | (dolist (dir load-path) | 576 | (dolist (dir (car path-and-suffixes)) |
| 556 | (if string-dir (setq dir (expand-file-name string-dir dir))) | 577 | (if string-dir (setq dir (expand-file-name string-dir dir))) |
| 557 | (when (file-directory-p dir) | 578 | (when (file-directory-p dir) |
| 558 | (dolist (file (file-name-all-completions | 579 | (dolist (file (file-name-all-completions |
| @@ -562,13 +583,16 @@ colon-separated list of directories when resolving a relative directory name." | |||
| 562 | (setq file (substring file 0 (match-beginning 0))) | 583 | (setq file (substring file 0 (match-beginning 0))) |
| 563 | (push (if string-dir (concat string-dir file) file) names))))) | 584 | (push (if string-dir (concat string-dir file) file) names))))) |
| 564 | (if action | 585 | (if action |
| 565 | (all-completions string (mapcar 'list names) predicate) | 586 | (all-completions string (mapcar 'list names)) |
| 566 | (try-completion string (mapcar 'list names) predicate))))) | 587 | (try-completion string (mapcar 'list names)))))) |
| 567 | 588 | ||
| 568 | (defun load-library (library) | 589 | (defun load-library (library) |
| 569 | "Load the library named LIBRARY. | 590 | "Load the library named LIBRARY. |
| 570 | This is an interface to the function `load'." | 591 | This is an interface to the function `load'." |
| 571 | (interactive (list (completing-read "Load library: " 'load-completion))) | 592 | (interactive |
| 593 | (list (completing-read "Load library: " | ||
| 594 | 'locate-file-completion | ||
| 595 | (cons load-path load-suffixes)))) | ||
| 572 | (load library)) | 596 | (load library)) |
| 573 | 597 | ||
| 574 | (defun file-local-copy (file) | 598 | (defun file-local-copy (file) |
| @@ -3372,7 +3396,7 @@ See also `auto-save-file-name-p'." | |||
| 3372 | (if (string-match (car (car list)) filename) | 3396 | (if (string-match (car (car list)) filename) |
| 3373 | (setq result (replace-match (cadr (car list)) t nil | 3397 | (setq result (replace-match (cadr (car list)) t nil |
| 3374 | filename) | 3398 | filename) |
| 3375 | uniq (caddr (car list)))) | 3399 | uniq (car (cddr (car list))))) |
| 3376 | (setq list (cdr list))) | 3400 | (setq list (cdr list))) |
| 3377 | (if result | 3401 | (if result |
| 3378 | (if uniq | 3402 | (if uniq |