annotate lisp/filecache.el @ 46377:d50779ef2a76

* lisp.h (STRING_INTERVALS): Produce rvalue. (STRING_SET_INTERVALS): New macro.
author Ken Raeburn <raeburn@raeburn.org>
date Mon, 15 Jul 2002 06:54:23 +0000
parents dc980af6073b
children 99be3a1e2589
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45046
dc980af6073b Lowercase the first letter in the header.
Pavel Janík <Pavel@Janik.cz>
parents: 41568
diff changeset
1 ;;; filecache.el --- find files using a pre-loaded cache
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;;
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
3 ;; Author: Peter Breton <pbreton@cs.umb.edu>
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Created: Sun Nov 10 1996
22250
a77d473867b8 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21886
diff changeset
5 ;; Keywords: convenience
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;;
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
7 ;; Copyright (C) 1996, 2000 Free Software Foundation, Inc.
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
8
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
9 ;; This file is part of GNU Emacs.
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
10
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
15
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
19 ;; GNU General Public License for more details.
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
20
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
24 ;; Boston, MA 02111-1307, USA.
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
25
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; The file-cache package is an attempt to make it easy to locate files
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; by name, without having to remember exactly where they are located.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; This is very handy when working with source trees. You can also add
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; frequently used files to the cache to create a hotlist effect.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; The cache can be used with any interactive command which takes a
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; filename as an argument.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; It is worth noting that this package works best when most of the files
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; in the cache have unique names, or (if they have the same name) exist in
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; only a few directories. The worst case is many files all with
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; the same name and in different directories, for example a big source tree
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; with a Makefile in each directory. In such a case, you should probably
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; use an alternate strategy to find the files.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; ADDING FILES TO THE CACHE:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; Use the following functions to add items to the file cache:
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
45 ;;
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; * `file-cache-add-file': Adds a single file to the cache
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; * `file-cache-add-file-list': Adds a list of files to the cache
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; The following functions use the regular expressions in
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; `file-cache-delete-regexps' to eliminate unwanted files:
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
52 ;;
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; * `file-cache-add-directory': Adds the files in a directory to the
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; cache. You can also specify a regular expression to match the files
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; which should be added.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; * `file-cache-add-directory-list': Same as above, but acts on a list
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; of directories. You can use `load-path', `exec-path' and the like.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; * `file-cache-add-directory-using-find': Uses the `find' command to
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; add a directory tree to the cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; * `file-cache-add-directory-using-locate': Uses the `locate' command to
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; add files matching a pattern to the cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; Use the function `file-cache-clear-cache' to remove all items from the
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; cache. There are a number of `file-cache-delete' functions provided
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; as well, but in general it is probably better to not worry too much
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; about extra files in the cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; The most convenient way to initialize the cache is with an
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
72 ;; `eval-after-load' function, as noted in the ADDING FILES
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
73 ;; AUTOMATICALLY section.
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; FINDING FILES USING THE CACHE:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; You can use the file-cache with any function that expects a filename as
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; an argument. For example:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; 1) Invoke a function which expects a filename as an argument:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; M-x find-file
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; 2) Begin typing a file name.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; 3) Invoke `file-cache-minibuffer-complete' (bound by default to
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; C-TAB) to complete on the filename using the cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; 4) When you have found a unique completion, the minibuffer contents
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; will change to the full name of that file.
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
90 ;;
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; If there are a number of directories which contain the completion,
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; invoking `file-cache-minibuffer-complete' repeatedly will cycle through
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; them.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; 5) You can then edit the minibuffer contents, or press RETURN.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; It is much easier to simply try it than trying to explain it :)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
99 ;;; ADDING FILES AUTOMATICALLY
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; For maximum utility, you should probably define an `eval-after-load'
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; form which loads your favorite files:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;;
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
104 ;; (eval-after-load
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; "filecache"
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; '(progn
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;; (message "Loading file cache...")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; (file-cache-add-directory-using-find "~/projects")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; (file-cache-add-directory-list load-path)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; (file-cache-add-directory "~/")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;; (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar"))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; ))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; If you clear and reload the cache frequently, it is probably easiest
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; to put your initializations in a function:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;;
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
117 ;; (eval-after-load
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; "filecache"
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; '(my-file-cache-initialize))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
120 ;;
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; (defun my-file-cache-initialize ()
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;; (interactive)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;; (message "Loading file cache...")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; (file-cache-add-directory-using-find "~/projects")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; (file-cache-add-directory-list load-path)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; (file-cache-add-directory "~/")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar"))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; ))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; Of course, you can still add files to the cache afterwards, via
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; Lisp functions.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; RELATED WORK:
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
134 ;;
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;; This package is a distant relative of Noah Friedman's fff utilities.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; Our goal is pretty similar, but the implementation strategies are
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; different.
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
138
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;;; Code:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
141 (defgroup file-cache nil
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
142 "Find files using a pre-loaded cache."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
143 :group 'files
22250
a77d473867b8 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21886
diff changeset
144 :group 'convenience
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
145 :prefix "file-cache-")
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
146
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
148 ;; Customization Variables
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; User-modifiable variables
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
152 (defcustom file-cache-filter-regexps
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
153 (list "~$" "\\.o$" "\\.exe$" "\\.a$" "\\.elc$" ",v$" "\\.output$"
24340
9d52c9051940 (file-cache-filter-regexps): Added .class.
Richard M. Stallman <rms@gnu.org>
parents: 22250
diff changeset
154 "\\.$" "#$" "\\.class$")
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "*List of regular expressions used as filters by the file cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 File names which match these expressions will not be added to the cache.
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
157 Note that the functions `file-cache-add-file' and `file-cache-add-file-list'
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
158 do not use this variable."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
159 :type '(repeat regexp)
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
160 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
162 (defcustom file-cache-find-command "find"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
163 "*External program used by `file-cache-add-directory-using-find'."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
164 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
165 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
167 (defcustom file-cache-locate-command "locate"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
168 "*External program used by `file-cache-add-directory-using-locate'."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
169 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
170 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; Minibuffer messages
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
173 (defcustom file-cache-no-match-message " [File Cache: No match]"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
174 "Message to display when there is no completion."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
175 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
176 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
178 (defcustom file-cache-sole-match-message " [File Cache: sole completion]"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
179 "Message to display when there is only one completion."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
180 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
181 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
183 (defcustom file-cache-non-unique-message
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
184 " [File Cache: complete but not unique]"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
185 "Message to display when there is a non-unique completion."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
186 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
187 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
189 (defcustom file-cache-completion-ignore-case
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
190 (if (memq system-type (list 'ms-dos 'windows-nt))
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
191 t
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
192 completion-ignore-case)
25907
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
193 "If non-nil, file-cache completion should ignore case.
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
194 Defaults to the value of `completion-ignore-case'."
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
195 :type 'sexp
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
196 :group 'file-cache
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
197 )
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
198
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
199 (defcustom file-cache-case-fold-search
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
200 (if (memq system-type (list 'ms-dos 'windows-nt))
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
201 t
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
202 case-fold-search)
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
203 "If non-nil, file-cache completion should ignore case.
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
204 Defaults to the value of `case-fold-search'."
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
205 :type 'sexp
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
206 :group 'file-cache
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
207 )
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
208
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
209 (defcustom file-cache-assoc-function
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
210 (if (memq system-type (list 'ms-dos 'windows-nt))
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
211 'assoc-ignore-case
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
212 'assoc)
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
213 "Function to use to check completions in the file cache.
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
214 Defaults to `assoc-ignore-case' on DOS and Windows, and `assoc' on
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
215 other systems."
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
216 :type 'sexp
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
217 :group 'file-cache
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
218 )
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
219
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (defvar file-cache-multiple-directory-message nil)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; Internal variables
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; This should be named *Completions* because that's what the function
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; switch-to-completions in simple.el expects
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
225 (defcustom file-cache-completions-buffer "*Completions*"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
226 "Buffer to display completions when using the file cache."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
227 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
228 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
230 (defcustom file-cache-buffer "*File Cache*"
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
231 "Buffer to hold the cache of file names."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
232 :type 'string
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
233 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234
20597
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
235 (defcustom file-cache-buffer-default-regexp "^.+$"
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
236 "Regexp to match files in `file-cache-buffer'."
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
237 :type 'regexp
886039ba7b3e Customized.
Andreas Schwab <schwab@suse.de>
parents: 20578
diff changeset
238 :group 'file-cache)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (defvar file-cache-last-completion nil)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (defvar file-cache-alist nil
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 "Internal data structure to hold cache of file names.")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (defvar file-cache-completions-keymap nil
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 "Keymap for file cache completions buffer.")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 ;; Functions to add files to the cache
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (defun file-cache-add-directory (directory &optional regexp)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 "Add DIRECTORY to the file cache.
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
254 If the optional REGEXP argument is non-nil, only files which match it will
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 be added to the cache."
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
256 (interactive "DAdd files from directory: ")
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
257 ;; Not an error, because otherwise we can't use load-paths that
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
258 ;; contain non-existent directories.
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
259 (if (not (file-accessible-directory-p directory))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
260 (message "Directory %s does not exist" directory)
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
261 (let* ((dir (expand-file-name directory))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
262 (dir-files (directory-files dir t regexp))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
263 )
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
264 ;; Filter out files we don't want to see
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
265 (mapcar
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
266 '(lambda (file)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
267 (mapcar
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 '(lambda (regexp)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (if (string-match regexp file)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (setq dir-files (delq file dir-files))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 file-cache-filter-regexps))
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
272 dir-files)
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
273 (file-cache-add-file-list dir-files))))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (defun file-cache-add-directory-list (directory-list &optional regexp)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 "Add DIRECTORY-LIST (a list of directory names) to the file cache.
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
277 If the optional REGEXP argument is non-nil, only files which match it
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
278 will be added to the cache. Note that the REGEXP is applied to the files
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 in each directory, not to the directory list itself."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (interactive "XAdd files from directory list: ")
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
281 (mapcar
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 '(lambda (dir) (file-cache-add-directory dir regexp))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 directory-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (defun file-cache-add-file-list (file-list)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 "Add FILE-LIST (a list of files names) to the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (interactive "XFile List: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (mapcar 'file-cache-add-file file-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 ;; Workhorse function
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (defun file-cache-add-file (file)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 "Add FILE to the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (interactive "fAdd File: ")
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
294 (if (not (file-exists-p file))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
295 (message "File %s does not exist" file)
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
296 (let* ((file-name (file-name-nondirectory file))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
297 (dir-name (file-name-directory file))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
298 (the-entry (funcall file-cache-assoc-function
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
299 file-name file-cache-alist))
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
300 )
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
301 ;; Does the entry exist already?
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
302 (if the-entry
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
303 (if (or (and (stringp (cdr the-entry))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
304 (string= dir-name (cdr the-entry)))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
305 (and (listp (cdr the-entry))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
306 (member dir-name (cdr the-entry))))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
307 nil
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
308 (setcdr the-entry (append (list dir-name) (cdr the-entry)))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
309 )
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
310 ;; If not, add it to the cache
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
311 (setq file-cache-alist
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
312 (cons (cons file-name (list dir-name))
21886
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
313 file-cache-alist)))
ca7b274a97d9 (file-cache-add-file): Checks to see if file exists
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
314 )))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
315
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (defun file-cache-add-directory-using-find (directory)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 "Use the `find' command to add files to the file cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 Find is run in DIRECTORY."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (interactive "DAdd files under directory: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (let ((dir (expand-file-name directory)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (set-buffer (get-buffer-create file-cache-buffer))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (erase-buffer)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
323 (call-process file-cache-find-command nil
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (get-buffer file-cache-buffer) nil
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
325 dir "-name"
31313
2c7c30fea1ab (file-cache-add-directory-using-find): Don't quote wildcards on MS-DOS.
Peter Breton <pbreton@attbi.com>
parents: 31235
diff changeset
326 (if (eq system-type 'windows-nt) "'*'" "*")
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 "-print")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (file-cache-add-from-file-cache-buffer)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (defun file-cache-add-directory-using-locate (string)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 "Use the `locate' command to add files to the file cache.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 STRING is passed as an argument to the locate command."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (interactive "sAdd files using locate string: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (set-buffer (get-buffer-create file-cache-buffer))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (erase-buffer)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
336 (call-process file-cache-locate-command nil
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (get-buffer file-cache-buffer) nil
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 string)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (file-cache-add-from-file-cache-buffer))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (defun file-cache-add-from-file-cache-buffer (&optional regexp)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 "Add any entries found in the file cache buffer.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 Each entry matches the regular expression `file-cache-buffer-default-regexp'
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 or the optional REGEXP argument."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (set-buffer file-cache-buffer)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
346 (mapcar
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (function (lambda (elt)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (goto-char (point-min))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (delete-matching-lines elt)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 file-cache-filter-regexps)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (goto-char (point-min))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (let ((full-filename))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (while (re-search-forward
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
354 (or regexp file-cache-buffer-default-regexp)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (point-max) t)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (setq full-filename (buffer-substring-no-properties
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
357 (match-beginning 0) (match-end 0)))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (file-cache-add-file full-filename))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 ;; Functions to delete from the cache
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (defun file-cache-clear-cache ()
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 "Clear the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (interactive)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (setq file-cache-alist nil))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 ;; This clears *all* files with the given name
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (defun file-cache-delete-file (file)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 "Delete FILE from the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (interactive
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (list (completing-read "Delete file from cache: " file-cache-alist)))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
374 (setq file-cache-alist
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
375 (delq (funcall file-cache-assoc-function file file-cache-alist)
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
376 file-cache-alist)))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (defun file-cache-delete-file-list (file-list)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 "Delete FILE-LIST (a list of files) from the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (interactive "XFile List: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (mapcar 'file-cache-delete-file file-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (defun file-cache-delete-file-regexp (regexp)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 "Delete files matching REGEXP from the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (interactive "sRegexp: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (let ((delete-list))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
387 (mapcar '(lambda (elt)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (and (string-match regexp (car elt))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (setq delete-list (cons (car elt) delete-list))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 file-cache-alist)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (file-cache-delete-file-list delete-list)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (message "Deleted %d files from file cache" (length delete-list))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (defun file-cache-delete-directory (directory)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 "Delete DIRECTORY from the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (interactive "DDelete directory from file cache: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (let ((dir (expand-file-name directory))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (result 0))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
399 (mapcar
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
400 '(lambda (entry)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (if (file-cache-do-delete-directory dir entry)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (setq result (1+ result))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 file-cache-alist)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (if (zerop result)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (error "No entries containing %s found in cache" directory)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (message "Deleted %d entries" result))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (defun file-cache-do-delete-directory (dir entry)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (let ((directory-list (cdr entry))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (directory (file-cache-canonical-directory dir))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (and (member directory directory-list)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (if (equal 1 (length directory-list))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
414 (setq file-cache-alist
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (delq entry file-cache-alist))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (setcdr entry (delete directory directory-list)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 ))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (defun file-cache-delete-directory-list (directory-list)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 "Delete DIRECTORY-LIST (a list of directories) from the file cache."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (interactive "XDirectory List: ")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (mapcar 'file-cache-delete-directory directory-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ;; Utility functions
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 ;; Returns the name of a directory for a file in the cache
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (defun file-cache-directory-name (file)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
431 (let* ((directory-list (cdr (funcall file-cache-assoc-function
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
432 file file-cache-alist)))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (len (length directory-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (directory)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (num)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (if (not (listp directory-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (error "Unknown type in file-cache-alist for key %s" file))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
439 (cond
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 ;; Single element
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 ((eq 1 len)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (setq directory (elt directory-list 0)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 ;; No elements
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 ((eq 0 len)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (error "No directory found for key %s" file))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 ;; Multiple elements
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (t
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
448 (let* ((minibuffer-dir (file-name-directory (minibuffer-contents)))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (dir-list (member minibuffer-dir directory-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (setq directory
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 ;; If the directory is in the list, return the next element
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 ;; Otherwise, return the first element
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
454 (if dir-list
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
455 (or (elt directory-list
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (setq num (1+ (- len (length dir-list)))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (elt directory-list (setq num 0)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (elt directory-list (setq num 0))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 ;; If there were multiple directories, set up a minibuffer message
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (setq file-cache-multiple-directory-message
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (and num (format " [%d of %d]" (1+ num) len)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 directory))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 ;; Returns the name of a file in the cache
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (defun file-cache-file-name (file)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (let ((directory (file-cache-directory-name file)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (concat directory file)))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
471
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 ;; Return a canonical directory for comparison purposes.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 ;; Such a directory ends with a forward slash.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (defun file-cache-canonical-directory (dir)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (let ((directory dir))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (if (not (char-equal ?/ (string-to-char (substring directory -1))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (concat directory "/")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 directory)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 ;; Minibuffer functions
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
484 ;; The prefix argument works around a bug in the minibuffer completion.
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
485 ;; The completion function doesn't distinguish between the states:
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
486 ;;
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
487 ;; "Multiple completions of name" (eg, Makefile, Makefile.in)
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
488 ;; "Name available in multiple directories" (/tmp/Makefile, ~me/Makefile)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
489 ;;
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
490 ;; The default is to do the former; a prefix arg forces the latter.
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
491
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 ;;;###autoload
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
493 (defun file-cache-minibuffer-complete (arg)
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
494 "Complete a filename in the minibuffer using a preloaded cache.
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
495 Filecache does two kinds of substitution: it completes on names in
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
496 the cache, and, once it has found a unique name, it cycles through
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
497 the directories that the name is available in. With a prefix argument,
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
498 the name is considered already unique; only the second substitution
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
499 \(directories) is done."
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
500 (interactive "P")
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
501 (let*
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (
25907
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
503 (completion-ignore-case file-cache-completion-ignore-case)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
504 (case-fold-search file-cache-case-fold-search)
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
505 (string (file-name-nondirectory (minibuffer-contents)))
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
506 (completion-string (try-completion string file-cache-alist))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (completion-list)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (len)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (file-cache-string)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 )
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
511 (cond
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
512 ;; If it's the only match, replace the original contents
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
513 ((or arg (eq completion-string t))
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
514 (setq file-cache-string (file-cache-file-name string))
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
515 (if (string= file-cache-string (minibuffer-contents))
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
516 (file-cache-temp-minibuffer-message file-cache-sole-match-message)
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
517 (delete-minibuffer-contents)
41568
1aef79dfa6fe (file-cache-minibuffer-complete): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents: 34072
diff changeset
518 (insert file-cache-string)
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
519 (if file-cache-multiple-directory-message
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
520 (file-cache-temp-minibuffer-message
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
521 file-cache-multiple-directory-message))
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
522 ))
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
523
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 ;; If it's the longest match, insert it
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 ((stringp completion-string)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 ;; If we've already inserted a unique string, see if the user
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 ;; wants to use that one
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (if (and (string= string completion-string)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
529 (funcall file-cache-assoc-function string file-cache-alist))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (if (and (eq last-command this-command)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (string= file-cache-last-completion completion-string))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
532 (progn
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
533 (delete-minibuffer-contents)
41568
1aef79dfa6fe (file-cache-minibuffer-complete): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents: 34072
diff changeset
534 (insert (file-cache-file-name completion-string))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (setq file-cache-last-completion nil)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (file-cache-temp-minibuffer-message file-cache-non-unique-message)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (setq file-cache-last-completion string)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (setq file-cache-last-completion string)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (setq completion-list (all-completions string file-cache-alist)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 len (length completion-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (if (> len 1)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (progn
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (goto-char (point-max))
41568
1aef79dfa6fe (file-cache-minibuffer-complete): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents: 34072
diff changeset
546 (insert
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (substring completion-string (length string)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 ;; Add our own setup function to the Completions Buffer
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (let ((completion-setup-hook
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
550 (reverse
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (append (list 'file-cache-completion-setup-function)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 completion-setup-hook)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (with-output-to-temp-buffer file-cache-completions-buffer
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (display-completion-list completion-list))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (setq file-cache-string (file-cache-file-name completion-string))
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
559 (if (string= file-cache-string (minibuffer-contents))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
560 (file-cache-temp-minibuffer-message
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
561 file-cache-sole-match-message)
34072
24c9291f8fa8 (file-cache-directory-name, file-cache-minibuffer-complete):
Miles Bader <miles@gnu.org>
parents: 34070
diff changeset
562 (delete-minibuffer-contents)
41568
1aef79dfa6fe (file-cache-minibuffer-complete): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents: 34072
diff changeset
563 (insert file-cache-string)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (if file-cache-multiple-directory-message
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
565 (file-cache-temp-minibuffer-message
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 file-cache-multiple-directory-message)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 )))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
568
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 ;; No match
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 ((eq completion-string nil)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (file-cache-temp-minibuffer-message file-cache-no-match-message))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 ))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 ;; Lifted from "complete.el"
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (defun file-cache-temp-minibuffer-message (msg)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 "A Lisp version of `temp_minibuffer_message' from minibuf.c."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (let ((savemax (point-max)))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (save-excursion
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (goto-char (point-max))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (insert msg))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (let ((inhibit-quit t))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (sit-for 2)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (delete-region savemax (point-max))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (if quit-flag
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (setq quit-flag nil
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 unread-command-events (list 7))))))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 ;; Completion functions
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (defun file-cache-completion-setup-function ()
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (set-buffer file-cache-completions-buffer)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (if file-cache-completions-keymap
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 nil
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
598 (setq file-cache-completions-keymap
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (copy-keymap completion-list-mode-map))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
600 (define-key file-cache-completions-keymap [mouse-2]
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
601 'file-cache-mouse-choose-completion)
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
602 (define-key file-cache-completions-keymap "\C-m"
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 'file-cache-choose-completion))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (use-local-map file-cache-completions-keymap)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (defun file-cache-choose-completion ()
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 "Choose a completion in the `*Completions*' buffer."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (interactive)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (let ((completion-no-auto-exit t))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (choose-completion)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (select-window (active-minibuffer-window))
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
614 (file-cache-minibuffer-complete nil)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (defun file-cache-mouse-choose-completion (event)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 "Choose a completion with the mouse."
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (interactive "e")
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (let ((completion-no-auto-exit t))
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (mouse-choose-completion event)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (select-window (active-minibuffer-window))
20578
7eb29ad824eb (file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents: 18388
diff changeset
624 (file-cache-minibuffer-complete nil)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25907
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
629 ;; Show parts of the cache
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
631
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
632 (defun file-cache-files-matching-internal (regexp)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
633 "Output a list of files whose names (not including directories)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
634 match REGEXP."
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
635 (let ((results))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
636 (mapcar
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
637 (function
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
638 (lambda(cache-element)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
639 (and (string-match regexp
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
640 (elt cache-element 0))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
641 (if results
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
642 (nconc results (list (elt cache-element 0)))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
643 (setq results (list (elt cache-element 0)))))))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
644 file-cache-alist)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
645 results))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
646
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
647 (defun file-cache-files-matching (regexp)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
648 "Output a list of files whose names (not including directories)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
649 match REGEXP."
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
650 (interactive "sFind files matching regexp: ")
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
651 (let ((results
25907
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
652 (file-cache-files-matching-internal regexp))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
653 buf)
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
654 (set-buffer
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
655 (setq buf (get-buffer-create
25907
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
656 "*File Cache Files Matching*")))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
657 (erase-buffer)
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
658 (insert
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
659 (mapconcat
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
660 'identity
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
661 results
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
662 "\n"))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
663 (goto-char (point-min))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
664 (display-buffer buf)))
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
665
10d0bb886b1e (file-cache-completion-ignore-case): New variable,
Gerd Moellmann <gerd@gnu.org>
parents: 24340
diff changeset
666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 ;; Debugging functions
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (defun file-cache-debug-read-from-minibuffer (file)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 "Debugging function."
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
672 (interactive
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (list (completing-read "File Cache: " file-cache-alist)))
31235
5102c4c410c2 Added file-cache-case-fold-search and file-cache-assoc-function variables
Peter Breton <pbreton@attbi.com>
parents: 25907
diff changeset
674 (message "%s" (funcall file-cache-assoc-function file file-cache-alist))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 )
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 ;; Keybindings
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 ;;;###autoload (define-key minibuffer-local-completion-map [C-tab] 'file-cache-minibuffer-complete)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 ;;;###autoload (define-key minibuffer-local-map [C-tab] 'file-cache-minibuffer-complete)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 ;;;###autoload (define-key minibuffer-local-must-match-map [C-tab] 'file-cache-minibuffer-complete)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (provide 'filecache)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 ;;; filecache.el ends here