63 |
;; * `file-cache-add-directory-using-locate': Uses the `locate' command to |
;; * `file-cache-add-directory-using-locate': Uses the `locate' command to |
64 |
;; add files matching a pattern to the cache. |
;; 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. |
68 |
|
;; |
69 |
;; Use the function `file-cache-clear-cache' to remove all items from the |
;; Use the function `file-cache-clear-cache' to remove all items from the |
70 |
;; cache. There are a number of `file-cache-delete' functions provided |
;; cache. There are a number of `file-cache-delete' functions provided |
71 |
;; as well, but in general it is probably better to not worry too much |
;; as well, but in general it is probably better to not worry too much |
141 |
|
|
142 |
;;; Code: |
;;; Code: |
143 |
|
|
144 |
|
(eval-when-compile |
145 |
|
(require 'find-lisp)) |
146 |
|
|
147 |
(defgroup file-cache nil |
(defgroup file-cache nil |
148 |
"Find files using a pre-loaded cache." |
"Find files using a pre-loaded cache." |
149 |
:group 'files |
:group 'files |
193 |
:group 'file-cache) |
:group 'file-cache) |
194 |
|
|
195 |
(defcustom file-cache-completion-ignore-case |
(defcustom file-cache-completion-ignore-case |
196 |
(if (memq system-type (list 'ms-dos 'windows-nt)) |
(if (memq system-type (list 'ms-dos 'windows-nt 'cygwin)) |
197 |
t |
t |
198 |
completion-ignore-case) |
completion-ignore-case) |
199 |
"If non-nil, file-cache completion should ignore case. |
"If non-nil, file-cache completion should ignore case. |
203 |
) |
) |
204 |
|
|
205 |
(defcustom file-cache-case-fold-search |
(defcustom file-cache-case-fold-search |
206 |
(if (memq system-type (list 'ms-dos 'windows-nt)) |
(if (memq system-type (list 'ms-dos 'windows-nt 'cygwin)) |
207 |
t |
t |
208 |
case-fold-search) |
case-fold-search) |
209 |
"If non-nil, file-cache completion should ignore case. |
"If non-nil, file-cache completion should ignore case. |
213 |
) |
) |
214 |
|
|
215 |
(defcustom file-cache-assoc-function |
(defcustom file-cache-assoc-function |
216 |
(if (memq system-type (list 'ms-dos 'windows-nt)) |
(if (memq system-type (list 'ms-dos 'windows-nt 'cygwin)) |
217 |
'assoc-ignore-case |
'assoc-ignore-case |
218 |
'assoc) |
'assoc) |
219 |
"Function to use to check completions in the file cache. |
"Function to use to check completions in the file cache. |
344 |
string) |
string) |
345 |
(file-cache-add-from-file-cache-buffer)) |
(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 "^")))) |
370 |
|
|
371 |
(defun file-cache-add-from-file-cache-buffer (&optional regexp) |
(defun file-cache-add-from-file-cache-buffer (&optional regexp) |
372 |
"Add any entries found in the file cache buffer. |
"Add any entries found in the file cache buffer. |
373 |
Each entry matches the regular expression `file-cache-buffer-default-regexp' |
Each entry matches the regular expression `file-cache-buffer-default-regexp' |
655 |
) |
) |
656 |
) |
) |
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 |
|
|
682 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
683 |
;; Show parts of the cache |
;; Show parts of the cache |
684 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
728 |
(message "%s" (funcall file-cache-assoc-function file file-cache-alist)) |
(message "%s" (funcall file-cache-assoc-function file file-cache-alist)) |
729 |
) |
) |
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 |
|
|
746 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
747 |
;; Keybindings |
;; Keybindings |
748 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |