Include GFDL in org.texi
[emacs.git] / lisp / filecache.el
blob422b33f5dcb5f87858d4169f7ef1d223852ca5db
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 (eval-when-compile
143 (require 'find-lisp))
145 (defgroup file-cache nil
146 "Find files using a pre-loaded cache."
147 :group 'files
148 :group 'convenience
149 :prefix "file-cache-")
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; Customization Variables
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
155 ;; User-modifiable variables
156 (defcustom file-cache-filter-regexps
157 ;; These are also used in buffers containing lines of file names,
158 ;; so the end-of-name is matched with $ rather than \\'.
159 (list "~$" "\\.o$" "\\.exe$" "\\.a$" "\\.elc$" ",v$" "\\.output$"
160 "\\.$" "#$" "\\.class$")
161 "List of regular expressions used as filters by the file cache.
162 File names which match these expressions will not be added to the cache.
163 Note that the functions `file-cache-add-file' and `file-cache-add-file-list'
164 do not use this variable."
165 :type '(repeat regexp)
166 :group 'file-cache)
168 (defcustom file-cache-find-command "find"
169 "External program used by `file-cache-add-directory-using-find'."
170 :type 'string
171 :group 'file-cache)
173 (defcustom file-cache-find-command-posix-flag 'not-defined
174 "Set to t, if `file-cache-find-command' handles wildcards POSIX style.
175 This variable is automatically set to nil or non-nil
176 if it has the initial value `not-defined' whenever you first
177 call the `file-cache-add-directory-using-find'.
179 Under Windows operating system where Cygwin is available, this value
180 should be t."
181 :type '(choice (const :tag "Yes" t)
182 (const :tag "No" nil)
183 (const :tag "Unknown" not-defined))
184 :group 'file-cache)
186 (defcustom file-cache-locate-command "locate"
187 "External program used by `file-cache-add-directory-using-locate'."
188 :type 'string
189 :group 'file-cache)
191 ;; Minibuffer messages
192 (defcustom file-cache-no-match-message " [File Cache: No match]"
193 "Message to display when there is no completion."
194 :type 'string
195 :group 'file-cache)
197 (defcustom file-cache-sole-match-message " [File Cache: sole completion]"
198 "Message to display when there is only one completion."
199 :type 'string
200 :group 'file-cache)
202 (defcustom file-cache-non-unique-message
203 " [File Cache: complete but not unique]"
204 "Message to display when there is a non-unique completion."
205 :type 'string
206 :group 'file-cache)
208 (defcustom file-cache-completion-ignore-case
209 (if (memq system-type '(ms-dos windows-nt cygwin))
211 completion-ignore-case)
212 "If non-nil, file-cache completion should ignore case.
213 Defaults to the value of `completion-ignore-case'."
214 :type 'boolean
215 :group 'file-cache)
217 (defcustom file-cache-case-fold-search
218 (if (memq system-type '(ms-dos windows-nt cygwin))
220 case-fold-search)
221 "If non-nil, file-cache completion should ignore case.
222 Defaults to the value of `case-fold-search'."
223 :type 'boolean
224 :group 'file-cache)
226 (defcustom file-cache-ignore-case
227 (memq system-type '(ms-dos windows-nt cygwin))
228 "Non-nil means ignore case when checking completions in the file cache.
229 Defaults to nil on DOS and Windows, and t on other systems."
230 :type 'boolean
231 :group 'file-cache)
233 (defvar file-cache-multiple-directory-message nil)
235 ;; Internal variables
236 ;; This should be named *Completions* because that's what the function
237 ;; switch-to-completions in simple.el expects
238 (defcustom file-cache-completions-buffer "*Completions*"
239 "Buffer to display completions when using the file cache."
240 :type 'string
241 :group 'file-cache)
243 (defcustom file-cache-buffer "*File Cache*"
244 "Buffer to hold the cache of file names."
245 :type 'string
246 :group 'file-cache)
248 (defcustom file-cache-buffer-default-regexp "^.+$"
249 "Regexp to match files in `file-cache-buffer'."
250 :type 'regexp
251 :group 'file-cache)
253 (defvar file-cache-last-completion nil)
255 (defvar file-cache-alist nil
256 "Internal data structure to hold cache of file names.
257 It is a list of entries of the form (FILENAME DIRNAME1 DIRNAME2 ...)
258 where FILENAME is a file name component and the entry represents N
259 files of names DIRNAME1/FILENAME, DIRNAME2/FILENAME, ...")
261 (defvar file-cache-completions-keymap
262 (let ((map (make-sparse-keymap)))
263 (set-keymap-parent map completion-list-mode-map)
264 (define-key map [mouse-2] 'file-cache-choose-completion)
265 (define-key map "\C-m" 'file-cache-choose-completion)
266 map)
267 "Keymap for file cache completions buffer.")
269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
270 ;; Functions to add files to the cache
271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
273 ;;;###autoload
274 (defun file-cache-add-directory (directory &optional regexp)
275 "Add DIRECTORY to the file cache.
276 If the optional REGEXP argument is non-nil, only files which match it will
277 be added to the cache."
278 (interactive "DAdd files from directory: ")
279 ;; Not an error, because otherwise we can't use load-paths that
280 ;; contain non-existent directories.
281 (if (not (file-accessible-directory-p directory))
282 (message "Directory %s does not exist" directory)
283 (let* ((dir (expand-file-name directory))
284 (dir-files (directory-files dir t regexp)))
285 ;; Filter out files we don't want to see
286 (dolist (file dir-files)
287 (if (file-directory-p file)
288 (setq dir-files (delq file dir-files))
289 (dolist (regexp file-cache-filter-regexps)
290 (if (string-match regexp file)
291 (setq dir-files (delq file dir-files))))))
292 (file-cache-add-file-list dir-files))))
294 ;;;###autoload
295 (defun file-cache-add-directory-list (directory-list &optional regexp)
296 "Add DIRECTORY-LIST (a list of directory names) to the file cache.
297 If the optional REGEXP argument is non-nil, only files which match it
298 will be added to the cache. Note that the REGEXP is applied to the
299 files in each directory, not to the directory list itself."
300 (interactive "XAdd files from directory list: ")
301 (mapcar
302 (lambda (dir) (file-cache-add-directory dir regexp))
303 directory-list))
305 (defun file-cache-add-file-list (file-list)
306 "Add FILE-LIST (a list of file names) to the file cache.
307 Interactively, FILE-LIST is read as a Lisp expression, which
308 should evaluate to the desired list of file names."
309 (interactive "XFile List: ")
310 (mapcar 'file-cache-add-file file-list))
312 ;; Workhorse function
314 ;;;###autoload
315 (defun file-cache-add-file (file)
316 "Add FILE to the file cache."
317 (interactive "fAdd File: ")
318 (if (not (file-exists-p file))
319 (message "Filecache: file %s does not exist" file)
320 (let* ((file-name (file-name-nondirectory file))
321 (dir-name (file-name-directory file))
322 (the-entry (assoc-string
323 file-name file-cache-alist
324 file-cache-ignore-case)))
325 ;; Does the entry exist already?
326 (if the-entry
327 (if (or (and (stringp (cdr the-entry))
328 (string= dir-name (cdr the-entry)))
329 (and (listp (cdr the-entry))
330 (member dir-name (cdr the-entry))))
332 (setcdr the-entry (cons dir-name (cdr the-entry))))
333 ;; If not, add it to the cache
334 (push (list file-name dir-name) file-cache-alist)))))
336 ;;;###autoload
337 (defun file-cache-add-directory-using-find (directory)
338 "Use the `find' command to add files to the file cache.
339 Find is run in DIRECTORY."
340 (interactive "DAdd files under directory: ")
341 (let ((dir (expand-file-name directory)))
342 (when (memq system-type '(windows-nt cygwin))
343 (if (eq file-cache-find-command-posix-flag 'not-defined)
344 (setq file-cache-find-command-posix-flag
345 (executable-command-find-posix-p file-cache-find-command))))
346 (set-buffer (get-buffer-create file-cache-buffer))
347 (erase-buffer)
348 (call-process file-cache-find-command nil
349 (get-buffer file-cache-buffer) nil
350 dir "-name"
351 (if (memq system-type '(windows-nt cygwin))
352 (if file-cache-find-command-posix-flag
353 "\\*"
354 "'*'")
355 "*")
356 "-print")
357 (file-cache-add-from-file-cache-buffer)))
359 ;;;###autoload
360 (defun file-cache-add-directory-using-locate (string)
361 "Use the `locate' command to add files to the file cache.
362 STRING is passed as an argument to the locate command."
363 (interactive "sAdd files using locate string: ")
364 (set-buffer (get-buffer-create file-cache-buffer))
365 (erase-buffer)
366 (call-process file-cache-locate-command nil
367 (get-buffer file-cache-buffer) nil
368 string)
369 (file-cache-add-from-file-cache-buffer))
371 ;;;###autoload
372 (defun file-cache-add-directory-recursively (dir &optional regexp)
373 "Adds DIR and any subdirectories to the file-cache.
374 This function does not use any external programs.
375 If the optional REGEXP argument is non-nil, only files which match it
376 will be added to the cache. Note that the REGEXP is applied to the
377 files in each directory, not to the directory list itself."
378 (interactive "DAdd directory: ")
379 (require 'find-lisp)
380 (mapcar
381 (function
382 (lambda (file)
383 (or (file-directory-p file)
384 (let (filtered)
385 (dolist (regexp file-cache-filter-regexps)
386 (and (string-match regexp file)
387 (setq filtered t)))
388 filtered)
389 (file-cache-add-file file))))
390 (find-lisp-find-files dir (if regexp regexp "^"))))
392 (defun file-cache-add-from-file-cache-buffer (&optional regexp)
393 "Add any entries found in the file cache buffer.
394 Each entry matches the regular expression `file-cache-buffer-default-regexp'
395 or the optional REGEXP argument."
396 (set-buffer file-cache-buffer)
397 (dolist (elt file-cache-filter-regexps)
398 (goto-char (point-min))
399 (delete-matching-lines elt))
400 (goto-char (point-min))
401 (let ((full-filename))
402 (while (re-search-forward
403 (or regexp file-cache-buffer-default-regexp)
404 (point-max) t)
405 (setq full-filename (buffer-substring-no-properties
406 (match-beginning 0) (match-end 0)))
407 (file-cache-add-file full-filename))))
409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410 ;; Functions to delete from the cache
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
413 (defun file-cache-clear-cache ()
414 "Clear the file cache."
415 (interactive)
416 (setq file-cache-alist nil))
418 ;; This clears *all* files with the given name
419 (defun file-cache-delete-file (file)
420 "Delete FILE from the file cache."
421 (interactive
422 (list (completing-read "Delete file from cache: " file-cache-alist)))
423 (setq file-cache-alist
424 (delq (assoc-string file file-cache-alist file-cache-ignore-case)
425 file-cache-alist)))
427 (defun file-cache-delete-file-list (file-list)
428 "Delete FILE-LIST (a list of files) from the file cache."
429 (interactive "XFile List: ")
430 (mapcar 'file-cache-delete-file file-list))
432 (defun file-cache-delete-file-regexp (regexp)
433 "Delete files matching REGEXP from the file cache."
434 (interactive "sRegexp: ")
435 (let ((delete-list))
436 (dolist (elt file-cache-alist)
437 (and (string-match regexp (car elt))
438 (push (car elt) delete-list)))
439 (file-cache-delete-file-list delete-list)
440 (message "Filecache: deleted %d files from file cache"
441 (length delete-list))))
443 (defun file-cache-delete-directory (directory)
444 "Delete DIRECTORY from the file cache."
445 (interactive "DDelete directory from file cache: ")
446 (let ((dir (expand-file-name directory))
447 (result 0))
448 (dolist (entry file-cache-alist)
449 (if (file-cache-do-delete-directory dir entry)
450 (setq result (1+ result))))
451 (if (zerop result)
452 (error "Filecache: no entries containing %s found in cache" directory)
453 (message "Filecache: deleted %d entries" result))))
455 (defun file-cache-do-delete-directory (dir entry)
456 (let ((directory-list (cdr entry))
457 (directory (file-cache-canonical-directory dir)))
458 (and (member directory directory-list)
459 (if (equal 1 (length directory-list))
460 (setq file-cache-alist
461 (delq entry file-cache-alist))
462 (setcdr entry (delete directory directory-list))))))
464 (defun file-cache-delete-directory-list (directory-list)
465 "Delete DIRECTORY-LIST (a list of directories) from the file cache."
466 (interactive "XDirectory List: ")
467 (mapcar 'file-cache-delete-directory directory-list))
469 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
470 ;; Utility functions
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
473 ;; Returns the name of a directory for a file in the cache
474 (defun file-cache-directory-name (file)
475 (let* ((directory-list (cdr (assoc-string
476 file file-cache-alist
477 file-cache-ignore-case)))
478 (len (length directory-list))
479 (directory)
480 (num))
481 (if (not (listp directory-list))
482 (error "Filecache: unknown type in file-cache-alist for key %s" file))
483 (cond
484 ;; Single element
485 ((eq 1 len)
486 (setq directory (elt directory-list 0)))
487 ;; No elements
488 ((eq 0 len)
489 (error "Filecache: no directory found for key %s" file))
490 ;; Multiple elements
492 (let* ((minibuffer-dir (file-name-directory (minibuffer-contents)))
493 (dir-list (member minibuffer-dir directory-list)))
494 (setq directory
495 ;; If the directory is in the list, return the next element
496 ;; Otherwise, return the first element
497 (if dir-list
498 (or (elt directory-list
499 (setq num (1+ (- len (length dir-list)))))
500 (elt directory-list (setq num 0)))
501 (elt directory-list (setq num 0)))))))
502 ;; If there were multiple directories, set up a minibuffer message
503 (setq file-cache-multiple-directory-message
504 (and num (format " [%d of %d]" (1+ num) len)))
505 directory))
507 ;; Returns the name of a file in the cache
508 (defun file-cache-file-name (file)
509 (let ((directory (file-cache-directory-name file)))
510 (concat directory file)))
512 ;; Return a canonical directory for comparison purposes.
513 ;; Such a directory ends with a forward slash.
514 (defun file-cache-canonical-directory (dir)
515 (let ((directory dir))
516 (if (not (char-equal ?/ (string-to-char (substring directory -1))))
517 (concat directory "/")
518 directory)))
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
521 ;; Minibuffer functions
522 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
524 ;; The prefix argument works around a bug in the minibuffer completion.
525 ;; The completion function doesn't distinguish between the states:
527 ;; "Multiple completions of name" (eg, Makefile, Makefile.in)
528 ;; "Name available in multiple directories" (/tmp/Makefile, ~me/Makefile)
530 ;; The default is to do the former; a prefix arg forces the latter.
532 ;;;###autoload
533 (defun file-cache-minibuffer-complete (arg)
534 "Complete a filename in the minibuffer using a preloaded cache.
535 Filecache does two kinds of substitution: it completes on names in
536 the cache, and, once it has found a unique name, it cycles through
537 the directories that the name is available in. With a prefix argument,
538 the name is considered already unique; only the second substitution
539 \(directories) is done."
540 (interactive "P")
541 (let*
543 (completion-ignore-case file-cache-completion-ignore-case)
544 (case-fold-search file-cache-case-fold-search)
545 (string (file-name-nondirectory (minibuffer-contents)))
546 (completion-string (try-completion string file-cache-alist))
547 (completion-list)
548 (len)
549 (file-cache-string))
550 (cond
551 ;; If it's the only match, replace the original contents
552 ((or arg (eq completion-string t))
553 (setq file-cache-string (file-cache-file-name string))
554 (if (string= file-cache-string (minibuffer-contents))
555 (minibuffer-message file-cache-sole-match-message)
556 (delete-minibuffer-contents)
557 (insert file-cache-string)
558 (if file-cache-multiple-directory-message
559 (minibuffer-message file-cache-multiple-directory-message))))
561 ;; If it's the longest match, insert it
562 ((stringp completion-string)
563 ;; If we've already inserted a unique string, see if the user
564 ;; wants to use that one
565 (if (and (string= string completion-string)
566 (assoc-string string file-cache-alist
567 file-cache-ignore-case))
568 (if (and (eq last-command this-command)
569 (string= file-cache-last-completion completion-string))
570 (progn
571 (delete-minibuffer-contents)
572 (insert (file-cache-file-name completion-string))
573 (setq file-cache-last-completion nil))
574 (minibuffer-message file-cache-non-unique-message)
575 (setq file-cache-last-completion string))
576 (setq file-cache-last-completion string)
577 (setq completion-list (all-completions string file-cache-alist)
578 len (length completion-list))
579 (if (> len 1)
580 (progn
581 (goto-char (point-max))
582 (insert
583 (substring completion-string (length string)))
584 ;; Add our own setup function to the Completions Buffer
585 (let ((completion-setup-hook
586 (append completion-setup-hook
587 (list 'file-cache-completion-setup-function))))
588 (with-output-to-temp-buffer file-cache-completions-buffer
589 (display-completion-list completion-list string))))
590 (setq file-cache-string (file-cache-file-name completion-string))
591 (if (string= file-cache-string (minibuffer-contents))
592 (minibuffer-message file-cache-sole-match-message)
593 (delete-minibuffer-contents)
594 (insert file-cache-string)
595 (if file-cache-multiple-directory-message
596 (minibuffer-message file-cache-multiple-directory-message)))
599 ;; No match
600 ((eq completion-string nil)
601 (minibuffer-message file-cache-no-match-message)))))
603 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
604 ;; Completion functions
605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
607 (defun file-cache-completion-setup-function ()
608 (with-current-buffer standard-output ;; i.e. file-cache-completions-buffer
609 (use-local-map file-cache-completions-keymap)))
611 (defun file-cache-choose-completion (&optional event)
612 "Choose a completion in the `*Completions*' buffer."
613 (interactive (list last-nonmenu-event))
614 (let ((completion-no-auto-exit t))
615 (choose-completion event)
616 (select-window (active-minibuffer-window))
617 (file-cache-minibuffer-complete nil)))
619 (define-obsolete-function-alias 'file-cache-mouse-choose-completion
620 'file-cache-choose-completion "23.2")
622 (defun file-cache-complete ()
623 "Complete the word at point, using the filecache."
624 (interactive)
625 (let ((start
626 (save-excursion
627 (skip-syntax-backward "^\"")
628 (point))))
629 (completion-in-region start (point) file-cache-alist)))
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
632 ;; Show parts of the cache
633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635 (defun file-cache-files-matching-internal (regexp)
636 "Output a list of files whose names (not including directories)
637 match REGEXP."
638 (let ((results))
639 (dolist (cache-element file-cache-alist)
640 (and (string-match regexp (elt cache-element 0))
641 (push (elt cache-element 0) results)))
642 (nreverse results)))
644 (defun file-cache-files-matching (regexp)
645 "Output a list of files whose names (not including directories)
646 match REGEXP."
647 (interactive "sFind files matching regexp: ")
648 (let ((results
649 (file-cache-files-matching-internal regexp))
650 buf)
651 (set-buffer
652 (setq buf (get-buffer-create
653 "*File Cache Files Matching*")))
654 (erase-buffer)
655 (insert
656 (mapconcat
657 'identity
658 results
659 "\n"))
660 (goto-char (point-min))
661 (display-buffer buf)))
663 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
664 ;; Debugging functions
665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
667 (defun file-cache-debug-read-from-minibuffer (file)
668 "Debugging function."
669 (interactive
670 (list (completing-read "File Cache: " file-cache-alist)))
671 (message "%s" (assoc-string file file-cache-alist
672 file-cache-ignore-case)))
674 (defun file-cache-display ()
675 "Display the file cache."
676 (interactive)
677 (let ((buf "*File Cache Contents*"))
678 (with-current-buffer
679 (get-buffer-create buf)
680 (erase-buffer)
681 (dolist (item file-cache-alist)
682 (insert (nth 1 item) (nth 0 item) "\n"))
683 (pop-to-buffer buf))))
685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
686 ;; Keybindings
687 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
689 (provide 'filecache)
691 ;;; filecache.el ends here