comparison lisp/ido.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 1da4c425c852
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; ido.el --- interactively do things with buffers and files. 1 ;;; ido.el --- interactively do things with buffers and files.
2 2
3 ;; Copyright (C) 1996-2003 Free Software Foundation, Inc. 3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005 Free Software Foundation, Inc.
4 5
5 ;; Author: Kim F. Storm <storm@cua.dk> 6 ;; Author: Kim F. Storm <storm@cua.dk>
6 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk> 7 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
7 ;; Keywords: extensions convenience 8 ;; Keywords: extensions convenience
8 9
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details. 20 ;; GNU General Public License for more details.
20 21
21 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02110-1301, USA.
26
27
28 ;;; Commentary:
29
30 ;; Ido - interactive do - switches between buffers and opens files and
31 ;; directories with a minimum of keystrokes. It is a superset of
32 ;; iswitchb, the interactive buffer switching package by Stephen Eglen.
33
34 ;; Interactive substring matching
35 ;; ------------------------------
36 ;;
37 ;; As you type in a substring, the list of buffers or files currently
38 ;; matching the substring are displayed as you type. The list is
39 ;; ordered so that the most recent buffers or files visited come at
40 ;; the start of the list.
41 ;;
42 ;; The buffer or file at the start of the list will be the one visited
43 ;; when you press RETURN. By typing more of the substring, the list is
44 ;; narrowed down so that gradually the buffer or file you want will be
45 ;; at the top of the list. Alternatively, you can use C-s and C-r (or
46 ;; the right and left arrow keys) to rotate buffer or file names in the
47 ;; list until the one you want is at the top of the list.
48 ;;
49 ;; Completion is also available so that you can see what is common to
50 ;; all of the matching buffers or files as you type.
51 ;;
52 ;; Example:
53 ;;
54 ;; If I have two buffers called "123456" and "123", with "123456" the
55 ;; most recent, when I use ido-switch-buffer, I first of all get
56 ;; presented with the list of all the buffers
57 ;;
58 ;; Buffer: {123456 | 123}
59 ;;
60 ;; If I then press 2:
61 ;; Buffer: 2[3]{123456 | 123}
62 ;;
63 ;; The list in {...} are the matching buffers, most recent first
64 ;; (buffers visible in the current frame are put at the end of the
65 ;; list by default). At any time I can select the item at the head of
66 ;; the list by pressing RET. I can also put the first element at the
67 ;; end of the list by pressing C-s or [right], or bring the last
68 ;; element to the head of the list by pressing C-r or [left].
69 ;;
70 ;; The item in [...] indicates what can be added to my input by
71 ;; pressing TAB. In this case, I will get "3" added to my input.
72
73 ;; So, I press TAB:
74 ;; Buffer: 23{123456 | 123}
75 ;;
76 ;; At this point, I still have two matching buffers.
77 ;; If I want the first buffer in the list, I simply press RET. If I
78 ;; wanted the second in the list, I could press C-s to move it to the
79 ;; top of the list and then RET to select it.
80 ;;
81 ;; However, if I type 4, I only have one match left:
82 ;; Buffer: 234[123456]
83 ;;
84 ;; Since there is only one matching buffer left, it is given in [] and
85 ;; it is shown in the `ido-only-match' face (ForestGreen). I can now
86 ;; press TAB or RET to go to that buffer.
87 ;;
88 ;; If I want to create a new buffer named "234", I press C-j instead of
89 ;; TAB or RET.
90 ;;
91 ;; If instead, I type "a":
92 ;; Buffer: 234a [No match]
93 ;; There are no matching buffers. If I press RET or TAB, I can be
94 ;; prompted to create a new buffer called "234a".
95 ;;
96 ;; Of course, where this function comes in really useful is when you
97 ;; can specify the buffer using only a few keystrokes. In the above
98 ;; example, the quickest way to get to the "123456" file would be
99 ;; just to type 4 and then RET (assuming there isn't any newer buffer
100 ;; with 4 in its name).
101
102 ;; Likewise, if you use C-x C-f (ido-find-file), the list of files and
103 ;; directories in the current directory is provided in the same
104 ;; fashion as the buffers above. The files and directories are
105 ;; normally sorted in alphabetical order, but the most recently
106 ;; visited directory is placed first to speed up navigating to
107 ;; directories that you have visited recently.
108 ;;
109 ;; In addition to scrolling through the list using [right] and [left],
110 ;; you can use [up] and [down] to quickly scroll the list to the next
111 ;; or previous subdirectory.
112 ;;
113 ;; To go down into a subdirectory, and continue the file selection on
114 ;; the files in that directory, simply move the directory to the head
115 ;; of the list and hit RET.
116 ;;
117 ;; To go up to the parent directory, delete any partial file name
118 ;; already specified (e.g. using [backspace]) and hit [backspace].
119 ;;
120 ;; To go to the root directory (on the current drive), enter two
121 ;; slashes. On MS-DOS or Windows, to select the root of another
122 ;; drive, enter X:/ where X is the drive letter. You can also visit
123 ;; files on other hosts using the ange-ftp notations `/host:' and
124 ;; `/user@host:'. See the variable `ido-slow-ftp-hosts' if you want
125 ;; to inhibit the ido substring matching for ftp access.
126 ;;
127 ;; If for some reason you cannot specify the proper file using
128 ;; ido-find-file, you can press C-f to enter the normal find-file.
129 ;; You can also press C-b to drop into ido-switch-buffer.
130
131 ;; See the doc string of ido-switch-buffer and ido-find-file for full
132 ;; keybindings and features.
133 ;; (describe-function 'ido-find-file)
134
135 ;; Hidden buffers and files
136 ;; ------------------------
137 ;;
138 ;; Normally, ido does not include hidden buffers (whose name starts
139 ;; with a space) and hidden files and directories (whose name starts
140 ;; with `.') in the list of possible completions. However, if the
141 ;; substring you enter does not match any of the visible buffers or
142 ;; files, ido will automatically look for completions among the hidden
143 ;; buffers or files.
144 ;;
145 ;; You can toggle display of the hidden buffers and files with C-a.
146
147 ;; Additional functionality
148 ;; ------------------------
149 ;;
150 ;; After C-x b, the buffer at the head of the list can be killed by
151 ;; pressing C-k. If the buffer needs saving, you will be queried
152 ;; before the buffer is killed.
153 ;;
154 ;; Likewise, after C-x C-f, you can delete (i.e. physically remove)
155 ;; the file at the head of the list with C-k. You will always be
156 ;; asked for confirmation before the file is deleted.
157 ;;
158 ;; If you enter C-x b to switch to a buffer visiting a given file, and
159 ;; you find that the file you are after is not in any buffer, you can
160 ;; press C-f to immediately drop into ido-find-file. And you can
161 ;; switch back to buffer selection with C-b.
162
163 ;; Prefix matching
164 ;; ---------------
165 ;;
166 ;; The standard way of completion with Unix-shells and Emacs is to insert a
167 ;; PREFIX and then hitting TAB (or another completion key). Cause of this
168 ;; behavior has become second nature to a lot of emacs users `ido' offers in
169 ;; addition to the default substring-matching-method (look above) also the
170 ;; prefix-matching-method. The kind of matching is the only difference to
171 ;; the description of the substring-matching above.
172 ;;
173 ;; You can toggle prefix matching with C-p.
174 ;;
175 ;; Example:
176 ;;
177 ;; If you have again two Buffers "123456" and "123" then hitting "2" does
178 ;; not match because "2" is not a PREFIX in any of the buffer-names.
179
180 ;; Flexible matching
181 ;; -----------------
182 ;;
183 ;; If you set ido-enable-flex-matching, ido will do a more flexible
184 ;; matching (unless regexp matching is active) to find possible matches
185 ;; among the available buffer or file names if no matches are found using
186 ;; the normal prefix or substring matching.
187 ;;
188 ;; The flexible matching implies that any item which simply contains all
189 ;; of the entered characters in the specified sequence will match.
190 ;;
191 ;; Example:
192 ;;
193 ;; If you have four files "alpha", "beta", "gamma", and "delta",
194 ;; entering "aa" will match "alpha" and "gamma", while "ea" matches
195 ;; "beta" and "delta". If prefix matching is also active, "aa" only
196 ;; matches "alpha", while "ea" does not match any files.
197
198 ;; Regexp matching
199 ;; ---------------
200 ;;
201 ;; There is limited provision for regexp matching within ido,
202 ;; enabled through `ido-enable-regexp' (toggle with C-t).
203 ;; This allows you to type `[ch]$' for example and see all file names
204 ;; ending in `c' or `h'.
205 ;;
206 ;; Note: ido-style completion is inhibited when you enable regexp matching.
207
208
209 ;; Customization
210 ;; -------------
211 ;;
212 ;; Customize the `ido' group to change the `ido' functionality.
213 ;;
214 ;; To modify the keybindings, use the ido-setup-hook. For example:
215 ;;(add-hook 'ido-setup-hook 'ido-my-keys)
216 ;;
217 ;;(defun ido-my-keys ()
218 ;; "Add my keybindings for ido."
219 ;; (define-key ido-completion-map " " 'ido-next-match)
220 ;; )
221
222 ;; Seeing all the matching buffers or files
223 ;; ----------------------------------------
224 ;;
225 ;; If you have many matching files, they may not all fit onto one
226 ;; line of the minibuffer. Normally, the minibuffer window will grow
227 ;; to show you more of the matching files (depending on the setting
228 ;; of the variables `resize-mini-windows' and `max-mini-window-height').
229 ;; If you want ido to behave differently from the default minibuffer
230 ;; resizing behaviour, set the variable `ido-max-window-height'.
231 ;;
232 ;; Also, to improve the responsiveness of ido, the maximum number of
233 ;; matching items is limited to 12, but you can increase or removed
234 ;; this limit via the `ido-max-prospects' variable.
235
236 ;; To see a full list of all matching buffers in a separate buffer,
237 ;; hit ? or press TAB when there are no further completions to the
238 ;; substring. Repeated TAB presses will scroll you through this
239 ;; separate buffer.
240
241 ;; Changing the list of files
242 ;; --------------------------
243
244 ;; By default, the list of current files is most recent first,
245 ;; oldest last, with the exception that the files visible in the
246 ;; current frame are put at the end of the list. A hook exists to
247 ;; allow other functions to order the list. For example, if you add:
248 ;;
249 ;; (add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end)
250 ;;
251 ;; then all files matching "Summary" are moved to the end of the
252 ;; list. (I find this handy for keeping the INBOX Summary and so on
253 ;; out of the way.) It also moves files matching "output\*$" to the
254 ;; end of the list (these are created by AUCTeX when compiling.)
255 ;; Other functions could be made available which alter the list of
256 ;; matching files (either deleting or rearranging elements.)
257
258 ;; Highlighting
259 ;; ------------
260
261 ;; The highlighting of matching items is controlled via ido-use-faces.
262 ;; The faces used are ido-first-match, ido-only-match and
263 ;; ido-subdir.
264 ;; Colouring of the matching item was suggested by
265 ;; Carsten Dominik (dominik@strw.leidenuniv.nl).
266
267 ;; Replacement for read-buffer and read-file-name
268 ;; ----------------------------------------------
269
270 ;; ido-read-buffer and ido-read-file-name have been written to be drop
271 ;; in replacements for the normal buffer and file name reading
272 ;; functions `read-buffer' and `read-file-name'.
273
274 ;; To use ido for all buffer and file selections in Emacs, customize the
275 ;; variable `ido-everywhere'.
276
277 ;; Using ido-like behaviour in other lisp packages
278 ;; -----------------------------------------------
279
280 ;; If you don't want to rely on the `ido-everywhere' functionality,
281 ;; ido-read-buffer, ido-read-file-name, and ido-read-directory-name
282 ;; can be used by other packages to read a buffer name, a file name,
283 ;; or a directory name in the `ido' way.
25 284
26 ;;; Acknowledgements 285 ;;; Acknowledgements
27 286
28 ;; Infinite amounts of gratitude goes to Stephen Eglen <stephen@cns.ed.ac.uk> 287 ;; Infinite amounts of gratitude goes to Stephen Eglen <stephen@cns.ed.ac.uk>
29 ;; who wrote iswitch-buffer mode - from which I ripped off 99% of the code 288 ;; who wrote iswitch-buffer mode - from which I ripped off 99% of the code
30 ;; for ido-switch-buffer and found the inspiration for ido-find-file. 289 ;; for ido-switch-buffer and found the inspiration for ido-find-file.
31 ;; The ido package would never have existed without his work. 290 ;; The ido package would never have existed without his work.
32 291
33 ;; Also thanks to Klaus Berndl, Rohit Namjoshi, Robert Fenk, Alex Schroeder, 292 ;; Also thanks to Klaus Berndl, Rohit Namjoshi, Robert Fenk, Alex
34 ;; Bill Benedetto, and Stephen Eglen for bug fixes and improvements. 293 ;; Schroeder, Bill Benedetto, Stephen Eglen, and many others for bug
294 ;; fixes and improvements.
35 295
36 ;;; History 296 ;;; History
37 297
38 ;; Since I discovered Stephen Eglen's excellent iswitchb package, I just 298 ;; Since I discovered Stephen Eglen's excellent iswitchb package, I just
39 ;; couldn't live without it, but once being addicted to switching buffers 299 ;; couldn't live without it, but once being addicted to switching buffers
53 ;; This is basically what ido (interactively do) is all about; but I 313 ;; This is basically what ido (interactively do) is all about; but I
54 ;; found it ackward to merge my changes into the "iswitchb-" namespace, 314 ;; found it ackward to merge my changes into the "iswitchb-" namespace,
55 ;; so I invented a common "ido-" namespace for the merged packages. 315 ;; so I invented a common "ido-" namespace for the merged packages.
56 ;; 316 ;;
57 ;; This version is based on ido.el version 1.57 released on 317 ;; This version is based on ido.el version 1.57 released on
58 ;; gnu.emacs.sources adapted for emacs 21.4 to use command remapping 318 ;; gnu.emacs.sources adapted for emacs 22.1 to use command remapping
59 ;; and optionally hooking the read-buffer and read-file-name functions. 319 ;; and optionally hooking the read-buffer and read-file-name functions.
60 ;; 320 ;;
61 ;; Prefix matching was added by Klaus Berndl <klaus.berndl@sdm.de> based on 321 ;; Prefix matching was added by Klaus Berndl <klaus.berndl@sdm.de> based on
62 ;; an idea of Yuji Minejima <ggb01164@nifty.ne.jp> and his mcomplete-package. 322 ;; an idea of Yuji Minejima <ggb01164@nifty.ne.jp> and his mcomplete-package.
63 323
64 324
65 ;;; Commentary:
66
67 ;; Ido - interactive do - switches between buffers and opens files and
68 ;; directories with a minimum of keystrokes. It is a superset of
69 ;; iswitchb, the interactive buffer switching package by Stephen Eglen.
70
71 ;; Interactive substring matching
72 ;; ------------------------------
73 ;;
74 ;; As you type in a substring, the list of buffers or files currently
75 ;; matching the substring are displayed as you type. The list is
76 ;; ordered so that the most recent buffers or files visited come at
77 ;; the start of the list.
78 ;;
79 ;; The buffer or file at the start of the list will be the one visited
80 ;; when you press RETURN. By typing more of the substring, the list is
81 ;; narrowed down so that gradually the buffer or file you want will be
82 ;; at the top of the list. Alternatively, you can use C-s and C-r (or
83 ;; the right and left arrow keys) to rotate buffer or file names in the
84 ;; list until the one you want is at the top of the list.
85 ;;
86 ;; Completion is also available so that you can see what is common to
87 ;; all of the matching buffers or files as you type.
88 ;;
89 ;; Example:
90 ;;
91 ;; If I have two buffers called "123456" and "123", with "123456" the
92 ;; most recent, when I use ido-switch-buffer, I first of all get
93 ;; presented with the list of all the buffers
94 ;;
95 ;; Buffer: {123456,123}
96 ;;
97 ;; If I then press 2:
98 ;; Buffer: 2[3]{123456,123}
99 ;;
100 ;; The list in {...} are the matching buffers, most recent first
101 ;; (buffers visible in the current frame are put at the end of the
102 ;; list by default). At any time I can select the item at the head of
103 ;; the list by pressing RET. I can also bring the put the first
104 ;; element at the end of the list by pressing C-s or [right], or put
105 ;; the last element at the head of the list by pressing C-r or [left].
106 ;;
107 ;; The item in [...] indicates what can be added to my input by
108 ;; pressing TAB. In this case, I will get "3" added to my input.
109
110 ;; So, I press TAB:
111 ;; Buffer: 23{123456,123}
112 ;;
113 ;; At this point, I still have two matching buffers.
114 ;; If I want the first buffer in the list, I simply press RET. If I
115 ;; wanted the second in the list, I could press C-s to move it to the
116 ;; top of the list and then RET to select it.
117 ;;
118 ;; However, if I type 4, I only have one match left:
119 ;; Buffer: 234[123456] [Matched]
120 ;;
121 ;; Since there is only one matching buffer left, it is given in [] and we
122 ;; see the text [Matched] afterwards. I can now press TAB or RET to go
123 ;; to that buffer.
124 ;;
125 ;; If however, I now type "a":
126 ;; Buffer: 234a [No match]
127 ;; There are no matching buffers. If I press RET or TAB, I can be
128 ;; prompted to create a new buffer called "234a".
129 ;;
130 ;; Of course, where this function comes in really useful is when you
131 ;; can specify the buffer using only a few keystrokes. In the above
132 ;; example, the quickest way to get to the "123456" file would be
133 ;; just to type 4 and then RET (assuming there isn't any newer buffer
134 ;; with 4 in its name).
135
136 ;; Likewise, if you use C-x C-f (ido-find-file), the list of files and
137 ;; directories in the current directory is provided in the same
138 ;; fashion as the buffers above. The files and directories are
139 ;; normally sorted in alphabetical order, but the most recently
140 ;; visited directory is placed first to speed up navigating to
141 ;; directories that you have visited recently.
142 ;;
143 ;; In addition to scrolling through the list using [right] and [left],
144 ;; you can use [up] and [down] to quickly scroll the list to the next
145 ;; or previous subdirectory.
146 ;;
147 ;; To go down into a subdirectory, and continue the file selection on
148 ;; the files in that directory, simply move the directory to the head
149 ;; of the list and hit RET.
150 ;;
151 ;; To go up to the parent directory, delete any partial file name
152 ;; already specified (e.g. using [backspace]) and hit [backspace].
153 ;;
154 ;; To go to the root directory (on the current drive), enter two
155 ;; slashes. On MS-DOS or Windows, to select the root of another
156 ;; drive, enter X:/ where X is the drive letter. You can also visit
157 ;; files on other hosts using the ange-ftp notations `/host:' and
158 ;; `/user@host:'. See the variable `ido-slow-ftp-hosts' if you want
159 ;; to inhibit the ido substring matching for ftp access.
160 ;;
161 ;; If for some reason you cannot specify the proper file using
162 ;; ido-find-file, you can press C-f to enter the normal find-file.
163 ;; You can also press C-b to drop into ido-switch-buffer.
164
165 ;; See the doc string of ido-switch-buffer and ido-find-file for full
166 ;; keybindings and features.
167 ;; (describe-function 'ido-find-file)
168
169 ;; Hidden buffers and files
170 ;; ------------------------
171 ;;
172 ;; Normally, ido does not include hidden buffers (whose name starts
173 ;; with a space) and hidden files and directories (whose name starts
174 ;; with `.') in the list of possible completions. However, if the
175 ;; substring you enter does not match any of the visible buffers or
176 ;; files, ido will automatically look for completions among the hidden
177 ;; buffers or files.
178 ;;
179 ;; You can toggle display of the hidden buffers and files with C-a.
180
181 ;; Additional functionality
182 ;; ------------------------
183 ;;
184 ;; After C-x b, the buffer at the head of the list can be killed by
185 ;; pressing C-k. If the buffer needs saving, you will be queried
186 ;; before the buffer is killed.
187 ;;
188 ;; Likewise, after C-x C-f, you can delete (i.e. physically remove)
189 ;; the file at the head of the list with C-k. You will always be
190 ;; asked for confirmation before the file is deleted.
191 ;;
192 ;; If you enter C-x b to switch to a buffer visiting a given file, and
193 ;; you find that the file you are after is not in any buffer, you can
194 ;; press C-f to immediately drop into ido-find-file. And you can
195 ;; switch back to buffer selection with C-b.
196
197 ;; Prefix matching
198 ;; ---------------
199 ;;
200 ;; The standard way of completion with Unix-shells and Emacs is to insert a
201 ;; PREFIX and then hitting TAB (or another completion key). Cause of this
202 ;; behavior has become second nature to a lot of emacs users `ido' offers in
203 ;; addition to the default substring-matching-method (look above) also the
204 ;; prefix-matching-method. The kind of matching is the only difference to
205 ;; the description of the substring-matching above.
206 ;;
207 ;; You can toggle prefix matching with C-p.
208 ;;
209 ;; Example:
210 ;;
211 ;; If you have again two Buffers "123456" and "123" then hitting "2" does
212 ;; not match because "2" is not a PREFIX in any of the buffer-names. This
213 ;; is the only difference between the substring and prefix matching.
214
215 ;; Flexible matching
216 ;; -----------------
217 ;;
218 ;; If you set ido-enable-flex-matching, ido will do a more flexible
219 ;; matching (unless regexp matching is active) to find possible matches
220 ;; among the available buffer or file names if no matches are found using
221 ;; the normal prefix or substring matching.
222 ;;
223 ;; The flexible matching implies that any item which simply contains all
224 ;; of the entered characters in the specified sequence will match.
225 ;;
226 ;; Example:
227 ;;
228 ;; If you have four files "alpha", "beta", "gamma", and "delta",
229 ;; entering "aa" will match "alpha" and "gamma", while "ea" matches
230 ;; "beta" and "delta". If prefix matching is also active, "aa" only
231 ;; matches "alpha", while "ea" does not match any files.
232
233 ;; Regexp matching
234 ;; ---------------
235 ;;
236 ;; There is limited provision for regexp matching within ido,
237 ;; enabled through `ido-enable-regexp' (toggle with C-t).
238 ;; This allows you to type `c$' for example and see all file names
239 ;; ending in `c'. This facility is quite limited though in two
240 ;; respects. First, you can't currently type in expressions like
241 ;; `[0-9]' directly -- you have to type them in when ido-enable-regexp
242 ;; is nil and then toggle on the regexp functionality. Likewise,
243 ;; don't enter an expression containing `\' in regexp mode. If you
244 ;; try, ido gets confused, so just hit C-g and try again. Secondly,
245 ;; no completion mechanism is currently offered with regexp searching.
246
247
248 ;; Customization
249 ;; -------------
250 ;;
251 ;; Customize the `ido' group to change the `ido' functionality.
252 ;;
253 ;; To modify the keybindings, use the hook provided. For example:
254 ;;(add-hook 'ido-define-mode-map-hook 'ido-my-keys)
255 ;;
256 ;;(defun ido-my-keys ()
257 ;; "Add my keybindings for ido."
258 ;; (define-key ido-mode-map " " 'ido-next-match)
259 ;; )
260
261 ;; Seeing all the matching buffers or files
262 ;; ----------------------------------------
263 ;;
264 ;; If you have many matching files, they may not all fit onto one
265 ;; line of the minibuffer. Normally, the minibuffer window will grow
266 ;; to show you more of the matching files (depending on the setting
267 ;; of the variables `resize-mini-windows' and `max-mini-window-height').
268 ;; If you want ido to behave differently from the default minibuffer
269 ;; resizing behaviour, set the variable `ido-max-window-height'.
270 ;;
271 ;; Also, to improve the responsiveness of ido, the maximum number of
272 ;; matching items is limited to 12, but you can increase or removed
273 ;; this limit via the `ido-max-prospects' variable.
274
275 ;; To see a full list of all matching buffers in a separate buffer,
276 ;; hit ? or press TAB when there are no further completions to the
277 ;; substring. Repeated TAB presses will scroll you through this
278 ;; separate buffer.
279
280 ;; Changing the list of files
281 ;; --------------------------
282
283 ;; By default, the list of current files is most recent first,
284 ;; oldest last, with the exception that the files visible in the
285 ;; current frame are put at the end of the list. A hook exists to
286 ;; allow other functions to order the list. For example, if you add:
287 ;;
288 ;; (add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end)
289 ;;
290 ;; then all files matching "Summary" are moved to the end of the
291 ;; list. (I find this handy for keeping the INBOX Summary and so on
292 ;; out of the way.) It also moves files matching "output\*$" to the
293 ;; end of the list (these are created by AUC TeX when compiling.)
294 ;; Other functions could be made available which alter the list of
295 ;; matching files (either deleting or rearranging elements.)
296
297 ;; Highlighting
298 ;; ------------
299
300 ;; The highlighting of matching items is controlled via ido-use-faces.
301 ;; The faces used are ido-first-match-face, ido-only-match-face and
302 ;; ido-subdir-face.
303 ;; Colouring of the matching item was suggested by
304 ;; Carsten Dominik (dominik@strw.leidenuniv.nl).
305
306 ;; Replacement for read-buffer and read-file-name
307 ;; ----------------------------------------------
308
309 ;; ido-read-buffer and ido-read-file-name have been written to be drop
310 ;; in replacements for the normal buffer and file name reading
311 ;; functions `read-buffer' and `read-file-name'.
312
313 ;; To use ido for all buffer and file selections in Emacs, customize the
314 ;; variable `ido-everywhere'.
315
316 ;; Using ido-like behaviour in other lisp packages
317 ;; -----------------------------------------------
318
319 ;; If you don't want to rely on the `ido-everywhere' functionality,
320 ;; ido-read-buffer, ido-read-file-name, and ido-read-directory-name
321 ;; can be used by other packages to read a buffer name, a file name,
322 ;; or a directory name in the `ido' way.
323
324
325 ;;; Code: 325 ;;; Code:
326 326
327 (provide 'ido) 327 (provide 'ido)
328
329 (defvar cua-inhibit-cua-keys)
328 330
329 ;;; User Variables 331 ;;; User Variables
330 ;; 332 ;;
331 ;; These are some things you might want to change. 333 ;; These are some things you might want to change.
332 334
335 337
336 (defgroup ido nil 338 (defgroup ido nil
337 "Switch between files using substrings." 339 "Switch between files using substrings."
338 :group 'extensions 340 :group 'extensions
339 :group 'convenience 341 :group 'convenience
342 :version "22.1"
340 :link '(emacs-commentary-link :tag "Commentary" "ido.el") 343 :link '(emacs-commentary-link :tag "Commentary" "ido.el")
341 :link '(emacs-library-link :tag "Lisp File" "ido.el")) 344 :link '(emacs-library-link :tag "Lisp File" "ido.el"))
342 345
343 ;;;###autoload 346 ;;;###autoload
344 (defcustom ido-mode nil 347 (defcustom ido-mode nil
345 "Determines for which functional group \(buffer and files) ido behavior 348 "Determines for which functional group \(buffer and files) ido behavior
346 should be enabled. The following values are possible: 349 should be enabled. The following values are possible:
347 - `buffer': Turn only on ido buffer behavior \(switching, killing, 350 - `buffer': Turn only on ido buffer behavior \(switching, killing,
348 displaying...) 351 displaying...)
349 - `file': Turn only on ido file behavior \(finding, writing, inserting...) 352 - `file': Turn only on ido file behavior \(finding, writing, inserting...)
350 - `both': Turn on ido buffer and file behavior. 353 - `both': Turn on ido buffer and file behavior.
351 - `nil': Turn off any ido switching. 354 - `nil': Turn off any ido switching.
352 355
353 Setting this variable directly does not take effect; 356 Setting this variable directly does not take effect;
354 use either \\[customize] or the function `ido-mode'." 357 use either \\[customize] or the function `ido-mode'."
355 :set #'(lambda (symbol value) 358 :set #'(lambda (symbol value)
356 (ido-mode value)) 359 (ido-mode value))
357 :initialize 'custom-initialize-default 360 :initialize 'custom-initialize-set
358 :require 'ido 361 :require 'ido
359 :link '(emacs-commentary-link "ido.el") 362 :link '(emacs-commentary-link "ido.el")
360 :set-after '(ido-save-directory-list-file) 363 :set-after '(ido-save-directory-list-file)
361 :version "21.4"
362 :type '(choice (const :tag "Turn on only buffer" buffer) 364 :type '(choice (const :tag "Turn on only buffer" buffer)
363 (const :tag "Turn on only file" file) 365 (const :tag "Turn on only file" file)
364 (const :tag "Turn on both buffer and file" both) 366 (const :tag "Turn on both buffer and file" both)
365 (const :tag "Switch off all" nil)) 367 (const :tag "Switch off all" nil))
366 :group 'ido) 368 :group 'ido)
368 (defcustom ido-everywhere nil 370 (defcustom ido-everywhere nil
369 "Use ido everywhere for reading file names and directories. 371 "Use ido everywhere for reading file names and directories.
370 Setting this variable directly does not work. Use `customize' or 372 Setting this variable directly does not work. Use `customize' or
371 call the function `ido-everywhere'." 373 call the function `ido-everywhere'."
372 :set #'(lambda (symbol value) 374 :set #'(lambda (symbol value)
373 (ido-everywhere value)) 375 (ido-everywhere (if value 1 -1)))
374 :initialize 'custom-initialize-default 376 :initialize 'custom-initialize-default
375 :type 'boolean 377 :type 'boolean
376 :group 'ido) 378 :group 'ido)
377 379
378 (defcustom ido-case-fold case-fold-search 380 (defcustom ido-case-fold case-fold-search
405 407
406 (defcustom ido-show-dot-for-dired nil 408 (defcustom ido-show-dot-for-dired nil
407 "*Non-nil means to always put . as the first item in file name lists. 409 "*Non-nil means to always put . as the first item in file name lists.
408 This allows the current directory to be opened immediate with `dired'." 410 This allows the current directory to be opened immediate with `dired'."
409 :type 'boolean 411 :type 'boolean
412 :group 'ido)
413
414 (defcustom ido-file-extensions-order nil
415 "*List of file extensions specifying preferred order of file selections.
416 Each element is either a string with `.' as the first char, an empty
417 string matching files without extension, or t which is the default order
418 for files with an unlisted file extension."
419 :type '(repeat (choice string
420 (const :tag "Default order" t)))
410 :group 'ido) 421 :group 'ido)
411 422
412 (defcustom ido-ignore-directories 423 (defcustom ido-ignore-directories
413 '("\\`CVS/" "\\`\\.\\./" "\\`\\./") 424 '("\\`CVS/" "\\`\\.\\./" "\\`\\./")
414 "*List of regexps or functions matching sub-directory names to ignore." 425 "*List of regexps or functions matching sub-directory names to ignore."
441 `otherwindow' Show new file in another window (same frame) 452 `otherwindow' Show new file in another window (same frame)
442 `display' Display file in another window without switching to it 453 `display' Display file in another window without switching to it
443 `otherframe' Show new file in another frame 454 `otherframe' Show new file in another frame
444 `maybe-frame' If a file is visible in another frame, prompt to ask if you 455 `maybe-frame' If a file is visible in another frame, prompt to ask if you
445 you want to see the file in the same window of the current 456 you want to see the file in the same window of the current
446 frame or in the other frame. 457 frame or in the other frame
447 `always-frame' If a file is visible in another frame, raise that 458 `always-frame' If a file is visible in another frame, raise that
448 frame. Otherwise, visit the file in the same window." 459 frame; otherwise, visit the file in the same window"
449 :type '(choice (const samewindow) 460 :type '(choice (const samewindow)
450 (const otherwindow) 461 (const otherwindow)
451 (const display) 462 (const display)
452 (const otherframe) 463 (const otherframe)
453 (const maybe-frame) 464 (const maybe-frame)
454 (const always-frame)) 465 (const always-frame))
455 :group 'ido) 466 :group 'ido)
456 467
457 (defcustom ido-default-buffer-method 'always-frame 468 (defcustom ido-default-buffer-method 'always-frame
458 "*How to switch to new buffer when using `ido-switch-buffer'. 469 "*How to switch to new buffer when using `ido-switch-buffer'.
459 See ido-default-file-method for details." 470 See `ido-default-file-method' for details."
460 :type '(choice (const samewindow) 471 :type '(choice (const samewindow)
461 (const otherwindow) 472 (const otherwindow)
462 (const display) 473 (const display)
463 (const otherframe) 474 (const otherframe)
464 (const maybe-frame) 475 (const maybe-frame)
479 Value can be toggled within `ido' using `ido-toggle-regexp'." 490 Value can be toggled within `ido' using `ido-toggle-regexp'."
480 :type 'boolean 491 :type 'boolean
481 :group 'ido) 492 :group 'ido)
482 493
483 (defcustom ido-enable-prefix nil 494 (defcustom ido-enable-prefix nil
484 "*Nil means that `ido' will match if the inserted text is an 495 "*Non-nil means only match if the entered text is a prefix of file name.
485 arbitrary substring (default). If non-nil `ido' will only match if the inserted 496 This behavior is like the standard emacs-completion.
486 text is a prefix \(this behavior is like the standard unix- or 497 Nil means to match if the entered text is an arbitrary substring.
487 emacs-completion works).
488 Value can be toggled within `ido' using `ido-toggle-prefix'." 498 Value can be toggled within `ido' using `ido-toggle-prefix'."
499 :type 'boolean
500 :group 'ido)
501
502 (defcustom ido-enable-dot-prefix nil
503 "*Non-nil means to match leading dot as prefix.
504 I.e. hidden files and buffers will match only if you type a dot
505 as first char even if `ido-enable-prefix' is nil."
506 :type 'boolean
507 :group 'ido)
508
509 (defcustom ido-confirm-unique-completion nil
510 "*Non-nil means that even a unique completion must be confirmed.
511 This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer]
512 even when there is only one unique completion."
489 :type 'boolean 513 :type 'boolean
490 :group 'ido) 514 :group 'ido)
491 515
492 (defcustom ido-cannot-complete-command 'ido-completion-help 516 (defcustom ido-cannot-complete-command 'ido-completion-help
493 "*Command run when `ido-complete' can't complete any more. 517 "*Command run when `ido-complete' can't complete any more.
505 :group 'ido) 529 :group 'ido)
506 530
507 (defcustom ido-max-prospects 12 531 (defcustom ido-max-prospects 12
508 "*Non-zero means that the prospect list will be limited to than number of items. 532 "*Non-zero means that the prospect list will be limited to than number of items.
509 For a long list of prospects, building the full list for the minibuffer can take a 533 For a long list of prospects, building the full list for the minibuffer can take a
510 non-negletable amount of time; setting this variable reduces that time." 534 non-negligible amount of time; setting this variable reduces that time."
511 :type 'integer 535 :type 'integer
512 :group 'ido) 536 :group 'ido)
513 537
514 (defcustom ido-max-file-prompt-width 0.35 538 (defcustom ido-max-file-prompt-width 0.35
515 "*Non-zero means that the prompt string be limited to than number of characters. 539 "*Non-zero means that the prompt string be limited to than number of characters.
551 the `ido-work-directory-list' list." 575 the `ido-work-directory-list' list."
552 :type '(repeat regexp) 576 :type '(repeat regexp)
553 :group 'ido) 577 :group 'ido)
554 578
555 579
580 (defcustom ido-use-filename-at-point nil
581 "*Non-nil means that ido shall look for a filename at point.
582 May use `ffap-guesser' to guess whether text at point is a filename.
583 If found, use that as the starting point for filename selection."
584 :type '(choice
585 (const :tag "Disabled" nil)
586 (const :tag "Guess filename" guess)
587 (other :tag "Use literal filename" t))
588 :group 'ido)
589
590
591 (defcustom ido-use-url-at-point nil
592 "*Non-nil means that ido shall look for a URL at point.
593 If found, call `find-file-at-point' to visit it."
594 :type 'boolean
595 :group 'ido)
596
597
556 (defcustom ido-enable-tramp-completion t 598 (defcustom ido-enable-tramp-completion t
557 "*Non-nil means that ido shall perform tramp method and server name completion. 599 "*Non-nil means that ido shall perform tramp method and server name completion.
558 A tramp file name uses the following syntax: /method:user@host:filename." 600 A tramp file name uses the following syntax: /method:user@host:filename."
559 :type 'boolean 601 :type 'boolean
560 :group 'ido) 602 :group 'ido)
576 :group 'ido) 618 :group 'ido)
577 619
578 (defcustom ido-slow-ftp-hosts nil 620 (defcustom ido-slow-ftp-hosts nil
579 "*List of slow ftp hosts where ido prompting should not be used. 621 "*List of slow ftp hosts where ido prompting should not be used.
580 If an ftp host is on this list, ido automatically switches to the non-ido 622 If an ftp host is on this list, ido automatically switches to the non-ido
581 equivalent function, e.g. find-file rather than ido-find-file." 623 equivalent function, e.g. `find-file' rather than `ido-find-file'."
582 :type '(repeat string) 624 :type '(repeat string)
583 :group 'ido) 625 :group 'ido)
584 626
585 (defcustom ido-slow-ftp-host-regexps nil 627 (defcustom ido-slow-ftp-host-regexps nil
586 "*List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')." 628 "*List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')."
636 `ido-reread-directory' command (C-l) in the minibuffer. 678 `ido-reread-directory' command (C-l) in the minibuffer.
637 See also `ido-dir-file-cache' and `ido-save-directory-list-file'." 679 See also `ido-dir-file-cache' and `ido-save-directory-list-file'."
638 :type 'integer 680 :type 'integer
639 :group 'ido) 681 :group 'ido)
640 682
683 (defcustom ido-max-directory-size 30000
684 "*Maximum size (in bytes) for directories to use ido completion.
685 If you enter a directory with a size larger than this size, ido will
686 not provide the normal completion. To show the completions, use C-a."
687 :type '(choice (const :tag "No limit" nil)
688 (integer :tag "Size in bytes" 30000))
689 :group 'ido)
690
641 (defcustom ido-rotate-file-list-default nil 691 (defcustom ido-rotate-file-list-default nil
642 "*Non-nil means that `ido' will always rotate file list to get default in front." 692 "*Non-nil means that `ido' will always rotate file list to get default in front."
643 :type 'boolean 693 :type 'boolean
644 :group 'ido) 694 :group 'ido)
645 695
646 (defcustom ido-enter-single-matching-directory 'slash 696 (defcustom ido-enter-matching-directory 'only
647 "*Automatically enter sub-directory if it is the only matching item, if non-nil. 697 "*Additional methods to enter sub-directory of first/only matching item.
648 If value is 'slash, only enter if typing final slash, else do it always." 698 If value is 'first, enter first matching sub-directory when typing a slash.
699 If value is 'only, typing a slash only enters the sub-directory if it is
700 the only matching item.
701 If value is t, automatically enter a sub-directory when it is the only
702 matching item, even without typing a slash."
649 :type '(choice (const :tag "Never" nil) 703 :type '(choice (const :tag "Never" nil)
650 (const :tag "When typing /" slash) 704 (const :tag "Slash enters first directory" first)
651 (other :tag "Always" t)) 705 (const :tag "Slash enters first and only directory" only)
706 (other :tag "Always enter unique directory" t))
652 :group 'ido) 707 :group 'ido)
653 708
654 (defcustom ido-create-new-buffer 'prompt 709 (defcustom ido-create-new-buffer 'prompt
655 "*Specify whether a new buffer is created if no buffer matches substring. 710 "*Specify whether a new buffer is created if no buffer matches substring.
656 Choices are 'always to create new buffers unconditionally, 'prompt to 711 Choices are 'always to create new buffers unconditionally, 'prompt to
658 :type '(choice (const always) 713 :type '(choice (const always)
659 (const prompt) 714 (const prompt)
660 (const never)) 715 (const never))
661 :group 'ido) 716 :group 'ido)
662 717
663 (defcustom ido-define-mode-map-hook nil 718 (defcustom ido-setup-hook nil
664 "*Hook to define keys in `ido-mode-map' for extra keybindings." 719 "*Hook run after the ido variables and keymap have been setup.
720 The dynamic variable `ido-cur-item' contains the current type of item that
721 is read by ido, possible values are file, dir, buffer, and list.
722 Additional keys can be defined in `ido-completion-map'."
665 :type 'hook 723 :type 'hook
666 :group 'ido) 724 :group 'ido)
667 725
668 (defcustom ido-separator nil 726 (defcustom ido-separator nil
669 "*String used by ido to separate the alternatives in the minibuffer. 727 "*String used by ido to separate the alternatives in the minibuffer.
670 Obsolete. Set 3rd element of `ido-decorations' instead." 728 Obsolete. Set 3rd element of `ido-decorations' instead."
671 :type '(choice string (const nil)) 729 :type '(choice string (const nil))
672 :group 'ido) 730 :group 'ido)
673 731
674 (defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]") 732 (defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]")
675 "*List of strings used by ido to display the alternatives in the minibuffer. 733 "*List of strings used by ido to display the alternatives in the minibuffer.
676 There are 8 elements in this list, each is a pair of strings: 734 There are 10 elements in this list:
677 1st and 2nd elements are used as brackets around the prospect list, 735 1st and 2nd elements are used as brackets around the prospect list,
678 3rd element is the separator between prospects (ignored if ido-separator is set), 736 3rd element is the separator between prospects (ignored if ido-separator is set),
679 4th element is the string inserted at the end of a truncated list of prospects, 737 4th element is the string inserted at the end of a truncated list of prospects,
680 5th and 6th elements are used as brackets around the common match string which 738 5th and 6th elements are used as brackets around the common match string which
681 can be completed using TAB, 739 can be completed using TAB,
682 7th element is the string displayed when there are a no matches, and 740 7th element is the string displayed when there are no matches, and
683 8th element displayed if there is a single match (and faces are not used)." 741 8th element is displayed if there is a single match (and faces are not used),
742 9th element is displayed when the current directory is non-readable,
743 10th element is displayed when directory exceeds `ido-max-directory-size'."
684 :type '(repeat string) 744 :type '(repeat string)
685 :group 'ido) 745 :group 'ido)
686 746
687 (defcustom ido-use-faces t 747 (defcustom ido-use-faces t
688 "*Non-nil means use ido faces to highlighting first match, only match and 748 "*Non-nil means use ido faces to highlighting first match, only match and
689 subdirs in the alternatives." 749 subdirs in the alternatives."
690 :type 'boolean 750 :type 'boolean
691 :group 'ido) 751 :group 'ido)
692 752
693 (defface ido-first-match-face '((t (:bold t))) 753 (defface ido-first-match '((t (:bold t)))
694 "*Font used by ido for highlighting first match." 754 "*Font used by ido for highlighting first match."
695 :group 'ido) 755 :group 'ido)
696 756
697 (defface ido-only-match-face '((((class color)) 757 (defface ido-only-match '((((class color))
698 (:foreground "ForestGreen")) 758 (:foreground "ForestGreen"))
699 (t (:italic t))) 759 (t (:italic t)))
700 "*Font used by ido for highlighting only match." 760 "*Font used by ido for highlighting only match."
701 :group 'ido) 761 :group 'ido)
702 762
703 (defface ido-subdir-face '((((class color)) 763 (defface ido-subdir '((((min-colors 88) (class color))
764 (:foreground "red1"))
765 (((class color))
704 (:foreground "red")) 766 (:foreground "red"))
705 (t (:underline t))) 767 (t (:underline t)))
706 "*Font used by ido for highlighting subdirs in the alternatives." 768 "*Font used by ido for highlighting subdirs in the alternatives."
707 :group 'ido) 769 :group 'ido)
708 770
709 (defface ido-indicator-face '((((class color)) 771 (defface ido-indicator '((((min-colors 88) (class color))
772 (:foreground "yellow1"
773 :background "red1"
774 :width condensed))
775 (((class color))
710 (:foreground "yellow" 776 (:foreground "yellow"
711 :background "red" 777 :background "red"
712 :width condensed)) 778 :width condensed))
713 (t (:inverse-video t))) 779 (t (:inverse-video t)))
714 "*Font used by ido for highlighting its indicators." 780 "*Font used by ido for highlighting its indicators."
781 :group 'ido)
782
783 (defface ido-incomplete-regexp
784 '((t
785 (:inherit font-lock-warning-face)))
786 "Ido face for indicating incomplete regexps."
715 :group 'ido) 787 :group 'ido)
716 788
717 (defcustom ido-make-file-list-hook nil 789 (defcustom ido-make-file-list-hook nil
718 "*List of functions to run when the list of matching files is created. 790 "*List of functions to run when the list of matching files is created.
719 Each function on the list may modify the dynamically bound variable 791 Each function on the list may modify the dynamically bound variable
806 :group 'ido) 878 :group 'ido)
807 879
808 (defcustom ido-read-file-name-as-directory-commands '() 880 (defcustom ido-read-file-name-as-directory-commands '()
809 "List of commands which uses read-file-name to read a directory name. 881 "List of commands which uses read-file-name to read a directory name.
810 When `ido-everywhere' is non-nil, the commands in this list will read 882 When `ido-everywhere' is non-nil, the commands in this list will read
811 the directory using ido-read-directory-name." 883 the directory using `ido-read-directory-name'."
812 :type '(repeat symbol) 884 :type '(repeat symbol)
813 :group 'ido) 885 :group 'ido)
814 886
815 (defcustom ido-read-file-name-non-ido '() 887 (defcustom ido-read-file-name-non-ido '()
816 "List of commands which shall not read file names the ido way. 888 "List of commands which shall not read file names the ido way.
817 When `ido-everywhere' is non-nil, the commands in this list will read 889 When `ido-everywhere' is non-nil, the commands in this list will read
818 the file name using normal read-file-name style." 890 the file name using normal `read-file-name' style."
819 :type '(repeat symbol) 891 :type '(repeat symbol)
820 :group 'ido) 892 :group 'ido)
821 893
894 (defcustom ido-before-fallback-functions '()
895 "List of functions to call before calling a fallback command.
896 The fallback command is passed as an argument to the functions."
897 :type 'hook
898 :group 'ido)
899
822 ;;; Internal Variables 900 ;;; Internal Variables
823 901
824 ;; Persistent variables 902 ;; Persistent variables
825 903
826 (defvar ido-mode-map nil 904 (defvar ido-completion-map nil
827 "Keymap for `ido-find-file' and `ido-switch-buffer'.") 905 "Currently active keymap for ido commands.")
906
907 (defvar ido-common-completion-map nil
908 "Keymap for all ido commands.")
909
910 (defvar ido-file-completion-map nil
911 "Keymap for ido file commands.")
912
913 (defvar ido-file-dir-completion-map nil
914 "Keymap for ido file and directory commands.")
915
916 (defvar ido-buffer-completion-map nil
917 "Keymap for ido buffer commands.")
828 918
829 (defvar ido-file-history nil 919 (defvar ido-file-history nil
830 "History of files selected using `ido-find-file'.") 920 "History of files selected using `ido-find-file'.")
831 921
832 (defvar ido-buffer-history nil 922 (defvar ido-buffer-history nil
837 See `ido-enable-last-directory-history' for details.") 927 See `ido-enable-last-directory-history' for details.")
838 928
839 (defvar ido-work-directory-list nil 929 (defvar ido-work-directory-list nil
840 "List of actual working directory names. 930 "List of actual working directory names.
841 The current directory is inserted at the front of this list whenever a 931 The current directory is inserted at the front of this list whenever a
842 file is opened with ido-find-file and family.") 932 file is opened with `ido-find-file' and family.")
843 933
844 (defvar ido-work-file-list nil 934 (defvar ido-work-file-list nil
845 "List of actual work file names. 935 "List of actual work file names.
846 Opening a file with `ido-find-file' and similar functions 936 Opening a file with `ido-find-file' and similar functions
847 inserts the current file name (relative to its containing directory) 937 inserts the current file name (relative to its containing directory)
851 "List of `file-name-all-completions' results. 941 "List of `file-name-all-completions' results.
852 Each element in the list is of the form (DIR (MTIME) FILE...).") 942 Each element in the list is of the form (DIR (MTIME) FILE...).")
853 943
854 (defvar ido-ignore-item-temp-list nil 944 (defvar ido-ignore-item-temp-list nil
855 "List of items to ignore in current ido invocation. 945 "List of items to ignore in current ido invocation.
856 Intended to be let-bound by functions which calls ido repeatedly. 946 Intended to be let-bound by functions which call ido repeatedly.
857 Should never be set permanently.") 947 Should never be set permanently.")
858 948
859 ;; Temporary storage 949 ;; Temporary storage
860 950
861 (defvar ido-eoinput 1 951 (defvar ido-eoinput 1
876 "Stores the users string as it is typed in.") 966 "Stores the users string as it is typed in.")
877 967
878 (defvar ido-text-init nil 968 (defvar ido-text-init nil
879 "The initial string for the users string it is typed in.") 969 "The initial string for the users string it is typed in.")
880 970
971 (defvar ido-input-stack nil
972 "Stores the users strings when user hits M-b/M-f.")
973
881 (defvar ido-matches nil 974 (defvar ido-matches nil
882 "List of files currently matching `ido-text'.") 975 "List of files currently matching `ido-text'.")
883 976
884 (defvar ido-report-no-match t 977 (defvar ido-report-no-match t
885 "Report [No Match] when no completions matches ido-text.") 978 "Report [No Match] when no completions matches ido-text.")
888 "Flag to monitor how `ido-find-file' exits. 981 "Flag to monitor how `ido-find-file' exits.
889 If equal to `takeprompt', we use the prompt as the file name to be 982 If equal to `takeprompt', we use the prompt as the file name to be
890 selected.") 983 selected.")
891 984
892 (defvar ido-current-directory nil 985 (defvar ido-current-directory nil
893 "Current directory for ido-find-file.") 986 "Current directory for `ido-find-file'.")
894 987
895 (defvar ido-auto-merge-timer nil 988 (defvar ido-auto-merge-timer nil
896 "Delay timer for auto merge.") 989 "Delay timer for auto merge.")
897 990
898 (defvar ido-use-mycompletion-depth 0 991 (defvar ido-use-mycompletion-depth 0
899 "Non-nil means use `ido' completion feedback. 992 "Non-nil means use `ido' completion feedback.
900 Is set by ido functions to the current minibuffer-depth, so that 993 Is set by ido functions to the current minibuffer-depth, so that
901 it doesn't interfere with other minibuffer usage.") 994 it doesn't interfere with other minibuffer usage.")
902 995
996 (defvar ido-incomplete-regexp nil
997 "Non-nil if an incomplete regexp is entered.")
903 998
904 ;;; Variables with dynamic bindings. 999 ;;; Variables with dynamic bindings.
905 ;;; Declared here to keep the byte compiler quiet. 1000 ;;; Declared here to keep the byte compiler quiet.
906 1001
907 ;; Stores the current ido item type ('file, 'dir or 'buffer). 1002 ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list).
908 (defvar ido-cur-item) 1003 (defvar ido-cur-item)
909 1004
910 ;; Stores the current list of items that will be searched through. 1005 ;; Stores the current list of items that will be searched through.
911 ;; The list is ordered, so that the most interesting item comes first, 1006 ;; The list is ordered, so that the most interesting item comes first,
912 ;; although by default, the files visible in the current frame are put 1007 ;; although by default, the files visible in the current frame are put
913 ;; at the end of the list. Created by `ido-make-item-list'. 1008 ;; at the end of the list. Created by `ido-make-item-list'.
914 (defvar ido-cur-list) 1009 (defvar ido-cur-list)
915 1010
1011 ;; Stores the choice list for ido-completing-read
1012 (defvar ido-choice-list)
1013
916 ;; Stores the list of items which are ignored when building 1014 ;; Stores the list of items which are ignored when building
917 ;; `ido-cur-list'. It is in no specific order. 1015 ;; `ido-cur-list'. It is in no specific order.
918 (defvar ido-ignored-list) 1016 (defvar ido-ignored-list)
919 1017
1018 ;; Remember if current directory is non-readable (so we cannot do completion).
1019 (defvar ido-directory-nonreadable)
1020
1021 ;; Remember if current directory is 'huge' (so we don't want to do completion).
1022 (defvar ido-directory-too-big)
1023
920 ;; Keep current item list if non-nil. 1024 ;; Keep current item list if non-nil.
921 (defvar ido-keep-item-list) 1025 (defvar ido-keep-item-list)
922 1026
923 ;; Process ido-ignore-* lists. 1027 ;; Process ido-ignore-* lists.
924 (defvar ido-process-ignore-lists) 1028 (defvar ido-process-ignore-lists)
952 1056
953 ;; Saved state prior to last work directory merge. 1057 ;; Saved state prior to last work directory merge.
954 ;; Value is a list (ido-text dir cur-list ignored-list matches). 1058 ;; Value is a list (ido-text dir cur-list ignored-list matches).
955 (defvar ido-pre-merge-state) 1059 (defvar ido-pre-merge-state)
956 1060
957 ;; Original value of vc-master-templates for use in ido-toggle-vc. 1061 ;; Original value of vc-handled-backends for use in ido-toggle-vc.
958 (defvar ido-saved-vc-mt) 1062 (defvar ido-saved-vc-hb)
959 1063
960 ;; Stores temporary state of literal find file. 1064 ;; Stores temporary state of literal find file.
961 (defvar ido-find-literal) 1065 (defvar ido-find-literal)
962 1066
1067 ;; Set to 'ignore to inhibit switching between find-file/switch-buffer.
1068 (defvar ido-context-switch-command)
963 1069
964 ;;; FUNCTIONS 1070 ;;; FUNCTIONS
965 1071
966 (defun ido-active (&optional merge) 1072 (defun ido-active (&optional merge)
967 (if merge 1073 (if merge
991 (kill-buffer b) 1097 (kill-buffer b)
992 (pop-to-buffer b t t) 1098 (pop-to-buffer b t t)
993 (setq truncate-lines t))))) 1099 (setq truncate-lines t)))))
994 1100
995 (defun ido-is-tramp-root (&optional dir) 1101 (defun ido-is-tramp-root (&optional dir)
996 (setq dir (or dir ido-current-directory))
997 (and ido-enable-tramp-completion 1102 (and ido-enable-tramp-completion
998 (string-match "\\`/[^/][^/]+:\\([^/:@]+@\\)?\\'" dir))) 1103 (string-match "\\`/[^/]+[@:]\\'"
1104 (or dir ido-current-directory))))
999 1105
1000 (defun ido-is-root-directory (&optional dir) 1106 (defun ido-is-root-directory (&optional dir)
1001 (setq dir (or dir ido-current-directory)) 1107 (setq dir (or dir ido-current-directory))
1002 (or 1108 (or
1003 (string-equal "/" dir) 1109 (string-equal "/" dir)
1043 (< (- (ido-time-stamp) time) ido-cache-ftp-work-directory-time)))) 1149 (< (- (ido-time-stamp) time) ido-cache-ftp-work-directory-time))))
1044 1150
1045 (defun ido-may-cache-directory (&optional dir) 1151 (defun ido-may-cache-directory (&optional dir)
1046 (setq dir (or dir ido-current-directory)) 1152 (setq dir (or dir ido-current-directory))
1047 (cond 1153 (cond
1154 ((ido-directory-too-big-p dir)
1155 nil)
1048 ((and (ido-is-root-directory dir) 1156 ((and (ido-is-root-directory dir)
1049 (or ido-enable-tramp-completion 1157 (or ido-enable-tramp-completion
1050 (memq system-type '(windows-nt ms-dos)))) 1158 (memq system-type '(windows-nt ms-dos))))
1051 nil) 1159 nil)
1052 ((not (ido-is-ftp-directory dir)) 1160 ((not (ido-is-ftp-directory dir))
1206 (setq e (car l) l (cdr l)) 1314 (setq e (car l) l (cdr l))
1207 (if (listp e) 1315 (if (listp e)
1208 (while e 1316 (while e
1209 (setq d (car e) e (cdr e)) 1317 (setq d (car e) e (cdr e))
1210 (if (not (consp d)) 1318 (if (not (consp d))
1211 (set-text-properties 0 (length d) nil d)))))) 1319 (set-text-properties 0 (length d) nil d)))))))
1212 )
1213 1320
1214 1321
1215 (defun ido-kill-emacs-hook () 1322 (defun ido-kill-emacs-hook ()
1216 ;; ido kill emacs hook 1323 ;; ido kill emacs hook
1217 (ido-save-history)) 1324 (ido-save-history))
1218 1325
1219 (defvar ido-minor-mode-map-entry nil) 1326 (defvar ido-minor-mode-map-entry nil)
1220 1327
1221 ;;;###autoload 1328 ;;;###autoload
1222 (defun ido-mode (&optional arg nobind) 1329 (defun ido-mode (&optional arg)
1223 "Toggle ido speed-ups on or off. 1330 "Toggle ido speed-ups on or off.
1224 With ARG, turn ido speed-up on if arg is positive, off otherwise. 1331 With ARG, turn ido speed-up on if arg is positive, off otherwise.
1225 If second argument NOBIND is non-nil, no keys are rebound; otherwise, 1332 Turning on ido-mode will remap (via a minor-mode keymap) the default
1226 turning on ido-mode will modify the default keybindings for the 1333 keybindings for the `find-file' and `switch-to-buffer' families of
1227 find-file and switch-to-buffer families of commands to the ido 1334 commands to the ido versions of these functions.
1228 versions of these functions. 1335 However, if ARG arg equals 'files, remap only commands for files, or
1229 However, if second arg equals 'files, bind only for files, or if it 1336 if it equals 'buffers, remap only commands for buffer switching.
1230 equals 'buffers, bind only for buffers.
1231 This function also adds a hook to the minibuffer." 1337 This function also adds a hook to the minibuffer."
1232 (interactive "P") 1338 (interactive "P")
1233 (setq ido-mode 1339 (setq ido-mode
1234 (cond 1340 (cond
1235 ((null arg) (if ido-mode nil 'both)) 1341 ((null arg) (if ido-mode nil 'both))
1239 ((memq arg '(file buffer both)) arg) 1345 ((memq arg '(file buffer both)) arg)
1240 ((> (prefix-numeric-value arg) 0) 'both) 1346 ((> (prefix-numeric-value arg) 0) 'both)
1241 (t nil))) 1347 (t nil)))
1242 1348
1243 (ido-everywhere (if ido-everywhere 1 -1)) 1349 (ido-everywhere (if ido-everywhere 1 -1))
1350 (when ido-mode
1351 (ido-init-completion-maps))
1244 1352
1245 (when ido-mode 1353 (when ido-mode
1246 (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup) 1354 (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup)
1247 (add-hook 'choose-completion-string-functions 'ido-choose-completion-string) 1355 (add-hook 'choose-completion-string-functions 'ido-choose-completion-string)
1248 (ido-load-history) 1356 (ido-load-history)
1249 1357
1250 (add-hook 'kill-emacs-hook 'ido-kill-emacs-hook) 1358 (add-hook 'kill-emacs-hook 'ido-kill-emacs-hook)
1251 1359
1252 (unless ido-minor-mode-map-entry 1360 (let ((map (make-sparse-keymap)))
1253 (setq ido-minor-mode-map-entry (cons 'ido-mode (make-sparse-keymap)))
1254 (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry))
1255
1256 (let ((map (cdr ido-minor-mode-map-entry)))
1257 (when (memq ido-mode '(file both)) 1361 (when (memq ido-mode '(file both))
1258 (define-key map [remap find-file] 'ido-find-file) 1362 (define-key map [remap find-file] 'ido-find-file)
1259 (define-key map [remap find-file-read-only] 'ido-find-file-read-only) 1363 (define-key map [remap find-file-read-only] 'ido-find-file-read-only)
1260 (define-key map [remap find-alternate-file] 'ido-find-alternate-file) 1364 (define-key map [remap find-alternate-file] 'ido-find-alternate-file)
1261 (define-key map [remap write-file] 'ido-write-file) 1365 (define-key map [remap write-file] 'ido-write-file)
1271 (define-key map [remap switch-to-buffer] 'ido-switch-buffer) 1375 (define-key map [remap switch-to-buffer] 'ido-switch-buffer)
1272 (define-key map [remap switch-to-buffer-other-window] 'ido-switch-buffer-other-window) 1376 (define-key map [remap switch-to-buffer-other-window] 'ido-switch-buffer-other-window)
1273 (define-key map [remap switch-to-buffer-other-frame] 'ido-switch-buffer-other-frame) 1377 (define-key map [remap switch-to-buffer-other-frame] 'ido-switch-buffer-other-frame)
1274 (define-key map [remap insert-buffer] 'ido-insert-buffer) 1378 (define-key map [remap insert-buffer] 'ido-insert-buffer)
1275 (define-key map [remap kill-buffer] 'ido-kill-buffer) 1379 (define-key map [remap kill-buffer] 'ido-kill-buffer)
1276 (define-key map [remap display-buffer] 'ido-display-buffer))))) 1380 (define-key map [remap display-buffer] 'ido-display-buffer))
1381
1382 (if ido-minor-mode-map-entry
1383 (setcdr ido-minor-mode-map-entry map)
1384 (setq ido-minor-mode-map-entry (cons 'ido-mode map))
1385 (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry)))))
1386
1277 1387
1278 (defun ido-everywhere (arg) 1388 (defun ido-everywhere (arg)
1279 "Enable ido everywhere file and directory names are read." 1389 "Toggle using ido speed-ups everywhere file and directory names are read.
1390 With ARG, turn ido speed-up on if arg is positive, off otherwise."
1280 (interactive "P") 1391 (interactive "P")
1281 (setq ido-everywhere (if arg 1392 (setq ido-everywhere (if arg
1282 (> (prefix-numeric-value arg) 0) 1393 (> (prefix-numeric-value arg) 0)
1283 (not ido-everywhere))) 1394 (not ido-everywhere)))
1284 (setq read-file-name-function 1395 (when (get 'ido-everywhere 'file)
1285 (and ido-everywhere (memq ido-mode '(both file)) 1396 (setq read-file-name-function (car (get 'ido-everywhere 'file)))
1286 'ido-read-file-name)) 1397 (put 'ido-everywhere 'file nil))
1287 (setq read-buffer-function 1398 (when (get 'ido-everywhere 'buffer)
1288 (and ido-everywhere (memq ido-mode '(both buffer)) 1399 (setq read-buffer-function (car (get 'ido-everywhere 'buffer)))
1289 'ido-read-buffer))) 1400 (put 'ido-everywhere 'buffer nil))
1401 (when ido-everywhere
1402 (when (memq ido-mode '(both file))
1403 (put 'ido-everywhere 'file (cons read-file-name-function nil))
1404 (setq read-file-name-function 'ido-read-file-name))
1405 (when (memq ido-mode '(both buffer))
1406 (put 'ido-everywhere 'buffer (cons read-buffer-function nil))
1407 (setq read-buffer-function 'ido-read-buffer))))
1290 1408
1291 1409
1292 ;;; IDO KEYMAP 1410 ;;; IDO KEYMAP
1293 (defun ido-define-mode-map () 1411 (defun ido-init-completion-maps ()
1294 "Set up the keymap for `ido'." 1412 "Set up the completion keymaps used by `ido'."
1295 (let (map) 1413
1296 ;; generated every time so that it can inherit new functions. 1414 ;; Common map
1297 1415 (let ((map (make-sparse-keymap)))
1298 (setq map (copy-keymap minibuffer-local-map))
1299 (define-key map "\C-a" 'ido-toggle-ignore) 1416 (define-key map "\C-a" 'ido-toggle-ignore)
1300 (define-key map "\C-c" 'ido-toggle-case) 1417 (define-key map "\C-c" 'ido-toggle-case)
1301 (define-key map "\C-e" 'ido-edit-input) 1418 (define-key map "\C-e" 'ido-edit-input)
1302 (define-key map "\t" 'ido-complete) 1419 (define-key map "\t" 'ido-complete)
1303 (define-key map " " 'ido-complete-space) 1420 (define-key map " " 'ido-complete-space)
1306 (define-key map "\C-p" 'ido-toggle-prefix) 1423 (define-key map "\C-p" 'ido-toggle-prefix)
1307 (define-key map "\C-r" 'ido-prev-match) 1424 (define-key map "\C-r" 'ido-prev-match)
1308 (define-key map "\C-s" 'ido-next-match) 1425 (define-key map "\C-s" 'ido-next-match)
1309 (define-key map "\C-t" 'ido-toggle-regexp) 1426 (define-key map "\C-t" 'ido-toggle-regexp)
1310 (define-key map "\C-z" 'ido-undo-merge-work-directory) 1427 (define-key map "\C-z" 'ido-undo-merge-work-directory)
1311 (define-key map [(control ? )] 'ido-restrict-to-matches) 1428 (define-key map [(control ?\s)] 'ido-restrict-to-matches)
1312 (define-key map [(control ?@)] 'ido-restrict-to-matches) 1429 (define-key map [(control ?@)] 'ido-restrict-to-matches)
1313 (define-key map [right] 'ido-next-match) 1430 (define-key map [right] 'ido-next-match)
1314 (define-key map [left] 'ido-prev-match) 1431 (define-key map [left] 'ido-prev-match)
1315 (define-key map "?" 'ido-completion-help) 1432 (define-key map "?" 'ido-completion-help)
1316 1433 ;; Magic commands.
1317 (when (memq ido-cur-item '(file dir)) 1434 (define-key map "\C-b" 'ido-magic-backward-char)
1318 (define-key map "\C-b" 'ido-enter-switch-buffer) 1435 (define-key map "\C-f" 'ido-magic-forward-char)
1319 (define-key map "\C-d" 'ido-enter-dired) 1436 (define-key map "\C-d" 'ido-magic-delete-char)
1320 (define-key map "\C-f" 'ido-fallback-command) 1437 (set-keymap-parent map minibuffer-local-map)
1321 (define-key map [down] 'ido-next-match-dir) 1438 (setq ido-common-completion-map map))
1322 (define-key map [up] 'ido-prev-match-dir) 1439
1323 (define-key map [(meta up)] 'ido-prev-work-directory) 1440 ;; File and directory map
1324 (define-key map [(meta down)] 'ido-next-work-directory) 1441 (let ((map (make-sparse-keymap)))
1325 (define-key map [backspace] 'ido-delete-backward-updir) 1442 (define-key map "\C-x\C-b" 'ido-enter-switch-buffer)
1326 (define-key map "\d" 'ido-delete-backward-updir) 1443 (define-key map "\C-x\C-f" 'ido-fallback-command)
1327 (define-key map [(meta backspace)] 'ido-delete-backward-word-updir) 1444 (define-key map "\C-x\C-d" 'ido-enter-dired)
1328 (define-key map [(control backspace)] 'ido-up-directory) 1445 (define-key map [down] 'ido-next-match-dir)
1329 (define-key map [(meta ?b)] 'ido-next-work-file) 1446 (define-key map [up] 'ido-prev-match-dir)
1330 (define-key map [(meta ?d)] 'ido-wide-find-dir) 1447 (define-key map [(meta up)] 'ido-prev-work-directory)
1331 (define-key map [(meta ?f)] 'ido-wide-find-file) 1448 (define-key map [(meta down)] 'ido-next-work-directory)
1332 (define-key map [(meta ?k)] 'ido-forget-work-directory) 1449 (define-key map [backspace] 'ido-delete-backward-updir)
1333 (define-key map [(meta ?m)] 'ido-make-directory) 1450 (define-key map "\d" 'ido-delete-backward-updir)
1334 (define-key map [(meta ?n)] 'ido-next-work-directory) 1451 (define-key map [(meta backspace)] 'ido-delete-backward-word-updir)
1335 (define-key map [(meta ?o)] 'ido-prev-work-file) 1452 (define-key map [(control backspace)] 'ido-up-directory)
1336 (define-key map [(meta ?p)] 'ido-prev-work-directory) 1453 (define-key map "\C-l" 'ido-reread-directory)
1337 (define-key map [(meta ?s)] 'ido-merge-work-directories) 1454 (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
1338 ) 1455 (define-key map [(meta ?b)] 'ido-push-dir)
1339 1456 (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
1340 (when (eq ido-cur-item 'file) 1457 (define-key map [(meta ?k)] 'ido-forget-work-directory)
1341 (define-key map "\C-k" 'ido-delete-file-at-head) 1458 (define-key map [(meta ?m)] 'ido-make-directory)
1342 (define-key map "\C-o" 'ido-copy-current-word) 1459 (define-key map [(meta ?n)] 'ido-next-work-directory)
1343 (define-key map "\C-l" 'ido-reread-directory) 1460 (define-key map [(meta ?o)] 'ido-prev-work-file)
1344 (define-key map "\C-w" 'ido-copy-current-file-name) 1461 (define-key map [(meta control ?o)] 'ido-next-work-file)
1345 (define-key map [(meta ?l)] 'ido-toggle-literal) 1462 (define-key map [(meta ?p)] 'ido-prev-work-directory)
1346 (define-key map "\C-v" 'ido-toggle-vc) 1463 (define-key map [(meta ?s)] 'ido-merge-work-directories)
1347 ) 1464 (set-keymap-parent map ido-common-completion-map)
1348 1465 (setq ido-file-dir-completion-map map))
1349 (when (eq ido-cur-item 'buffer) 1466
1350 (define-key map "\C-b" 'ido-fallback-command) 1467 ;; File only map
1351 (define-key map "\C-f" 'ido-enter-find-file) 1468 (let ((map (make-sparse-keymap)))
1352 (define-key map "\C-k" 'ido-kill-buffer-at-head) 1469 (define-key map "\C-k" 'ido-delete-file-at-head)
1353 ) 1470 (define-key map "\C-o" 'ido-copy-current-word)
1354 1471 (define-key map "\C-w" 'ido-copy-current-file-name)
1355 (when (if (boundp 'viper-mode) viper-mode) 1472 (define-key map [(meta ?l)] 'ido-toggle-literal)
1356 (define-key map [remap viper-intercept-ESC-key] 'ignore) 1473 (define-key map "\C-v" 'ido-toggle-vc)
1357 (when (memq ido-cur-item '(file dir)) 1474 (set-keymap-parent map ido-file-dir-completion-map)
1475 (setq ido-file-completion-map map))
1476
1477 ;; Buffer map
1478 (let ((map (make-sparse-keymap)))
1479 (define-key map "\C-x\C-f" 'ido-enter-find-file)
1480 (define-key map "\C-x\C-b" 'ido-fallback-command)
1481 (define-key map "\C-k" 'ido-kill-buffer-at-head)
1482 (set-keymap-parent map ido-common-completion-map)
1483 (setq ido-buffer-completion-map map)))
1484
1485
1486 (defun ido-setup-completion-map ()
1487 "Set up the keymap for `ido'."
1488
1489 ;; generated every time so that it can inherit new functions.
1490 (let ((map (make-sparse-keymap))
1491 (viper-p (if (boundp 'viper-mode) viper-mode)))
1492
1493 (when viper-p
1494 (define-key map [remap viper-intercept-ESC-key] 'ignore))
1495
1496 (cond
1497 ((memq ido-cur-item '(file dir))
1498 (when ido-context-switch-command
1499 (define-key map "\C-x\C-b" ido-context-switch-command)
1500 (define-key map "\C-x\C-d" 'ignore))
1501 (when viper-p
1358 (define-key map [remap viper-backward-char] 'ido-delete-backward-updir) 1502 (define-key map [remap viper-backward-char] 'ido-delete-backward-updir)
1359 (define-key map [remap viper-del-backward-char-in-insert] 'ido-delete-backward-updir) 1503 (define-key map [remap viper-del-backward-char-in-insert] 'ido-delete-backward-updir)
1360 (define-key map [remap viper-delete-backward-word] 'ido-delete-backward-word-updir))) 1504 (define-key map [remap viper-delete-backward-word] 'ido-delete-backward-word-updir))
1361 1505 (set-keymap-parent map
1362 (setq ido-mode-map map) 1506 (if (eq ido-cur-item 'file)
1363 (run-hooks 'ido-define-mode-map-hook))) 1507 ido-file-completion-map
1508 ido-file-dir-completion-map)))
1509
1510 ((eq ido-cur-item 'buffer)
1511 (when ido-context-switch-command
1512 (define-key map "\C-x\C-f" ido-context-switch-command))
1513 (set-keymap-parent map ido-buffer-completion-map))
1514
1515 (t
1516 (set-keymap-parent map ido-common-completion-map)))
1517
1518 (setq ido-completion-map map)))
1364 1519
1365 (defun ido-final-slash (dir &optional fix-it) 1520 (defun ido-final-slash (dir &optional fix-it)
1366 ;; return DIR if DIR has final slash. 1521 ;; return DIR if DIR has final slash.
1367 ;; else if FIX-IT is non-nil, return DIR/ 1522 ;; else if FIX-IT is non-nil, return DIR/
1368 ;; else return nil. 1523 ;; else return nil.
1371 ((string-match "/\\'" dir) dir) 1526 ((string-match "/\\'" dir) dir)
1372 ((ido-is-tramp-root dir) dir) 1527 ((ido-is-tramp-root dir) dir)
1373 (fix-it (concat dir "/")) 1528 (fix-it (concat dir "/"))
1374 (t nil))) 1529 (t nil)))
1375 1530
1531 (defun ido-no-final-slash (s)
1532 ;; Remove optional final slash from string S
1533 (let ((l (1- (length s))))
1534 (if (and (> l 0) (eq (aref s l) ?/))
1535 (substring s 0 l)
1536 s)))
1537
1538 (defun ido-nonreadable-directory-p (dir)
1539 ;; Return t if dir is a directory, but not readable
1540 ;; Do not check for non-readable directories via tramp, as this causes a premature
1541 ;; connect on incomplete tramp paths (after entring just method:).
1542 (let ((ido-enable-tramp-completion nil))
1543 (and (ido-final-slash dir)
1544 (file-directory-p dir)
1545 (not (file-readable-p dir)))))
1546
1547 (defun ido-directory-too-big-p (dir)
1548 ;; Return t if dir is a directory, but too big to show
1549 ;; Do not check for non-readable directories via tramp, as this causes a premature
1550 ;; connect on incomplete tramp paths (after entring just method:).
1551 (let ((ido-enable-tramp-completion nil))
1552 (and (numberp ido-max-directory-size)
1553 (ido-final-slash dir)
1554 (file-directory-p dir)
1555 (> (nth 7 (file-attributes dir)) ido-max-directory-size))))
1556
1376 (defun ido-set-current-directory (dir &optional subdir no-merge) 1557 (defun ido-set-current-directory (dir &optional subdir no-merge)
1377 ;; Set ido's current directory to DIR or DIR/SUBDIR 1558 ;; Set ido's current directory to DIR or DIR/SUBDIR
1378 (setq dir (ido-final-slash dir t)) 1559 (unless (and ido-enable-tramp-completion
1560 (string-match "\\`/[^/]*@\\'" dir))
1561 (setq dir (ido-final-slash dir t)))
1379 (setq ido-use-merged-list nil 1562 (setq ido-use-merged-list nil
1380 ido-try-merged-list (not no-merge)) 1563 ido-try-merged-list (not no-merge))
1381 (if subdir 1564 (when subdir
1382 (setq dir (ido-final-slash (concat dir subdir) t))) 1565 (setq dir (concat dir subdir))
1566 (unless (and ido-enable-tramp-completion
1567 (string-match "\\`/[^/]*@\\'" dir))
1568 (setq dir (ido-final-slash dir t))))
1383 (if (equal dir ido-current-directory) 1569 (if (equal dir ido-current-directory)
1384 nil 1570 nil
1385 (ido-trace "cd" dir) 1571 (ido-trace "cd" dir)
1386 (setq ido-current-directory dir) 1572 (setq ido-current-directory dir)
1387 (if (get-buffer ido-completion-buffer) 1573 (if (get-buffer ido-completion-buffer)
1388 (kill-buffer ido-completion-buffer)) 1574 (kill-buffer ido-completion-buffer))
1575 (setq ido-directory-nonreadable (ido-nonreadable-directory-p dir))
1576 (setq ido-directory-too-big (and (not ido-directory-nonreadable)
1577 (ido-directory-too-big-p dir)))
1389 t)) 1578 t))
1390 1579
1391 (defun ido-set-current-home (&optional dir) 1580 (defun ido-set-current-home (&optional dir)
1392 ;; Set ido's current directory to user's home directory 1581 ;; Set ido's current directory to user's home directory
1393 (ido-set-current-directory (expand-file-name (or dir "~/")))) 1582 (ido-set-current-directory (expand-file-name (or dir "~/"))))
1407 (let ((dirname (abbreviate-file-name ido-current-directory)) 1596 (let ((dirname (abbreviate-file-name ido-current-directory))
1408 (max-width (if (and ido-max-file-prompt-width (floatp ido-max-file-prompt-width)) 1597 (max-width (if (and ido-max-file-prompt-width (floatp ido-max-file-prompt-width))
1409 (floor (* (frame-width) ido-max-file-prompt-width)) 1598 (floor (* (frame-width) ido-max-file-prompt-width))
1410 ido-max-file-prompt-width)) 1599 ido-max-file-prompt-width))
1411 (literal (and (boundp 'ido-find-literal) ido-find-literal "(literal) ")) 1600 (literal (and (boundp 'ido-find-literal) ido-find-literal "(literal) "))
1412 (vc-off (and ido-saved-vc-mt (not vc-master-templates) "[-VC] ")) 1601 (vc-off (and ido-saved-vc-hb (not vc-handled-backends) "[-VC] "))
1413 (prefix nil) 1602 (prefix nil)
1414 (rule ido-rewrite-file-prompt-rules)) 1603 (rule ido-rewrite-file-prompt-rules))
1415 (let ((case-fold-search nil)) 1604 (let ((case-fold-search nil))
1416 (while rule 1605 (while rule
1417 (if (and (consp (car rule)) 1606 (if (and (consp (car rule))
1496 (ido-case-fold ido-case-fold) 1685 (ido-case-fold ido-case-fold)
1497 (ido-enable-prefix ido-enable-prefix) 1686 (ido-enable-prefix ido-enable-prefix)
1498 (ido-enable-regexp ido-enable-regexp) 1687 (ido-enable-regexp ido-enable-regexp)
1499 ) 1688 )
1500 1689
1501 (ido-define-mode-map) 1690 (ido-setup-completion-map)
1502 (setq ido-text-init initial) 1691 (setq ido-text-init initial)
1692 (setq ido-input-stack nil)
1693
1694 (run-hooks 'ido-setup-hook)
1695
1503 (while (not done) 1696 (while (not done)
1504 (ido-trace "\n_LOOP_" ido-text-init) 1697 (ido-trace "\n_LOOP_" ido-text-init)
1505 (setq ido-exit nil) 1698 (setq ido-exit nil)
1506 (setq ido-rescan t) 1699 (setq ido-rescan t)
1507 (setq ido-rotate nil) 1700 (setq ido-rotate nil)
1528 (oign ido-ignored-list) 1721 (oign ido-ignored-list)
1529 (omat ido-matches) 1722 (omat ido-matches)
1530 (l (ido-make-merged-file-list ido-text-init 1723 (l (ido-make-merged-file-list ido-text-init
1531 (eq ido-use-merged-list 'auto) 1724 (eq ido-use-merged-list 'auto)
1532 (eq ido-try-merged-list 'wide)))) 1725 (eq ido-try-merged-list 'wide))))
1726 (ido-trace "merged" l)
1533 (cond 1727 (cond
1534 ((not l) 1728 ((not l)
1535 (if (eq ido-try-merged-list 'wide) 1729 (if (eq ido-try-merged-list 'wide)
1536 (setq ido-pre-merge-state 1730 (setq ido-pre-merge-state
1537 (list "" ido-current-directory olist oign omat) 1731 (list "" ido-current-directory olist oign omat)
1547 ido-keep-item-list t 1741 ido-keep-item-list t
1548 ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil) 1742 ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil)
1549 ido-use-merged-list nil))) 1743 ido-use-merged-list nil)))
1550 ((eq l t) 1744 ((eq l t)
1551 (setq ido-use-merged-list nil)) 1745 (setq ido-use-merged-list nil))
1746 ((eq l 'input-pending-p)
1747 (setq ido-try-merged-list t
1748 ido-use-merged-list nil))
1552 (t 1749 (t
1553 (setq ido-pre-merge-state 1750 (setq ido-pre-merge-state
1554 (list ido-text-init ido-current-directory olist oign omat)) 1751 (list ido-text-init ido-current-directory olist oign omat))
1555 (ido-set-current-directory (car (cdr (car l)))) 1752 (ido-set-current-directory (car (cdr (car l))))
1556 (if (ido-final-slash ido-text-init) 1753 (if (ido-final-slash ido-text-init)
1568 (ido-keep-item-list 1765 (ido-keep-item-list
1569 (setq ido-keep-item-list nil 1766 (setq ido-keep-item-list nil
1570 ido-rescan nil)) 1767 ido-rescan nil))
1571 ((eq ido-cur-item 'file) 1768 ((eq ido-cur-item 'file)
1572 (setq ido-ignored-list nil 1769 (setq ido-ignored-list nil
1573 ido-cur-list (ido-make-file-list ido-default-item))) 1770 ido-cur-list (and (not ido-directory-nonreadable)
1771 (not ido-directory-too-big)
1772 (ido-make-file-list ido-default-item))))
1574 ((eq ido-cur-item 'dir) 1773 ((eq ido-cur-item 'dir)
1575 (setq ido-ignored-list nil 1774 (setq ido-ignored-list nil
1576 ido-cur-list (ido-make-dir-list ido-default-item))) 1775 ido-cur-list (and (not ido-directory-nonreadable)
1776 (not ido-directory-too-big)
1777 (ido-make-dir-list ido-default-item))))
1577 ((eq ido-cur-item 'buffer) 1778 ((eq ido-cur-item 'buffer)
1578 (setq ido-ignored-list nil 1779 (setq ido-ignored-list nil
1579 ido-cur-list (ido-make-buffer-list ido-default-item))) 1780 ido-cur-list (ido-make-buffer-list ido-default-item)))
1781 ((eq ido-cur-item 'list)
1782 (setq ido-ignored-list nil
1783 ido-cur-list (ido-make-choice-list ido-default-item)))
1580 (t nil)) 1784 (t nil))
1581 (setq ido-rotate-temp nil) 1785 (setq ido-rotate-temp nil)
1582 1786
1583 (if ido-process-ignore-lists-inhibit 1787 (if ido-process-ignore-lists-inhibit
1584 (setq ido-process-ignore-lists t 1788 (setq ido-process-ignore-lists t
1586 1790
1587 (ido-set-matches) 1791 (ido-set-matches)
1588 (if (and ido-matches (eq ido-try-merged-list 'auto)) 1792 (if (and ido-matches (eq ido-try-merged-list 'auto))
1589 (setq ido-try-merged-list t)) 1793 (setq ido-try-merged-list t))
1590 (let 1794 (let
1591 ((minibuffer-local-completion-map ido-mode-map) 1795 ((minibuffer-local-completion-map ido-completion-map)
1796 (minibuffer-local-filename-completion-map ido-completion-map)
1592 (max-mini-window-height (or ido-max-window-height 1797 (max-mini-window-height (or ido-max-window-height
1593 (and (boundp 'max-mini-window-height) max-mini-window-height))) 1798 (and (boundp 'max-mini-window-height) max-mini-window-height)))
1594 (ido-completing-read t) 1799 (ido-completing-read t)
1595 (ido-require-match require-match) 1800 (ido-require-match require-match)
1596 (ido-use-mycompletion-depth (1+ (minibuffer-depth))) 1801 (ido-use-mycompletion-depth (1+ (minibuffer-depth)))
1624 ido-exit nil)) 1829 ido-exit nil))
1625 1830
1626 ((memq ido-exit '(edit chdir)) 1831 ((memq ido-exit '(edit chdir))
1627 (cond 1832 (cond
1628 ((memq ido-cur-item '(file dir)) 1833 ((memq ido-cur-item '(file dir))
1629 (let* ((process-environment (cons "HOME=/" process-environment)) ;; cheat read-file-name 1834 (let* ((read-file-name-function nil)
1630 (read-file-name-function nil)
1631 (edit (eq ido-exit 'edit)) 1835 (edit (eq ido-exit 'edit))
1632 (d ido-current-directory) 1836 (d ido-current-directory)
1633 (f ido-text-init) 1837 (f ido-text-init)
1634 (new t)) 1838 (new t))
1635 (setq ido-text-init "") 1839 (setq ido-text-init "")
1636 (while new 1840 (while new
1637 (setq new (if edit 1841 (setq new (if edit
1638 (read-file-name (concat prompt "[EDIT] ") d (concat d f) nil f) 1842 (condition-case nil
1843 (read-file-name (concat prompt "[EDIT] ")
1844 (expand-file-name d)
1845 (concat d f) nil f)
1846 (quit (concat d f)))
1639 f) 1847 f)
1640 d (or (file-name-directory new) "/") 1848 d (or (file-name-directory new) "/")
1641 f (file-name-nondirectory new) 1849 f (file-name-nondirectory new)
1642 edit t) 1850 edit t)
1643 (if (or 1851 (if (or
1652 (progn 1860 (progn
1653 (ido-set-current-directory d nil (eq ido-exit 'chdir)) 1861 (ido-set-current-directory d nil (eq ido-exit 'chdir))
1654 (setq ido-text-init f 1862 (setq ido-text-init f
1655 new nil)))))) 1863 new nil))))))
1656 (t 1864 (t
1657 (setq ido-text-init (read-string (concat prompt "[EDIT] ") ido-final-text)))) 1865 (setq ido-text-init
1866 (condition-case nil
1867 (read-string (concat prompt "[EDIT] ") ido-final-text)
1868 (quit ido-final-text)))))
1869
1658 nil) 1870 nil)
1659 1871
1660 ((eq ido-exit 'keep) 1872 ((eq ido-exit 'keep)
1661 (setq ido-keep-item-list t)) 1873 (setq ido-keep-item-list t))
1662 1874
1663 ((memq ido-exit '(dired fallback findfile findbuffer)) 1875 ((memq ido-exit '(dired fallback find-file switch-to-buffer insert-buffer insert-file))
1664 (setq done t)) 1876 (setq done t))
1665 1877
1666 ((eq ido-exit 'updir) 1878 ((memq ido-exit '(updir push))
1667 ;; cannot go up if already at the root-dir (Unix) or at the 1879 ;; cannot go up if already at the root-dir (Unix) or at the
1668 ;; root-dir of a certain drive (Windows or MS-DOS). 1880 ;; root-dir of a certain drive (Windows or MS-DOS).
1669 (if (ido-is-tramp-root) 1881 (if (ido-is-tramp-root)
1670 (when (string-match "\\`\\(/\\([^/]+[:@]\\)*\\)\\([^/]+\\)[:@]\\'" ido-current-directory) 1882 (when (string-match "\\`\\(/\\([^/]+[:@]\\)*\\)\\([^/]+\\)[:@]\\'" ido-current-directory)
1671 (setq ido-text-init (match-string 3 ido-current-directory)) 1883 (setq ido-text-init (match-string 3 ido-current-directory))
1672 (ido-set-current-directory (match-string 1 ido-current-directory)) 1884 (ido-set-current-directory (match-string 1 ido-current-directory))
1673 (setq ido-set-default-item t)) 1885 (setq ido-set-default-item t))
1674 (unless (ido-is-root-directory) 1886 (unless (ido-is-root-directory)
1887 (when (eq ido-exit 'push)
1888 (setq ido-input-stack (cons (cons ido-cur-item ido-text) ido-input-stack))
1889 (setq ido-cur-item 'dir)
1890 (setq ido-text-init (file-name-nondirectory (substring ido-current-directory 0 -1)))
1891 (ido-trace "push" ido-input-stack))
1675 (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))) 1892 (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1)))
1676 (setq ido-set-default-item t)))) 1893 (setq ido-set-default-item t))))
1677 1894
1895 ((eq ido-exit 'pop)
1896 (ido-trace "pop" ido-input-stack)
1897 (let ((elt (car ido-input-stack)))
1898 (setq ido-input-stack (cdr ido-input-stack))
1899 (ido-set-current-directory (concat ido-current-directory ido-text))
1900 (setq ido-cur-item (car elt))
1901 (setq ido-text-init (cdr elt))))
1902
1903 ((eq ido-exit 'pop-all)
1904 (ido-trace "pop-all" ido-input-stack)
1905 (while ido-input-stack
1906 (let ((elt (car ido-input-stack)))
1907 (setq ido-input-stack (cdr ido-input-stack))
1908 (ido-set-current-directory (concat ido-current-directory ido-text))
1909 (setq ido-cur-item (car elt))
1910 (setq ido-text-init (cdr elt)))))
1911
1678 ;; Handling the require-match must be done in a better way. 1912 ;; Handling the require-match must be done in a better way.
1679 ((and require-match (not (ido-existing-item-p))) 1913 ((and require-match
1914 (not (if ido-directory-too-big
1915 (file-exists-p (concat ido-current-directory ido-final-text))
1916 (ido-existing-item-p))))
1680 (error "must specify valid item")) 1917 (error "must specify valid item"))
1681 1918
1682 (t 1919 (t
1683 (setq ido-selected 1920 (setq ido-selected
1684 (if (or (eq ido-exit 'takeprompt) 1921 (if (or (eq ido-exit 'takeprompt)
1686 ido-final-text 1923 ido-final-text
1687 ;; else take head of list 1924 ;; else take head of list
1688 (ido-name (car ido-matches)))) 1925 (ido-name (car ido-matches))))
1689 1926
1690 (cond 1927 (cond
1691 ((eq item 'buffer) 1928 ((memq item '(buffer list))
1692 (setq done t)) 1929 (setq done t))
1693 1930
1694 ((string-equal "./" ido-selected) 1931 ((string-equal "./" ido-selected)
1695 nil) 1932 nil)
1696 1933
1724 (if x 1961 (if x
1725 (setcdr x ido-selected) 1962 (setcdr x ido-selected)
1726 (setq ido-last-directory-list 1963 (setq ido-last-directory-list
1727 (cons (cons ido-current-directory ido-selected) ido-last-directory-list))))) 1964 (cons (cons ido-current-directory ido-selected) ido-last-directory-list)))))
1728 (ido-set-current-directory ido-current-directory ido-selected) 1965 (ido-set-current-directory ido-current-directory ido-selected)
1729 (setq ido-set-default-item t)) 1966 (if ido-input-stack
1967 (while ido-input-stack
1968 (let ((elt (car ido-input-stack)))
1969 (if (setq ido-input-stack (cdr ido-input-stack))
1970 (ido-set-current-directory ido-current-directory (cdr elt))
1971 (setq ido-text-init (cdr elt)))
1972 (setq ido-cur-item (car elt))))
1973 (setq ido-set-default-item t)))
1730 1974
1731 (t 1975 (t
1732 (setq done t)))))) 1976 (setq done t))))))
1733 ido-selected)) 1977 ido-selected))
1734 1978
1738 (setq ido-text-init ido-text) 1982 (setq ido-text-init ido-text)
1739 (setq ido-exit 'edit) 1983 (setq ido-exit 'edit)
1740 (exit-minibuffer)) 1984 (exit-minibuffer))
1741 1985
1742 ;;; MAIN FUNCTIONS 1986 ;;; MAIN FUNCTIONS
1743 (defun ido-buffer-internal (method &optional fallback prompt default initial) 1987 (defun ido-buffer-internal (method &optional fallback prompt default initial switch-cmd)
1744 ;; Internal function for ido-switch-buffer and friends 1988 ;; Internal function for ido-switch-buffer and friends
1745 (if (not ido-mode) 1989 (if (not ido-mode)
1746 (call-interactively (or fallback 'switch-to-buffer)) 1990 (progn
1747 (let ((buf (ido-read-buffer (or prompt "Buffer: ") default nil initial))) 1991 (run-hook-with-args 'ido-before-fallback-functions
1992 (or fallback 'switch-to-buffer))
1993 (call-interactively (or fallback 'switch-to-buffer)))
1994 (let* ((ido-context-switch-command switch-cmd)
1995 (ido-current-directory nil)
1996 (ido-directory-nonreadable nil)
1997 (ido-directory-too-big nil)
1998 (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default nil initial)))
1748 1999
1749 ;; Choose the buffer name: either the text typed in, or the head 2000 ;; Choose the buffer name: either the text typed in, or the head
1750 ;; of the list of matches 2001 ;; of the list of matches
1751 2002
1752 (cond 2003 (cond
1753 ((eq ido-exit 'findfile) 2004 ((eq ido-exit 'find-file)
1754 (ido-file-internal ido-default-file-method nil nil nil nil ido-text)) 2005 (ido-file-internal ido-default-file-method nil nil nil nil ido-text))
2006
2007 ((eq ido-exit 'insert-file)
2008 (ido-file-internal 'insert 'insert-file nil "Insert file: " nil ido-text 'ido-enter-insert-buffer))
1755 2009
1756 ((eq ido-exit 'fallback) 2010 ((eq ido-exit 'fallback)
1757 (let ((read-buffer-function nil)) 2011 (let ((read-buffer-function nil))
2012 (run-hook-with-args 'ido-before-fallback-functions
2013 (or fallback 'switch-to-buffer))
1758 (call-interactively (or fallback 'switch-to-buffer)))) 2014 (call-interactively (or fallback 'switch-to-buffer))))
1759 2015
1760 ;; Check buf is non-nil. 2016 ;; Check buf is non-nil.
1761 ((not buf) nil) 2017 ((not buf) nil)
1762 ((= (length buf) 0) nil) 2018 ((= (length buf) 0) nil)
1764 ;; View buffer if it exists 2020 ;; View buffer if it exists
1765 ((get-buffer buf) 2021 ((get-buffer buf)
1766 (if (eq method 'insert) 2022 (if (eq method 'insert)
1767 (progn 2023 (progn
1768 (ido-record-command 'insert-buffer buf) 2024 (ido-record-command 'insert-buffer buf)
1769 (insert-buffer buf)) 2025 (with-no-warnings
2026 ;; we really want to run insert-buffer here
2027 (insert-buffer buf)))
1770 (ido-visit-buffer buf method t))) 2028 (ido-visit-buffer buf method t)))
1771 2029
1772 ;; buffer doesn't exist 2030 ;; buffer doesn't exist
1773 ((eq ido-create-new-buffer 'never) 2031 ((eq ido-create-new-buffer 'never)
1774 (message "no buffer matching `%s'" buf)) 2032 (message "no buffer matching `%s'" buf))
1781 (t 2039 (t
1782 (setq buf (get-buffer-create buf)) 2040 (setq buf (get-buffer-create buf))
1783 (if (fboundp 'set-buffer-major-mode) 2041 (if (fboundp 'set-buffer-major-mode)
1784 (set-buffer-major-mode buf)) 2042 (set-buffer-major-mode buf))
1785 (ido-visit-buffer buf method t)))))) 2043 (ido-visit-buffer buf method t))))))
1786
1787 ;;;###autoload
1788 (defun ido-read-buffer (prompt &optional default require-match initial)
1789 "Replacement for the built-in `read-buffer'.
1790 Return the name of a buffer selected.
1791 PROMPT is the prompt to give to the user. DEFAULT if given is the default
1792 buffer to be selected, which will go to the front of the list.
1793 If REQUIRE-MATCH is non-nil, an existing-buffer must be selected.
1794 If INITIAL is non-nil, it specifies the initial input string."
1795 (let ((ido-current-directory nil))
1796 (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match initial)))
1797 2044
1798 (defun ido-record-work-directory (&optional dir) 2045 (defun ido-record-work-directory (&optional dir)
1799 (when (and (numberp ido-max-work-directory-list) (> ido-max-work-directory-list 0)) 2046 (when (and (numberp ido-max-work-directory-list) (> ido-max-work-directory-list 0))
1800 (if (and (setq dir (or dir ido-current-directory)) (> (length dir) 0)) 2047 (if (and (setq dir (or dir ido-current-directory)) (> (length dir) 0))
1801 (let ((items ido-work-directory-list-ignore-regexps) 2048 (let ((items ido-work-directory-list-ignore-regexps)
1829 (and ido-work-file-list (equal (car ido-work-file-list) name)) 2076 (and ido-work-file-list (equal (car ido-work-file-list) name))
1830 (setq ido-work-file-list (cons name (delete name ido-work-file-list)))) 2077 (setq ido-work-file-list (cons name (delete name ido-work-file-list))))
1831 (if (> (length ido-work-file-list) ido-max-work-file-list) 2078 (if (> (length ido-work-file-list) ido-max-work-file-list)
1832 (setcdr (nthcdr (1- ido-max-work-file-list) ido-work-file-list) nil)))) 2079 (setcdr (nthcdr (1- ido-max-work-file-list) ido-work-file-list) nil))))
1833 2080
1834 (defun ido-file-internal (method &optional fallback default prompt item initial) 2081 (defun ido-expand-directory (dir)
2082 ;; Expand DIR or use DEFAULT-DIRECTORY if nil.
2083 ;; Add final slash to result in case it was missing from DEFAULT-DIRECTORY.
2084 (ido-final-slash (expand-file-name (or dir default-directory)) t))
2085
2086 (defun ido-file-internal (method &optional fallback default prompt item initial switch-cmd)
1835 ;; Internal function for ido-find-file and friends 2087 ;; Internal function for ido-find-file and friends
1836 (let ((ido-current-directory (expand-file-name (or default default-directory))) 2088 (unless item
2089 (setq item 'file))
2090 (let ((ido-current-directory (ido-expand-directory default))
2091 (ido-context-switch-command switch-cmd)
2092 ido-directory-nonreadable ido-directory-too-big
2093 (minibuffer-completing-file-name t)
1837 filename) 2094 filename)
1838 2095
1839 (if (or (not ido-mode) (ido-is-slow-ftp-host)) 2096 (if (or (not ido-mode) (ido-is-slow-ftp-host))
1840 (setq filename t 2097 (setq filename t
1841 ido-exit 'fallback)) 2098 ido-exit 'fallback)
1842 2099 (setq ido-directory-nonreadable
1843 (let (ido-saved-vc-mt 2100 (ido-nonreadable-directory-p ido-current-directory)
1844 (vc-master-templates (and (boundp 'vc-master-templates) vc-master-templates)) 2101 ido-directory-too-big
2102 (and (not ido-directory-nonreadable)
2103 (ido-directory-too-big-p ido-current-directory))))
2104
2105 (when (and (eq item 'file)
2106 (or ido-use-url-at-point ido-use-filename-at-point))
2107 (let (fn d)
2108 (require 'ffap)
2109 ;; Duplicate code from ffap-guesser as we want different behaviour for files and URLs.
2110 (cond
2111 ((with-no-warnings
2112 (and ido-use-url-at-point
2113 ffap-url-regexp
2114 (ffap-fixup-url (or (ffap-url-at-point)
2115 (ffap-gopher-at-point)))))
2116 (setq ido-exit 'ffap
2117 filename t))
2118
2119 ((and ido-use-filename-at-point
2120 (setq fn (if (eq ido-use-filename-at-point 'guess)
2121 (with-no-warnings (ffap-guesser))
2122 (ffap-string-at-point)))
2123 (not (string-match "^http:/" fn))
2124 (setq d (file-name-directory fn))
2125 (file-directory-p d))
2126 (setq ido-current-directory d)
2127 (setq initial (file-name-nondirectory fn))))))
2128
2129 (let (ido-saved-vc-hb
2130 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
1845 (ido-work-directory-index -1) 2131 (ido-work-directory-index -1)
1846 (ido-work-file-index -1) 2132 (ido-work-file-index -1)
1847 (ido-find-literal nil)) 2133 (ido-find-literal nil))
1848 2134
1849 (unless filename 2135 (unless filename
1850 (setq ido-saved-vc-mt vc-master-templates) 2136 (setq ido-saved-vc-hb vc-handled-backends)
1851 (setq filename (ido-read-internal (or item 'file) 2137 (setq filename (ido-read-internal item
1852 (or prompt "Find file: ") 2138 (or prompt "Find file: ")
1853 'ido-file-history nil nil initial))) 2139 'ido-file-history nil nil initial)))
1854 2140
1855 ;; Choose the file name: either the text typed in, or the head 2141 ;; Choose the file name: either the text typed in, or the head
1856 ;; of the list of matches 2142 ;; of the list of matches
1859 ((eq ido-exit 'fallback) 2145 ((eq ido-exit 'fallback)
1860 ;; Need to guard setting of default-directory here, since 2146 ;; Need to guard setting of default-directory here, since
1861 ;; we don't want to change directory of current buffer. 2147 ;; we don't want to change directory of current buffer.
1862 (let ((default-directory ido-current-directory) 2148 (let ((default-directory ido-current-directory)
1863 (read-file-name-function nil)) 2149 (read-file-name-function nil))
2150 (run-hook-with-args 'ido-before-fallback-functions
2151 (or fallback 'find-file))
1864 (call-interactively (or fallback 'find-file)))) 2152 (call-interactively (or fallback 'find-file))))
1865 2153
1866 ((eq ido-exit 'findbuffer) 2154 ((eq ido-exit 'switch-to-buffer)
1867 (ido-buffer-internal ido-default-buffer-method nil nil nil ido-text)) 2155 (ido-buffer-internal ido-default-buffer-method nil nil nil ido-text))
2156
2157 ((eq ido-exit 'insert-buffer)
2158 (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil ido-text 'ido-enter-insert-file))
1868 2159
1869 ((eq ido-exit 'dired) 2160 ((eq ido-exit 'dired)
1870 (dired (concat ido-current-directory (or ido-text "")))) 2161 (dired (concat ido-current-directory (or ido-text ""))))
2162
2163 ((eq ido-exit 'ffap)
2164 (find-file-at-point))
1871 2165
1872 ((eq method 'alt-file) 2166 ((eq method 'alt-file)
1873 (ido-record-work-file filename) 2167 (ido-record-work-file filename)
1874 (setq default-directory ido-current-directory) 2168 (setq default-directory ido-current-directory)
1875 (ido-record-work-directory) 2169 (ido-record-work-directory)
1890 ((file-exists-p file) 2184 ((file-exists-p file)
1891 (ido-record-command method ido-current-directory) 2185 (ido-record-command method ido-current-directory)
1892 (ido-record-work-directory) 2186 (ido-record-work-directory)
1893 (funcall method ido-current-directory) 2187 (funcall method ido-current-directory)
1894 (if (eq method 'dired) 2188 (if (eq method 'dired)
1895 (dired-goto-file (expand-file-name file)))) 2189 (with-no-warnings
2190 (dired-goto-file (expand-file-name file)))))
1896 ((string-match "[[*?]" filename) 2191 ((string-match "[[*?]" filename)
1897 (setq dirname (concat ido-current-directory filename)) 2192 (setq dirname (concat ido-current-directory filename))
1898 (ido-record-command method dirname) 2193 (ido-record-command method dirname)
1899 (ido-record-work-directory) 2194 (ido-record-work-directory)
1900 (funcall method dirname)) 2195 (funcall method dirname))
1901 ((y-or-n-p (format "Directory %s does not exist. Create it " filename)) 2196 ((y-or-n-p (format "Directory %s does not exist. Create it? " filename))
1902 (ido-record-command method dirname) 2197 (ido-record-command method dirname)
1903 (ido-record-work-directory dirname) 2198 (ido-record-work-directory dirname)
1904 (make-directory-internal dirname) 2199 (make-directory-internal dirname)
1905 (funcall method dirname)) 2200 (funcall method dirname))
1906 (t 2201 (t
1918 ((eq method 'read-only) 2213 ((eq method 'read-only)
1919 (ido-record-work-file filename) 2214 (ido-record-work-file filename)
1920 (setq filename (concat ido-current-directory filename)) 2215 (setq filename (concat ido-current-directory filename))
1921 (ido-record-command fallback filename) 2216 (ido-record-command fallback filename)
1922 (ido-record-work-directory) 2217 (ido-record-work-directory)
2218 (run-hook-with-args 'ido-before-fallback-functions fallback)
1923 (funcall fallback filename)) 2219 (funcall fallback filename))
1924 2220
1925 ((eq method 'insert) 2221 ((eq method 'insert)
1926 (ido-record-work-file filename) 2222 (ido-record-work-file filename)
1927 (setq filename (concat ido-current-directory filename)) 2223 (setq filename (concat ido-current-directory filename))
1962 (defun ido-complete () 2258 (defun ido-complete ()
1963 "Try and complete the current pattern amongst the file names." 2259 "Try and complete the current pattern amongst the file names."
1964 (interactive) 2260 (interactive)
1965 (let (res) 2261 (let (res)
1966 (cond 2262 (cond
2263 (ido-incomplete-regexp
2264 ;; Do nothing
2265 )
1967 ((and (memq ido-cur-item '(file dir)) 2266 ((and (memq ido-cur-item '(file dir))
1968 (string-match "[$]" ido-text)) 2267 (string-match "[$]" ido-text))
1969 (let ((evar (substitute-in-file-name (concat ido-current-directory ido-text)))) 2268 (let ((evar (substitute-in-file-name (concat ido-current-directory ido-text))))
1970 (if (not (file-exists-p (file-name-directory evar))) 2269 (if (not (file-exists-p (file-name-directory evar)))
1971 (message "Expansion generates non-existing directory name") 2270 (message "Expansion generates non-existing directory name")
1977 (ido-set-current-directory d) 2276 (ido-set-current-directory d)
1978 (setq ido-text-init f)))) 2277 (setq ido-text-init f))))
1979 (setq ido-exit 'refresh) 2278 (setq ido-exit 'refresh)
1980 (exit-minibuffer)))) 2279 (exit-minibuffer))))
1981 2280
2281 (ido-directory-too-big
2282 (setq ido-directory-too-big nil)
2283 (setq ido-text-init ido-text)
2284 (setq ido-exit 'refresh)
2285 (exit-minibuffer))
2286
1982 ((not ido-matches) 2287 ((not ido-matches)
1983 (when ido-completion-buffer 2288 (when ido-completion-buffer
1984 (call-interactively (setq this-command ido-cannot-complete-command)))) 2289 (call-interactively (setq this-command ido-cannot-complete-command))))
1985 2290
1986 ((and (= 1 (length ido-matches)) 2291 ((and (= 1 (length ido-matches))
1987 (not (and ido-enable-tramp-completion 2292 (not (and ido-enable-tramp-completion
1988 (string-equal ido-current-directory "/") 2293 (string-equal ido-current-directory "/")
1989 (string-match "..[@:]\\'" (car ido-matches))))) 2294 (string-match "..[@:]\\'" (car ido-matches)))))
1990 ;; only one choice, so select it. 2295 ;; only one choice, so select it.
1991 (exit-minibuffer)) 2296 (if (not ido-confirm-unique-completion)
2297 (exit-minibuffer)
2298 (setq ido-rescan (not ido-enable-prefix))
2299 (delete-region (minibuffer-prompt-end) (point))
2300 (insert (car ido-matches))))
1992 2301
1993 (t ;; else there could be some completions 2302 (t ;; else there could be some completions
1994 (setq res ido-common-match-string) 2303 (setq res ido-common-match-string)
1995 (if (and (not (memq res '(t nil))) 2304 (if (and (not (memq res '(t nil)))
1996 (not (equal res ido-text))) 2305 (not (equal res ido-text)))
2050 (ido-matches 2359 (ido-matches
2051 (setq ido-try-merged-list t)) 2360 (setq ido-try-merged-list t))
2052 ((not ido-use-merged-list) 2361 ((not ido-use-merged-list)
2053 (ido-merge-work-directories)))) 2362 (ido-merge-work-directories))))
2054 2363
2364 ;;; Magic C-f
2365
2366 (defun ido-magic-forward-char ()
2367 "Move forward in user input or perform magic action.
2368 If no user input is present, or at end of input, perform magic actions:
2369 C-x C-b ... C-f switch to ido-find-file.
2370 C-x C-f ... C-f fallback to non-ido find-file.
2371 C-x C-d ... C-f fallback to non-ido brief dired.
2372 C-x d ... C-f fallback to non-ido dired."
2373 (interactive)
2374 (cond
2375 ((not (eobp))
2376 (forward-char 1))
2377 ((memq ido-cur-item '(file dir))
2378 (ido-fallback-command))
2379 (ido-context-switch-command
2380 (call-interactively ido-context-switch-command))
2381 ((eq ido-cur-item 'buffer)
2382 (ido-enter-find-file))))
2383
2384 ;;; Magic C-b
2385
2386 (defun ido-magic-backward-char ()
2387 "Move backward in user input or perform magic action.
2388 If no user input is present, or at start of input, perform magic actions:
2389 C-x C-f C-b switch to ido-switch-buffer.
2390 C-x C-d C-b switch to ido-switch-buffer.
2391 C-x d C-b switch to ido-switch-buffer.
2392 C-x C-b C-b fallback to non-ido switch-to-buffer."
2393 (interactive)
2394 (cond
2395 ((> (point) (minibuffer-prompt-end))
2396 (forward-char -1))
2397 ((eq ido-cur-item 'buffer)
2398 (ido-fallback-command))
2399 (ido-context-switch-command
2400 (call-interactively ido-context-switch-command))
2401 (t
2402 (ido-enter-switch-buffer))))
2403
2404 ;;; Magic C-d
2405
2406 (defun ido-magic-delete-char ()
2407 "Delete following char in user input or perform magic action.
2408 If at end of user input, perform magic actions:
2409 C-x C-f ... C-d enter dired on current directory."
2410 (interactive)
2411 (cond
2412 ((not (eobp))
2413 (delete-char 1))
2414 (ido-context-switch-command
2415 nil)
2416 ((memq ido-cur-item '(file dir))
2417 (ido-enter-dired))))
2418
2419
2055 ;;; TOGGLE FUNCTIONS 2420 ;;; TOGGLE FUNCTIONS
2056 2421
2057 (defun ido-toggle-case () 2422 (defun ido-toggle-case ()
2058 "Toggle the value of `ido-case-fold'." 2423 "Toggle the value of `ido-case-fold'."
2059 (interactive) 2424 (interactive)
2076 (setq ido-rescan t)) 2441 (setq ido-rescan t))
2077 2442
2078 (defun ido-toggle-ignore () 2443 (defun ido-toggle-ignore ()
2079 "Toggle ignoring files specified with `ido-ignore-files'." 2444 "Toggle ignoring files specified with `ido-ignore-files'."
2080 (interactive) 2445 (interactive)
2081 (setq ido-process-ignore-lists (not ido-process-ignore-lists)) 2446 (if ido-directory-too-big
2447 (setq ido-directory-too-big nil)
2448 (setq ido-process-ignore-lists (not ido-process-ignore-lists)))
2082 (setq ido-text-init ido-text) 2449 (setq ido-text-init ido-text)
2083 (setq ido-exit 'refresh) 2450 (setq ido-exit 'refresh)
2084 (exit-minibuffer)) 2451 (exit-minibuffer))
2085 2452
2086 (defun ido-toggle-vc () 2453 (defun ido-toggle-vc ()
2087 "Disable version control for this file." 2454 "Disable version control for this file."
2088 (interactive) 2455 (interactive)
2089 (if (and ido-mode (eq ido-cur-item 'file)) 2456 (if (and ido-mode (eq ido-cur-item 'file))
2090 (progn 2457 (progn
2091 (setq vc-master-templates 2458 (setq vc-handled-backends
2092 (if vc-master-templates nil ido-saved-vc-mt)) 2459 (if vc-handled-backends nil ido-saved-vc-hb))
2093 (setq ido-text-init ido-text) 2460 (setq ido-text-init ido-text)
2094 (setq ido-exit 'keep) 2461 (setq ido-exit 'keep)
2095 (exit-minibuffer)))) 2462 (exit-minibuffer))))
2096 2463
2097 (defun ido-toggle-literal () 2464 (defun ido-toggle-literal ()
2118 (exit-minibuffer)))) 2485 (exit-minibuffer))))
2119 2486
2120 (defun ido-exit-minibuffer () 2487 (defun ido-exit-minibuffer ()
2121 "Exit minibuffer, but make sure we have a match if one is needed." 2488 "Exit minibuffer, but make sure we have a match if one is needed."
2122 (interactive) 2489 (interactive)
2123 (if (or (not ido-require-match) 2490 (if (and (or (not ido-require-match)
2124 (ido-existing-item-p)) 2491 (ido-existing-item-p))
2125 (throw 'exit nil))) 2492 (not ido-incomplete-regexp))
2493 (exit-minibuffer)))
2126 2494
2127 (defun ido-select-text () 2495 (defun ido-select-text ()
2128 "Select the buffer or file named by the prompt. 2496 "Select the buffer or file named by the prompt.
2129 If no buffer or file exactly matching the prompt exists, maybe create a new one." 2497 If no buffer or file exactly matching the prompt exists, maybe create a new one."
2130 (interactive) 2498 (interactive)
2132 (exit-minibuffer)) 2500 (exit-minibuffer))
2133 2501
2134 (defun ido-fallback-command () 2502 (defun ido-fallback-command ()
2135 "Fallback to non-ido version of current command." 2503 "Fallback to non-ido version of current command."
2136 (interactive) 2504 (interactive)
2505 (let ((i (length ido-text)))
2506 (while (> i 0)
2507 (push (aref ido-text (setq i (1- i))) unread-command-events)))
2137 (setq ido-exit 'fallback) 2508 (setq ido-exit 'fallback)
2138 (exit-minibuffer)) 2509 (exit-minibuffer))
2139 2510
2140 (defun ido-enter-find-file () 2511 (defun ido-enter-find-file ()
2141 "Drop into find-file from buffer switching." 2512 "Drop into `find-file' from buffer switching."
2142 (interactive) 2513 (interactive)
2143 (setq ido-exit 'findfile) 2514 (setq ido-exit 'find-file)
2144 (exit-minibuffer)) 2515 (exit-minibuffer))
2145 2516
2146 (defun ido-enter-switch-buffer () 2517 (defun ido-enter-switch-buffer ()
2147 "Drop into ido-switch-buffer from file switching." 2518 "Drop into `ido-switch-buffer' from file switching."
2148 (interactive) 2519 (interactive)
2149 (setq ido-exit 'findbuffer) 2520 (setq ido-exit 'switch-to-buffer)
2150 (exit-minibuffer)) 2521 (exit-minibuffer))
2151 2522
2152 (defun ido-enter-dired () 2523 (defun ido-enter-dired ()
2153 "Drop into dired from file switching." 2524 "Drop into dired from file switching."
2154 (interactive) 2525 (interactive)
2155 (setq ido-exit 'dired) 2526 (setq ido-exit 'dired)
2527 (exit-minibuffer))
2528
2529 (defun ido-enter-insert-buffer ()
2530 "Drop into insert buffer from insert file."
2531 (interactive)
2532 (setq ido-exit 'insert-buffer)
2533 (exit-minibuffer))
2534
2535 (defun ido-enter-insert-file ()
2536 "Drop into insert file from insert buffer."
2537 (interactive)
2538 (setq ido-exit 'insert-file)
2156 (exit-minibuffer)) 2539 (exit-minibuffer))
2157 2540
2158 2541
2159 (defun ido-up-directory (&optional clear) 2542 (defun ido-up-directory (&optional clear)
2160 "Go up one directory level." 2543 "Go up one directory level."
2206 (setq dir (nth i ido-work-directory-list)) 2589 (setq dir (nth i ido-work-directory-list))
2207 (if (and dir 2590 (if (and dir
2208 (not (equal dir ido-current-directory)) 2591 (not (equal dir ido-current-directory))
2209 (file-directory-p dir) 2592 (file-directory-p dir)
2210 (or (not must-match) 2593 (or (not must-match)
2211 (ido-set-matches1 2594 ;; TODO. check for nonreadable and too-big.
2595 (ido-set-matches-1
2212 (if (eq ido-cur-item 'file) 2596 (if (eq ido-cur-item 'file)
2213 (ido-make-file-list1 dir) 2597 (ido-make-file-list-1 dir)
2214 (ido-make-dir-list1 dir))))) 2598 (ido-make-dir-list-1 dir)))))
2215 (setq j n) 2599 (setq j n)
2216 (setq dir nil))) 2600 (setq dir nil)))
2217 (if dir 2601 (if dir
2218 (setq ido-work-directory-index i)) 2602 (setq ido-work-directory-index i))
2219 dir)) 2603 dir))
2251 2635
2252 (defun ido-wide-find-file (&optional file) 2636 (defun ido-wide-find-file (&optional file)
2253 "Prompt for FILE to search for using find, starting from current directory." 2637 "Prompt for FILE to search for using find, starting from current directory."
2254 (interactive) 2638 (interactive)
2255 (unless file 2639 (unless file
2256 (setq file (read-string (concat "Wide find file: " ido-current-directory) ido-text))) 2640 (let ((enable-recursive-minibuffers t))
2641 (setq file
2642 (condition-case nil
2643 (read-string (concat "Wide find file: " ido-current-directory) ido-text)
2644 (quit "")))))
2257 (when (> (length file) 0) 2645 (when (> (length file) 0)
2258 (setq ido-use-merged-list t ido-try-merged-list 'wide) 2646 (setq ido-use-merged-list t ido-try-merged-list 'wide)
2259 (setq ido-exit 'refresh) 2647 (setq ido-exit 'refresh)
2260 (setq ido-text-init file) 2648 (setq ido-text-init file)
2261 (setq ido-rotate-temp t) 2649 (setq ido-rotate-temp t)
2263 2651
2264 (defun ido-wide-find-dir (&optional dir) 2652 (defun ido-wide-find-dir (&optional dir)
2265 "Prompt for DIR to search for using find, starting from current directory." 2653 "Prompt for DIR to search for using find, starting from current directory."
2266 (interactive) 2654 (interactive)
2267 (unless dir 2655 (unless dir
2268 (setq dir (read-string (concat "Wide find directory: " ido-current-directory) ido-text))) 2656 (let ((enable-recursive-minibuffers t))
2657 (setq dir
2658 (condition-case nil
2659 (read-string (concat "Wide find directory: " ido-current-directory) ido-text)
2660 (quit "")))))
2269 (when (> (length dir) 0) 2661 (when (> (length dir) 0)
2270 (setq ido-use-merged-list t ido-try-merged-list 'wide) 2662 (setq ido-use-merged-list t ido-try-merged-list 'wide)
2271 (setq ido-exit 'refresh) 2663 (setq ido-exit 'refresh)
2272 (setq ido-text-init (ido-final-slash dir t)) 2664 (setq ido-text-init (ido-final-slash dir t))
2273 (setq ido-rotate-temp t) 2665 (setq ido-rotate-temp t)
2274 (exit-minibuffer))) 2666 (exit-minibuffer)))
2275 2667
2668 (defun ido-wide-find-dir-or-delete-dir (&optional dir)
2669 "Prompt for DIR to search for using find, starting from current directory.
2670 If input stack is non-empty, delete current directory component."
2671 (interactive)
2672 (if ido-input-stack
2673 (ido-delete-backward-word-updir 1)
2674 (ido-wide-find-dir)))
2675
2676 (defun ido-push-dir ()
2677 "Move to previous directory in file name, push current input on stack."
2678 (interactive)
2679 (setq ido-exit 'push)
2680 (exit-minibuffer))
2681
2682 (defun ido-pop-dir (arg)
2683 "Pop directory from input stack back to input.
2684 With \\[universal-argument], pop all element."
2685 (interactive "P")
2686 (when ido-input-stack
2687 (setq ido-exit (if arg 'pop-all 'pop))
2688 (exit-minibuffer)))
2689
2690 (defun ido-wide-find-file-or-pop-dir (arg)
2691 (interactive "P")
2692 (if ido-input-stack
2693 (ido-pop-dir arg)
2694 (ido-wide-find-file)))
2695
2276 (defun ido-make-directory (&optional dir) 2696 (defun ido-make-directory (&optional dir)
2277 "Prompt for DIR to create in current directory." 2697 "Prompt for DIR to create in current directory."
2278 (interactive) 2698 (interactive)
2279 (unless dir 2699 (unless dir
2280 (setq dir (read-string (concat "Make directory: " ido-current-directory) ido-text))) 2700 (let ((enable-recursive-minibuffers t))
2701 (setq dir
2702 (read-string (concat "Make directory: " ido-current-directory) ido-text))))
2281 (when (> (length dir) 0) 2703 (when (> (length dir) 0)
2282 (setq dir (concat ido-current-directory dir)) 2704 (setq dir (concat ido-current-directory dir))
2283 (unless (file-exists-p dir) 2705 (unless (file-exists-p dir)
2284 (make-directory dir t) 2706 (make-directory dir t)
2285 (ido-set-current-directory dir) 2707 (ido-set-current-directory dir)
2457 2879
2458 ;;; CREATE LIST OF ALL CURRENT FILES 2880 ;;; CREATE LIST OF ALL CURRENT FILES
2459 2881
2460 (defun ido-all-completions () 2882 (defun ido-all-completions ()
2461 ;; Return unsorted list of all competions. 2883 ;; Return unsorted list of all competions.
2462 (let ((ido-process-ignore-lists nil)) 2884 (let ((ido-process-ignore-lists nil)
2885 (ido-directory-too-big nil))
2463 (cond 2886 (cond
2464 ((eq ido-cur-item 'file) 2887 ((eq ido-cur-item 'file)
2465 (ido-make-file-list1 ido-current-directory)) 2888 (ido-make-file-list-1 ido-current-directory))
2466 ((eq ido-cur-item 'dir) 2889 ((eq ido-cur-item 'dir)
2467 (ido-make-dir-list1 ido-current-directory)) 2890 (ido-make-dir-list-1 ido-current-directory))
2468 ((eq ido-cur-item 'buffer) 2891 ((eq ido-cur-item 'buffer)
2469 (ido-make-buffer-list1)) 2892 (ido-make-buffer-list-1))
2893 ((eq ido-cur-item 'list)
2894 ido-choice-list)
2470 (t nil)))) 2895 (t nil))))
2471 2896
2472 2897
2473 (defun ido-sort-list (items) 2898 ;; File list sorting
2474 ;; Simple list of file or buffer names 2899
2475 (sort items (lambda (a b) (string-lessp a b)))) 2900 (defun ido-file-lessp (a b)
2901 ;; Simple compare two file names.
2902 (string-lessp (ido-no-final-slash a) (ido-no-final-slash b)))
2903
2904
2905 (defun ido-file-extension-lessp (a b)
2906 ;; Compare file names according to ido-file-extensions-order list.
2907 (let ((n (compare-strings a 0 nil b 0 nil nil))
2908 lessp p)
2909 (if (eq n t)
2910 nil
2911 (if (< n 0)
2912 (setq n (1- (- n))
2913 p a a b b p
2914 lessp t)
2915 (setq n (1- n)))
2916 (cond
2917 ((= n 0)
2918 lessp)
2919 ((= (aref a n) ?.)
2920 (ido-file-extension-aux a b n lessp))
2921 (t
2922 (while (and (> n 2) (/= (aref a n) ?.))
2923 (setq n (1- n)))
2924 (if (> n 1)
2925 (ido-file-extension-aux a b n lessp)
2926 lessp))))))
2927
2928 (defun ido-file-extension-aux (a b n lessp)
2929 (let ((oa (ido-file-extension-order a n))
2930 (ob (ido-file-extension-order b n)))
2931 (cond
2932 ((= oa ob)
2933 lessp)
2934 ((and oa ob)
2935 (if lessp
2936 (> oa ob)
2937 (< oa ob)))
2938 (oa
2939 (not lessp))
2940 (ob
2941 lessp)
2942 (t
2943 lessp))))
2944
2945 (defun ido-file-extension-order (s n)
2946 (let ((l ido-file-extensions-order)
2947 (i 0) o do)
2948 (while l
2949 (cond
2950 ((eq (car l) t)
2951 (setq do i
2952 l (cdr l)))
2953 ((eq (compare-strings s n nil (car l) 0 nil nil) t)
2954 (setq o i
2955 l nil))
2956 (t
2957 (setq l (cdr l))))
2958 (setq i (1+ i)))
2959 (or o do)))
2960
2476 2961
2477 (defun ido-sort-merged-list (items promote) 2962 (defun ido-sort-merged-list (items promote)
2478 ;; Input is list of ("file" . "dir") cons cells. 2963 ;; Input is list of ("file" . "dir") cons cells.
2479 ;; Output is sorted list of ("file "dir" ...) lists 2964 ;; Output is sorted list of ("file "dir" ...) lists
2480 (let ((l (sort items (lambda (a b) (string-lessp (car b) (car a))))) 2965 (let ((l (sort items (lambda (a b) (string-lessp (car b) (car a)))))
2520 (setq res (cons (concat (car dirs) file) res) 3005 (setq res (cons (concat (car dirs) file) res)
2521 dirs (cdr dirs)))) 3006 dirs (cdr dirs))))
2522 (setq items (cdr items))) 3007 (setq items (cdr items)))
2523 res)) 3008 res))
2524 3009
2525 (defun ido-make-merged-file-list (text auto wide) 3010
3011 (defun ido-make-merged-file-list-1 (text auto wide)
2526 (let (res) 3012 (let (res)
2527 (message "Searching for `%s'...." text)
2528 (if (and (ido-final-slash text) ido-dir-file-cache) 3013 (if (and (ido-final-slash text) ido-dir-file-cache)
2529 (if wide 3014 (if wide
2530 (setq res (ido-wide-find-dirs-or-files 3015 (setq res (ido-wide-find-dirs-or-files
2531 ido-current-directory (substring text 0 -1) ido-enable-prefix t)) 3016 ido-current-directory (substring text 0 -1) ido-enable-prefix t))
2532 ;; Use list of cached directories 3017 ;; Use list of cached directories
2573 dirs (cdr dirs)) 3058 dirs (cdr dirs))
2574 (when (and dir (stringp dir) 3059 (when (and dir (stringp dir)
2575 (or ido-merge-ftp-work-directories 3060 (or ido-merge-ftp-work-directories
2576 (not (ido-is-ftp-directory dir))) 3061 (not (ido-is-ftp-directory dir)))
2577 (file-directory-p dir) 3062 (file-directory-p dir)
3063 ;; TODO. check for nonreadable and too-big.
2578 (setq fl (if (eq ido-cur-item 'file) 3064 (setq fl (if (eq ido-cur-item 'file)
2579 (ido-make-file-list1 dir t) 3065 (ido-make-file-list-1 dir t)
2580 (ido-make-dir-list1 dir t)))) 3066 (ido-make-dir-list-1 dir t))))
2581 (if must-match 3067 (if must-match
2582 (setq fl (ido-set-matches1 fl))) 3068 (setq fl (ido-set-matches-1 fl)))
2583 (if fl 3069 (if fl
2584 (setq res (nconc fl res)))) 3070 (setq res (nconc fl res))))
2585 (if (and auto (input-pending-p)) 3071 (if (and auto (input-pending-p))
2586 (setq dirs nil 3072 (setq dirs nil
2587 res t)))))) 3073 res t))))))
2588 (if (and res (not (eq res t))) 3074 res))
2589 (setq res (ido-sort-merged-list res auto))) 3075
3076 (defun ido-make-merged-file-list (text auto wide)
3077 (let (res)
3078 (message "Searching for `%s'...." text)
3079 (condition-case nil
3080 (if (eq t (setq res
3081 (while-no-input
3082 (ido-make-merged-file-list-1 text auto wide))))
3083 (setq res 'input-pending-p))
3084 (quit
3085 (setq res t
3086 ido-try-merged-list nil
3087 ido-use-merged-list nil)))
3088 (when (and res (listp res))
3089 (setq res (ido-sort-merged-list res auto)))
2590 (when (and (or ido-rotate-temp ido-rotate-file-list-default) 3090 (when (and (or ido-rotate-temp ido-rotate-file-list-default)
2591 (listp res) 3091 (listp res)
2592 (> (length text) 0)) 3092 (> (length text) 0))
2593 (let ((elt (assoc text res))) 3093 (let ((elt (assoc text res)))
2594 (when (and elt (not (eq elt (car res)))) 3094 (when (and elt (not (eq elt (car res))))
2595 (setq res (delq elt res)) 3095 (setq res (delq elt res))
2596 (setq res (cons elt res))))) 3096 (setq res (cons elt res)))))
2597 (message nil) 3097 (message nil)
2598 res)) 3098 res))
2599 3099
2600 (defun ido-make-buffer-list1 (&optional frame visible) 3100 (defun ido-make-buffer-list-1 (&optional frame visible)
2601 ;; Return list of non-ignored buffer names 3101 ;; Return list of non-ignored buffer names
2602 (delq nil 3102 (delq nil
2603 (mapcar 3103 (mapcar
2604 (lambda (x) 3104 (lambda (x)
2605 (let ((name (buffer-name x))) 3105 (let ((name (buffer-name x)))
2608 (buffer-list frame)))) 3108 (buffer-list frame))))
2609 3109
2610 (defun ido-make-buffer-list (default) 3110 (defun ido-make-buffer-list (default)
2611 ;; Return the current list of buffers. 3111 ;; Return the current list of buffers.
2612 ;; Currently visible buffers are put at the end of the list. 3112 ;; Currently visible buffers are put at the end of the list.
2613 ;; The hook `ido-make-buflist-hook' is run after the list has been 3113 ;; The hook `ido-make-buffer-list-hook' is run after the list has been
2614 ;; created to allow the user to further modify the order of the buffer names 3114 ;; created to allow the user to further modify the order of the buffer names
2615 ;; in this list. If DEFAULT is non-nil, and corresponds to an existing buffer, 3115 ;; in this list. If DEFAULT is non-nil, and corresponds to an existing buffer,
2616 ;; it is put to the start of the list. 3116 ;; it is put to the start of the list.
2617 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current)) 3117 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current))
2618 (ido-temp-list (ido-make-buffer-list1 (selected-frame) ido-current-buffers))) 3118 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers)))
2619 (if ido-temp-list 3119 (if ido-temp-list
2620 (nconc ido-temp-list ido-current-buffers) 3120 (nconc ido-temp-list ido-current-buffers)
2621 (setq ido-temp-list ido-current-buffers)) 3121 (setq ido-temp-list ido-current-buffers))
2622 (if default 3122 (if default
2623 (progn 3123 (progn
2626 (setq ido-temp-list 3126 (setq ido-temp-list
2627 (cons default ido-temp-list)))) 3127 (cons default ido-temp-list))))
2628 (run-hooks 'ido-make-buffer-list-hook) 3128 (run-hooks 'ido-make-buffer-list-hook)
2629 ido-temp-list)) 3129 ido-temp-list))
2630 3130
3131 (defun ido-make-choice-list (default)
3132 ;; Return the current list of choices.
3133 ;; If DEFAULT is non-nil, and corresponds to an element of choices,
3134 ;; it is put to the start of the list.
3135 (let ((ido-temp-list ido-choice-list))
3136 (if default
3137 (progn
3138 (setq ido-temp-list
3139 (delete default ido-temp-list))
3140 (setq ido-temp-list
3141 (cons default ido-temp-list))))
3142 ; (run-hooks 'ido-make-choice-list-hook)
3143 ido-temp-list))
3144
2631 (defun ido-to-end (items) 3145 (defun ido-to-end (items)
2632 ;; Move the elements from ITEMS to the end of `ido-temp-list' 3146 ;; Move the elements from ITEMS to the end of `ido-temp-list'
2633 (mapcar 3147 (mapcar
2634 (lambda (elem) 3148 (lambda (elem)
2635 (setq ido-temp-list (delq elem ido-temp-list))) 3149 (setq ido-temp-list (delq elem ido-temp-list)))
2636 items) 3150 items)
2637 (if ido-temp-list 3151 (if ido-temp-list
2638 (nconc ido-temp-list items) 3152 (nconc ido-temp-list items)
2639 (setq ido-temp-list items))) 3153 (setq ido-temp-list items)))
2640 3154
2641 (defun ido-file-name-all-completions1 (dir) 3155 (defun ido-file-name-all-completions-1 (dir)
2642 (if (and ido-enable-tramp-completion 3156 (cond
2643 (string-match "\\`/\\([^/:]+:\\([^/:@]+@\\)?\\)\\'" dir)) 3157 ((ido-nonreadable-directory-p dir) '())
2644 3158 ;; do not check (ido-directory-too-big-p dir) here.
2645 ;; Trick tramp's file-name-all-completions handler to DTRT, as it 3159 ;; Caller must have done that if necessary.
2646 ;; has some pretty obscure requirements. This seems to work... 3160
2647 ;; /ftp: => (f-n-a-c "/ftp:" "") 3161 ((and ido-enable-tramp-completion
2648 ;; /ftp:kfs: => (f-n-a-c "" "/ftp:kfs:") 3162 (or (fboundp 'tramp-completion-mode)
2649 ;; /ftp:kfs@ => (f-n-a-c "ftp:kfs@" "/") 3163 (require 'tramp nil t))
2650 ;; /ftp:kfs@kfs: => (f-n-a-c "" "/ftp:kfs@kfs:") 3164 (string-match "\\`/[^/]+[:@]\\'" dir))
2651 ;; Currently no attempt is made to handle multi: stuff. 3165 ;; Strip method:user@host: part of tramp completions.
2652 3166 ;; Tramp completions do not include leading slash.
2653 (let* ((prefix (match-string 1 dir)) 3167 (let ((len (1- (length dir)))
2654 (user-flag (match-beginning 2)) 3168 (compl
2655 (len (and prefix (length prefix))) 3169 (or (file-name-all-completions "" dir)
2656 compl) 3170 ;; work around bug in ange-ftp.
2657 (if user-flag 3171 ;; /ftp:user@host: => nil
2658 (setq dir (substring dir 1))) 3172 ;; /ftp:user@host:./ => ok
2659 (require 'tramp nil t) 3173 (and
2660 (ido-trace "tramp complete" dir) 3174 (not (string= "/ftp:" dir))
2661 (setq compl (file-name-all-completions dir (if user-flag "/" ""))) 3175 (tramp-tramp-file-p dir)
2662 (if (> len 0) 3176 (fboundp 'tramp-ftp-file-name-p)
2663 (mapcar (lambda (c) (substring c len)) compl) 3177 (funcall 'tramp-ftp-file-name-p dir)
2664 compl)) 3178 (string-match ":\\'" dir)
2665 (file-name-all-completions "" dir))) 3179 (file-name-all-completions "" (concat dir "./"))))))
3180 (if (and compl
3181 (> (length (car compl)) len)
3182 (string= (substring (car compl) 0 len) (substring dir 1)))
3183 (mapcar (lambda (c) (substring c len)) compl)
3184 compl)))
3185 (t
3186 (file-name-all-completions "" dir))))
2666 3187
2667 (defun ido-file-name-all-completions (dir) 3188 (defun ido-file-name-all-completions (dir)
2668 ;; Return name of all files in DIR 3189 ;; Return name of all files in DIR
2669 ;; Uses and updates ido-dir-file-cache 3190 ;; Uses and updates ido-dir-file-cache
2670 (if (and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0) 3191 (if (and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0)
2688 cached nil))) 3209 cached nil)))
2689 (unless cached 3210 (unless cached
2690 (if (and ftp (file-readable-p dir)) 3211 (if (and ftp (file-readable-p dir))
2691 (setq mtime (cons 'ftp (ido-time-stamp)))) 3212 (setq mtime (cons 'ftp (ido-time-stamp))))
2692 (if mtime 3213 (if mtime
2693 (setq cached (cons dir (cons mtime (ido-file-name-all-completions1 dir))) 3214 (setq cached (cons dir (cons mtime (ido-file-name-all-completions-1 dir)))
2694 ido-dir-file-cache (cons cached ido-dir-file-cache))) 3215 ido-dir-file-cache (cons cached ido-dir-file-cache)))
2695 (if (> (length ido-dir-file-cache) ido-max-dir-file-cache) 3216 (if (> (length ido-dir-file-cache) ido-max-dir-file-cache)
2696 (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil))) 3217 (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil)))
2697 (and cached 3218 (and cached
2698 (cdr (cdr cached)))) 3219 (cdr (cdr cached))))
2699 (ido-file-name-all-completions1 dir))) 3220 (ido-file-name-all-completions-1 dir)))
2700 3221
2701 (defun ido-remove-cached-dir (dir) 3222 (defun ido-remove-cached-dir (dir)
2702 ;; Remove dir from ido-dir-file-cache 3223 ;; Remove dir from ido-dir-file-cache
2703 (if (and ido-dir-file-cache 3224 (if (and ido-dir-file-cache
2704 (stringp dir) (> (length dir) 0)) 3225 (stringp dir) (> (length dir) 0))
2705 (let ((cached (assoc dir ido-dir-file-cache))) 3226 (let ((cached (assoc dir ido-dir-file-cache)))
2706 (if cached 3227 (if cached
2707 (setq ido-dir-file-cache (delq cached ido-dir-file-cache)))))) 3228 (setq ido-dir-file-cache (delq cached ido-dir-file-cache))))))
2708 3229
2709 3230
2710 (defun ido-make-file-list1 (dir &optional merged) 3231 (defun ido-make-file-list-1 (dir &optional merged)
2711 ;; Return list of non-ignored files in DIR 3232 ;; Return list of non-ignored files in DIR
2712 ;; If MERGED is non-nil, each file is cons'ed with DIR 3233 ;; If MERGED is non-nil, each file is cons'ed with DIR
2713 (and (or (ido-is-tramp-root dir) (file-directory-p dir)) 3234 (and (or (ido-is-tramp-root dir) (file-directory-p dir))
2714 (delq nil 3235 (delq nil
2715 (mapcar 3236 (mapcar
2722 ;; Return the current list of files. 3243 ;; Return the current list of files.
2723 ;; Currently visible files are put at the end of the list. 3244 ;; Currently visible files are put at the end of the list.
2724 ;; The hook `ido-make-file-list-hook' is run after the list has been 3245 ;; The hook `ido-make-file-list-hook' is run after the list has been
2725 ;; created to allow the user to further modify the order of the file names 3246 ;; created to allow the user to further modify the order of the file names
2726 ;; in this list. 3247 ;; in this list.
2727 (let ((ido-temp-list (ido-make-file-list1 ido-current-directory))) 3248 (let ((ido-temp-list (ido-make-file-list-1 ido-current-directory)))
2728 (setq ido-temp-list (ido-sort-list ido-temp-list)) 3249 (setq ido-temp-list (sort ido-temp-list
2729 (let ((default-directory ido-current-directory)) 3250 (if ido-file-extensions-order
2730 (ido-to-end ;; move ftp hosts and visited files to end 3251 #'ido-file-extension-lessp
2731 (delq nil (mapcar 3252 #'ido-file-lessp)))
2732 (lambda (x) (if (or (string-match "..:\\'" x) 3253 (unless (ido-is-tramp-root ido-current-directory)
2733 (and (not (ido-final-slash x)) 3254 (let ((default-directory ido-current-directory))
2734 (get-file-buffer x))) x)) 3255 (ido-to-end ;; move ftp hosts and visited files to end
2735 ido-temp-list)))) 3256 (delq nil (mapcar
3257 (lambda (x) (if (or (string-match "..:\\'" x)
3258 (and (not (ido-final-slash x))
3259 (get-file-buffer x))) x))
3260 ido-temp-list)))))
2736 (ido-to-end ;; move . files to end 3261 (ido-to-end ;; move . files to end
2737 (delq nil (mapcar 3262 (delq nil (mapcar
2738 (lambda (x) (if (string-equal (substring x 0 1) ".") x)) 3263 (lambda (x) (if (string-equal (substring x 0 1) ".") x))
2739 ido-temp-list))) 3264 ido-temp-list)))
2740 (if (and default (member default ido-temp-list)) 3265 (if (and default (member default ido-temp-list))
2755 (setq ido-temp-list (delete "." ido-temp-list)) 3280 (setq ido-temp-list (delete "." ido-temp-list))
2756 (setq ido-temp-list (cons "." ido-temp-list))) 3281 (setq ido-temp-list (cons "." ido-temp-list)))
2757 (run-hooks 'ido-make-file-list-hook) 3282 (run-hooks 'ido-make-file-list-hook)
2758 ido-temp-list)) 3283 ido-temp-list))
2759 3284
2760 (defun ido-make-dir-list1 (dir &optional merged) 3285 (defun ido-make-dir-list-1 (dir &optional merged)
2761 ;; Return list of non-ignored subdirs in DIR 3286 ;; Return list of non-ignored subdirs in DIR
2762 ;; If MERGED is non-nil, each subdir is cons'ed with DIR 3287 ;; If MERGED is non-nil, each subdir is cons'ed with DIR
2763 (and (or (ido-is-tramp-root dir) (file-directory-p dir)) 3288 (and (or (ido-is-tramp-root dir) (file-directory-p dir))
2764 (delq nil 3289 (delq nil
2765 (mapcar 3290 (mapcar
2771 (defun ido-make-dir-list (default) 3296 (defun ido-make-dir-list (default)
2772 ;; Return the current list of directories. 3297 ;; Return the current list of directories.
2773 ;; The hook `ido-make-dir-list-hook' is run after the list has been 3298 ;; The hook `ido-make-dir-list-hook' is run after the list has been
2774 ;; created to allow the user to further modify the order of the 3299 ;; created to allow the user to further modify the order of the
2775 ;; directory names in this list. 3300 ;; directory names in this list.
2776 (let ((ido-temp-list (ido-make-dir-list1 ido-current-directory))) 3301 (let ((ido-temp-list (ido-make-dir-list-1 ido-current-directory)))
2777 (setq ido-temp-list (ido-sort-list ido-temp-list)) 3302 (setq ido-temp-list (sort ido-temp-list #'ido-file-lessp))
2778 (ido-to-end ;; move . files to end 3303 (ido-to-end ;; move . files to end
2779 (delq nil (mapcar 3304 (delq nil (mapcar
2780 (lambda (x) (if (string-equal (substring x 0 1) ".") x)) 3305 (lambda (x) (if (string-equal (substring x 0 1) ".") x))
2781 ido-temp-list))) 3306 ido-temp-list)))
2782 (if (and default (member default ido-temp-list)) 3307 (if (and default (member default ido-temp-list))
2792 (setq ido-temp-list 3317 (setq ido-temp-list
2793 (delete default ido-temp-list)) 3318 (delete default ido-temp-list))
2794 (setq ido-temp-list 3319 (setq ido-temp-list
2795 (cons default ido-temp-list)))) 3320 (cons default ido-temp-list))))
2796 (setq ido-temp-list (delete "." ido-temp-list)) 3321 (setq ido-temp-list (delete "." ido-temp-list))
2797 (setq ido-temp-list (cons "." ido-temp-list)) 3322 (unless ido-input-stack
3323 (setq ido-temp-list (cons "." ido-temp-list)))
2798 (run-hooks 'ido-make-dir-list-hook) 3324 (run-hooks 'ido-make-dir-list-hook)
2799 ido-temp-list)) 3325 ido-temp-list))
2800 3326
2801 ;; List of the files visible in the current frame. 3327 ;; List of the files visible in the current frame.
2802 (defvar ido-bufs-in-frame) 3328 (defvar ido-bufs-in-frame)
2824 (setq ido-bufs-in-frame 3350 (setq ido-bufs-in-frame
2825 (cons buf ido-bufs-in-frame))))) 3351 (cons buf ido-bufs-in-frame)))))
2826 3352
2827 ;;; FIND MATCHING ITEMS 3353 ;;; FIND MATCHING ITEMS
2828 3354
2829 (defun ido-set-matches1 (items &optional do-full) 3355 (defun ido-set-matches-1 (items &optional do-full)
2830 ;; Return list of matches in items 3356 ;; Return list of matches in items
2831 (let* ((case-fold-search ido-case-fold) 3357 (let* ((case-fold-search ido-case-fold)
2832 (slash (and (not ido-enable-prefix) (ido-final-slash ido-text))) 3358 (slash (and (not ido-enable-prefix) (ido-final-slash ido-text)))
2833 (text (if slash (substring ido-text 0 -1) ido-text)) 3359 (text (if slash (substring ido-text 0 -1) ido-text))
2834 (rexq (concat (if ido-enable-regexp text (regexp-quote text)) (if slash ".*/" ""))) 3360 (rexq (concat (if ido-enable-regexp text (regexp-quote text)) (if slash ".*/" "")))
2835 (re (if ido-enable-prefix (concat "\\`" rexq) rexq)) 3361 (re (if ido-enable-prefix (concat "\\`" rexq) rexq))
2836 (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" re)) 3362 (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" re))
2837 (concat "\\`" re "\\'"))) 3363 (concat "\\`" re "\\'")))
2838 (prefix-re (and full-re (not ido-enable-prefix) 3364 (prefix-re (and full-re (not ido-enable-prefix)
2839 (concat "\\`" rexq))) 3365 (concat "\\`" rexq)))
3366 (non-prefix-dot (or (not ido-enable-dot-prefix)
3367 (not ido-process-ignore-lists)
3368 ido-enable-prefix
3369 (= (length ido-text) 0)))
3370
2840 full-matches 3371 full-matches
2841 prefix-matches 3372 prefix-matches
2842 matches) 3373 matches)
2843 (mapcar 3374 (setq ido-incomplete-regexp nil)
2844 (lambda (item) 3375 (condition-case error
2845 (let ((name (ido-name item))) 3376 (mapcar
2846 (if (string-match re name) 3377 (lambda (item)
2847 (cond 3378 (let ((name (ido-name item)))
2848 ((and full-re (string-match full-re name)) 3379 (if (and (or non-prefix-dot
2849 (setq full-matches (cons item full-matches))) 3380 (if (= (aref ido-text 0) ?.)
2850 ((and prefix-re (string-match prefix-re name)) 3381 (= (aref name 0) ?.)
2851 (setq prefix-matches (cons item prefix-matches))) 3382 (/= (aref name 0) ?.)))
2852 (t (setq matches (cons item matches)))))) 3383 (string-match re name))
2853 t) 3384 (cond
2854 items) 3385 ((and full-re (string-match full-re name))
3386 (setq full-matches (cons item full-matches)))
3387 ((and prefix-re (string-match prefix-re name))
3388 (setq prefix-matches (cons item prefix-matches)))
3389 (t (setq matches (cons item matches))))))
3390 t)
3391 items)
3392 (invalid-regexp
3393 (setq ido-incomplete-regexp t
3394 ;; Consider the invalid regexp message internally as a
3395 ;; special-case single match, and handle appropriately
3396 ;; elsewhere.
3397 matches (cdr error))))
2855 (if prefix-matches 3398 (if prefix-matches
2856 (setq matches (nconc prefix-matches matches))) 3399 (setq matches (nconc prefix-matches matches)))
2857 (if full-matches 3400 (if full-matches
2858 (setq matches (nconc full-matches matches))) 3401 (setq matches (nconc full-matches matches)))
2859 (when (and (null matches) 3402 (when (and (null matches)
2873 3416
2874 3417
2875 (defun ido-set-matches () 3418 (defun ido-set-matches ()
2876 ;; Set `ido-matches' to the list of items matching prompt 3419 ;; Set `ido-matches' to the list of items matching prompt
2877 (when ido-rescan 3420 (when ido-rescan
2878 (setq ido-matches (ido-set-matches1 (reverse ido-cur-list) (not ido-rotate)) 3421 (setq ido-matches (ido-set-matches-1 (reverse ido-cur-list) (not ido-rotate))
2879 ido-rotate nil))) 3422 ido-rotate nil)))
2880 3423
2881 (defun ido-ignore-item-p (name re-list &optional ignore-ext) 3424 (defun ido-ignore-item-p (name re-list &optional ignore-ext)
2882 ;; Return t if the buffer or file NAME should be ignored. 3425 ;; Return t if the buffer or file NAME should be ignored.
2883 (or (member name ido-ignore-item-temp-list) 3426 (or (member name ido-ignore-item-temp-list)
2884 (and 3427 (and
2885 ido-process-ignore-lists re-list 3428 ido-process-ignore-lists re-list
2886 (let ((data (match-data)) 3429 (save-match-data
2887 (ext-list (and ignore-ext ido-ignore-extensions 3430 (let ((ext-list (and ignore-ext ido-ignore-extensions
2888 completion-ignored-extensions)) 3431 completion-ignored-extensions))
2889 ignorep nextstr 3432 (case-fold-search ido-case-fold)
2890 (flen (length name)) slen) 3433 ignorep nextstr
2891 (while ext-list 3434 (flen (length name)) slen)
2892 (setq nextstr (car ext-list)) 3435 (while ext-list
2893 (if (cond 3436 (setq nextstr (car ext-list))
2894 ((stringp nextstr) 3437 (if (cond
2895 (and (>= flen (setq slen (length nextstr))) 3438 ((stringp nextstr)
2896 (string-equal (substring name (- flen slen)) nextstr))) 3439 (and (>= flen (setq slen (length nextstr)))
2897 ((fboundp nextstr) (funcall nextstr name)) 3440 (string-equal (substring name (- flen slen)) nextstr)))
2898 (t nil)) 3441 ((fboundp nextstr) (funcall nextstr name))
2899 (setq ignorep t 3442 (t nil))
2900 ext-list nil 3443 (setq ignorep t
2901 re-list nil) 3444 ext-list nil
2902 (setq ext-list (cdr ext-list)))) 3445 re-list nil)
2903 (while re-list 3446 (setq ext-list (cdr ext-list))))
2904 (setq nextstr (car re-list)) 3447 (while re-list
2905 (if (cond 3448 (setq nextstr (car re-list))
2906 ((stringp nextstr) (string-match nextstr name)) 3449 (if (cond
2907 ((fboundp nextstr) (funcall nextstr name)) 3450 ((stringp nextstr) (string-match nextstr name))
2908 (t nil)) 3451 ((fboundp nextstr) (funcall nextstr name))
2909 (setq ignorep t 3452 (t nil))
2910 re-list nil) 3453 (setq ignorep t
2911 (setq re-list (cdr re-list)))) 3454 re-list nil)
2912 ;; return the result 3455 (setq re-list (cdr re-list))))
2913 (if ignorep 3456 ;; return the result
2914 (setq ido-ignored-list (cons name ido-ignored-list))) 3457 (if ignorep
2915 (set-match-data data) 3458 (setq ido-ignored-list (cons name ido-ignored-list)))
2916 ignorep)))) 3459 ignorep)))))
2917
2918 3460
2919 ;; Private variable used by `ido-word-matching-substring'. 3461 ;; Private variable used by `ido-word-matching-substring'.
2920 (defvar ido-change-word-sub) 3462 (defvar ido-change-word-sub)
2921 3463
2922 (defun ido-find-common-substring (items subs) 3464 (defun ido-find-common-substring (items subs)
2985 (set-buffer temp-buf) 3527 (set-buffer temp-buf)
2986 (setq win (get-buffer-window temp-buf)) 3528 (setq win (get-buffer-window temp-buf))
2987 (if (pos-visible-in-window-p (point-max) win) 3529 (if (pos-visible-in-window-p (point-max) win)
2988 (if (or ido-completion-buffer-all-completions (boundp 'ido-completion-buffer-full)) 3530 (if (or ido-completion-buffer-all-completions (boundp 'ido-completion-buffer-full))
2989 (set-window-start win (point-min)) 3531 (set-window-start win (point-min))
2990 (set (make-local-variable 'ido-completion-buffer-full) t) 3532 (with-no-warnings
3533 (set (make-local-variable 'ido-completion-buffer-full) t))
2991 (setq full-list t 3534 (setq full-list t
2992 display-it t)) 3535 display-it t))
2993 (scroll-other-window)) 3536 (scroll-other-window))
2994 (set-buffer buf)) 3537 (set-buffer buf))
2995 (setq display-it t)) 3538 (setq display-it t))
2996 (if display-it 3539 (if display-it
2997 (with-output-to-temp-buffer ido-completion-buffer 3540 (with-output-to-temp-buffer ido-completion-buffer
2998 (let ((completion-list (ido-sort-list 3541 (let ((completion-list (sort
2999 (cond 3542 (cond
3000 (ido-use-merged-list 3543 (ido-use-merged-list
3001 (ido-flatten-merged-list (or ido-matches ido-cur-list))) 3544 (ido-flatten-merged-list (or ido-matches ido-cur-list)))
3002 ((or full-list ido-completion-buffer-all-completions) 3545 ((or full-list ido-completion-buffer-all-completions)
3003 (ido-all-completions)) 3546 (ido-all-completions))
3004 (t 3547 (t
3005 (copy-sequence (or ido-matches ido-cur-list))))))) 3548 (copy-sequence (or ido-matches ido-cur-list))))
3549 #'ido-file-lessp)))
3006 (if (featurep 'xemacs) 3550 (if (featurep 'xemacs)
3007 ;; XEmacs extents are put on by default, doesn't seem to be 3551 ;; XEmacs extents are put on by default, doesn't seem to be
3008 ;; any way of switching them off. 3552 ;; any way of switching them off.
3009 ;; This obscure code avoids a byte compiler warning in Emacs. 3553 ;; This obscure code avoids a byte compiler warning in Emacs.
3010 (let ((f 'display-completion-list)) 3554 (let ((f 'display-completion-list))
3041 (setq file (concat ido-current-directory file))) 3585 (setq file (concat ido-current-directory file)))
3042 (when (and file 3586 (when (and file
3043 (file-exists-p file) 3587 (file-exists-p file)
3044 (not (file-directory-p file)) 3588 (not (file-directory-p file))
3045 (file-writable-p ido-current-directory) 3589 (file-writable-p ido-current-directory)
3046 (yes-or-no-p (concat "Delete " file " "))) 3590 (yes-or-no-p (concat "Delete " file "? ")))
3047 (delete-file file) 3591 (delete-file file)
3048 ;; Check if file still exists. 3592 ;; Check if file still exists.
3049 (if (file-exists-p file) 3593 (if (file-exists-p file)
3050 ;; file could not be deleted 3594 ;; file could not be deleted
3051 (setq ido-rescan t) 3595 (setq ido-rescan t)
3054 3598
3055 3599
3056 ;;; VISIT CHOSEN BUFFER 3600 ;;; VISIT CHOSEN BUFFER
3057 (defun ido-visit-buffer (buffer method &optional record) 3601 (defun ido-visit-buffer (buffer method &optional record)
3058 "Visit file named FILE according to METHOD. 3602 "Visit file named FILE according to METHOD.
3059 Record command in command-history if optional RECORD is non-nil." 3603 Record command in `command-history' if optional RECORD is non-nil."
3060 3604
3061 (let (win newframe) 3605 (let (win newframe)
3062 (cond 3606 (cond
3063 ((eq method 'kill) 3607 ((eq method 'kill)
3064 (if record 3608 (if record
3127 default is to show it in the same window, unless it is already visible 3671 default is to show it in the same window, unless it is already visible
3128 in another frame. 3672 in another frame.
3129 3673
3130 As you type in a string, all of the buffers matching the string are 3674 As you type in a string, all of the buffers matching the string are
3131 displayed if substring-matching is used \(default). Look at 3675 displayed if substring-matching is used \(default). Look at
3132 `ido-enable-prefix' and `ido-toggle-prefix'. When you have found the 3676 `ido-enable-prefix' and `ido-toggle-prefix'. When you have found the
3133 buffer you want, it can then be selected. As you type, most keys have their 3677 buffer you want, it can then be selected. As you type, most keys have
3134 normal keybindings, except for the following: \\<ido-mode-map> 3678 their normal keybindings, except for the following: \\<ido-buffer-completion-map>
3135 3679
3136 RET Select the buffer at the front of the list of matches. If the 3680 RET Select the buffer at the front of the list of matches. If the
3137 list is empty, possibly prompt to create new buffer. 3681 list is empty, possibly prompt to create new buffer.
3138 3682
3139 \\[ido-select-text] Select the current prompt as the buffer. 3683 \\[ido-select-text] Select the current prompt as the buffer.
3169 (defun ido-display-buffer () 3713 (defun ido-display-buffer ()
3170 "Display a buffer in another window but don't select it. 3714 "Display a buffer in another window but don't select it.
3171 The buffer name is selected interactively by typing a substring. 3715 The buffer name is selected interactively by typing a substring.
3172 For details of keybindings, do `\\[describe-function] ido'." 3716 For details of keybindings, do `\\[describe-function] ido'."
3173 (interactive) 3717 (interactive)
3174 (ido-buffer-internal 'display 'display-buffer)) 3718 (ido-buffer-internal 'display 'display-buffer nil nil nil 'ignore))
3175 3719
3176 ;;;###autoload 3720 ;;;###autoload
3177 (defun ido-kill-buffer () 3721 (defun ido-kill-buffer ()
3178 "Kill a buffer. 3722 "Kill a buffer.
3179 The buffer name is selected interactively by typing a substring. 3723 The buffer name is selected interactively by typing a substring.
3180 For details of keybindings, do `\\[describe-function] ido'." 3724 For details of keybindings, do `\\[describe-function] ido'."
3181 (interactive) 3725 (interactive)
3182 (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " (buffer-name (current-buffer)))) 3726 (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " (buffer-name (current-buffer)) nil 'ignore))
3183 3727
3184 ;;;###autoload 3728 ;;;###autoload
3185 (defun ido-insert-buffer () 3729 (defun ido-insert-buffer ()
3186 "Insert contents of a buffer in current buffer after point. 3730 "Insert contents of a buffer in current buffer after point.
3187 The buffer name is selected interactively by typing a substring. 3731 The buffer name is selected interactively by typing a substring.
3188 For details of keybindings, do `\\[describe-function] ido'." 3732 For details of keybindings, do `\\[describe-function] ido'."
3189 (interactive) 3733 (interactive)
3190 (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: ")) 3734 (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil nil 'ido-enter-insert-file))
3191 3735
3192 ;;;###autoload 3736 ;;;###autoload
3193 (defun ido-switch-buffer-other-frame () 3737 (defun ido-switch-buffer-other-frame ()
3194 "Switch to another buffer and show it in another frame. 3738 "Switch to another buffer and show it in another frame.
3195 The buffer name is selected interactively by typing a substring. 3739 The buffer name is selected interactively by typing a substring.
3203 (defun ido-find-file-in-dir (dir) 3747 (defun ido-find-file-in-dir (dir)
3204 "Switch to another file starting from DIR." 3748 "Switch to another file starting from DIR."
3205 (interactive "DDir: ") 3749 (interactive "DDir: ")
3206 (if (not (equal (substring dir -1) "/")) 3750 (if (not (equal (substring dir -1) "/"))
3207 (setq dir (concat dir "/"))) 3751 (setq dir (concat dir "/")))
3208 (ido-file-internal ido-default-file-method nil dir)) 3752 (ido-file-internal ido-default-file-method nil dir nil nil nil 'ignore))
3209 3753
3210 ;;;###autoload 3754 ;;;###autoload
3211 (defun ido-find-file () 3755 (defun ido-find-file ()
3212 "Edit file with name obtained via minibuffer. 3756 "Edit file with name obtained via minibuffer.
3213 The file is displayed according to `ido-default-file-method' -- the 3757 The file is displayed according to `ido-default-file-method' -- the
3214 default is to show it in the same window, unless it is already 3758 default is to show it in the same window, unless it is already
3215 visible in another frame. 3759 visible in another frame.
3216 3760
3217 The file name is selected interactively by typing a substring. As you type 3761 The file name is selected interactively by typing a substring. As you
3218 in a string, all of the filenames matching the string are displayed if 3762 type in a string, all of the filenames matching the string are displayed
3219 substring-matching is used \(default). Look at `ido-enable-prefix' and 3763 if substring-matching is used \(default). Look at `ido-enable-prefix' and
3220 `ido-toggle-prefix'. When you have found the filename you want, it can 3764 `ido-toggle-prefix'. When you have found the filename you want, it can
3221 then be selected. As you type, most keys have their normal keybindings, 3765 then be selected. As you type, most keys have their normal keybindings,
3222 except for the following: \\<ido-mode-map> 3766 except for the following: \\<ido-file-completion-map>
3223 3767
3224 RET Select the file at the front of the list of matches. If the 3768 RET Select the file at the front of the list of matches. If the
3225 list is empty, possibly prompt to create new file. 3769 list is empty, possibly prompt to create new file.
3226 3770
3227 \\[ido-select-text] Select the current prompt as the buffer or file. 3771 \\[ido-select-text] Select the current prompt as the buffer or file.
3236 \\[ido-edit-input] Edit input string (including directory). 3780 \\[ido-edit-input] Edit input string (including directory).
3237 \\[ido-prev-work-directory] or \\[ido-next-work-directory] go to previous/next directory in work directory history. 3781 \\[ido-prev-work-directory] or \\[ido-next-work-directory] go to previous/next directory in work directory history.
3238 \\[ido-merge-work-directories] search for file in the work directory history. 3782 \\[ido-merge-work-directories] search for file in the work directory history.
3239 \\[ido-forget-work-directory] removes current directory from the work directory history. 3783 \\[ido-forget-work-directory] removes current directory from the work directory history.
3240 \\[ido-prev-work-file] or \\[ido-next-work-file] cycle through the work file history. 3784 \\[ido-prev-work-file] or \\[ido-next-work-file] cycle through the work file history.
3241 \\[ido-wide-find-file] and \\[ido-wide-find-dir] prompts and uses find to locate files or directories. 3785 \\[ido-wide-find-file-or-pop-dir] and \\[ido-wide-find-dir-or-delete-dir] prompts and uses find to locate files or directories.
3242 \\[ido-make-directory] prompts for a directory to create in current directory. 3786 \\[ido-make-directory] prompts for a directory to create in current directory.
3243 \\[ido-fallback-command] Fallback to non-ido version of current command. 3787 \\[ido-fallback-command] Fallback to non-ido version of current command.
3244 \\[ido-toggle-regexp] Toggle regexp searching. 3788 \\[ido-toggle-regexp] Toggle regexp searching.
3245 \\[ido-toggle-prefix] Toggle between substring and prefix matching. 3789 \\[ido-toggle-prefix] Toggle between substring and prefix matching.
3246 \\[ido-toggle-case] Toggle case-sensitive searching of file names. 3790 \\[ido-toggle-case] Toggle case-sensitive searching of file names.
3296 (defun ido-display-file () 3840 (defun ido-display-file ()
3297 "Display a file in another window but don't select it. 3841 "Display a file in another window but don't select it.
3298 The file name is selected interactively by typing a substring. 3842 The file name is selected interactively by typing a substring.
3299 For details of keybindings, do `\\[describe-function] ido-find-file'." 3843 For details of keybindings, do `\\[describe-function] ido-find-file'."
3300 (interactive) 3844 (interactive)
3301 (ido-file-internal 'display)) 3845 (ido-file-internal 'display nil nil nil nil nil 'ignore))
3302 3846
3303 ;;;###autoload 3847 ;;;###autoload
3304 (defun ido-find-file-other-frame () 3848 (defun ido-find-file-other-frame ()
3305 "Switch to another file and show it in another frame. 3849 "Switch to another file and show it in another frame.
3306 The file name is selected interactively by typing a substring. 3850 The file name is selected interactively by typing a substring.
3316 (interactive) 3860 (interactive)
3317 (let ((ido-process-ignore-lists t) 3861 (let ((ido-process-ignore-lists t)
3318 (ido-work-directory-match-only nil) 3862 (ido-work-directory-match-only nil)
3319 (ido-ignore-files (cons "[^/]\\'" ido-ignore-files)) 3863 (ido-ignore-files (cons "[^/]\\'" ido-ignore-files))
3320 (ido-report-no-match nil) 3864 (ido-report-no-match nil)
3865 (ido-confirm-unique-completion t)
3321 (ido-auto-merge-work-directories-length -1)) 3866 (ido-auto-merge-work-directories-length -1))
3322 (ido-file-internal 'write 'write-file nil "Write file: "))) 3867 (ido-file-internal 'write 'write-file nil "Write file: " nil nil 'ignore)))
3323 3868
3324 ;;;###autoload 3869 ;;;###autoload
3325 (defun ido-insert-file () 3870 (defun ido-insert-file ()
3326 "Insert contents of file in current buffer. 3871 "Insert contents of file in current buffer.
3327 The file name is selected interactively by typing a substring. 3872 The file name is selected interactively by typing a substring.
3328 For details of keybindings, do `\\[describe-function] ido-find-file'." 3873 For details of keybindings, do `\\[describe-function] ido-find-file'."
3329 (interactive) 3874 (interactive)
3330 (ido-file-internal 'insert 'insert-file nil "Insert file: ")) 3875 (ido-file-internal 'insert 'insert-file nil "Insert file: " nil nil 'ido-enter-insert-buffer))
3331 3876
3332 ;;;###autoload 3877 ;;;###autoload
3333 (defun ido-dired () 3878 (defun ido-dired ()
3334 "Call dired the ido way. 3879 "Call dired the ido way.
3335 The directory is selected interactively by typing a substring. 3880 The directory is selected interactively by typing a substring.
3406 (make-local-variable 'ido-eoinput)) 3951 (make-local-variable 'ido-eoinput))
3407 (setq ido-eoinput (point)) 3952 (setq ido-eoinput (point))
3408 3953
3409 ;; Handle explicit directory changes 3954 ;; Handle explicit directory changes
3410 (cond 3955 (cond
3411 ((eq ido-cur-item 'buffer) 3956 ((memq ido-cur-item '(buffer list))
3412 ) 3957 )
3413 3958
3414 ((= (length contents) 0) 3959 ((= (length contents) 0)
3415 ) 3960 )
3416 3961
3462 (ido-set-current-directory 4007 (ido-set-current-directory
3463 (if (memq system-type '(windows-nt ms-dos)) 4008 (if (memq system-type '(windows-nt ms-dos))
3464 (expand-file-name "/" ido-current-directory) 4009 (expand-file-name "/" ido-current-directory)
3465 "/")) 4010 "/"))
3466 (setq refresh t)) 4011 (setq refresh t))
4012 ((and (or ido-directory-nonreadable ido-directory-too-big)
4013 (file-directory-p (concat ido-current-directory (file-name-directory contents))))
4014 (ido-set-current-directory
4015 (concat ido-current-directory (file-name-directory contents)))
4016 (setq refresh t))
3467 (t 4017 (t
3468 (ido-trace "try single dir") 4018 (ido-trace "try single dir")
3469 (setq try-single-dir-match t)))) 4019 (setq try-single-dir-match t))))
3470 4020
3471 ((and (string-equal (substring contents -2 -1) "/") 4021 ((and (string-equal (substring contents -2 -1) "/")
3505 ;; Update the list of matches 4055 ;; Update the list of matches
3506 (setq ido-text contents) 4056 (setq ido-text contents)
3507 (ido-set-matches) 4057 (ido-set-matches)
3508 (ido-trace "new " ido-matches) 4058 (ido-trace "new " ido-matches)
3509 4059
3510 (when (and ido-enter-single-matching-directory 4060 (when (and ido-enter-matching-directory
3511 ido-matches 4061 ido-matches
3512 (null (cdr ido-matches)) 4062 (or (eq ido-enter-matching-directory 'first)
4063 (null (cdr ido-matches)))
3513 (ido-final-slash (car ido-matches)) 4064 (ido-final-slash (car ido-matches))
3514 (or try-single-dir-match 4065 (or try-single-dir-match
3515 (eq ido-enter-single-matching-directory t))) 4066 (eq ido-enter-matching-directory t)))
3516 (ido-trace "single match" (car ido-matches)) 4067 (ido-trace "single match" (car ido-matches))
3517 (ido-set-current-directory 4068 (ido-set-current-directory
3518 (concat ido-current-directory (car ido-matches))) 4069 (concat ido-current-directory (car ido-matches)))
3519 (setq ido-exit 'refresh) 4070 (setq ido-exit 'refresh)
3520 (exit-minibuffer)) 4071 (exit-minibuffer))
3521 4072
3522 (when (and (not ido-matches) 4073 (when (and (not ido-matches)
4074 (not ido-directory-nonreadable)
4075 (not ido-directory-too-big)
3523 ;; ido-rescan ? 4076 ;; ido-rescan ?
3524 ido-process-ignore-lists 4077 ido-process-ignore-lists
3525 ido-ignored-list) 4078 ido-ignored-list)
3526 (let ((ido-process-ignore-lists nil) 4079 (let ((ido-process-ignore-lists nil)
3527 (ido-rotate ido-rotate) 4080 (ido-rotate ido-rotate)
3540 ido-rescan 4093 ido-rescan
3541 (not ido-matches) 4094 (not ido-matches)
3542 (memq ido-cur-item '(file dir)) 4095 (memq ido-cur-item '(file dir))
3543 (not (ido-is-root-directory)) 4096 (not (ido-is-root-directory))
3544 (> (length contents) 1) 4097 (> (length contents) 1)
3545 (not (string-match "[$]" contents))) 4098 (not (string-match "[$]" contents))
4099 (not ido-directory-nonreadable)
4100 (not ido-directory-too-big))
3546 (ido-trace "merge?") 4101 (ido-trace "merge?")
3547 (if ido-use-merged-list 4102 (if ido-use-merged-list
3548 (ido-undo-merge-work-directory contents nil) 4103 (ido-undo-merge-work-directory contents nil)
3549 (when (and (eq ido-try-merged-list t) 4104 (when (and (eq ido-try-merged-list t)
3550 (numberp ido-auto-merge-work-directories-length) 4105 (numberp ido-auto-merge-work-directories-length)
3587 (ind (and (consp (car comps)) (> (length (cdr (car comps))) 1) 4142 (ind (and (consp (car comps)) (> (length (cdr (car comps))) 1)
3588 ido-merged-indicator)) 4143 ido-merged-indicator))
3589 first) 4144 first)
3590 4145
3591 (if (and ind ido-use-faces) 4146 (if (and ind ido-use-faces)
3592 (put-text-property 0 1 'face 'ido-indicator-face ind)) 4147 (put-text-property 0 1 'face 'ido-indicator ind))
3593 4148
3594 (if (and ido-use-faces comps) 4149 (if (and ido-use-faces comps)
3595 (let* ((fn (ido-name (car comps))) 4150 (let* ((fn (ido-name (car comps)))
3596 (ln (length fn))) 4151 (ln (length fn)))
3597 (setq first (format "%s" fn)) 4152 (setq first (format "%s" fn))
3598 (put-text-property 0 ln 'face 4153 (put-text-property 0 ln 'face
3599 (if (= (length comps) 1) 4154 (if (= (length comps) 1)
3600 'ido-only-match-face 4155 (if ido-incomplete-regexp
3601 'ido-first-match-face) 4156 'ido-incomplete-regexp
4157 'ido-only-match)
4158 'ido-first-match)
3602 first) 4159 first)
3603 (if ind (setq first (concat first ind))) 4160 (if ind (setq first (concat first ind)))
3604 (setq comps (cons first (cdr comps))))) 4161 (setq comps (cons first (cdr comps)))))
3605 4162
3606 (cond ((null comps) 4163 (cond ((null comps)
3607 (if ido-report-no-match 4164 (cond
3608 (nth 6 ido-decorations) ;; [No Match] 4165 (ido-directory-nonreadable
3609 "")) 4166 (or (nth 8 ido-decorations) " [Not readable]"))
3610 4167 (ido-directory-too-big
4168 (or (nth 9 ido-decorations) " [Too big]"))
4169 (ido-report-no-match
4170 (nth 6 ido-decorations)) ;; [No match]
4171 (t "")))
4172 (ido-incomplete-regexp
4173 (concat " " (car comps)))
3611 ((null (cdr comps)) ;one match 4174 ((null (cdr comps)) ;one match
3612 (concat (if (> (length (ido-name (car comps))) (length name)) 4175 (concat (if (if (not ido-enable-regexp)
3613 ;; when there is one match, show the matching file name in full 4176 (= (length (ido-name (car comps))) (length name))
3614 (concat (nth 4 ido-decorations) ;; [ ... ] 4177 ;; We can't rely on the length of the input
3615 (ido-name (car comps)) 4178 ;; for regexps, so explicitly check for a
3616 (nth 5 ido-decorations)) 4179 ;; complete match
3617 "") 4180 (string-match name (ido-name (car comps)))
4181 (string-equal (match-string 0 (ido-name (car comps)))
4182 (ido-name (car comps))))
4183 ""
4184 ;; when there is one match, show the matching file name in full
4185 (concat (nth 4 ido-decorations) ;; [ ... ]
4186 (ido-name (car comps))
4187 (nth 5 ido-decorations)))
3618 (if (not ido-use-faces) (nth 7 ido-decorations)))) ;; [Matched] 4188 (if (not ido-use-faces) (nth 7 ido-decorations)))) ;; [Matched]
3619 (t ;multiple matches 4189 (t ;multiple matches
3620 (let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999)) 4190 (let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999))
3621 (alternatives 4191 (alternatives
3622 (apply 4192 (apply
3634 (list (or ido-separator (nth 2 ido-decorations)) ; " | " 4204 (list (or ido-separator (nth 2 ido-decorations)) ; " | "
3635 (let ((str (substring com 0))) 4205 (let ((str (substring com 0)))
3636 (if (and ido-use-faces 4206 (if (and ido-use-faces
3637 (not (string= str first)) 4207 (not (string= str first))
3638 (ido-final-slash str)) 4208 (ido-final-slash str))
3639 (put-text-property 0 (length str) 'face 'ido-subdir-face str)) 4209 (put-text-property 0 (length str) 'face 'ido-subdir str))
3640 str))))) 4210 str)))))
3641 comps)))))) 4211 comps))))))
3642 4212
3643 (concat 4213 (concat
3644 ;; put in common completion item -- what you get by pressing tab 4214 ;; put in common completion item -- what you get by pressing tab
3705 ido-temp-list)))) 4275 ido-temp-list))))
3706 (ido-to-end summaries))) 4276 (ido-to-end summaries)))
3707 4277
3708 ;;; Helper functions for other programs 4278 ;;; Helper functions for other programs
3709 4279
4280 (put 'dired-do-rename 'ido 'ignore)
4281 (put 'ibuffer-find-file 'ido 'find-file)
4282 (put 'dired-other-window 'ido 'dir)
4283
4284 ;;;###autoload
4285 (defun ido-read-buffer (prompt &optional default require-match)
4286 "Ido replacement for the built-in `read-buffer'.
4287 Return the name of a buffer selected.
4288 PROMPT is the prompt to give to the user. DEFAULT if given is the default
4289 buffer to be selected, which will go to the front of the list.
4290 If REQUIRE-MATCH is non-nil, an existing buffer must be selected."
4291 (let* ((ido-current-directory nil)
4292 (ido-directory-nonreadable nil)
4293 (ido-directory-too-big nil)
4294 (ido-context-switch-command 'ignore)
4295 (buf (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match)))
4296 (if (eq ido-exit 'fallback)
4297 (let ((read-buffer-function nil))
4298 (run-hook-with-args 'ido-before-fallback-functions 'read-buffer)
4299 (read-buffer prompt default require-match))
4300 buf)))
4301
3710 ;;;###autoload 4302 ;;;###autoload
3711 (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate) 4303 (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
3712 "Read file name, prompting with PROMPT and completing in directory DIR. 4304 "Ido replacement for the built-in `read-file-name'.
4305 Read file name, prompting with PROMPT and completing in directory DIR.
3713 See `read-file-name' for additional parameters." 4306 See `read-file-name' for additional parameters."
3714 (cond 4307 (let (filename)
3715 ((or (eq predicate 'file-directory-p) 4308 (cond
3716 (memq this-command ido-read-file-name-as-directory-commands)) 4309 ((or (eq predicate 'file-directory-p)
3717 (ido-read-directory-name prompt dir default-filename mustmatch initial)) 4310 (eq (get this-command 'ido) 'dir)
3718 ((and (not (memq this-command ido-read-file-name-non-ido)) 4311 (memq this-command ido-read-file-name-as-directory-commands))
3719 (or (null predicate) (eq predicate 'file-exists-p))) 4312 (setq filename
3720 (let (filename 4313 (ido-read-directory-name prompt dir default-filename mustmatch initial))
3721 ido-saved-vc-mt 4314 (if (eq ido-exit 'fallback)
3722 (vc-master-templates (and (boundp 'vc-master-templates) vc-master-templates)) 4315 (setq filename 'fallback)))
3723 (ido-current-directory (expand-file-name (or dir default-directory))) 4316 ((and (not (eq (get this-command 'ido) 'ignore))
3724 (ido-work-directory-index -1) 4317 (not (memq this-command ido-read-file-name-non-ido))
3725 (ido-work-file-index -1) 4318 (or (null predicate) (eq predicate 'file-exists-p)))
3726 (ido-find-literal nil)) 4319 (let* (ido-saved-vc-hb
3727 (setq filename 4320 (ido-context-switch-command
3728 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial)) 4321 (if (eq (get this-command 'ido) 'find-file) nil 'ignore))
3729 (if filename 4322 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
3730 (concat ido-current-directory filename)))) 4323 (minibuffer-completing-file-name t)
3731 (t 4324 (ido-current-directory (ido-expand-directory dir))
3732 (let ((read-file-name-function nil)) 4325 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
3733 (read-file-name prompt dir default-filename mustmatch initial predicate))))) 4326 (ido-directory-too-big (and (not ido-directory-nonreadable)
4327 (ido-directory-too-big-p ido-current-directory)))
4328 (ido-work-directory-index -1)
4329 (ido-work-file-index -1)
4330 (ido-find-literal nil))
4331 (setq ido-exit nil)
4332 (setq filename
4333 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial))
4334 (cond
4335 ((eq ido-exit 'fallback)
4336 (setq filename 'fallback))
4337 ((eq ido-exit 'dired)
4338 (setq filename ido-current-directory))
4339 (filename
4340 (setq filename
4341 (concat ido-current-directory filename))))))
4342 (t
4343 (setq filename 'fallback)))
4344 (if (eq filename 'fallback)
4345 (let ((read-file-name-function nil))
4346 (run-hook-with-args 'ido-before-fallback-functions 'read-file-name)
4347 (read-file-name prompt dir default-filename mustmatch initial predicate))
4348 filename)))
3734 4349
3735 ;;;###autoload 4350 ;;;###autoload
3736 (defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial) 4351 (defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial)
3737 "Read directory name, prompting with PROMPT and completing in directory DIR. 4352 "Ido replacement for the built-in `read-directory-name'.
3738 See `read-file-name' for additional parameters." 4353 Read directory name, prompting with PROMPT and completing in directory DIR.
3739 (let (filename 4354 See `read-directory-name' for additional parameters."
3740 ido-saved-vc-mt 4355 (let* (filename
3741 (ido-current-directory (expand-file-name (or dir default-directory))) 4356 (minibuffer-completing-file-name t)
3742 (ido-work-directory-index -1) 4357 (ido-context-switch-command 'ignore)
3743 (ido-work-file-index -1)) 4358 ido-saved-vc-hb
4359 (ido-current-directory (ido-expand-directory dir))
4360 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
4361 (ido-directory-too-big (and (not ido-directory-nonreadable)
4362 (ido-directory-too-big-p ido-current-directory)))
4363 (ido-work-directory-index -1)
4364 (ido-work-file-index -1))
3744 (setq filename 4365 (setq filename
3745 (ido-read-internal 'dir prompt 'ido-file-history default-dirname mustmatch initial)) 4366 (ido-read-internal 'dir prompt 'ido-file-history default-dirname mustmatch initial))
3746 (if filename 4367 (if filename
3747 (if (and (stringp filename) (string-equal filename ".")) 4368 (if (and (stringp filename) (string-equal filename "."))
3748 ido-current-directory 4369 ido-current-directory
3749 (concat ido-current-directory filename))))) 4370 (concat ido-current-directory filename)))))
3750 4371
4372 ;;;###autoload
4373 (defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def)
4374 "Ido replacement for the built-in `completing-read'.
4375 Read a string in the minibuffer with ido-style completion.
4376 PROMPT is a string to prompt with; normally it ends in a colon and a space.
4377 CHOICES is a list of strings which are the possible completions.
4378 PREDICATE is currently ignored; it is included to be compatible
4379 with `completing-read'.
4380 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
4381 the input is (or completes to) an element of CHOICES or is null.
4382 If the input is null, `ido-completing-read' returns DEF, or an empty
4383 string if DEF is nil, regardless of the value of REQUIRE-MATCH.
4384 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially,
4385 with point positioned at the end.
4386 HIST, if non-nil, specifies a history list.
4387 DEF, if non-nil, is the default value."
4388 (let ((ido-current-directory nil)
4389 (ido-directory-nonreadable nil)
4390 (ido-directory-too-big nil)
4391 (ido-context-switch-command 'ignore)
4392 (ido-choice-list choices))
4393 (ido-read-internal 'list prompt hist def require-match initial-input)))
4394
4395
4396 ;;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
3751 ;;; ido.el ends here 4397 ;;; ido.el ends here