Merge from emacs-24; up to 2012-11-15T23:31:37Z!dancol@dancol.org
[emacs.git] / lisp / filecache.el
blobf868ef5e275bd4ae9b5728183815ae160353ee39
1 ;;; filecache.el --- find files using a pre-loaded cache
3 ;; Copyright (C) 1996, 2000-2012 Free Software Foundation, Inc.
5 ;; Author: Peter Breton <pbreton@cs.umb.edu>
6 ;; Created: Sun Nov 10 1996
7 ;; Keywords: convenience
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; The file-cache package is an attempt to make it easy to locate files
27 ;; by name, without having to remember exactly where they are located.
28 ;; This is very handy when working with source trees. You can also add
29 ;; frequently used files to the cache to create a hotlist effect.
30 ;; The cache can be used with any interactive command which takes a
31 ;; filename as an argument.
33 ;; It is worth noting that this package works best when most of the files
34 ;; in the cache have unique names, or (if they have the same name) exist in
35 ;; only a few directories. The worst case is many files all with
36 ;; the same name and in different directories, for example a big source tree
37 ;; with a Makefile in each directory. In such a case, you should probably
38 ;; use an alternate strategy to find the files.
40 ;; ADDING FILES TO THE CACHE:
42 ;; Use the following functions to add items to the file cache:
44 ;; * `file-cache-add-file': Adds a single file to the cache
46 ;; * `file-cache-add-file-list': Adds a list of files to the cache
48 ;; The following functions use the regular expressions in
49 ;; `file-cache-delete-regexps' to eliminate unwanted files:
51 ;; * `file-cache-add-directory': Adds the files in a directory to the
52 ;; cache. You can also specify a regular expression to match the files
53 ;; which should be added.
55 ;; * `file-cache-add-directory-list': Same as above, but acts on a list
56 ;; of directories. You can use `load-path', `exec-path' and the like.
58 ;; * `file-cache-add-directory-using-find': Uses the `find' command to
59 ;; add a directory tree to the cache.
61 ;; * `file-cache-add-directory-using-locate': Uses the `locate' command to
62 ;; add files matching a pattern to the cache.
64 ;; * `file-cache-add-directory-recursively': Uses the find-lisp package to
65 ;; add all files matching a pattern to the cache.
67 ;; Use the function `file-cache-clear-cache' to remove all items from the
68 ;; cache. There are a number of `file-cache-delete' functions provided
69 ;; as well, but in general it is probably better to not worry too much
70 ;; about extra files in the cache.
72 ;; The most convenient way to initialize the cache is with an
73 ;; `eval-after-load' function, as noted in the ADDING FILES
74 ;; AUTOMATICALLY section.
76 ;; FINDING FILES USING THE CACHE:
78 ;; You can use the file-cache with any function that expects a filename as
79 ;; an argument. For example:
81 ;; 1) Invoke a function which expects a filename as an argument:
82 ;; M-x find-file
84 ;; 2) Begin typing a file name.
86 ;; 3) Invoke `file-cache-minibuffer-complete' (bound by default to
87 ;; C-TAB) to complete on the filename using the cache.
89 ;; 4) When you have found a unique completion, the minibuffer contents
90 ;; will change to the full name of that file.
92 ;; If there are a number of directories which contain the completion,
93 ;; invoking `file-cache-minibuffer-complete' repeatedly will cycle through
94 ;; them.
96 ;; 5) You can then edit the minibuffer contents, or press RETURN.
98 ;; It is much easier to simply try it than trying to explain it :)
100 ;;; ADDING FILES AUTOMATICALLY
102 ;; For maximum utility, you should probably define an `eval-after-load'
103 ;; form which loads your favorite files:
105 ;; (eval-after-load
106 ;; "filecache"
107 ;; '(progn
108 ;; (message "Loading file cache...")
109 ;; (file-cache-add-directory-using-find "~/projects")
110 ;; (file-cache-add-directory-list load-path)
111 ;; (file-cache-add-directory "~/")
112 ;; (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar"))
113 ;; ))
115 ;; If you clear and reload the cache frequently, it is probably easiest
116 ;; to put your initializations in a function:
118 ;; (eval-after-load
119 ;; "filecache"
120 ;; '(my-file-cache-initialize))
122 ;; (defun my-file-cache-initialize ()
123 ;; (interactive)
124 ;; (message "Loading file cache...")
125 ;; (file-cache-add-directory-using-find "~/projects")
126 ;; (file-cache-add-directory-list load-path)
127 ;; (file-cache-add-directory "~/")
128 ;; (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar"))
129 ;; ))
131 ;; Of course, you can still add files to the cache afterwards, via
132 ;; Lisp functions.
134 ;; RELATED WORK:
136 ;; This package is a distant relative of Noah Friedman's fff utilities.
137 ;; Our goal is pretty similar, but the implementation strategies are
138 ;; different.
140 ;;; Code:
142 (defgroup file-cache nil
143 "Find files using a pre-loaded cache."
144 :group 'files
145 :group 'convenience
146 :prefix "file-cache-")
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 ;; Customization Variables
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; User-modifiable variables
153 (defcustom file-cache-filter-regexps
154 ;; These are also used in buffers containing lines of file names,
155 ;; so the end-of-name is matched with $ rather than \\'.
156 (list "~$" "\\.o$" "\\.exe$" "\\.a$" "\\.elc$" ",v$" "\\.output$"
157 "\\.$" "#$" "\\.class$")
158 "List of regular expressions used as filters by the file cache.
159 File names which match these expressions will not be added to the cache.
160 Note that the functions `file-cache-add-file' and `file-cache-add-file-list'
161 do not use this variable."
162 :type '(repeat regexp)
163 :group 'file-cache)
165 (defcustom file-cache-find-command "find"
166 "External program used by `file-cache-add-directory-using-find'."
167 :type 'string
168 :group 'file-cache)
170 (defcustom file-cache-find-command-posix-flag 'not-defined
171 "Set to t, if `file-cache-find-command' handles wildcards POSIX style.
172 This variable is automatically set to nil or non-nil
173 if it has the initial value `not-defined' whenever you first
174 call the `file-cache-add-directory-using-find'.
176 Under Windows operating system where Cygwin is available, this value
177 should be t."
178 :type '(choice (const :tag "Yes" t)
179 (const :tag "No" nil)
180 (const :tag "Unknown" not-defined))
181 :group 'file-cache)
183 (defcustom file-cache-locate-command "locate"
184 "External program used by `file-cache-add-directory-using-locate'."
185 :type 'string
186 :group 'file-cache)
188 ;; Minibuffer messages
189 (defcustom file-cache-no-match-message " [File Cache: No match]"
190 "Message to display when there is no completion."
191 :type 'string
192 :group 'file-cache)
194 (defcustom file-cache-sole-match-message " [File Cache: sole completion]"
195 "Message to display when there is only one completion."
196 :type 'string
197 :group 'file-cache)
199 (defcustom file-cache-non-unique-message
200 " [File Cache: complete but not unique]"
201 "Message to display when there is a non-unique completion."
202 :type 'string
203 :group 'file-cache)
205 (defcustom file-cache-completion-ignore-case
206 (if (memq system-type '(ms-dos windows-nt cygwin))
208 completion-ignore-case)
209 "If non-nil, file-cache completion should ignore case.
210 Defaults to the value of `completion-ignore-case'."
211 :type 'boolean
212 :group 'file-cache)
214 (defcustom file-cache-case-fold-search
215 (if (memq system-type '(ms-dos windows-nt cygwin))
217 case-fold-search)
218 "If non-nil, file-cache completion should ignore case.
219 Defaults to the value of `case-fold-search'."
220 :type 'boolean
221 :group 'file-cache)
223 (defcustom file-cache-ignore-case
224 (memq system-type '(ms-dos windows-nt cygwin))
225 "Non-nil means ignore case when checking completions in the file cache.
226 Defaults to nil on DOS and Windows, and t on other systems."
227 :type 'boolean
228 :group 'file-cache)
230 (defvar file-cache-multiple-directory-message nil)
232 ;; Internal variables
233 ;; This should be named *Completions* because that's what the function
234 ;; switch-to-completions in simple.el expects
235 (defcustom file-cache-completions-buffer "*Completions*"
236 "Buffer to display completions when using the file cache."
237 :type 'string
238 :group 'file-cache)
240 (defcustom file-cache-buffer "*File Cache*"
241 "Buffer to hold the cache of file names."
242 :type 'string
243 :group 'file-cache)
245 (defcustom file-cache-buffer-default-regexp "^.+$"
246 "Regexp to match files in `file-cache-buffer'."
247 :type 'regexp
248 :group 'file-cache)
250 (defvar file-cache-last-completion nil)
252 (defvar file-cache-alist nil
253 "Internal data structure to hold cache of file names.
254 It is a list of entries of the form (FILENAME DIRNAME1 DIRNAME2 ...)
255 where FILENAME is a file name component and the entry represents N
256 files of names DIRNAME1/FILENAME, DIRNAME2/FILENAME, ...")
258 (defvar file-cache-completions-keymap
259 (let ((map (make-sparse-keymap)))
260 (set-keymap-parent map completion-list-mode-map)
261 (define-key map [mouse-2] 'file-cache-choose-completion)
262 (define-key map "\C-m" 'file-cache-choose-completion)
263 map)
264 "Keymap for file cache completions buffer.")
266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267 ;; Functions to add files to the cache
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
270 ;;;###autoload
271 (defun file-cache-add-directory (directory &optional regexp)
272 "Add DIRECTORY to the file cache.
273 If the optional REGEXP argument is non-nil, only files which match it will
274 be added to the cache."
275 (interactive "DAdd files from directory: ")
276 ;; Not an error, because otherwise we can't use load-paths that
277 ;; contain non-existent directories.
278 (if (not (file-accessible-directory-p directory))
279 (message "Directory %s does not exist" directory)
280 (let* ((dir (expand-file-name directory))
281 (dir-files (directory-files dir t regexp)))
282 ;; Filter out files we don't want to see
283 (dolist (file dir-files)
284 (if (file-directory-p file)
285 (setq dir-files (delq file dir-files))
286 (dolist (regexp file-cache-filter-regexps)
287 (if (string-match regexp file)
288 (setq dir-files (delq file dir-files))))))
289 (file-cache-add-file-list dir-files))))
291 ;;;###autoload
292 (defun file-cache-add-directory-list (directory-list &optional regexp)
293 "Add DIRECTORY-LIST (a list of directory names) to the file cache.
294 If the optional REGEXP argument is non-nil, only files which match it
295 will be added to the cache. Note that the REGEXP is applied to the
296 files in each directory, not to the directory list itself."
297 (interactive "XAdd files from directory list: ")
298 (mapcar
299 (lambda (dir) (file-cache-add-directory dir regexp))
300 directory-list))
302 (defun file-cache-add-file-list (file-list)
303 "Add FILE-LIST (a list of file names) to the file cache.
304 Interactively, FILE-LIST is read as a Lisp expression, which
305 should evaluate to the desired list of file names."
306 (interactive "XFile List: ")
307 (mapcar 'file-cache-add-file file-list))
309 ;; Workhorse function
311 ;;;###autoload
312 (defun file-cache-add-file (file)
313 "Add FILE to the file cache."
314 (interactive "fAdd File: ")
315 (setq file (file-truename file))
316 (unless (file-exists-p file)
317 (error "Filecache: file %s does not exist" file))
318 (let* ((file-name (file-name-nondirectory file))
319 (dir-name (file-name-directory file))
320 (the-entry (assoc-string file-name file-cache-alist
321 file-cache-ignore-case)))
322 ;; Does the entry exist already?
323 (if the-entry
324 (unless (or (and (stringp (cdr the-entry))
325 (string= dir-name (cdr the-entry)))
326 (and (listp (cdr the-entry))
327 (member dir-name (cdr the-entry))))
328 (setcdr the-entry (cons dir-name (cdr the-entry))))
329 ;; If not, add it to the cache
330 (push (list file-name dir-name) file-cache-alist))))
332 ;;;###autoload
333 (defun file-cache-add-directory-using-find (directory)
334 "Use the `find' command to add files to the file cache.
335 Find is run in DIRECTORY."
336 (interactive "DAdd files under directory: ")
337 (let ((dir (expand-file-name directory)))
338 (when (memq system-type '(windows-nt cygwin))
339 (if (eq file-cache-find-command-posix-flag 'not-defined)
340 (setq file-cache-find-command-posix-flag
341 (executable-command-find-posix-p file-cache-find-command))))
342 (set-buffer (get-buffer-create file-cache-buffer))
343 (erase-buffer)
344 (call-process file-cache-find-command nil
345 (get-buffer file-cache-buffer) nil
346 dir "-name"
347 (if (memq system-type '(windows-nt cygwin))
348 (if file-cache-find-command-posix-flag
349 "\\*"
350 "'*'")
351 "*")
352 "-print")
353 (file-cache-add-from-file-cache-buffer)))
355 ;;;###autoload
356 (defun file-cache-add-directory-using-locate (string)
357 "Use the `locate' command to add files to the file cache.
358 STRING is passed as an argument to the locate command."
359 (interactive "sAdd files using locate string: ")
360 (set-buffer (get-buffer-create file-cache-buffer))
361 (erase-buffer)
362 (call-process file-cache-locate-command nil
363 (get-buffer file-cache-buffer) nil
364 string)
365 (file-cache-add-from-file-cache-buffer))
367 (autoload 'find-lisp-find-files "find-lisp")
369 ;;;###autoload
370 (defun file-cache-add-directory-recursively (dir &optional regexp)
371 "Adds DIR and any subdirectories to the file-cache.
372 This function does not use any external programs.
373 If the optional REGEXP argument is non-nil, only files which match it
374 will be added to the cache. Note that the REGEXP is applied to the
375 files in each directory, not to the directory list itself."
376 (interactive "DAdd directory: ")
377 (mapcar
378 (lambda (file)
379 (or (file-directory-p file)
380 (let (filtered)
381 (dolist (regexp file-cache-filter-regexps)
382 (and (string-match regexp file)
383 (setq filtered t)))
384 filtered)
385 (file-cache-add-file file)))
386 (find-lisp-find-files dir (or regexp "^"))))
388 (defun file-cache-add-from-file-cache-buffer (&optional regexp)
389 "Add any entries found in the file cache buffer.
390 Each entry matches the regular expression `file-cache-buffer-default-regexp'
391 or the optional REGEXP argument."
392 (set-buffer file-cache-buffer)
393 (dolist (elt file-cache-filter-regexps)
394 (goto-char (point-min))
395 (delete-matching-lines elt))
396 (goto-char (point-min))
397 (let ((full-filename))
398 (while (re-search-forward
399 (or regexp file-cache-buffer-default-regexp)
400 (point-max) t)
401 (setq full-filename (buffer-substring-no-properties
402 (match-beginning 0) (match-end 0)))
403 (file-cache-add-file full-filename))))
405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 ;; Functions to delete from the cache
407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 (defun file-cache-clear-cache ()
410 "Clear the file cache."
411 (interactive)
412 (setq file-cache-alist nil))
414 ;; This clears *all* files with the given name
415 (defun file-cache-delete-file (file)
416 "Delete FILE from the file cache."
417 (interactive
418 (list (completing-read "Delete file from cache: " file-cache-alist)))
419 (setq file-cache-alist
420 (delq (assoc-string file file-cache-alist file-cache-ignore-case)
421 file-cache-alist)))
423 (defun file-cache-delete-file-list (file-list)
424 "Delete FILE-LIST (a list of files) from the file cache."
425 (interactive "XFile List: ")
426 (mapcar 'file-cache-delete-file file-list))
428 (defun file-cache-delete-file-regexp (regexp)
429 "Delete files matching REGEXP from the file cache."
430 (interactive "sRegexp: ")
431 (let ((delete-list))
432 (dolist (elt file-cache-alist)
433 (and (string-match regexp (car elt))
434 (push (car elt) delete-list)))
435 (file-cache-delete-file-list delete-list)
436 (message "Filecache: deleted %d files from file cache"
437 (length delete-list))))
439 (defun file-cache-delete-directory (directory)
440 "Delete DIRECTORY from the file cache."
441 (interactive "DDelete directory from file cache: ")
442 (let ((dir (expand-file-name directory))
443 (result 0))
444 (dolist (entry file-cache-alist)
445 (if (file-cache-do-delete-directory dir entry)
446 (setq result (1+ result))))
447 (if (zerop result)
448 (error "Filecache: no entries containing %s found in cache" directory)
449 (message "Filecache: deleted %d entries" result))))
451 (defun file-cache-do-delete-directory (dir entry)
452 (let ((directory-list (cdr entry))
453 (directory (file-cache-canonical-directory dir)))
454 (and (member directory directory-list)
455 (if (equal 1 (length directory-list))
456 (setq file-cache-alist
457 (delq entry file-cache-alist))
458 (setcdr entry (delete directory directory-list))))))
460 (defun file-cache-delete-directory-list (directory-list)
461 "Delete DIRECTORY-LIST (a list of directories) from the file cache."
462 (interactive "XDirectory List: ")
463 (mapcar 'file-cache-delete-directory directory-list))
465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
466 ;; Utility functions
467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
469 ;; Returns the name of a directory for a file in the cache
470 (defun file-cache-directory-name (file)
471 (let* ((directory-list (cdr (assoc-string
472 file file-cache-alist
473 file-cache-ignore-case)))
474 (len (length directory-list))
475 (directory)
476 (num))
477 (if (not (listp directory-list))
478 (error "Filecache: unknown type in file-cache-alist for key %s" file))
479 (cond
480 ;; Single element
481 ((eq 1 len)
482 (setq directory (elt directory-list 0)))
483 ;; No elements
484 ((eq 0 len)
485 (error "Filecache: no directory found for key %s" file))
486 ;; Multiple elements
488 (let* ((minibuffer-dir (file-name-directory (minibuffer-contents)))
489 (dir-list (member minibuffer-dir directory-list)))
490 (setq directory
491 ;; If the directory is in the list, return the next element
492 ;; Otherwise, return the first element
493 (if dir-list
494 (or (elt directory-list
495 (setq num (1+ (- len (length dir-list)))))
496 (elt directory-list (setq num 0)))
497 (elt directory-list (setq num 0)))))))
498 ;; If there were multiple directories, set up a minibuffer message
499 (setq file-cache-multiple-directory-message
500 (and num (format " [%d of %d]" (1+ num) len)))
501 directory))
503 ;; Returns the name of a file in the cache
504 (defun file-cache-file-name (file)
505 (let ((directory (file-cache-directory-name file)))
506 (concat directory file)))
508 ;; Return a canonical directory for comparison purposes.
509 ;; Such a directory ends with a forward slash.
510 (defun file-cache-canonical-directory (dir)
511 (let ((directory dir))
512 (if (not (char-equal ?/ (string-to-char (substring directory -1))))
513 (concat directory "/")
514 directory)))
516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
517 ;; Minibuffer functions
518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
520 ;; The prefix argument works around a bug in the minibuffer completion.
521 ;; The completion function doesn't distinguish between the states:
523 ;; "Multiple completions of name" (eg, Makefile, Makefile.in)
524 ;; "Name available in multiple directories" (/tmp/Makefile, ~me/Makefile)
526 ;; The default is to do the former; a prefix arg forces the latter.
528 ;;;###autoload
529 (defun file-cache-minibuffer-complete (arg)
530 "Complete a filename in the minibuffer using a preloaded cache.
531 Filecache does two kinds of substitution: it completes on names in
532 the cache, and, once it has found a unique name, it cycles through
533 the directories that the name is available in. With a prefix argument,
534 the name is considered already unique; only the second substitution
535 \(directories) is done."
536 (interactive "P")
537 (let*
539 (completion-ignore-case file-cache-completion-ignore-case)
540 (case-fold-search file-cache-case-fold-search)
541 (string (file-name-nondirectory (minibuffer-contents)))
542 (completion-string (try-completion string file-cache-alist))
543 (completion-list)
544 (len)
545 (file-cache-string))
546 (cond
547 ;; If it's the only match, replace the original contents
548 ((or arg (eq completion-string t))
549 (setq file-cache-string (file-cache-file-name string))
550 (if (string= file-cache-string (minibuffer-contents))
551 (minibuffer-message file-cache-sole-match-message)
552 (delete-minibuffer-contents)
553 (insert file-cache-string)
554 (if file-cache-multiple-directory-message
555 (minibuffer-message file-cache-multiple-directory-message))))
557 ;; If it's the longest match, insert it
558 ((stringp completion-string)
559 ;; If we've already inserted a unique string, see if the user
560 ;; wants to use that one
561 (if (and (string= string completion-string)
562 (assoc-string string file-cache-alist
563 file-cache-ignore-case))
564 (if (and (eq last-command this-command)
565 (string= file-cache-last-completion completion-string))
566 (progn
567 (delete-minibuffer-contents)
568 (insert (file-cache-file-name completion-string))
569 (setq file-cache-last-completion nil))
570 (minibuffer-message file-cache-non-unique-message)
571 (setq file-cache-last-completion string))
572 (setq file-cache-last-completion string)
573 (setq completion-list (all-completions string file-cache-alist)
574 len (length completion-list))
575 (if (> len 1)
576 (progn
577 (goto-char (point-max))
578 (insert
579 (substring completion-string (length string)))
580 ;; Add our own setup function to the Completions Buffer
581 (let ((completion-setup-hook
582 (append completion-setup-hook
583 (list 'file-cache-completion-setup-function))))
584 (with-output-to-temp-buffer file-cache-completions-buffer
585 (display-completion-list completion-list string))))
586 (setq file-cache-string (file-cache-file-name completion-string))
587 (if (string= file-cache-string (minibuffer-contents))
588 (minibuffer-message file-cache-sole-match-message)
589 (delete-minibuffer-contents)
590 (insert file-cache-string)
591 (if file-cache-multiple-directory-message
592 (minibuffer-message file-cache-multiple-directory-message)))
595 ;; No match
596 ((eq completion-string nil)
597 (minibuffer-message file-cache-no-match-message)))))
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
600 ;; Completion functions
601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603 (defun file-cache-completion-setup-function ()
604 (with-current-buffer standard-output ;; i.e. file-cache-completions-buffer
605 (use-local-map file-cache-completions-keymap)))
607 (defun file-cache-choose-completion (&optional event)
608 "Choose a completion in the `*Completions*' buffer."
609 (interactive (list last-nonmenu-event))
610 (let ((completion-no-auto-exit t))
611 (choose-completion event)
612 (select-window (active-minibuffer-window))
613 (file-cache-minibuffer-complete nil)))
615 (define-obsolete-function-alias 'file-cache-mouse-choose-completion
616 'file-cache-choose-completion "23.2")
618 (defun file-cache-complete ()
619 "Complete the word at point, using the filecache."
620 (interactive)
621 (let ((start
622 (save-excursion
623 (skip-syntax-backward "^\"")
624 (point))))
625 (completion-in-region start (point) file-cache-alist)))
627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
628 ;; Show parts of the cache
629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
631 (defun file-cache-files-matching-internal (regexp)
632 "Output a list of files whose names (not including directories)
633 match REGEXP."
634 (let ((results))
635 (dolist (cache-element file-cache-alist)
636 (and (string-match regexp (elt cache-element 0))
637 (push (elt cache-element 0) results)))
638 (nreverse results)))
640 (defun file-cache-files-matching (regexp)
641 "Output a list of files whose names (not including directories)
642 match REGEXP."
643 (interactive "sFind files matching regexp: ")
644 (let ((results
645 (file-cache-files-matching-internal regexp))
646 buf)
647 (set-buffer
648 (setq buf (get-buffer-create
649 "*File Cache Files Matching*")))
650 (erase-buffer)
651 (insert
652 (mapconcat
653 'identity
654 results
655 "\n"))
656 (goto-char (point-min))
657 (display-buffer buf)))
659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
660 ;; Debugging functions
661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663 (defun file-cache-debug-read-from-minibuffer (file)
664 "Debugging function."
665 (interactive
666 (list (completing-read "File Cache: " file-cache-alist)))
667 (message "%s" (assoc-string file file-cache-alist
668 file-cache-ignore-case)))
670 (defun file-cache-display ()
671 "Display the file cache."
672 (interactive)
673 (let ((buf "*File Cache Contents*"))
674 (with-current-buffer
675 (get-buffer-create buf)
676 (erase-buffer)
677 (dolist (item file-cache-alist)
678 (insert (nth 1 item) (nth 0 item) "\n"))
679 (pop-to-buffer buf))))
681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
682 ;; Keybindings
683 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
685 (provide 'filecache)
687 ;;; filecache.el ends here