Mercurial > emacs
annotate lisp/filecache.el @ 46824:86fa1b4393a2
(ibuffer-mode-map): Added ibuffer-filter-by-used-mode.
(ibuffer-mode-map): Added ibuffer-filter-by-used-mode.
(ibuffer-mode): Added ibuffer-filter-by-used-mode to doc string.
author | Colin Walters <walters@gnu.org> |
---|---|
date | Tue, 06 Aug 2002 06:04:22 +0000 |
parents | dc980af6073b |
children | 99be3a1e2589 |
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 | 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 | 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 | 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 | 12 ;; it under the terms of the GNU General Public License as published by |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
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 | 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 | 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 | 26 ;;; Commentary: |
27 ;; | |
28 ;; The file-cache package is an attempt to make it easy to locate files | |
29 ;; by name, without having to remember exactly where they are located. | |
30 ;; This is very handy when working with source trees. You can also add | |
31 ;; frequently used files to the cache to create a hotlist effect. | |
32 ;; The cache can be used with any interactive command which takes a | |
33 ;; filename as an argument. | |
34 ;; | |
35 ;; It is worth noting that this package works best when most of the files | |
36 ;; in the cache have unique names, or (if they have the same name) exist in | |
37 ;; only a few directories. The worst case is many files all with | |
38 ;; the same name and in different directories, for example a big source tree | |
39 ;; with a Makefile in each directory. In such a case, you should probably | |
40 ;; use an alternate strategy to find the files. | |
41 ;; | |
42 ;; ADDING FILES TO THE CACHE: | |
43 ;; | |
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 | 46 ;; * `file-cache-add-file': Adds a single file to the cache |
47 ;; | |
48 ;; * `file-cache-add-file-list': Adds a list of files to the cache | |
49 ;; | |
50 ;; The following functions use the regular expressions in | |
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 | 53 ;; * `file-cache-add-directory': Adds the files in a directory to the |
54 ;; cache. You can also specify a regular expression to match the files | |
55 ;; which should be added. | |
56 ;; | |
57 ;; * `file-cache-add-directory-list': Same as above, but acts on a list | |
58 ;; of directories. You can use `load-path', `exec-path' and the like. | |
59 ;; | |
60 ;; * `file-cache-add-directory-using-find': Uses the `find' command to | |
61 ;; add a directory tree to the cache. | |
62 ;; | |
63 ;; * `file-cache-add-directory-using-locate': Uses the `locate' command to | |
64 ;; add files matching a pattern to the cache. | |
65 ;; | |
66 ;; Use the function `file-cache-clear-cache' to remove all items from the | |
67 ;; cache. There are a number of `file-cache-delete' functions provided | |
68 ;; as well, but in general it is probably better to not worry too much | |
69 ;; about extra files in the cache. | |
70 ;; | |
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 | 74 ;; |
75 ;; FINDING FILES USING THE CACHE: | |
76 ;; | |
77 ;; You can use the file-cache with any function that expects a filename as | |
78 ;; an argument. For example: | |
79 ;; | |
80 ;; 1) Invoke a function which expects a filename as an argument: | |
81 ;; M-x find-file | |
82 ;; | |
83 ;; 2) Begin typing a file name. | |
84 ;; | |
85 ;; 3) Invoke `file-cache-minibuffer-complete' (bound by default to | |
86 ;; C-TAB) to complete on the filename using the cache. | |
87 ;; | |
88 ;; 4) When you have found a unique completion, the minibuffer contents | |
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 | 91 ;; If there are a number of directories which contain the completion, |
92 ;; invoking `file-cache-minibuffer-complete' repeatedly will cycle through | |
93 ;; them. | |
94 ;; | |
95 ;; 5) You can then edit the minibuffer contents, or press RETURN. | |
96 ;; | |
97 ;; It is much easier to simply try it than trying to explain it :) | |
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 | 100 ;; |
101 ;; For maximum utility, you should probably define an `eval-after-load' | |
102 ;; form which loads your favorite files: | |
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 | 105 ;; "filecache" |
106 ;; '(progn | |
107 ;; (message "Loading file cache...") | |
108 ;; (file-cache-add-directory-using-find "~/projects") | |
109 ;; (file-cache-add-directory-list load-path) | |
110 ;; (file-cache-add-directory "~/") | |
111 ;; (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar")) | |
112 ;; )) | |
113 ;; | |
114 ;; If you clear and reload the cache frequently, it is probably easiest | |
115 ;; to put your initializations in a function: | |
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 | 118 ;; "filecache" |
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 | 121 ;; (defun my-file-cache-initialize () |
122 ;; (interactive) | |
123 ;; (message "Loading file cache...") | |
124 ;; (file-cache-add-directory-using-find "~/projects") | |
125 ;; (file-cache-add-directory-list load-path) | |
126 ;; (file-cache-add-directory "~/") | |
127 ;; (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar")) | |
128 ;; )) | |
129 ;; | |
130 ;; Of course, you can still add files to the cache afterwards, via | |
131 ;; Lisp functions. | |
132 ;; | |
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 | 135 ;; This package is a distant relative of Noah Friedman's fff utilities. |
136 ;; Our goal is pretty similar, but the implementation strategies are | |
137 ;; different. | |
20578
7eb29ad824eb
(file-cache-minibuffer-complete): Accept a prefix arg.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
138 |
18388 | 139 ;;; Code: |
140 | |
20597 | 141 (defgroup file-cache nil |
142 "Find files using a pre-loaded cache." | |
143 :group 'files | |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21886
diff
changeset
|
144 :group 'convenience |
20597 | 145 :prefix "file-cache-") |
146 | |
18388 | 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 | 149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
150 | |
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 | 155 "*List of regular expressions used as filters by the file cache. |
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 | 158 do not use this variable." |
159 :type '(repeat regexp) | |
160 :group 'file-cache) | |
18388 | 161 |
20597 | 162 (defcustom file-cache-find-command "find" |
163 "*External program used by `file-cache-add-directory-using-find'." | |
164 :type 'string | |
165 :group 'file-cache) | |
18388 | 166 |
20597 | 167 (defcustom file-cache-locate-command "locate" |
168 "*External program used by `file-cache-add-directory-using-locate'." | |
169 :type 'string | |
170 :group 'file-cache) | |
18388 | 171 |
172 ;; Minibuffer messages | |
20597 | 173 (defcustom file-cache-no-match-message " [File Cache: No match]" |
174 "Message to display when there is no completion." | |
175 :type 'string | |
176 :group 'file-cache) | |
18388 | 177 |
20597 | 178 (defcustom file-cache-sole-match-message " [File Cache: sole completion]" |
179 "Message to display when there is only one completion." | |
180 :type 'string | |
181 :group 'file-cache) | |
18388 | 182 |
20597 | 183 (defcustom file-cache-non-unique-message |
184 " [File Cache: complete but not unique]" | |
185 "Message to display when there is a non-unique completion." | |
186 :type 'string | |
187 :group 'file-cache) | |
18388 | 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 | 220 (defvar file-cache-multiple-directory-message nil) |
221 | |
222 ;; Internal variables | |
223 ;; This should be named *Completions* because that's what the function | |
224 ;; switch-to-completions in simple.el expects | |
20597 | 225 (defcustom file-cache-completions-buffer "*Completions*" |
226 "Buffer to display completions when using the file cache." | |
227 :type 'string | |
228 :group 'file-cache) | |
18388 | 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 | 231 "Buffer to hold the cache of file names." |
232 :type 'string | |
233 :group 'file-cache) | |
18388 | 234 |
20597 | 235 (defcustom file-cache-buffer-default-regexp "^.+$" |
236 "Regexp to match files in `file-cache-buffer'." | |
237 :type 'regexp | |
238 :group 'file-cache) | |
18388 | 239 |
240 (defvar file-cache-last-completion nil) | |
241 | |
242 (defvar file-cache-alist nil | |
243 "Internal data structure to hold cache of file names.") | |
244 | |
245 (defvar file-cache-completions-keymap nil | |
246 "Keymap for file cache completions buffer.") | |
247 | |
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
249 ;; Functions to add files to the cache | |
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
251 | |
252 (defun file-cache-add-directory (directory &optional regexp) | |
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 | 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 | 268 '(lambda (regexp) |
269 (if (string-match regexp file) | |
270 (setq dir-files (delq file dir-files)))) | |
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 | 274 |
275 (defun file-cache-add-directory-list (directory-list &optional regexp) | |
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 | 279 in each directory, not to the directory list itself." |
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 | 282 '(lambda (dir) (file-cache-add-directory dir regexp)) |
283 directory-list)) | |
284 | |
285 (defun file-cache-add-file-list (file-list) | |
286 "Add FILE-LIST (a list of files names) to the file cache." | |
287 (interactive "XFile List: ") | |
288 (mapcar 'file-cache-add-file file-list)) | |
289 | |
290 ;; Workhorse function | |
291 (defun file-cache-add-file (file) | |
292 "Add FILE to the file cache." | |
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 | 316 (defun file-cache-add-directory-using-find (directory) |
317 "Use the `find' command to add files to the file cache. | |
318 Find is run in DIRECTORY." | |
319 (interactive "DAdd files under directory: ") | |
320 (let ((dir (expand-file-name directory))) | |
321 (set-buffer (get-buffer-create file-cache-buffer)) | |
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 | 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 | 327 "-print") |
328 (file-cache-add-from-file-cache-buffer))) | |
329 | |
330 (defun file-cache-add-directory-using-locate (string) | |
331 "Use the `locate' command to add files to the file cache. | |
332 STRING is passed as an argument to the locate command." | |
333 (interactive "sAdd files using locate string: ") | |
334 (set-buffer (get-buffer-create file-cache-buffer)) | |
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 | 337 (get-buffer file-cache-buffer) nil |
338 string) | |
339 (file-cache-add-from-file-cache-buffer)) | |
340 | |
341 (defun file-cache-add-from-file-cache-buffer (&optional regexp) | |
342 "Add any entries found in the file cache buffer. | |
343 Each entry matches the regular expression `file-cache-buffer-default-regexp' | |
344 or the optional REGEXP argument." | |
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 | 347 (function (lambda (elt) |
348 (goto-char (point-min)) | |
349 (delete-matching-lines elt))) | |
350 file-cache-filter-regexps) | |
351 (goto-char (point-min)) | |
352 (let ((full-filename)) | |
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 | 355 (point-max) t) |
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 | 358 (file-cache-add-file full-filename)))) |
359 | |
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
361 ;; Functions to delete from the cache | |
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
363 | |
364 (defun file-cache-clear-cache () | |
365 "Clear the file cache." | |
366 (interactive) | |
367 (setq file-cache-alist nil)) | |
368 | |
369 ;; This clears *all* files with the given name | |
370 (defun file-cache-delete-file (file) | |
371 "Delete FILE from the file cache." | |
372 (interactive | |
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 | 377 |
378 (defun file-cache-delete-file-list (file-list) | |
379 "Delete FILE-LIST (a list of files) from the file cache." | |
380 (interactive "XFile List: ") | |
381 (mapcar 'file-cache-delete-file file-list)) | |
382 | |
383 (defun file-cache-delete-file-regexp (regexp) | |
384 "Delete files matching REGEXP from the file cache." | |
385 (interactive "sRegexp: ") | |
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 | 388 (and (string-match regexp (car elt)) |
389 (setq delete-list (cons (car elt) delete-list)))) | |
390 file-cache-alist) | |
391 (file-cache-delete-file-list delete-list) | |
392 (message "Deleted %d files from file cache" (length delete-list)))) | |
393 | |
394 (defun file-cache-delete-directory (directory) | |
395 "Delete DIRECTORY from the file cache." | |
396 (interactive "DDelete directory from file cache: ") | |
397 (let ((dir (expand-file-name directory)) | |
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 | 401 (if (file-cache-do-delete-directory dir entry) |
402 (setq result (1+ result)))) | |
403 file-cache-alist) | |
404 (if (zerop result) | |
405 (error "No entries containing %s found in cache" directory) | |
406 (message "Deleted %d entries" result)))) | |
407 | |
408 (defun file-cache-do-delete-directory (dir entry) | |
409 (let ((directory-list (cdr entry)) | |
410 (directory (file-cache-canonical-directory dir)) | |
411 ) | |
412 (and (member directory directory-list) | |
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 | 415 (delq entry file-cache-alist)) |
416 (setcdr entry (delete directory directory-list))) | |
417 ) | |
418 )) | |
419 | |
420 (defun file-cache-delete-directory-list (directory-list) | |
421 "Delete DIRECTORY-LIST (a list of directories) from the file cache." | |
422 (interactive "XDirectory List: ") | |
423 (mapcar 'file-cache-delete-directory directory-list)) | |
424 | |
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
426 ;; Utility functions | |
427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
428 | |
429 ;; Returns the name of a directory for a file in the cache | |
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 | 433 (len (length directory-list)) |
434 (directory) | |
435 (num) | |
436 ) | |
437 (if (not (listp directory-list)) | |
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 | 440 ;; Single element |
441 ((eq 1 len) | |
442 (setq directory (elt directory-list 0))) | |
443 ;; No elements | |
444 ((eq 0 len) | |
445 (error "No directory found for key %s" file)) | |
446 ;; Multiple elements | |
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 | 449 (dir-list (member minibuffer-dir directory-list)) |
450 ) | |
451 (setq directory | |
452 ;; If the directory is in the list, return the next element | |
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 | 456 (setq num (1+ (- len (length dir-list))))) |
457 (elt directory-list (setq num 0))) | |
458 (elt directory-list (setq num 0)))) | |
459 ) | |
460 ) | |
461 ) | |
462 ;; If there were multiple directories, set up a minibuffer message | |
463 (setq file-cache-multiple-directory-message | |
464 (and num (format " [%d of %d]" (1+ num) len))) | |
465 directory)) | |
466 | |
467 ;; Returns the name of a file in the cache | |
468 (defun file-cache-file-name (file) | |
469 (let ((directory (file-cache-directory-name file))) | |
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 | 472 ;; Return a canonical directory for comparison purposes. |
473 ;; Such a directory ends with a forward slash. | |
474 (defun file-cache-canonical-directory (dir) | |
475 (let ((directory dir)) | |
476 (if (not (char-equal ?/ (string-to-char (substring directory -1)))) | |
477 (concat directory "/") | |
478 directory))) | |
479 | |
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
481 ;; Minibuffer functions | |
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
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 | 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 | 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 | 507 (completion-list) |
508 (len) | |
509 (file-cache-string) | |
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 | 524 ;; If it's the longest match, insert it |
525 ((stringp completion-string) | |
526 ;; If we've already inserted a unique string, see if the user | |
527 ;; wants to use that one | |
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 | 530 (if (and (eq last-command this-command) |
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 | 535 (setq file-cache-last-completion nil) |
536 ) | |
537 (file-cache-temp-minibuffer-message file-cache-non-unique-message) | |
538 (setq file-cache-last-completion string) | |
539 ) | |
540 (setq file-cache-last-completion string) | |
541 (setq completion-list (all-completions string file-cache-alist) | |
542 len (length completion-list)) | |
543 (if (> len 1) | |
544 (progn | |
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 | 547 (substring completion-string (length string))) |
548 ;; Add our own setup function to the Completions Buffer | |
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 | 551 (append (list 'file-cache-completion-setup-function) |
552 completion-setup-hook))) | |
553 ) | |
554 (with-output-to-temp-buffer file-cache-completions-buffer | |
555 (display-completion-list completion-list)) | |
556 ) | |
557 ) | |
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 | 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 | 566 file-cache-multiple-directory-message))) |
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 | 569 ;; No match |
570 ((eq completion-string nil) | |
571 (file-cache-temp-minibuffer-message file-cache-no-match-message)) | |
572 ) | |
573 )) | |
574 | |
575 ;; Lifted from "complete.el" | |
576 (defun file-cache-temp-minibuffer-message (msg) | |
577 "A Lisp version of `temp_minibuffer_message' from minibuf.c." | |
578 (let ((savemax (point-max))) | |
579 (save-excursion | |
580 (goto-char (point-max)) | |
581 (insert msg)) | |
582 (let ((inhibit-quit t)) | |
583 (sit-for 2) | |
584 (delete-region savemax (point-max)) | |
585 (if quit-flag | |
586 (setq quit-flag nil | |
587 unread-command-events (list 7)))))) | |
588 | |
589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
590 ;; Completion functions | |
591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
592 | |
593 (defun file-cache-completion-setup-function () | |
594 (set-buffer file-cache-completions-buffer) | |
595 | |
596 (if file-cache-completions-keymap | |
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 | 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 | 603 'file-cache-choose-completion)) |
604 | |
605 (use-local-map file-cache-completions-keymap) | |
606 ) | |
607 | |
608 (defun file-cache-choose-completion () | |
609 "Choose a completion in the `*Completions*' buffer." | |
610 (interactive) | |
611 (let ((completion-no-auto-exit t)) | |
612 (choose-completion) | |
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 | 615 ) |
616 ) | |
617 | |
618 (defun file-cache-mouse-choose-completion (event) | |
619 "Choose a completion with the mouse." | |
620 (interactive "e") | |
621 (let ((completion-no-auto-exit t)) | |
622 (mouse-choose-completion event) | |
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 | 625 ) |
626 ) | |
627 | |
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 | 667 ;; Debugging functions |
668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
669 | |
670 (defun file-cache-debug-read-from-minibuffer (file) | |
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 | 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 | 675 ) |
676 | |
677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
678 ;; Keybindings | |
679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
680 | |
681 ;;;###autoload (define-key minibuffer-local-completion-map [C-tab] 'file-cache-minibuffer-complete) | |
682 ;;;###autoload (define-key minibuffer-local-map [C-tab] 'file-cache-minibuffer-complete) | |
683 ;;;###autoload (define-key minibuffer-local-must-match-map [C-tab] 'file-cache-minibuffer-complete) | |
684 | |
685 (provide 'filecache) | |
686 | |
687 ;;; filecache.el ends here |