Mercurial > emacs
comparison lisp/filecache.el @ 50263:1f6e75676769
Add file-cache-add-directory-recursively function
Add file-cache-complete function
Add file-cache-display function
author | Peter Breton <pbreton@attbi.com> |
---|---|
date | Sat, 22 Mar 2003 12:43:50 +0000 |
parents | 99be3a1e2589 |
children | 695cf19ef79e |
comparison
equal
deleted
inserted
replaced
50262:a7d9ef484195 | 50263:1f6e75676769 |
---|---|
60 ;; * `file-cache-add-directory-using-find': Uses the `find' command to | 60 ;; * `file-cache-add-directory-using-find': Uses the `find' command to |
61 ;; add a directory tree to the cache. | 61 ;; add a directory tree to the cache. |
62 ;; | 62 ;; |
63 ;; * `file-cache-add-directory-using-locate': Uses the `locate' command to | 63 ;; * `file-cache-add-directory-using-locate': Uses the `locate' command to |
64 ;; add files matching a pattern to the cache. | 64 ;; add files matching a pattern to the cache. |
65 ;; | |
66 ;; * `file-cache-add-directory-recursively': Uses the find-lisp package to | |
67 ;; add all files matching a pattern to the cache. | |
65 ;; | 68 ;; |
66 ;; Use the function `file-cache-clear-cache' to remove all items from the | 69 ;; Use the function `file-cache-clear-cache' to remove all items from the |
67 ;; cache. There are a number of `file-cache-delete' functions provided | 70 ;; cache. There are a number of `file-cache-delete' functions provided |
68 ;; as well, but in general it is probably better to not worry too much | 71 ;; as well, but in general it is probably better to not worry too much |
69 ;; about extra files in the cache. | 72 ;; about extra files in the cache. |
135 ;; This package is a distant relative of Noah Friedman's fff utilities. | 138 ;; This package is a distant relative of Noah Friedman's fff utilities. |
136 ;; Our goal is pretty similar, but the implementation strategies are | 139 ;; Our goal is pretty similar, but the implementation strategies are |
137 ;; different. | 140 ;; different. |
138 | 141 |
139 ;;; Code: | 142 ;;; Code: |
143 | |
144 (eval-when-compile | |
145 (require 'find-lisp)) | |
140 | 146 |
141 (defgroup file-cache nil | 147 (defgroup file-cache nil |
142 "Find files using a pre-loaded cache." | 148 "Find files using a pre-loaded cache." |
143 :group 'files | 149 :group 'files |
144 :group 'convenience | 150 :group 'convenience |
335 (erase-buffer) | 341 (erase-buffer) |
336 (call-process file-cache-locate-command nil | 342 (call-process file-cache-locate-command nil |
337 (get-buffer file-cache-buffer) nil | 343 (get-buffer file-cache-buffer) nil |
338 string) | 344 string) |
339 (file-cache-add-from-file-cache-buffer)) | 345 (file-cache-add-from-file-cache-buffer)) |
346 | |
347 (defun file-cache-add-directory-recursively (dir &optional regexp) | |
348 "Adds DIR and any subdirectories to the file-cache. | |
349 This function does not use any external programs | |
350 If the optional REGEXP argument is non-nil, only files which match it | |
351 will be added to the cache. Note that the REGEXP is applied to the files | |
352 in each directory, not to the directory list itself." | |
353 (interactive "DAdd directory: ") | |
354 (require 'find-lisp) | |
355 (mapcar | |
356 (function | |
357 (lambda(file) | |
358 (or (file-directory-p file) | |
359 (let (filtered) | |
360 (mapcar | |
361 (function | |
362 (lambda(regexp) | |
363 (and (string-match regexp file) | |
364 (setq filtered t)) | |
365 )) | |
366 file-cache-filter-regexps) | |
367 filtered) | |
368 (file-cache-add-file file)))) | |
369 (find-lisp-find-files dir (if regexp regexp "^")))) | |
340 | 370 |
341 (defun file-cache-add-from-file-cache-buffer (&optional regexp) | 371 (defun file-cache-add-from-file-cache-buffer (&optional regexp) |
342 "Add any entries found in the file cache buffer. | 372 "Add any entries found in the file cache buffer. |
343 Each entry matches the regular expression `file-cache-buffer-default-regexp' | 373 Each entry matches the regular expression `file-cache-buffer-default-regexp' |
344 or the optional REGEXP argument." | 374 or the optional REGEXP argument." |
623 (select-window (active-minibuffer-window)) | 653 (select-window (active-minibuffer-window)) |
624 (file-cache-minibuffer-complete nil) | 654 (file-cache-minibuffer-complete nil) |
625 ) | 655 ) |
626 ) | 656 ) |
627 | 657 |
658 (defun file-cache-complete () | |
659 "Complete the word at point, using the filecache." | |
660 (interactive) | |
661 (let (start pattern completion all) | |
662 (save-excursion | |
663 (skip-syntax-backward "^\"") | |
664 (setq start (point))) | |
665 (setq pattern (buffer-substring-no-properties start (point))) | |
666 (setq completion (try-completion pattern file-cache-alist)) | |
667 (setq all (all-completions pattern file-cache-alist nil)) | |
668 (cond ((eq completion t)) | |
669 ((null completion) | |
670 (message "Can't find completion for \"%s\"" pattern) | |
671 (ding)) | |
672 ((not (string= pattern completion)) | |
673 (delete-region start (point)) | |
674 (insert completion) | |
675 ) | |
676 (t | |
677 (with-output-to-temp-buffer "*Completions*" | |
678 (display-completion-list all)) | |
679 )) | |
680 )) | |
681 | |
628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 682 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
629 ;; Show parts of the cache | 683 ;; Show parts of the cache |
630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 684 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
631 | 685 |
632 (defun file-cache-files-matching-internal (regexp) | 686 (defun file-cache-files-matching-internal (regexp) |
672 (interactive | 726 (interactive |
673 (list (completing-read "File Cache: " file-cache-alist))) | 727 (list (completing-read "File Cache: " file-cache-alist))) |
674 (message "%s" (funcall file-cache-assoc-function file file-cache-alist)) | 728 (message "%s" (funcall file-cache-assoc-function file file-cache-alist)) |
675 ) | 729 ) |
676 | 730 |
731 (defun file-cache-display () | |
732 "Display the file cache." | |
733 (interactive) | |
734 (let ((buf "*File Cache Contents*")) | |
735 (with-current-buffer | |
736 (get-buffer-create buf) | |
737 (erase-buffer) | |
738 (mapcar | |
739 (function | |
740 (lambda(item) | |
741 (insert (nth 1 item) (nth 0 item) "\n"))) | |
742 file-cache-alist) | |
743 (pop-to-buffer buf) | |
744 ))) | |
745 | |
677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
678 ;; Keybindings | 747 ;; Keybindings |
679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
680 | 749 |
681 ;;;###autoload (define-key minibuffer-local-completion-map [C-tab] 'file-cache-minibuffer-complete) | 750 ;;;###autoload (define-key minibuffer-local-completion-map [C-tab] 'file-cache-minibuffer-complete) |