Commit | Line | Data |
---|---|---|
06b60517 | 1 | ;;; ido.el --- interactively do things with buffers and files |
789d1bf0 | 2 | |
ba318903 | 3 | ;; Copyright (C) 1996-2014 Free Software Foundation, Inc. |
789d1bf0 KS |
4 | |
5 | ;; Author: Kim F. Storm <storm@cua.dk> | |
6 | ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk> | |
7 | ;; Keywords: extensions convenience | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
789d1bf0 | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
789d1bf0 KS |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
789d1bf0 | 23 | |
789d1bf0 KS |
24 | |
25 | ;;; Commentary: | |
26 | ||
27 | ;; Ido - interactive do - switches between buffers and opens files and | |
28 | ;; directories with a minimum of keystrokes. It is a superset of | |
29 | ;; iswitchb, the interactive buffer switching package by Stephen Eglen. | |
30 | ||
31 | ;; Interactive substring matching | |
32 | ;; ------------------------------ | |
33 | ;; | |
34 | ;; As you type in a substring, the list of buffers or files currently | |
35 | ;; matching the substring are displayed as you type. The list is | |
36 | ;; ordered so that the most recent buffers or files visited come at | |
37 | ;; the start of the list. | |
38 | ;; | |
39 | ;; The buffer or file at the start of the list will be the one visited | |
40 | ;; when you press RETURN. By typing more of the substring, the list is | |
41 | ;; narrowed down so that gradually the buffer or file you want will be | |
42 | ;; at the top of the list. Alternatively, you can use C-s and C-r (or | |
43 | ;; the right and left arrow keys) to rotate buffer or file names in the | |
44 | ;; list until the one you want is at the top of the list. | |
45 | ;; | |
46 | ;; Completion is also available so that you can see what is common to | |
47 | ;; all of the matching buffers or files as you type. | |
48 | ;; | |
49 | ;; Example: | |
50 | ;; | |
51 | ;; If I have two buffers called "123456" and "123", with "123456" the | |
52 | ;; most recent, when I use ido-switch-buffer, I first of all get | |
53 | ;; presented with the list of all the buffers | |
54 | ;; | |
04c95147 | 55 | ;; Buffer: {123456 | 123} |
789d1bf0 KS |
56 | ;; |
57 | ;; If I then press 2: | |
04c95147 | 58 | ;; Buffer: 2[3]{123456 | 123} |
789d1bf0 KS |
59 | ;; |
60 | ;; The list in {...} are the matching buffers, most recent first | |
61 | ;; (buffers visible in the current frame are put at the end of the | |
62 | ;; list by default). At any time I can select the item at the head of | |
f2801d2a KS |
63 | ;; the list by pressing RET. I can also put the first element at the |
64 | ;; end of the list by pressing C-s or [right], or bring the last | |
65 | ;; element to the head of the list by pressing C-r or [left]. | |
789d1bf0 KS |
66 | ;; |
67 | ;; The item in [...] indicates what can be added to my input by | |
68 | ;; pressing TAB. In this case, I will get "3" added to my input. | |
69 | ||
70 | ;; So, I press TAB: | |
04c95147 | 71 | ;; Buffer: 23{123456 | 123} |
789d1bf0 KS |
72 | ;; |
73 | ;; At this point, I still have two matching buffers. | |
74 | ;; If I want the first buffer in the list, I simply press RET. If I | |
75 | ;; wanted the second in the list, I could press C-s to move it to the | |
76 | ;; top of the list and then RET to select it. | |
77 | ;; | |
78 | ;; However, if I type 4, I only have one match left: | |
04c95147 KS |
79 | ;; Buffer: 234[123456] |
80 | ;; | |
81 | ;; Since there is only one matching buffer left, it is given in [] and | |
82 | ;; it is shown in the `ido-only-match' face (ForestGreen). I can now | |
83 | ;; press TAB or RET to go to that buffer. | |
789d1bf0 | 84 | ;; |
04c95147 KS |
85 | ;; If I want to create a new buffer named "234", I press C-j instead of |
86 | ;; TAB or RET. | |
789d1bf0 | 87 | ;; |
04c95147 | 88 | ;; If instead, I type "a": |
789d1bf0 KS |
89 | ;; Buffer: 234a [No match] |
90 | ;; There are no matching buffers. If I press RET or TAB, I can be | |
91 | ;; prompted to create a new buffer called "234a". | |
92 | ;; | |
93 | ;; Of course, where this function comes in really useful is when you | |
94 | ;; can specify the buffer using only a few keystrokes. In the above | |
95 | ;; example, the quickest way to get to the "123456" file would be | |
96 | ;; just to type 4 and then RET (assuming there isn't any newer buffer | |
97 | ;; with 4 in its name). | |
98 | ||
99 | ;; Likewise, if you use C-x C-f (ido-find-file), the list of files and | |
100 | ;; directories in the current directory is provided in the same | |
101 | ;; fashion as the buffers above. The files and directories are | |
102 | ;; normally sorted in alphabetical order, but the most recently | |
103 | ;; visited directory is placed first to speed up navigating to | |
104 | ;; directories that you have visited recently. | |
105 | ;; | |
106 | ;; In addition to scrolling through the list using [right] and [left], | |
107 | ;; you can use [up] and [down] to quickly scroll the list to the next | |
108 | ;; or previous subdirectory. | |
109 | ;; | |
110 | ;; To go down into a subdirectory, and continue the file selection on | |
111 | ;; the files in that directory, simply move the directory to the head | |
112 | ;; of the list and hit RET. | |
113 | ;; | |
114 | ;; To go up to the parent directory, delete any partial file name | |
115 | ;; already specified (e.g. using [backspace]) and hit [backspace]. | |
116 | ;; | |
117 | ;; To go to the root directory (on the current drive), enter two | |
118 | ;; slashes. On MS-DOS or Windows, to select the root of another | |
119 | ;; drive, enter X:/ where X is the drive letter. You can also visit | |
120 | ;; files on other hosts using the ange-ftp notations `/host:' and | |
121 | ;; `/user@host:'. See the variable `ido-slow-ftp-hosts' if you want | |
71296446 | 122 | ;; to inhibit the ido substring matching for ftp access. |
789d1bf0 KS |
123 | ;; |
124 | ;; If for some reason you cannot specify the proper file using | |
125 | ;; ido-find-file, you can press C-f to enter the normal find-file. | |
126 | ;; You can also press C-b to drop into ido-switch-buffer. | |
127 | ||
128 | ;; See the doc string of ido-switch-buffer and ido-find-file for full | |
129 | ;; keybindings and features. | |
130 | ;; (describe-function 'ido-find-file) | |
131 | ||
132 | ;; Hidden buffers and files | |
133 | ;; ------------------------ | |
134 | ;; | |
135 | ;; Normally, ido does not include hidden buffers (whose name starts | |
136 | ;; with a space) and hidden files and directories (whose name starts | |
137 | ;; with `.') in the list of possible completions. However, if the | |
138 | ;; substring you enter does not match any of the visible buffers or | |
139 | ;; files, ido will automatically look for completions among the hidden | |
140 | ;; buffers or files. | |
141 | ;; | |
142 | ;; You can toggle display of the hidden buffers and files with C-a. | |
143 | ||
144 | ;; Additional functionality | |
145 | ;; ------------------------ | |
146 | ;; | |
147 | ;; After C-x b, the buffer at the head of the list can be killed by | |
148 | ;; pressing C-k. If the buffer needs saving, you will be queried | |
149 | ;; before the buffer is killed. | |
150 | ;; | |
151 | ;; Likewise, after C-x C-f, you can delete (i.e. physically remove) | |
152 | ;; the file at the head of the list with C-k. You will always be | |
153 | ;; asked for confirmation before the file is deleted. | |
154 | ;; | |
155 | ;; If you enter C-x b to switch to a buffer visiting a given file, and | |
156 | ;; you find that the file you are after is not in any buffer, you can | |
157 | ;; press C-f to immediately drop into ido-find-file. And you can | |
158 | ;; switch back to buffer selection with C-b. | |
159 | ||
160 | ;; Prefix matching | |
161 | ;; --------------- | |
162 | ;; | |
163 | ;; The standard way of completion with Unix-shells and Emacs is to insert a | |
0e55c076 | 164 | ;; PREFIX and then hitting TAB (or another completion key). Cause of this |
d11320e5 | 165 | ;; behavior has become second nature to a lot of Emacs users, Ido offers in |
789d1bf0 | 166 | ;; addition to the default substring-matching-method (look above) also the |
0e55c076 | 167 | ;; prefix-matching-method. The kind of matching is the only difference to |
789d1bf0 KS |
168 | ;; the description of the substring-matching above. |
169 | ;; | |
170 | ;; You can toggle prefix matching with C-p. | |
171 | ;; | |
172 | ;; Example: | |
173 | ;; | |
174 | ;; If you have again two Buffers "123456" and "123" then hitting "2" does | |
f2801d2a | 175 | ;; not match because "2" is not a PREFIX in any of the buffer-names. |
789d1bf0 KS |
176 | |
177 | ;; Flexible matching | |
178 | ;; ----------------- | |
179 | ;; | |
180 | ;; If you set ido-enable-flex-matching, ido will do a more flexible | |
181 | ;; matching (unless regexp matching is active) to find possible matches | |
182 | ;; among the available buffer or file names if no matches are found using | |
183 | ;; the normal prefix or substring matching. | |
184 | ;; | |
185 | ;; The flexible matching implies that any item which simply contains all | |
186 | ;; of the entered characters in the specified sequence will match. | |
187 | ;; | |
188 | ;; Example: | |
189 | ;; | |
190 | ;; If you have four files "alpha", "beta", "gamma", and "delta", | |
191 | ;; entering "aa" will match "alpha" and "gamma", while "ea" matches | |
192 | ;; "beta" and "delta". If prefix matching is also active, "aa" only | |
193 | ;; matches "alpha", while "ea" does not match any files. | |
194 | ||
195 | ;; Regexp matching | |
196 | ;; --------------- | |
197 | ;; | |
198 | ;; There is limited provision for regexp matching within ido, | |
199 | ;; enabled through `ido-enable-regexp' (toggle with C-t). | |
f2801d2a KS |
200 | ;; This allows you to type `[ch]$' for example and see all file names |
201 | ;; ending in `c' or `h'. | |
202 | ;; | |
203 | ;; Note: ido-style completion is inhibited when you enable regexp matching. | |
789d1bf0 KS |
204 | |
205 | ||
206 | ;; Customization | |
207 | ;; ------------- | |
208 | ;; | |
d11320e5 | 209 | ;; Customize the Ido group to change the Ido functionality. |
789d1bf0 | 210 | ;; |
3729cc87 KS |
211 | ;; To modify the keybindings, use the ido-setup-hook. For example: |
212 | ;;(add-hook 'ido-setup-hook 'ido-my-keys) | |
789d1bf0 KS |
213 | ;; |
214 | ;;(defun ido-my-keys () | |
215 | ;; "Add my keybindings for ido." | |
facf67fd | 216 | ;; (define-key ido-completion-map " " 'ido-next-match) |
789d1bf0 KS |
217 | ;; ) |
218 | ||
219 | ;; Seeing all the matching buffers or files | |
220 | ;; ---------------------------------------- | |
221 | ;; | |
222 | ;; If you have many matching files, they may not all fit onto one | |
223 | ;; line of the minibuffer. Normally, the minibuffer window will grow | |
224 | ;; to show you more of the matching files (depending on the setting | |
225 | ;; of the variables `resize-mini-windows' and `max-mini-window-height'). | |
226 | ;; If you want ido to behave differently from the default minibuffer | |
fffa137c | 227 | ;; resizing behavior, set the variable `ido-max-window-height'. |
789d1bf0 KS |
228 | ;; |
229 | ;; Also, to improve the responsiveness of ido, the maximum number of | |
230 | ;; matching items is limited to 12, but you can increase or removed | |
231 | ;; this limit via the `ido-max-prospects' variable. | |
232 | ||
233 | ;; To see a full list of all matching buffers in a separate buffer, | |
234 | ;; hit ? or press TAB when there are no further completions to the | |
235 | ;; substring. Repeated TAB presses will scroll you through this | |
236 | ;; separate buffer. | |
237 | ||
238 | ;; Changing the list of files | |
239 | ;; -------------------------- | |
240 | ||
241 | ;; By default, the list of current files is most recent first, | |
242 | ;; oldest last, with the exception that the files visible in the | |
243 | ;; current frame are put at the end of the list. A hook exists to | |
244 | ;; allow other functions to order the list. For example, if you add: | |
245 | ;; | |
246 | ;; (add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end) | |
247 | ;; | |
248 | ;; then all files matching "Summary" are moved to the end of the | |
249 | ;; list. (I find this handy for keeping the INBOX Summary and so on | |
250 | ;; out of the way.) It also moves files matching "output\*$" to the | |
90a02640 | 251 | ;; end of the list (these are created by AUCTeX when compiling.) |
789d1bf0 KS |
252 | ;; Other functions could be made available which alter the list of |
253 | ;; matching files (either deleting or rearranging elements.) | |
254 | ||
255 | ;; Highlighting | |
256 | ;; ------------ | |
257 | ||
258 | ;; The highlighting of matching items is controlled via ido-use-faces. | |
ccba8bb6 KS |
259 | ;; The faces used are ido-first-match, ido-only-match and |
260 | ;; ido-subdir. | |
da6062e6 | 261 | ;; Coloring of the matching item was suggested by |
789d1bf0 KS |
262 | ;; Carsten Dominik (dominik@strw.leidenuniv.nl). |
263 | ||
264 | ;; Replacement for read-buffer and read-file-name | |
265 | ;; ---------------------------------------------- | |
266 | ||
267 | ;; ido-read-buffer and ido-read-file-name have been written to be drop | |
268 | ;; in replacements for the normal buffer and file name reading | |
269 | ;; functions `read-buffer' and `read-file-name'. | |
270 | ||
271 | ;; To use ido for all buffer and file selections in Emacs, customize the | |
272 | ;; variable `ido-everywhere'. | |
273 | ||
0e55c076 | 274 | ;; Using ido-like behavior in other Lisp packages |
789d1bf0 KS |
275 | ;; ----------------------------------------------- |
276 | ||
277 | ;; If you don't want to rely on the `ido-everywhere' functionality, | |
278 | ;; ido-read-buffer, ido-read-file-name, and ido-read-directory-name | |
279 | ;; can be used by other packages to read a buffer name, a file name, | |
d11320e5 | 280 | ;; or a directory name in the Ido way. |
789d1bf0 | 281 | |
09ae5da1 | 282 | ;;; Acknowledgments |
04c95147 KS |
283 | |
284 | ;; Infinite amounts of gratitude goes to Stephen Eglen <stephen@cns.ed.ac.uk> | |
285 | ;; who wrote iswitch-buffer mode - from which I ripped off 99% of the code | |
286 | ;; for ido-switch-buffer and found the inspiration for ido-find-file. | |
287 | ;; The ido package would never have existed without his work. | |
288 | ||
289 | ;; Also thanks to Klaus Berndl, Rohit Namjoshi, Robert Fenk, Alex | |
290 | ;; Schroeder, Bill Benedetto, Stephen Eglen, and many others for bug | |
291 | ;; fixes and improvements. | |
292 | ||
293 | ;;; History | |
294 | ||
295 | ;; Since I discovered Stephen Eglen's excellent iswitchb package, I just | |
296 | ;; couldn't live without it, but once being addicted to switching buffers | |
297 | ;; with a minimum of keystrokes, I soon found that opening files in the | |
298 | ;; old-fashioned way was just too slow - so I decided to write a package | |
299 | ;; which could open files with the same speed and ease as iswitchb could | |
300 | ;; switch buffers. | |
301 | ||
302 | ;; I originally wrote a separate ifindf.el package based on a copy of | |
303 | ;; iswitchb.el, which did for opening files what iswitchb did for | |
304 | ;; switching buffers. Along the way, I corrected a few errors in | |
305 | ;; ifindf which could have found its way back into iswitchb, but since | |
306 | ;; most of the functionality of the two package was practically | |
307 | ;; identical, I decided that the proper thing to do was to merge my | |
308 | ;; ifindf package back into iswitchb. | |
309 | ;; | |
310 | ;; This is basically what ido (interactively do) is all about; but I | |
a87ef899 | 311 | ;; found it awkward to merge my changes into the "iswitchb-" namespace, |
04c95147 KS |
312 | ;; so I invented a common "ido-" namespace for the merged packages. |
313 | ;; | |
314 | ;; This version is based on ido.el version 1.57 released on | |
0e55c076 | 315 | ;; gnu.emacs.sources adapted for Emacs 22.1 to use command remapping |
04c95147 KS |
316 | ;; and optionally hooking the read-buffer and read-file-name functions. |
317 | ;; | |
318 | ;; Prefix matching was added by Klaus Berndl <klaus.berndl@sdm.de> based on | |
319 | ;; an idea of Yuji Minejima <ggb01164@nifty.ne.jp> and his mcomplete-package. | |
320 | ||
789d1bf0 KS |
321 | |
322 | ;;; Code: | |
323 | ||
9caf8a8f | 324 | (defvar recentf-list) |
b2ddf2d2 | 325 | |
789d1bf0 KS |
326 | ;;; User Variables |
327 | ;; | |
328 | ;; These are some things you might want to change. | |
329 | ||
330 | (defun ido-fractionp (n) | |
0e55c076 | 331 | "Return t if N is a fraction." |
789d1bf0 KS |
332 | (and (numberp n) (> n 0.0) (<= n 1.0))) |
333 | ||
334 | (defgroup ido nil | |
335 | "Switch between files using substrings." | |
336 | :group 'extensions | |
337 | :group 'convenience | |
bf247b6e | 338 | :version "22.1" |
789d1bf0 | 339 | :link '(emacs-commentary-link :tag "Commentary" "ido.el") |
ed85dee6 RS |
340 | :link '(emacs-library-link :tag "Lisp File" "ido.el") |
341 | :link '(custom-manual "(ido) Top") | |
342 | :link '(info-link "(ido) Customization")) | |
789d1bf0 KS |
343 | |
344 | ;;;###autoload | |
345 | (defcustom ido-mode nil | |
0e55c076 XF |
346 | "Determines for which buffer/file Ido should be enabled. |
347 | The following values are possible: | |
d11320e5 | 348 | - `buffer': Turn only on Ido buffer behavior (switching, killing, |
71296446 | 349 | displaying...) |
d11320e5 JB |
350 | - `file': Turn only on Ido file behavior (finding, writing, inserting...) |
351 | - `both': Turn on Ido buffer and file behavior. | |
352 | - nil: Turn off any Ido switching. | |
789d1bf0 KS |
353 | |
354 | Setting this variable directly does not take effect; | |
355 | use either \\[customize] or the function `ido-mode'." | |
06b60517 | 356 | :set #'(lambda (_symbol value) |
789d1bf0 | 357 | (ido-mode value)) |
7103fd59 | 358 | :initialize 'custom-initialize-default |
789d1bf0 KS |
359 | :require 'ido |
360 | :link '(emacs-commentary-link "ido.el") | |
1b00bc64 | 361 | :set-after '(ido-save-directory-list-file |
b97f1994 | 362 | ;; This will clear ido-unc-hosts-cache, so set it |
1b00bc64 | 363 | ;; before loading history file. |
b97f1994 | 364 | ido-unc-hosts) |
71296446 | 365 | :type '(choice (const :tag "Turn on only buffer" buffer) |
789d1bf0 KS |
366 | (const :tag "Turn on only file" file) |
367 | (const :tag "Turn on both buffer and file" both) | |
368 | (const :tag "Switch off all" nil)) | |
369 | :group 'ido) | |
370 | ||
789d1bf0 | 371 | (defcustom ido-case-fold case-fold-search |
9201cc28 | 372 | "Non-nil if searching of buffer and file names should ignore case." |
789d1bf0 KS |
373 | :type 'boolean |
374 | :group 'ido) | |
375 | ||
376 | (defcustom ido-ignore-buffers | |
377 | '("\\` ") | |
9201cc28 | 378 | "List of regexps or functions matching buffer names to ignore. |
789d1bf0 KS |
379 | For example, traditional behavior is not to list buffers whose names begin |
380 | with a space, for which the regexp is `\\` '. See the source file for | |
79164cf4 | 381 | example functions that filter buffer names." |
789d1bf0 KS |
382 | :type '(repeat (choice regexp function)) |
383 | :group 'ido) | |
384 | ||
385 | (defcustom ido-ignore-files | |
386 | '("\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./") | |
9201cc28 | 387 | "List of regexps or functions matching file names to ignore. |
789d1bf0 KS |
388 | For example, traditional behavior is not to list files whose names begin |
389 | with a #, for which the regexp is `\\`#'. See the source file for | |
390 | example functions that filter filenames." | |
391 | :type '(repeat (choice regexp function)) | |
392 | :group 'ido) | |
393 | ||
394 | (defcustom ido-ignore-extensions t | |
9201cc28 | 395 | "Non-nil means ignore files in `completion-ignored-extensions' list." |
789d1bf0 KS |
396 | :type 'boolean |
397 | :group 'ido) | |
398 | ||
399 | (defcustom ido-show-dot-for-dired nil | |
9201cc28 | 400 | "Non-nil means to always put . as the first item in file name lists. |
a09e21bf | 401 | This allows the current directory to be opened immediately with `dired'." |
789d1bf0 KS |
402 | :type 'boolean |
403 | :group 'ido) | |
404 | ||
1de0ae85 | 405 | (defcustom ido-file-extensions-order nil |
9201cc28 | 406 | "List of file extensions specifying preferred order of file selections. |
1de0ae85 KS |
407 | Each element is either a string with `.' as the first char, an empty |
408 | string matching files without extension, or t which is the default order | |
616e8e5f | 409 | for files with an unlisted file extension." |
1de0ae85 KS |
410 | :type '(repeat (choice string |
411 | (const :tag "Default order" t))) | |
412 | :group 'ido) | |
413 | ||
789d1bf0 KS |
414 | (defcustom ido-ignore-directories |
415 | '("\\`CVS/" "\\`\\.\\./" "\\`\\./") | |
9201cc28 | 416 | "List of regexps or functions matching sub-directory names to ignore." |
789d1bf0 KS |
417 | :type '(repeat (choice regexp function)) |
418 | :group 'ido) | |
419 | ||
420 | (defcustom ido-ignore-directories-merge nil | |
9201cc28 | 421 | "List of regexps or functions matching directory names to ignore during merge. |
362cdb61 | 422 | Directory names matched by one of the regexps in this list are not inserted |
789d1bf0 KS |
423 | in merged file and directory lists." |
424 | :type '(repeat (choice regexp function)) | |
425 | :group 'ido) | |
426 | ||
3da360a7 SM |
427 | ;; Examples for setting the value of ido-ignore-buffers |
428 | ;;(defun ido-ignore-c-mode (name) | |
429 | ;; "Ignore all c mode buffers -- example function for ido." | |
430 | ;; (with-current-buffer name | |
431 | ;; (derived-mode-p 'c-mode))) | |
432 | ;; | |
94912b88 | 433 | ;;(setq ido-ignore-buffers '("\\` " ido-ignore-c-mode)) |
789d1bf0 | 434 | |
3da360a7 | 435 | ;; Examples for setting the value of ido-ignore-files |
94912b88 | 436 | ;;(setq ido-ignore-files '("\\` " "\\.c\\'" "\\.h\\'")) |
789d1bf0 | 437 | |
a11ad595 | 438 | (defcustom ido-default-file-method 'raise-frame |
9201cc28 | 439 | "How to visit a new file when using `ido-find-file'. |
789d1bf0 | 440 | Possible values: |
a11ad595 KS |
441 | `selected-window' Show new file in selected window |
442 | `other-window' Show new file in another window (same frame) | |
443 | `display' Display file in another window without selecting to it | |
444 | `other-frame' Show new file in another frame | |
445 | `maybe-frame' If a file is visible in another frame, prompt to ask if you | |
446 | you want to see the file in the same window of the current | |
447 | frame or in the other frame | |
448 | `raise-frame' If a file is visible in another frame, raise that | |
449 | frame; otherwise, visit the file in the same window" | |
450 | :type '(choice (const :tag "Visit in selected window" selected-window) | |
451 | (const :tag "Visit in other window" other-window) | |
452 | (const :tag "Display (no select) in other window" display) | |
453 | (const :tag "Visit in other frame" other-frame) | |
454 | (const :tag "Ask to visit in other frame" maybe-frame) | |
455 | (const :tag "Raise frame if already visited" raise-frame)) | |
789d1bf0 KS |
456 | :group 'ido) |
457 | ||
a11ad595 | 458 | (defcustom ido-default-buffer-method 'raise-frame |
9201cc28 | 459 | "How to switch to new buffer when using `ido-switch-buffer'. |
616e8e5f | 460 | See `ido-default-file-method' for details." |
a11ad595 KS |
461 | :type '(choice (const :tag "Show in selected window" selected-window) |
462 | (const :tag "Show in other window" other-window) | |
463 | (const :tag "Display (no select) in other window" display) | |
464 | (const :tag "Show in other frame" other-frame) | |
465 | (const :tag "Ask to show in other frame" maybe-frame) | |
466 | (const :tag "Raise frame if already shown" raise-frame)) | |
789d1bf0 KS |
467 | :group 'ido) |
468 | ||
469 | (defcustom ido-enable-flex-matching nil | |
d11320e5 | 470 | "Non-nil means that Ido will do flexible string matching. |
789d1bf0 KS |
471 | Flexible matching means that if the entered string does not |
472 | match any item, any item containing the entered characters | |
473 | in the given sequence will match." | |
474 | :type 'boolean | |
475 | :group 'ido) | |
476 | ||
477 | ||
478 | (defcustom ido-enable-regexp nil | |
d11320e5 JB |
479 | "Non-nil means that Ido will do regexp matching. |
480 | Value can be toggled within Ido using `ido-toggle-regexp'." | |
789d1bf0 KS |
481 | :type 'boolean |
482 | :group 'ido) | |
483 | ||
484 | (defcustom ido-enable-prefix nil | |
9201cc28 | 485 | "Non-nil means only match if the entered text is a prefix of file name. |
79164cf4 | 486 | This behavior is like the standard Emacs completion. |
29660eb7 | 487 | If nil, match if the entered text is an arbitrary substring. |
d11320e5 | 488 | Value can be toggled within Ido using `ido-toggle-prefix'." |
789d1bf0 KS |
489 | :type 'boolean |
490 | :group 'ido) | |
491 | ||
6d8b6cbd | 492 | (defcustom ido-enable-dot-prefix nil |
9201cc28 | 493 | "Non-nil means to match leading dot as prefix. |
6d8b6cbd KS |
494 | I.e. hidden files and buffers will match only if you type a dot |
495 | as first char even if `ido-enable-prefix' is nil." | |
496 | :type 'boolean | |
497 | :group 'ido) | |
498 | ||
a8c14da8 LL |
499 | ;; See http://debbugs.gnu.org/2042 for more info. |
500 | (defcustom ido-buffer-disable-smart-matches t | |
501 | "Non-nil means not to re-order matches for buffer switching. | |
d11320e5 | 502 | By default, Ido arranges matches in the following order: |
a8c14da8 LL |
503 | |
504 | full-matches > suffix matches > prefix matches > remaining matches | |
505 | ||
506 | which can get in the way for buffer switching." | |
2bc9406c | 507 | :version "24.3" |
a8c14da8 LL |
508 | :type 'boolean |
509 | :group 'ido) | |
510 | ||
d81aa76a | 511 | (defcustom ido-confirm-unique-completion nil |
9201cc28 | 512 | "Non-nil means that even a unique completion must be confirmed. |
d81aa76a KS |
513 | This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer] |
514 | even when there is only one unique completion." | |
515 | :type 'boolean | |
516 | :group 'ido) | |
517 | ||
d1a0acac | 518 | (defcustom ido-cannot-complete-command 'ido-completion-help |
9201cc28 | 519 | "Command run when `ido-complete' can't complete any more. |
d1a0acac KS |
520 | The most useful values are `ido-completion-help', which pops up a |
521 | window with completion alternatives, or `ido-next-match' or | |
522 | `ido-prev-match', which cycle the buffer list." | |
523 | :type 'function | |
524 | :group 'ido) | |
525 | ||
526 | ||
789d1bf0 | 527 | (defcustom ido-record-commands t |
04263d23 XF |
528 | "Non-nil means that Ido will record commands in command history. |
529 | Note that the non-Ido equivalent command is recorded." | |
789d1bf0 KS |
530 | :type 'boolean |
531 | :group 'ido) | |
532 | ||
533 | (defcustom ido-max-prospects 12 | |
0e55c076 XF |
534 | "Upper limit of the prospect list if non-zero. |
535 | Zero means no limit for the prospect list. | |
536 | For a long list of prospects, building the full list for the | |
537 | minibuffer can take a non-negligible amount of time; setting this | |
538 | variable reduces that time." | |
789d1bf0 KS |
539 | :type 'integer |
540 | :group 'ido) | |
541 | ||
a42e9704 | 542 | (defcustom ido-max-file-prompt-width 0.35 |
0e55c076 XF |
543 | "Upper limit of the prompt string. |
544 | If value is an integer, it specifies the number of characters of | |
545 | the string. | |
546 | If value is a floating point number, it specifies a fraction of | |
547 | the frame width." | |
789d1bf0 KS |
548 | :type '(choice |
549 | (integer :tag "Characters" :value 20) | |
550 | (restricted-sexp :tag "Fraction of frame width" | |
551 | :value 0.35 | |
552 | :match-alternatives (ido-fractionp))) | |
553 | :group 'ido) | |
554 | ||
555 | (defcustom ido-max-window-height nil | |
9201cc28 | 556 | "Non-nil specifies a value to override `max-mini-window-height'." |
789d1bf0 KS |
557 | :type '(choice |
558 | (const :tag "Don't override" nil) | |
559 | (integer :tag "Number of lines" :value 1) | |
560 | (restricted-sexp | |
561 | :tag "Fraction of window height" | |
562 | :value 0.25 | |
563 | :match-alternatives (ido-fractionp))) | |
564 | :group 'ido) | |
565 | ||
566 | (defcustom ido-enable-last-directory-history t | |
d11320e5 | 567 | "Non-nil means that Ido will remember latest selected directory names. |
789d1bf0 KS |
568 | See `ido-last-directory-list' and `ido-save-directory-list-file'." |
569 | :type 'boolean | |
570 | :group 'ido) | |
571 | ||
572 | (defcustom ido-max-work-directory-list 50 | |
9201cc28 | 573 | "Maximum number of working directories to record. |
789d1bf0 KS |
574 | This is the list of directories where files have most recently been opened. |
575 | See `ido-work-directory-list' and `ido-save-directory-list-file'." | |
576 | :type 'integer | |
577 | :group 'ido) | |
578 | ||
579 | (defcustom ido-work-directory-list-ignore-regexps nil | |
9201cc28 | 580 | "List of regexps matching directories which should not be recorded. |
362cdb61 | 581 | Directory names matched by one of the regexps in this list are not inserted in |
789d1bf0 KS |
582 | the `ido-work-directory-list' list." |
583 | :type '(repeat regexp) | |
584 | :group 'ido) | |
585 | ||
bad111c2 | 586 | |
310682e6 | 587 | (defcustom ido-use-filename-at-point nil |
d11320e5 | 588 | "Non-nil means that Ido shall look for a filename at point. |
3c88bdc5 | 589 | May use `ffap-guesser' to guess whether text at point is a filename. |
310682e6 | 590 | If found, use that as the starting point for filename selection." |
3c88bdc5 KS |
591 | :type '(choice |
592 | (const :tag "Disabled" nil) | |
593 | (const :tag "Guess filename" guess) | |
594 | (other :tag "Use literal filename" t)) | |
310682e6 KS |
595 | :group 'ido) |
596 | ||
597 | ||
598 | (defcustom ido-use-url-at-point nil | |
9201cc28 | 599 | "Non-nil means that ido shall look for a URL at point. |
310682e6 KS |
600 | If found, call `find-file-at-point' to visit it." |
601 | :type 'boolean | |
602 | :group 'ido) | |
603 | ||
604 | ||
bad111c2 | 605 | (defcustom ido-enable-tramp-completion t |
d11320e5 | 606 | "Non-nil means that Ido shall perform tramp method and server name completion. |
362cdb61 | 607 | A tramp file name uses the following syntax: /method:user@host:filename." |
bad111c2 KS |
608 | :type 'boolean |
609 | :group 'ido) | |
610 | ||
789d1bf0 | 611 | (defcustom ido-record-ftp-work-directories t |
d11320e5 | 612 | "Non-nil means record FTP file names in the work directory list." |
789d1bf0 KS |
613 | :type 'boolean |
614 | :group 'ido) | |
615 | ||
616 | (defcustom ido-merge-ftp-work-directories nil | |
d11320e5 | 617 | "If nil, merging ignores FTP file names in the work directory list." |
789d1bf0 KS |
618 | :type 'boolean |
619 | :group 'ido) | |
620 | ||
621 | (defcustom ido-cache-ftp-work-directory-time 1.0 | |
d11320e5 | 622 | "Maximum time to cache contents of an FTP directory (in hours). |
0e55c076 XF |
623 | \\<ido-file-completion-map> |
624 | Use \\[ido-reread-directory] in prompt to refresh list. | |
d11320e5 | 625 | If zero, FTP directories are not cached." |
789d1bf0 KS |
626 | :type 'number |
627 | :group 'ido) | |
628 | ||
629 | (defcustom ido-slow-ftp-hosts nil | |
d11320e5 JB |
630 | "List of slow FTP hosts where Ido prompting should not be used. |
631 | If an FTP host is on this list, Ido automatically switches to the non-Ido | |
616e8e5f | 632 | equivalent function, e.g. `find-file' rather than `ido-find-file'." |
789d1bf0 KS |
633 | :type '(repeat string) |
634 | :group 'ido) | |
635 | ||
636 | (defcustom ido-slow-ftp-host-regexps nil | |
d11320e5 | 637 | "List of regexps matching slow FTP hosts (see `ido-slow-ftp-hosts')." |
789d1bf0 KS |
638 | :type '(repeat regexp) |
639 | :group 'ido) | |
640 | ||
4c2ee078 | 641 | (defvar ido-unc-hosts-cache t |
0e55c076 | 642 | "Cached value from the function `ido-unc-hosts'.") |
4c2ee078 | 643 | |
dfebc0ae | 644 | (defcustom ido-unc-hosts nil |
9201cc28 | 645 | "List of known UNC host names to complete after initial //. |
4c2ee078 KS |
646 | If value is a function, that function is called to search network for |
647 | hosts on first use of UNC path." | |
648 | :type '(choice (repeat :tag "List of UNC host names" string) | |
649 | (function-item :tag "Use `NET VIEW'" | |
650 | :value ido-unc-hosts-net-view) | |
651 | (function :tag "Your own function")) | |
652 | :set #'(lambda (symbol value) | |
653 | (set symbol value) | |
654 | (setq ido-unc-hosts-cache t)) | |
655 | :group 'ido) | |
656 | ||
b97f1994 | 657 | (defcustom ido-downcase-unc-hosts t |
9201cc28 | 658 | "Non-nil if UNC host names should be downcased." |
b97f1994 KS |
659 | :type 'boolean |
660 | :group 'ido) | |
661 | ||
4c2ee078 | 662 | (defcustom ido-ignore-unc-host-regexps nil |
9201cc28 | 663 | "List of regexps matching UNC hosts to ignore. |
b97f1994 | 664 | Case is ignored if `ido-downcase-unc-hosts' is set." |
4c2ee078 | 665 | :type '(repeat regexp) |
dfebc0ae KS |
666 | :group 'ido) |
667 | ||
668 | (defcustom ido-cache-unc-host-shares-time 8.0 | |
9201cc28 | 669 | "Maximum time to cache shares of an UNC host (in hours). |
0e55c076 XF |
670 | \\<ido-file-completion-map> |
671 | Use \\[ido-reread-directory] in prompt to refresh list. | |
3903655d | 672 | If zero, UNC host shares are not cached." |
dfebc0ae KS |
673 | :type 'number |
674 | :group 'ido) | |
675 | ||
789d1bf0 | 676 | (defcustom ido-max-work-file-list 10 |
9201cc28 | 677 | "Maximum number of names of recently opened files to record. |
79164cf4 | 678 | This is the list of the file names (sans directory) which have most recently |
3903655d | 679 | been opened. See `ido-work-file-list' and `ido-save-directory-list-file'." |
789d1bf0 KS |
680 | :type 'integer |
681 | :group 'ido) | |
682 | ||
683 | (defcustom ido-work-directory-match-only t | |
9201cc28 | 684 | "Non-nil means to skip non-matching directories in the directory history. |
789d1bf0 KS |
685 | When some text is already entered at the `ido-find-file' prompt, using |
686 | \\[ido-prev-work-directory] or \\[ido-next-work-directory] will skip directories | |
687 | without any matching entries." | |
688 | :type 'boolean | |
689 | :group 'ido) | |
690 | ||
691 | (defcustom ido-auto-merge-work-directories-length 0 | |
9201cc28 | 692 | "Automatically switch to merged work directories during file name input. |
789d1bf0 KS |
693 | The value is number of characters to type before switching to merged mode. |
694 | If zero, the switch happens when no matches are found in the current directory. | |
695 | Automatic merging is disabled if the value is negative." | |
696 | :type 'integer | |
697 | :group 'ido) | |
698 | ||
699 | (defcustom ido-auto-merge-delay-time 0.70 | |
9201cc28 | 700 | "Delay in seconds to wait for more input before doing auto merge." |
789d1bf0 KS |
701 | :type 'number |
702 | :group 'ido) | |
703 | ||
704 | (defcustom ido-auto-merge-inhibit-characters-regexp "[][*?~]" | |
9201cc28 | 705 | "Regexp matching characters which should inhibit automatic merging. |
789d1bf0 KS |
706 | When a (partial) file name matches this regexp, merging is inhibited." |
707 | :type 'regexp | |
708 | :group 'ido) | |
709 | ||
710 | (defcustom ido-merged-indicator "^" | |
711 | "The string appended to first choice if it has multiple directory choices." | |
712 | :type 'string | |
713 | :group 'ido) | |
714 | ||
715 | (defcustom ido-max-dir-file-cache 100 | |
9201cc28 | 716 | "Maximum number of working directories to be cached. |
0e55c076 | 717 | \\<ido-file-completion-map> |
a09e21bf | 718 | This is the size of the cache of `file-name-all-completions' results. |
789d1bf0 KS |
719 | Each cache entry is time stamped with the modification time of the |
720 | directory. Some systems, like Windows, have unreliable directory | |
721 | modification times, so you may choose to disable caching on such | |
722 | systems, or explicitly refresh the cache contents using the command | |
0e55c076 | 723 | `ido-reread-directory' command (\\[ido-reread-directory]) in the minibuffer. |
789d1bf0 KS |
724 | See also `ido-dir-file-cache' and `ido-save-directory-list-file'." |
725 | :type 'integer | |
726 | :group 'ido) | |
727 | ||
ee41332b | 728 | (defcustom ido-max-directory-size nil |
d11320e5 | 729 | "Maximum size (in bytes) for directories to use Ido completion. |
0e55c076 | 730 | \\<ido-completion-map> |
d11320e5 | 731 | If you enter a directory with a size larger than this size, Ido will |
0e55c076 | 732 | not provide the normal completion. To show the completions, use \\[ido-toggle-ignore]." |
cb65c373 KS |
733 | :type '(choice (const :tag "No limit" nil) |
734 | (integer :tag "Size in bytes" 30000)) | |
735 | :group 'ido) | |
736 | ||
789d1bf0 | 737 | (defcustom ido-rotate-file-list-default nil |
d11320e5 | 738 | "Non-nil means that Ido will always rotate file list to get default in front." |
789d1bf0 KS |
739 | :type 'boolean |
740 | :group 'ido) | |
741 | ||
5702da69 | 742 | (defcustom ido-enter-matching-directory 'only |
9201cc28 | 743 | "Additional methods to enter sub-directory of first/only matching item. |
5702da69 KS |
744 | If value is 'first, enter first matching sub-directory when typing a slash. |
745 | If value is 'only, typing a slash only enters the sub-directory if it is | |
746 | the only matching item. | |
747 | If value is t, automatically enter a sub-directory when it is the only | |
748 | matching item, even without typing a slash." | |
71296446 | 749 | :type '(choice (const :tag "Never" nil) |
5702da69 KS |
750 | (const :tag "Slash enters first directory" first) |
751 | (const :tag "Slash enters first and only directory" only) | |
752 | (other :tag "Always enter unique directory" t)) | |
789d1bf0 KS |
753 | :group 'ido) |
754 | ||
789d1bf0 | 755 | (defcustom ido-create-new-buffer 'prompt |
9201cc28 | 756 | "Specify whether a new buffer is created if no buffer matches substring. |
789d1bf0 KS |
757 | Choices are 'always to create new buffers unconditionally, 'prompt to |
758 | ask user whether to create buffer, or 'never to never create new buffer." | |
71296446 | 759 | :type '(choice (const always) |
789d1bf0 KS |
760 | (const prompt) |
761 | (const never)) | |
762 | :group 'ido) | |
763 | ||
3729cc87 | 764 | (defcustom ido-setup-hook nil |
d11320e5 | 765 | "Hook run after the Ido variables and keymap have been setup. |
3729cc87 | 766 | The dynamic variable `ido-cur-item' contains the current type of item that |
d11320e5 | 767 | is read by Ido; possible values are file, dir, buffer, and list. |
facf67fd | 768 | Additional keys can be defined in `ido-completion-map'." |
789d1bf0 KS |
769 | :type 'hook |
770 | :group 'ido) | |
771 | ||
772 | (defcustom ido-separator nil | |
d11320e5 | 773 | "String used by Ido to separate the alternatives in the minibuffer." |
610a4f64 | 774 | :type '(choice string (const nil)) |
789d1bf0 | 775 | :group 'ido) |
d11320e5 JB |
776 | (make-obsolete-variable 'ido-separator |
777 | "set 3rd element of `ido-decorations' instead." nil) | |
789d1bf0 | 778 | |
d11320e5 JB |
779 | (defcustom ido-decorations '("{" "}" " | " " | ..." "[" "]" " [No match]" |
780 | " [Matched]" " [Not readable]" " [Too big]" " [Confirm]") | |
781 | "List of strings used by Ido to display the alternatives in the minibuffer. | |
632556e4 | 782 | There are between 11 and 13 elements in this list: |
789d1bf0 | 783 | 1st and 2nd elements are used as brackets around the prospect list, |
0e55c076 XF |
784 | 3rd element is the separator between prospects (ignored if |
785 | `ido-separator' is set), | |
789d1bf0 KS |
786 | 4th element is the string inserted at the end of a truncated list of prospects, |
787 | 5th and 6th elements are used as brackets around the common match string which | |
788 | can be completed using TAB, | |
616e8e5f JB |
789 | 7th element is the string displayed when there are no matches, and |
790 | 8th element is displayed if there is a single match (and faces are not used), | |
791 | 9th element is displayed when the current directory is non-readable, | |
11c238b3 | 792 | 10th element is displayed when directory exceeds `ido-max-directory-size', |
632556e4 SM |
793 | 11th element is displayed to confirm creating new file or buffer. |
794 | 12th and 13th elements (if present) are used as brackets around the sole | |
795 | remaining completion. If absent, elements 5 and 6 are used instead." | |
789d1bf0 KS |
796 | :type '(repeat string) |
797 | :group 'ido) | |
798 | ||
0523d117 | 799 | (defcustom ido-use-virtual-buffers nil |
fbb764b8 GM |
800 | "If non-nil, refer to past (\"virtual\") buffers as well as existing ones. |
801 | The options are: | |
802 | nil: Do not use virtual buffers. | |
3504a4be | 803 | t: Always use virtual buffers. |
fbb764b8 | 804 | auto: Use virtual buffers if the current input matches no existing buffer. |
3504a4be | 805 | |
f9a27d86 | 806 | Essentially it works as follows: Say you are visiting a file and |
53964682 | 807 | the buffer gets cleaned up by midnight.el. Later, you want to |
3504a4be LL |
808 | switch to that buffer, but find it's no longer open. With virtual |
809 | buffers enabled, the buffer name stays in the buffer list (using | |
810 | the `ido-virtual' face, and always at the end), and if you select | |
811 | it, it opens the file back up again. This allows you to think | |
812 | less about whether recently opened files are still open or not. | |
813 | Most of the time you can quit Emacs, restart, and then switch to | |
fbb764b8 GM |
814 | a file buffer that was previously open as if it still were. |
815 | ||
816 | This feature relies upon the `recentf' package, which will be | |
817 | enabled if this variable is configured to a non-nil value." | |
818 | :version "24.1" | |
3504a4be LL |
819 | :type '(choice (const :tag "Always" t) |
820 | (const :tag "Automatic" auto) | |
821 | (const :tag "Never" nil)) | |
0523d117 JW |
822 | :group 'ido) |
823 | ||
789d1bf0 | 824 | (defcustom ido-use-faces t |
d11320e5 | 825 | "Non-nil means use Ido faces to highlighting first match, only match and |
789d1bf0 KS |
826 | subdirs in the alternatives." |
827 | :type 'boolean | |
828 | :group 'ido) | |
829 | ||
4b56d0fe | 830 | (defface ido-first-match '((t :weight bold)) |
d11320e5 | 831 | "Face used by Ido for highlighting first match." |
789d1bf0 KS |
832 | :group 'ido) |
833 | ||
ccba8bb6 | 834 | (defface ido-only-match '((((class color)) |
4b56d0fe CY |
835 | :foreground "ForestGreen") |
836 | (t :slant italic)) | |
d11320e5 | 837 | "Face used by Ido for highlighting only match." |
789d1bf0 KS |
838 | :group 'ido) |
839 | ||
ccba8bb6 | 840 | (defface ido-subdir '((((min-colors 88) (class color)) |
4b56d0fe CY |
841 | :foreground "red1") |
842 | (((class color)) | |
843 | :foreground "red") | |
844 | (t :underline t)) | |
d11320e5 | 845 | "Face used by Ido for highlighting subdirs in the alternatives." |
789d1bf0 KS |
846 | :group 'ido) |
847 | ||
4b56d0fe | 848 | (defface ido-virtual '((t :inherit font-lock-builtin-face)) |
d11320e5 | 849 | "Face used by Ido for matching virtual buffer names." |
f9a27d86 | 850 | :version "24.1" |
0523d117 JW |
851 | :group 'ido) |
852 | ||
4b56d0fe CY |
853 | (defface ido-indicator '((((min-colors 88) (class color)) |
854 | :foreground "yellow1" :background "red1" :width condensed) | |
855 | (((class color)) | |
856 | :foreground "yellow" :background "red" :width condensed) | |
857 | (t :inverse-video t)) | |
d11320e5 | 858 | "Face used by Ido for highlighting its indicators." |
789d1bf0 KS |
859 | :group 'ido) |
860 | ||
665ed61a | 861 | (defface ido-incomplete-regexp |
4b56d0fe | 862 | '((t :inherit font-lock-warning-face)) |
665ed61a KS |
863 | "Ido face for indicating incomplete regexps." |
864 | :group 'ido) | |
865 | ||
789d1bf0 | 866 | (defcustom ido-make-file-list-hook nil |
9201cc28 | 867 | "List of functions to run when the list of matching files is created. |
789d1bf0 KS |
868 | Each function on the list may modify the dynamically bound variable |
869 | `ido-temp-list' which contains the current list of matching files." | |
870 | :type 'hook | |
871 | :group 'ido) | |
872 | ||
873 | (defcustom ido-make-dir-list-hook nil | |
9201cc28 | 874 | "List of functions to run when the list of matching directories is created. |
789d1bf0 KS |
875 | Each function on the list may modify the dynamically bound variable |
876 | `ido-temp-list' which contains the current list of matching directories." | |
877 | :type 'hook | |
878 | :group 'ido) | |
879 | ||
880 | (defcustom ido-make-buffer-list-hook nil | |
9201cc28 | 881 | "List of functions to run when the list of matching buffers is created. |
789d1bf0 KS |
882 | Each function on the list may modify the dynamically bound variable |
883 | `ido-temp-list' which contains the current list of matching buffer names." | |
884 | :type 'hook | |
885 | :group 'ido) | |
886 | ||
362cdb61 | 887 | (defcustom ido-rewrite-file-prompt-functions nil |
9201cc28 | 888 | "List of functions to run when the find-file prompt is created. |
789d1bf0 KS |
889 | Each function on the list may modify the following dynamically bound |
890 | variables: | |
337d2b66 RS |
891 | dirname - the (abbreviated) directory name |
892 | to be modified by the hook functions | |
893 | max-width - the max width of the resulting dirname; nil means no limit | |
894 | prompt - the basic prompt (e.g. \"Find File: \") | |
895 | literal - the string shown if doing \"literal\" find; set to nil to omit | |
79164cf4 | 896 | vc-off - the string shown if version control is inhibited; set to nil to omit |
337d2b66 RS |
897 | prefix - either nil or a fixed prefix for the dirname |
898 | ||
789d1bf0 | 899 | The following variables are available, but should not be changed: |
a09e21bf | 900 | `ido-current-directory' - the unabbreviated directory name |
337d2b66 | 901 | item - equals `file' or `dir' depending on the current mode." |
789d1bf0 KS |
902 | :type 'hook |
903 | :group 'ido) | |
904 | ||
362cdb61 | 905 | (defvar ido-rewrite-file-prompt-rules nil |
d11320e5 | 906 | "Alist of rewriting rules for directory names in Ido prompts. |
362cdb61 KS |
907 | A list of elements of the form (FROM . TO) or (FROM . FUNC), each |
908 | meaning to rewrite the directory name if matched by FROM by either | |
909 | substituting the matched string by TO or calling the function FUNC | |
910 | with the current directory name as its only argument and using the | |
911 | return value as the new directory name. In addition, each FUNC may | |
912 | also modify the dynamic variables described for the variable | |
913 | `ido-rewrite-file-prompt-functions'.") | |
789d1bf0 KS |
914 | |
915 | (defcustom ido-completion-buffer "*Ido Completions*" | |
d11320e5 | 916 | "Name of completion buffer used by Ido. |
789d1bf0 KS |
917 | Set to nil to disable completion buffers popping up." |
918 | :type 'string | |
919 | :group 'ido) | |
920 | ||
921 | (defcustom ido-completion-buffer-all-completions nil | |
9201cc28 | 922 | "Non-nil means to show all completions in completion buffer. |
789d1bf0 KS |
923 | Otherwise, only the current list of matches is shown." |
924 | :type 'boolean | |
925 | :group 'ido) | |
926 | ||
78f3273a CY |
927 | (defcustom ido-all-frames 'visible |
928 | "Argument to pass to `walk-windows' when Ido is finding buffers. | |
929 | See documentation of `walk-windows' for useful values." | |
930 | :type '(choice (const :tag "Selected frame only" nil) | |
931 | (const :tag "All existing frames" t) | |
932 | (const :tag "All visible frames" visible) | |
933 | (const :tag "All frames on this terminal" 0)) | |
934 | :group 'ido) | |
789d1bf0 KS |
935 | |
936 | (defcustom ido-minibuffer-setup-hook nil | |
9201cc28 | 937 | "Ido-specific customization of minibuffer setup. |
789d1bf0 | 938 | |
d11320e5 JB |
939 | This hook is run during minibuffer setup if Ido is active. |
940 | It is intended for use in customizing Ido for interoperation | |
789d1bf0 KS |
941 | with other packages. For instance: |
942 | ||
d11320e5 JB |
943 | (add-hook 'ido-minibuffer-setup-hook |
944 | (lambda () (setq-local max-mini-window-height 3))) | |
789d1bf0 | 945 | |
319a586a | 946 | will constrain Emacs to a maximum minibuffer height of 3 lines when |
d11320e5 | 947 | Ido is running. Copied from `icomplete-minibuffer-setup-hook'." |
789d1bf0 KS |
948 | :type 'hook |
949 | :group 'ido) | |
950 | ||
940e5099 SM |
951 | (defcustom ido-save-directory-list-file |
952 | (locate-user-emacs-file "ido.last" ".ido.last") | |
d11320e5 | 953 | "File in which the Ido state is saved between invocations. |
789d1bf0 KS |
954 | Variables stored are: `ido-last-directory-list', `ido-work-directory-list', |
955 | `ido-work-file-list', and `ido-dir-file-cache'. | |
d11320e5 | 956 | Must be set before enabling Ido mode." |
ece4bae5 | 957 | :version "24.4" ; added locate-user-emacs-file |
789d1bf0 KS |
958 | :type 'string |
959 | :group 'ido) | |
960 | ||
961 | (defcustom ido-read-file-name-as-directory-commands '() | |
d11320e5 | 962 | "List of commands which use `read-file-name' to read a directory name. |
789d1bf0 | 963 | When `ido-everywhere' is non-nil, the commands in this list will read |
616e8e5f | 964 | the directory using `ido-read-directory-name'." |
789d1bf0 KS |
965 | :type '(repeat symbol) |
966 | :group 'ido) | |
967 | ||
968 | (defcustom ido-read-file-name-non-ido '() | |
d11320e5 | 969 | "List of commands which shall not read file names the Ido way. |
789d1bf0 | 970 | When `ido-everywhere' is non-nil, the commands in this list will read |
616e8e5f | 971 | the file name using normal `read-file-name' style." |
789d1bf0 KS |
972 | :type '(repeat symbol) |
973 | :group 'ido) | |
974 | ||
b2d4c118 KS |
975 | (defcustom ido-before-fallback-functions '() |
976 | "List of functions to call before calling a fallback command. | |
977 | The fallback command is passed as an argument to the functions." | |
978 | :type 'hook | |
979 | :group 'ido) | |
980 | ||
789d1bf0 KS |
981 | ;;; Internal Variables |
982 | ||
983 | ;; Persistent variables | |
984 | ||
facf67fd | 985 | (defvar ido-completion-map nil |
d11320e5 | 986 | "Currently active keymap for Ido commands.") |
973495ca | 987 | |
facf67fd | 988 | (defvar ido-common-completion-map nil |
d11320e5 | 989 | "Keymap for all Ido commands.") |
973495ca | 990 | |
facf67fd | 991 | (defvar ido-file-completion-map nil |
d11320e5 | 992 | "Keymap for Ido file commands.") |
973495ca | 993 | |
facf67fd | 994 | (defvar ido-file-dir-completion-map nil |
d11320e5 | 995 | "Keymap for Ido file and directory commands.") |
973495ca | 996 | |
facf67fd | 997 | (defvar ido-buffer-completion-map nil |
d11320e5 | 998 | "Keymap for Ido buffer commands.") |
789d1bf0 KS |
999 | |
1000 | (defvar ido-file-history nil | |
1001 | "History of files selected using `ido-find-file'.") | |
1002 | ||
1003 | (defvar ido-buffer-history nil | |
1004 | "History of buffers selected using `ido-switch-buffer'.") | |
1005 | ||
789d1bf0 | 1006 | (defvar ido-last-directory-list nil |
362cdb61 | 1007 | "List of last selected directory names. |
789d1bf0 KS |
1008 | See `ido-enable-last-directory-history' for details.") |
1009 | ||
1010 | (defvar ido-work-directory-list nil | |
362cdb61 | 1011 | "List of actual working directory names. |
789d1bf0 | 1012 | The current directory is inserted at the front of this list whenever a |
616e8e5f | 1013 | file is opened with `ido-find-file' and family.") |
789d1bf0 KS |
1014 | |
1015 | (defvar ido-work-file-list nil | |
1016 | "List of actual work file names. | |
337d2b66 RS |
1017 | Opening a file with `ido-find-file' and similar functions |
1018 | inserts the current file name (relative to its containing directory) | |
1019 | at the front of this list.") | |
789d1bf0 KS |
1020 | |
1021 | (defvar ido-dir-file-cache nil | |
337d2b66 RS |
1022 | "List of `file-name-all-completions' results. |
1023 | Each element in the list is of the form (DIR (MTIME) FILE...).") | |
789d1bf0 | 1024 | |
69beb26d | 1025 | (defvar ido-ignore-item-temp-list nil |
d11320e5 JB |
1026 | "List of items to ignore in current Ido invocation. |
1027 | Intended to be let-bound by functions which call Ido repeatedly. | |
69beb26d KS |
1028 | Should never be set permanently.") |
1029 | ||
789d1bf0 KS |
1030 | ;; Temporary storage |
1031 | ||
1032 | (defvar ido-eoinput 1 | |
1033 | "Point where minibuffer input ends and completion info begins. | |
1034 | Copied from `icomplete-eoinput'.") | |
1035 | (make-variable-buffer-local 'ido-eoinput) | |
1036 | ||
1037 | (defvar ido-common-match-string nil | |
1038 | "Stores the string that is common to all matching files.") | |
1039 | ||
1040 | (defvar ido-rescan nil | |
1041 | "Non-nil means we need to regenerate the list of matching items.") | |
1042 | ||
1043 | (defvar ido-rotate nil | |
1044 | "Non-nil means we are rotating list of matches.") | |
1045 | ||
1046 | (defvar ido-text nil | |
d11320e5 | 1047 | "Stores the user's string as it is typed in.") |
789d1bf0 KS |
1048 | |
1049 | (defvar ido-text-init nil | |
d11320e5 | 1050 | "The initial string for the user's string it is typed in.") |
789d1bf0 | 1051 | |
3729cc87 | 1052 | (defvar ido-input-stack nil |
d11320e5 | 1053 | "Stores the user's strings when user hits M-b/M-f.") |
3729cc87 | 1054 | |
789d1bf0 KS |
1055 | (defvar ido-matches nil |
1056 | "List of files currently matching `ido-text'.") | |
1057 | ||
1058 | (defvar ido-report-no-match t | |
d11320e5 | 1059 | "Report \"[No Match]\" when no completions matches `ido-text'.") |
789d1bf0 | 1060 | |
71296446 JB |
1061 | (defvar ido-exit nil |
1062 | "Flag to monitor how `ido-find-file' exits. | |
789d1bf0 KS |
1063 | If equal to `takeprompt', we use the prompt as the file name to be |
1064 | selected.") | |
1065 | ||
1066 | (defvar ido-current-directory nil | |
616e8e5f | 1067 | "Current directory for `ido-find-file'.") |
789d1bf0 KS |
1068 | |
1069 | (defvar ido-auto-merge-timer nil | |
1070 | "Delay timer for auto merge.") | |
1071 | ||
1072 | (defvar ido-use-mycompletion-depth 0 | |
d11320e5 JB |
1073 | "Non-nil means use Ido completion feedback. |
1074 | Is set by Ido functions to the current `minibuffer-depth', | |
a09e21bf | 1075 | so that it doesn't interfere with other minibuffer usage.") |
789d1bf0 | 1076 | |
665ed61a KS |
1077 | (defvar ido-incomplete-regexp nil |
1078 | "Non-nil if an incomplete regexp is entered.") | |
789d1bf0 | 1079 | |
155943b9 KS |
1080 | (defvar ido-initial-position nil |
1081 | "Non-nil means to explicitly cursor on entry to minibuffer. | |
1082 | Value is an integer which is number of chars to right of prompt.") | |
1083 | ||
9caf8a8f JB |
1084 | (defvar ido-virtual-buffers nil |
1085 | "List of virtual buffers, that is, past visited files. | |
1086 | This is a copy of `recentf-list', pared down and with faces applied. | |
1087 | Only used if `ido-use-virtual-buffers' is non-nil.") | |
1088 | ||
789d1bf0 KS |
1089 | ;;; Variables with dynamic bindings. |
1090 | ;;; Declared here to keep the byte compiler quiet. | |
1091 | ||
db9f395b | 1092 | ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list). |
789d1bf0 KS |
1093 | (defvar ido-cur-item) |
1094 | ||
3d37467b KS |
1095 | ;;; Stores the current default item |
1096 | (defvar ido-default-item) | |
1097 | ||
789d1bf0 KS |
1098 | ;; Stores the current list of items that will be searched through. |
1099 | ;; The list is ordered, so that the most interesting item comes first, | |
1100 | ;; although by default, the files visible in the current frame are put | |
e0143335 LL |
1101 | ;; at the end of the list. Created by `ido-make-item-list'. |
1102 | (defvar ido-cur-list) | |
789d1bf0 | 1103 | |
db9f395b | 1104 | ;; Stores the choice list for ido-completing-read |
e0143335 | 1105 | (defvar ido-choice-list) |
db9f395b | 1106 | |
789d1bf0 KS |
1107 | ;; Stores the list of items which are ignored when building |
1108 | ;; `ido-cur-list'. It is in no specific order. | |
1109 | (defvar ido-ignored-list) | |
1110 | ||
a70343bd KS |
1111 | ;; Remember if current directory is non-readable (so we cannot do completion). |
1112 | (defvar ido-directory-nonreadable) | |
1113 | ||
cb65c373 KS |
1114 | ;; Remember if current directory is 'huge' (so we don't want to do completion). |
1115 | (defvar ido-directory-too-big) | |
1116 | ||
789d1bf0 KS |
1117 | ;; Keep current item list if non-nil. |
1118 | (defvar ido-keep-item-list) | |
1119 | ||
1120 | ;; Process ido-ignore-* lists. | |
1121 | (defvar ido-process-ignore-lists) | |
1122 | ||
1123 | ;; Don't process ido-ignore- lists once. | |
1124 | (defvar ido-process-ignore-lists-inhibit) | |
1125 | ||
3504a4be LL |
1126 | ;; Is ido using virtual buffers? |
1127 | (defvar ido-enable-virtual-buffers) | |
1128 | ||
789d1bf0 KS |
1129 | ;; Buffer from which ido was entered. |
1130 | (defvar ido-entry-buffer) | |
1131 | ||
1132 | ;; Non-nil if matching file must be selected. | |
1133 | (defvar ido-require-match) | |
1134 | ||
11c238b3 KS |
1135 | ;; Non-nil if we should add [confirm] to prompt |
1136 | (defvar ido-show-confirm-message) | |
1137 | ||
789d1bf0 KS |
1138 | ;; Stores a temporary version of the file list being created. |
1139 | (defvar ido-temp-list) | |
1140 | ||
1141 | ;; Non-nil if default list element should be rotated into place. | |
1142 | (defvar ido-rotate-temp) | |
1143 | ||
1144 | ;; Stores current index in ido-work-directory-list. | |
1145 | (defvar ido-work-directory-index) | |
1146 | ||
1147 | ;; Stores current index in ido-work-file-list. | |
1148 | (defvar ido-work-file-index) | |
1149 | ||
1150 | ;; Set when merged work directory list is in use. | |
1151 | (defvar ido-use-merged-list) | |
1152 | ||
1153 | ;; Set when merged work directory list not yet built. | |
1154 | (defvar ido-try-merged-list) | |
1155 | ||
1156 | ;; Saved state prior to last work directory merge. | |
1157 | ;; Value is a list (ido-text dir cur-list ignored-list matches). | |
1158 | (defvar ido-pre-merge-state) | |
1159 | ||
310682e6 KS |
1160 | ;; Original value of vc-handled-backends for use in ido-toggle-vc. |
1161 | (defvar ido-saved-vc-hb) | |
789d1bf0 KS |
1162 | |
1163 | ;; Stores temporary state of literal find file. | |
1164 | (defvar ido-find-literal) | |
1165 | ||
db9f395b KS |
1166 | ;; Set to 'ignore to inhibit switching between find-file/switch-buffer. |
1167 | (defvar ido-context-switch-command) | |
789d1bf0 | 1168 | |
06b60517 JB |
1169 | ;; Dynamically bound in ido-read-internal. |
1170 | (defvar ido-completing-read) | |
1171 | ||
789d1bf0 KS |
1172 | ;;; FUNCTIONS |
1173 | ||
1174 | (defun ido-active (&optional merge) | |
1175 | (if merge | |
1176 | ido-use-merged-list | |
cba9a3a5 KS |
1177 | (and (boundp 'ido-completing-read) |
1178 | (or (featurep 'xemacs) | |
1179 | (= ido-use-mycompletion-depth (minibuffer-depth)))))) | |
789d1bf0 KS |
1180 | |
1181 | (defvar ido-trace-enable nil) | |
1182 | ||
1183 | (defun ido-trace (p &optional s retval) | |
1184 | (if ido-trace-enable | |
1185 | (let ((b (get-buffer-create " *IDO Trace*")) | |
1186 | (deactivate-mark deactivate-mark)) | |
1187 | (save-excursion | |
1188 | (save-restriction | |
1189 | (set-buffer b) | |
1190 | (insert p ": " (if (stringp s) s (format "%S" s)) "\n"))))) | |
1191 | retval) | |
1192 | ||
1193 | (defun ido-toggle-trace (arg) | |
1194 | (interactive "P") | |
1195 | (setq ido-trace-enable (or arg (not ido-trace-enable))) | |
bad111c2 KS |
1196 | (if ido-trace-enable |
1197 | (message "IDO trace on")) | |
789d1bf0 KS |
1198 | (let ((b (get-buffer " *IDO Trace*"))) |
1199 | (if b | |
1200 | (if ido-trace-enable | |
1201 | (kill-buffer b) | |
bad111c2 KS |
1202 | (pop-to-buffer b t t) |
1203 | (setq truncate-lines t))))) | |
1204 | ||
10b19e88 KS |
1205 | (defun ido-local-file-exists-p (file) |
1206 | "Tell if FILE exists locally." | |
1207 | (let (file-name-handler-alist) | |
1208 | (file-exists-p file))) | |
1209 | ||
4c2ee078 KS |
1210 | (defun ido-unc-hosts (&optional query) |
1211 | "Return list of UNC host names." | |
b97f1994 KS |
1212 | (let ((hosts |
1213 | (cond | |
1214 | ((listp ido-unc-hosts) | |
1215 | ido-unc-hosts) ;; static list or nil | |
1216 | ((listp ido-unc-hosts-cache) | |
1217 | ido-unc-hosts-cache) ;; result of net search | |
1218 | ((and query (fboundp ido-unc-hosts)) | |
1219 | (message (propertize "Searching for UNC hosts..." 'face 'highlight)) | |
1220 | (setq ido-unc-hosts-cache (funcall ido-unc-hosts)) | |
1221 | (message nil) | |
1222 | ido-unc-hosts-cache) | |
1223 | (query | |
1224 | (setq ido-unc-hosts-cache nil)) | |
1225 | (t (fboundp ido-unc-hosts))))) | |
1226 | (when query | |
1227 | (let ((case-fold-search ido-downcase-unc-hosts) | |
1228 | res host re-list re) | |
1229 | (while hosts | |
1230 | (setq host (car hosts) | |
1231 | hosts (cdr hosts) | |
1232 | re-list (and ido-process-ignore-lists | |
1233 | ido-ignore-unc-host-regexps)) | |
1234 | (while re-list | |
1235 | (setq re (car re-list) | |
1236 | re-list (cdr re-list)) | |
1237 | (if (string-match re host) | |
1238 | (setq re-list nil | |
1239 | host nil))) | |
1240 | (when host | |
1241 | (when ido-downcase-unc-hosts | |
1242 | (setq host (downcase host))) | |
1243 | (setq res (cons host res)))) | |
1244 | (setq hosts (sort res #'string<)))) | |
1245 | hosts)) | |
4c2ee078 KS |
1246 | |
1247 | (defun ido-unc-hosts-net-view () | |
1248 | "Query network for list of UNC host names using `NET VIEW'." | |
1249 | (let (hosts) | |
1250 | (with-temp-buffer | |
1251 | (shell-command "net view" t) | |
1252 | (goto-char (point-min)) | |
1253 | (while (re-search-forward "^\\\\\\\\\\([[:graph:]]+\\)" nil t) | |
1254 | (setq hosts (cons (match-string 1) hosts)))) | |
1255 | hosts)) | |
1256 | ||
bad111c2 | 1257 | (defun ido-is-tramp-root (&optional dir) |
bad111c2 | 1258 | (and ido-enable-tramp-completion |
c577a4d2 KS |
1259 | (string-match "\\`/[^/]+[@:]\\'" |
1260 | (or dir ido-current-directory)))) | |
789d1bf0 | 1261 | |
dfebc0ae | 1262 | (defun ido-is-unc-root (&optional dir) |
4c2ee078 | 1263 | (and (ido-unc-hosts) |
dfebc0ae KS |
1264 | (string-equal "//" |
1265 | (or dir ido-current-directory)))) | |
1266 | ||
1267 | (defun ido-is-unc-host (&optional dir) | |
4c2ee078 | 1268 | (and (ido-unc-hosts) |
dfebc0ae KS |
1269 | (string-match "\\`//[^/]+/\\'" |
1270 | (or dir ido-current-directory)))) | |
1271 | ||
789d1bf0 KS |
1272 | (defun ido-is-root-directory (&optional dir) |
1273 | (setq dir (or dir ido-current-directory)) | |
bad111c2 KS |
1274 | (or |
1275 | (string-equal "/" dir) | |
1276 | (and (memq system-type '(windows-nt ms-dos)) | |
1277 | (string-match "\\`[a-zA-Z]:[/\\]\\'" dir)) | |
1278 | (if ido-enable-tramp-completion | |
1279 | (ido-is-tramp-root dir) | |
1280 | (string-match "\\`/[^:/][^:/]+:\\'" dir)))) | |
789d1bf0 KS |
1281 | |
1282 | (defun ido-is-ftp-directory (&optional dir) | |
71296446 | 1283 | (string-match |
bad111c2 | 1284 | (if ido-enable-tramp-completion |
d11320e5 JB |
1285 | ;; like tramp-file-name-regexp-unified, but doesn't match single drive letters |
1286 | "\\`/[^/:][^/:]+:" | |
bad111c2 KS |
1287 | "\\`/[^/:][^/:]+:/") |
1288 | (or dir ido-current-directory))) | |
789d1bf0 KS |
1289 | |
1290 | (defun ido-is-slow-ftp-host (&optional dir) | |
1291 | (and (or ido-slow-ftp-hosts ido-slow-ftp-host-regexps) | |
1292 | (setq dir (or dir ido-current-directory)) | |
1293 | ;; (featurep 'ange-ftp) | |
1294 | ;; (ange-ftp-ftp-name dir) | |
71296446 | 1295 | (string-match |
bad111c2 KS |
1296 | (if ido-enable-tramp-completion |
1297 | "\\`/\\([^/]+[@:]\\)*\\([^@/:][^@/:]+\\):" | |
1298 | "\\`/\\([^/:]*@\\)?\\([^@/:][^@/:]+\\):/") | |
1299 | dir) | |
789d1bf0 KS |
1300 | (let ((host (substring dir (match-beginning 2) (match-end 2)))) |
1301 | (or (member host ido-slow-ftp-hosts) | |
1302 | (let ((re ido-slow-ftp-host-regexps)) | |
1303 | (while (and re (not (string-match (car re) host))) | |
1304 | (setq re (cdr re))) | |
1305 | re))))) | |
1306 | ||
1307 | (defun ido-time-stamp (&optional time) | |
1308 | ;; Time is a floating point number (fractions of 1 hour) | |
1309 | (setq time (or time (current-time))) | |
1310 | (/ (+ (* (car time) 65536.0) (car (cdr time))) 3600.0)) | |
1311 | ||
1312 | (defun ido-cache-ftp-valid (&optional time) | |
1313 | (and (numberp ido-cache-ftp-work-directory-time) | |
1314 | (> ido-cache-ftp-work-directory-time 0) | |
1315 | (or (not time) | |
1316 | (< (- (ido-time-stamp) time) ido-cache-ftp-work-directory-time)))) | |
1317 | ||
dfebc0ae KS |
1318 | (defun ido-cache-unc-valid (&optional time) |
1319 | (and (numberp ido-cache-unc-host-shares-time) | |
1320 | (> ido-cache-unc-host-shares-time 0) | |
1321 | (or (not time) | |
1322 | (< (- (ido-time-stamp) time) ido-cache-unc-host-shares-time)))) | |
1323 | ||
789d1bf0 KS |
1324 | (defun ido-may-cache-directory (&optional dir) |
1325 | (setq dir (or dir ido-current-directory)) | |
bad111c2 KS |
1326 | (cond |
1327 | ((and (ido-is-root-directory dir) | |
1328 | (or ido-enable-tramp-completion | |
1329 | (memq system-type '(windows-nt ms-dos)))) | |
1330 | nil) | |
dfebc0ae KS |
1331 | ((ido-is-unc-host dir) |
1332 | (ido-cache-unc-valid)) | |
1333 | ((ido-is-ftp-directory dir) | |
1334 | (ido-cache-ftp-valid)) | |
821f936d KS |
1335 | ((ido-directory-too-big-p dir) |
1336 | nil) | |
dfebc0ae | 1337 | (t t))) |
789d1bf0 KS |
1338 | |
1339 | (defun ido-pp (list &optional sep) | |
1340 | (let ((print-level nil) (eval-expression-print-level nil) | |
1341 | (print-length nil) (eval-expression-print-length nil)) | |
1342 | (insert "\n;; ----- " (symbol-name list) " -----\n(\n ") | |
1343 | (setq list (symbol-value list)) | |
1344 | (while list | |
1345 | (let* ((elt (car list)) | |
1346 | (s (if (consp elt) (car elt) elt))) | |
1347 | (if (and (stringp s) (= (length s) 0)) | |
1348 | (setq s nil)) | |
1349 | (if s | |
1350 | (prin1 elt (current-buffer))) | |
1351 | (if (and (setq list (cdr list)) s) | |
1352 | (insert (or sep "\n "))))) | |
1353 | (insert "\n)\n"))) | |
1354 | ||
1355 | (defun ido-save-history () | |
d11320e5 | 1356 | "Save Ido history and cache information between sessions." |
789d1bf0 | 1357 | (interactive) |
782ea71a KS |
1358 | (when (and ido-last-directory-list ido-save-directory-list-file) |
1359 | (let ((buf (get-buffer-create " *ido session*")) | |
d725608c | 1360 | (version-control 'never)) |
782ea71a KS |
1361 | (unwind-protect |
1362 | (with-current-buffer buf | |
1363 | (erase-buffer) | |
efccebb5 | 1364 | (insert ";;; -*- coding: utf-8 -*-\n") |
d725608c | 1365 | (setq buffer-file-coding-system 'utf-8) |
782ea71a KS |
1366 | (ido-pp 'ido-last-directory-list) |
1367 | (ido-pp 'ido-work-directory-list) | |
1368 | (ido-pp 'ido-work-file-list) | |
1369 | (ido-pp 'ido-dir-file-cache "\n\n ") | |
1b00bc64 KS |
1370 | (if (listp ido-unc-hosts-cache) |
1371 | (ido-pp 'ido-unc-hosts-cache) | |
1372 | (insert "\n;; ----- ido-unc-hosts-cache -----\nt\n")) | |
789d1bf0 | 1373 | (write-file ido-save-directory-list-file nil)) |
782ea71a | 1374 | (kill-buffer buf))))) |
789d1bf0 KS |
1375 | |
1376 | (defun ido-load-history (&optional arg) | |
d11320e5 | 1377 | "Load Ido history and cache information from previous session. |
789d1bf0 KS |
1378 | With prefix argument, reload history unconditionally." |
1379 | (interactive "P") | |
1380 | (if (or arg (and ido-save-directory-list-file (not ido-last-directory-list))) | |
1381 | (let ((file (expand-file-name ido-save-directory-list-file)) | |
1382 | buf) | |
1383 | (when (file-readable-p file) | |
782ea71a KS |
1384 | (setq buf (get-buffer-create " *ido session*")) |
1385 | (unwind-protect | |
1386 | (with-current-buffer buf | |
1387 | (erase-buffer) | |
1388 | (insert-file-contents file) | |
1389 | (condition-case nil | |
1390 | (setq ido-last-directory-list (read (current-buffer)) | |
1391 | ido-work-directory-list (read (current-buffer)) | |
1392 | ido-work-file-list (read (current-buffer)) | |
1b00bc64 KS |
1393 | ido-dir-file-cache (read (current-buffer)) |
1394 | ido-unc-hosts-cache (read (current-buffer))) | |
782ea71a KS |
1395 | (error nil))) |
1396 | (kill-buffer buf))))) | |
789d1bf0 KS |
1397 | (ido-wash-history)) |
1398 | ||
1399 | (defun ido-wash-history () | |
d11320e5 | 1400 | "Clean-up Ido history and cache information. |
789d1bf0 KS |
1401 | Removes badly formatted data and ignored directories." |
1402 | (interactive) | |
1403 | ;; Check format of each of our lists, discard bogus elements | |
1404 | (setq ido-last-directory-list | |
1405 | (and (listp ido-last-directory-list) | |
1406 | (let ((l ido-last-directory-list) r) | |
1407 | (while l | |
1408 | (if (and (consp (car l)) | |
1409 | (stringp (car (car l))) | |
1410 | (stringp (cdr (car l)))) | |
1411 | (setq r (cons (car l) r))) | |
1412 | (setq l (cdr l))) | |
1413 | (nreverse r)))) | |
71296446 | 1414 | (setq ido-work-directory-list |
789d1bf0 KS |
1415 | (and (listp ido-work-directory-list) |
1416 | (let ((l ido-work-directory-list) r) | |
1417 | (while l | |
1418 | (if (and (stringp (car l)) | |
1419 | (or ido-record-ftp-work-directories | |
1420 | (not (ido-is-ftp-directory (car l))))) | |
1421 | (setq r (cons (car l) r))) | |
1422 | (setq l (cdr l))) | |
1423 | (nreverse r)))) | |
71296446 | 1424 | (setq ido-work-file-list |
789d1bf0 KS |
1425 | (and (listp ido-work-file-list) |
1426 | (let ((l ido-work-file-list) r) | |
1427 | (while l | |
1428 | (if (stringp (car l)) | |
1429 | (setq r (cons (car l) r))) | |
1430 | (setq l (cdr l))) | |
1431 | (nreverse r)))) | |
71296446 | 1432 | (setq ido-dir-file-cache |
789d1bf0 KS |
1433 | (and (listp ido-dir-file-cache) |
1434 | (let ((l ido-dir-file-cache) r) | |
1435 | (while l | |
1436 | (if (and (listp (car l)) | |
1437 | (> (length (car l)) 2) | |
1438 | (let ((dir (car (car l))) | |
1439 | (time (car (cdr (car l)))) | |
1440 | (files (cdr (cdr (car l))))) | |
1441 | (and | |
1442 | (stringp dir) | |
1443 | (consp time) | |
dfebc0ae KS |
1444 | (cond |
1445 | ((integerp (car time)) | |
1446 | (and (/= (car time) 0) | |
1447 | (integerp (car (cdr time))) | |
1448 | (/= (car (cdr time)) 0) | |
1449 | (ido-may-cache-directory dir))) | |
1450 | ((eq (car time) 'ftp) | |
1451 | (and (numberp (cdr time)) | |
789d1bf0 KS |
1452 | (ido-is-ftp-directory dir) |
1453 | (ido-cache-ftp-valid (cdr time)))) | |
dfebc0ae KS |
1454 | ((eq (car time) 'unc) |
1455 | (and (numberp (cdr time)) | |
1456 | (ido-is-unc-host dir) | |
1457 | (ido-cache-unc-valid (cdr time)))) | |
1458 | (t nil)) | |
789d1bf0 KS |
1459 | (let ((s files) (ok t)) |
1460 | (while s | |
1461 | (if (stringp (car s)) | |
1462 | (setq s (cdr s)) | |
1463 | (setq s nil ok nil))) | |
1464 | ok)))) | |
1465 | (setq r (cons (car l) r))) | |
1466 | (setq l (cdr l))) | |
1467 | (nreverse r)))) | |
1468 | ||
1469 | ;; Remove ignored directories from work directory list | |
1470 | ;; according to ido-work-directory-list-ignore-regexps | |
1471 | (if ido-work-directory-list | |
1472 | (let ((dirs (reverse ido-work-directory-list))) | |
1473 | (setq ido-work-directory-list nil) | |
1474 | (while dirs | |
1475 | (ido-record-work-directory (car dirs)) | |
1476 | (setq dirs (cdr dirs))))) | |
1477 | ;; Get rid of text properties | |
1478 | (let ((l ido-last-directory-list) e) | |
1479 | (while l | |
1480 | (setq e (car l) l (cdr l)) | |
1481 | (set-text-properties 0 (length (car e)) nil (car e)) | |
1482 | (set-text-properties 0 (length (cdr e)) nil (cdr e)))) | |
1483 | (let ((l ido-work-directory-list) e) | |
1484 | (while l | |
1485 | (setq e (car l) l (cdr l)) | |
1486 | (set-text-properties 0 (length e) nil e))) | |
1487 | (let ((l ido-work-file-list) e) | |
1488 | (while l | |
1489 | (setq e (car l) l (cdr l)) | |
1490 | (set-text-properties 0 (length e) nil e))) | |
1491 | (let ((l ido-dir-file-cache) e d) | |
1492 | (while l | |
1493 | (setq e (car l) l (cdr l)) | |
1494 | (if (listp e) | |
1495 | (while e | |
1496 | (setq d (car e) e (cdr e)) | |
1497 | (if (not (consp d)) | |
973495ca | 1498 | (set-text-properties 0 (length d) nil d))))))) |
789d1bf0 KS |
1499 | |
1500 | ||
1501 | (defun ido-kill-emacs-hook () | |
1502 | ;; ido kill emacs hook | |
1503 | (ido-save-history)) | |
1504 | ||
0fdd1db7 | 1505 | (defun ido-common-initialization () |
bd794450 LL |
1506 | (ido-init-completion-maps) |
1507 | (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup) | |
1508 | (add-hook 'choose-completion-string-functions 'ido-choose-completion-string)) | |
1509 | ||
e78e280d | 1510 | (define-minor-mode ido-everywhere |
06e21633 CY |
1511 | "Toggle use of Ido for all buffer/file reading. |
1512 | With a prefix argument ARG, enable this feature if ARG is | |
d11320e5 JB |
1513 | positive, and disable it otherwise. If called from Lisp, |
1514 | enable the mode if ARG is omitted or nil." | |
e78e280d SM |
1515 | :global t |
1516 | :group 'ido | |
1517 | (when (get 'ido-everywhere 'file) | |
1518 | (setq read-file-name-function (car (get 'ido-everywhere 'file))) | |
1519 | (put 'ido-everywhere 'file nil)) | |
1520 | (when (get 'ido-everywhere 'buffer) | |
1521 | (setq read-buffer-function (car (get 'ido-everywhere 'buffer))) | |
1522 | (put 'ido-everywhere 'buffer nil)) | |
1523 | (when ido-everywhere | |
1524 | (when (memq ido-mode '(both file)) | |
1525 | (put 'ido-everywhere 'file (cons read-file-name-function nil)) | |
1526 | (setq read-file-name-function 'ido-read-file-name)) | |
1527 | (when (memq ido-mode '(both buffer)) | |
1528 | (put 'ido-everywhere 'buffer (cons read-buffer-function nil)) | |
1529 | (setq read-buffer-function 'ido-read-buffer)))) | |
1530 | ||
789d1bf0 KS |
1531 | (defvar ido-minor-mode-map-entry nil) |
1532 | ||
1533 | ;;;###autoload | |
b0df3884 | 1534 | (defun ido-mode (&optional arg) |
d11320e5 JB |
1535 | "Toggle Ido mode on or off. |
1536 | With ARG, turn Ido mode on if arg is positive, off otherwise. | |
1537 | Turning on Ido mode will remap (via a minor-mode keymap) the default | |
b0df3884 | 1538 | keybindings for the `find-file' and `switch-to-buffer' families of |
d11320e5 | 1539 | commands to the Ido versions of these functions. |
b0df3884 KS |
1540 | However, if ARG arg equals 'files, remap only commands for files, or |
1541 | if it equals 'buffers, remap only commands for buffer switching. | |
789d1bf0 KS |
1542 | This function also adds a hook to the minibuffer." |
1543 | (interactive "P") | |
1544 | (setq ido-mode | |
71296446 | 1545 | (cond |
789d1bf0 KS |
1546 | ((null arg) (if ido-mode nil 'both)) |
1547 | ((eq arg t) 'both) | |
1548 | ((eq arg 'files) 'file) | |
1549 | ((eq arg 'buffers) 'buffer) | |
1550 | ((memq arg '(file buffer both)) arg) | |
1551 | ((> (prefix-numeric-value arg) 0) 'both) | |
1552 | (t nil))) | |
1553 | ||
1554 | (ido-everywhere (if ido-everywhere 1 -1)) | |
1555 | ||
1556 | (when ido-mode | |
0fdd1db7 | 1557 | (ido-common-initialization) |
789d1bf0 KS |
1558 | (ido-load-history) |
1559 | ||
1560 | (add-hook 'kill-emacs-hook 'ido-kill-emacs-hook) | |
1561 | ||
facf67fd | 1562 | (let ((map (make-sparse-keymap))) |
789d1bf0 KS |
1563 | (when (memq ido-mode '(file both)) |
1564 | (define-key map [remap find-file] 'ido-find-file) | |
1565 | (define-key map [remap find-file-read-only] 'ido-find-file-read-only) | |
1566 | (define-key map [remap find-alternate-file] 'ido-find-alternate-file) | |
1567 | (define-key map [remap write-file] 'ido-write-file) | |
1568 | (define-key map [remap insert-file] 'ido-insert-file) | |
1569 | (define-key map [remap list-directory] 'ido-list-directory) | |
1570 | (define-key map [remap dired] 'ido-dired) | |
e78e280d SM |
1571 | (define-key map [remap find-file-other-window] |
1572 | 'ido-find-file-other-window) | |
1573 | (define-key map [remap find-file-read-only-other-window] | |
1574 | 'ido-find-file-read-only-other-window) | |
1575 | (define-key map [remap find-file-other-frame] | |
1576 | 'ido-find-file-other-frame) | |
1577 | (define-key map [remap find-file-read-only-other-frame] | |
1578 | 'ido-find-file-read-only-other-frame)) | |
789d1bf0 KS |
1579 | |
1580 | (when (memq ido-mode '(buffer both)) | |
1581 | (define-key map [remap switch-to-buffer] 'ido-switch-buffer) | |
e78e280d SM |
1582 | (define-key map [remap switch-to-buffer-other-window] |
1583 | 'ido-switch-buffer-other-window) | |
1584 | (define-key map [remap switch-to-buffer-other-frame] | |
1585 | 'ido-switch-buffer-other-frame) | |
789d1bf0 KS |
1586 | (define-key map [remap insert-buffer] 'ido-insert-buffer) |
1587 | (define-key map [remap kill-buffer] 'ido-kill-buffer) | |
facf67fd KS |
1588 | (define-key map [remap display-buffer] 'ido-display-buffer)) |
1589 | ||
1590 | (if ido-minor-mode-map-entry | |
1591 | (setcdr ido-minor-mode-map-entry map) | |
1592 | (setq ido-minor-mode-map-entry (cons 'ido-mode map)) | |
7ff90407 CY |
1593 | (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry)))) |
1594 | ||
92f2affc LMI |
1595 | (when (called-interactively-p 'any) |
1596 | (message "Ido mode %s" (if ido-mode "enabled" "disabled")))) | |
facf67fd | 1597 | |
789d1bf0 | 1598 | |
71296446 | 1599 | ;;; IDO KEYMAP |
facf67fd | 1600 | (defun ido-init-completion-maps () |
d11320e5 | 1601 | "Set up the completion keymaps used by Ido." |
789d1bf0 | 1602 | |
973495ca KS |
1603 | ;; Common map |
1604 | (let ((map (make-sparse-keymap))) | |
789d1bf0 KS |
1605 | (define-key map "\C-a" 'ido-toggle-ignore) |
1606 | (define-key map "\C-c" 'ido-toggle-case) | |
1607 | (define-key map "\C-e" 'ido-edit-input) | |
1608 | (define-key map "\t" 'ido-complete) | |
030fa15b | 1609 | (define-key map " " 'ido-complete-space) |
789d1bf0 KS |
1610 | (define-key map "\C-j" 'ido-select-text) |
1611 | (define-key map "\C-m" 'ido-exit-minibuffer) | |
1612 | (define-key map "\C-p" 'ido-toggle-prefix) | |
1613 | (define-key map "\C-r" 'ido-prev-match) | |
1614 | (define-key map "\C-s" 'ido-next-match) | |
d7e76a89 J |
1615 | (define-key map [?\C-.] 'ido-next-match) |
1616 | (define-key map [?\C-,] 'ido-prev-match) | |
789d1bf0 KS |
1617 | (define-key map "\C-t" 'ido-toggle-regexp) |
1618 | (define-key map "\C-z" 'ido-undo-merge-work-directory) | |
bf67f27b | 1619 | (define-key map [(control ?\s)] 'ido-restrict-to-matches) |
a3f4d4d4 | 1620 | (define-key map [(meta ?\s)] 'ido-take-first-match) |
08bfde76 | 1621 | (define-key map [(control ?@)] 'ido-restrict-to-matches) |
789d1bf0 KS |
1622 | (define-key map [right] 'ido-next-match) |
1623 | (define-key map [left] 'ido-prev-match) | |
1624 | (define-key map "?" 'ido-completion-help) | |
ae9d279d KS |
1625 | ;; Magic commands. |
1626 | (define-key map "\C-b" 'ido-magic-backward-char) | |
1627 | (define-key map "\C-f" 'ido-magic-forward-char) | |
1628 | (define-key map "\C-d" 'ido-magic-delete-char) | |
973495ca | 1629 | (set-keymap-parent map minibuffer-local-map) |
facf67fd | 1630 | (setq ido-common-completion-map map)) |
973495ca KS |
1631 | |
1632 | ;; File and directory map | |
1633 | (let ((map (make-sparse-keymap))) | |
1634 | (define-key map "\C-x\C-b" 'ido-enter-switch-buffer) | |
1635 | (define-key map "\C-x\C-f" 'ido-fallback-command) | |
1636 | (define-key map "\C-x\C-d" 'ido-enter-dired) | |
1637 | (define-key map [down] 'ido-next-match-dir) | |
1638 | (define-key map [up] 'ido-prev-match-dir) | |
1639 | (define-key map [(meta up)] 'ido-prev-work-directory) | |
1640 | (define-key map [(meta down)] 'ido-next-work-directory) | |
1641 | (define-key map [backspace] 'ido-delete-backward-updir) | |
1642 | (define-key map "\d" 'ido-delete-backward-updir) | |
87498551 | 1643 | (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS |
542b315f KS |
1644 | (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir) ; M-DEL |
1645 | ||
973495ca KS |
1646 | (define-key map [(control backspace)] 'ido-up-directory) |
1647 | (define-key map "\C-l" 'ido-reread-directory) | |
1648 | (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir) | |
1649 | (define-key map [(meta ?b)] 'ido-push-dir) | |
a3f4d4d4 | 1650 | (define-key map [(meta ?v)] 'ido-push-dir-first) |
973495ca KS |
1651 | (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir) |
1652 | (define-key map [(meta ?k)] 'ido-forget-work-directory) | |
1653 | (define-key map [(meta ?m)] 'ido-make-directory) | |
1654 | (define-key map [(meta ?n)] 'ido-next-work-directory) | |
1655 | (define-key map [(meta ?o)] 'ido-prev-work-file) | |
1656 | (define-key map [(meta control ?o)] 'ido-next-work-file) | |
1657 | (define-key map [(meta ?p)] 'ido-prev-work-directory) | |
1658 | (define-key map [(meta ?s)] 'ido-merge-work-directories) | |
facf67fd KS |
1659 | (set-keymap-parent map ido-common-completion-map) |
1660 | (setq ido-file-dir-completion-map map)) | |
973495ca KS |
1661 | |
1662 | ;; File only map | |
1663 | (let ((map (make-sparse-keymap))) | |
1664 | (define-key map "\C-k" 'ido-delete-file-at-head) | |
1665 | (define-key map "\C-o" 'ido-copy-current-word) | |
1666 | (define-key map "\C-w" 'ido-copy-current-file-name) | |
1667 | (define-key map [(meta ?l)] 'ido-toggle-literal) | |
facf67fd KS |
1668 | (set-keymap-parent map ido-file-dir-completion-map) |
1669 | (setq ido-file-completion-map map)) | |
973495ca KS |
1670 | |
1671 | ;; Buffer map | |
1672 | (let ((map (make-sparse-keymap))) | |
1673 | (define-key map "\C-x\C-f" 'ido-enter-find-file) | |
1674 | (define-key map "\C-x\C-b" 'ido-fallback-command) | |
1675 | (define-key map "\C-k" 'ido-kill-buffer-at-head) | |
c5cbeb12 | 1676 | (define-key map "\C-o" 'ido-toggle-virtual-buffers) |
facf67fd KS |
1677 | (set-keymap-parent map ido-common-completion-map) |
1678 | (setq ido-buffer-completion-map map))) | |
ae9d279d | 1679 | |
789d1bf0 | 1680 | |
facf67fd | 1681 | (defun ido-setup-completion-map () |
d11320e5 | 1682 | "Set up the keymap for Ido." |
789d1bf0 | 1683 | |
973495ca KS |
1684 | ;; generated every time so that it can inherit new functions. |
1685 | (let ((map (make-sparse-keymap)) | |
1686 | (viper-p (if (boundp 'viper-mode) viper-mode))) | |
789d1bf0 | 1687 | |
973495ca KS |
1688 | (when viper-p |
1689 | (define-key map [remap viper-intercept-ESC-key] 'ignore)) | |
1690 | ||
1691 | (cond | |
1692 | ((memq ido-cur-item '(file dir)) | |
1693 | (when ido-context-switch-command | |
1694 | (define-key map "\C-x\C-b" ido-context-switch-command) | |
1695 | (define-key map "\C-x\C-d" 'ignore)) | |
1696 | (when viper-p | |
9f781d7e KS |
1697 | (define-key map [remap viper-backward-char] 'ido-delete-backward-updir) |
1698 | (define-key map [remap viper-del-backward-char-in-insert] 'ido-delete-backward-updir) | |
973495ca KS |
1699 | (define-key map [remap viper-delete-backward-word] 'ido-delete-backward-word-updir)) |
1700 | (set-keymap-parent map | |
1701 | (if (eq ido-cur-item 'file) | |
facf67fd KS |
1702 | ido-file-completion-map |
1703 | ido-file-dir-completion-map))) | |
973495ca KS |
1704 | |
1705 | ((eq ido-cur-item 'buffer) | |
1706 | (when ido-context-switch-command | |
1707 | (define-key map "\C-x\C-f" ido-context-switch-command)) | |
facf67fd | 1708 | (set-keymap-parent map ido-buffer-completion-map)) |
973495ca KS |
1709 | |
1710 | (t | |
facf67fd | 1711 | (set-keymap-parent map ido-common-completion-map))) |
f0a73ccc | 1712 | |
facf67fd | 1713 | (setq ido-completion-map map))) |
789d1bf0 KS |
1714 | |
1715 | (defun ido-final-slash (dir &optional fix-it) | |
1716 | ;; return DIR if DIR has final slash. | |
1717 | ;; else if FIX-IT is non-nil, return DIR/ | |
1718 | ;; else return nil. | |
1719 | (setq dir (ido-name dir)) | |
1720 | (cond | |
1721 | ((string-match "/\\'" dir) dir) | |
bad111c2 | 1722 | ((ido-is-tramp-root dir) dir) |
789d1bf0 KS |
1723 | (fix-it (concat dir "/")) |
1724 | (t nil))) | |
1725 | ||
310682e6 KS |
1726 | (defun ido-no-final-slash (s) |
1727 | ;; Remove optional final slash from string S | |
1728 | (let ((l (1- (length s)))) | |
1729 | (if (and (> l 0) (eq (aref s l) ?/)) | |
1730 | (substring s 0 l) | |
1731 | s))) | |
1732 | ||
866f2239 KS |
1733 | (defun ido-nonreadable-directory-p (dir) |
1734 | ;; Return t if dir is a directory, but not readable | |
1735 | ;; Do not check for non-readable directories via tramp, as this causes a premature | |
e4769531 | 1736 | ;; connect on incomplete tramp paths (after entering just method:). |
866f2239 KS |
1737 | (let ((ido-enable-tramp-completion nil)) |
1738 | (and (ido-final-slash dir) | |
dfebc0ae | 1739 | (not (ido-is-unc-host dir)) |
866f2239 KS |
1740 | (file-directory-p dir) |
1741 | (not (file-readable-p dir))))) | |
1742 | ||
cb65c373 KS |
1743 | (defun ido-directory-too-big-p (dir) |
1744 | ;; Return t if dir is a directory, but too big to show | |
1745 | ;; Do not check for non-readable directories via tramp, as this causes a premature | |
e4769531 | 1746 | ;; connect on incomplete tramp paths (after entering just method:). |
cb65c373 KS |
1747 | (let ((ido-enable-tramp-completion nil)) |
1748 | (and (numberp ido-max-directory-size) | |
1749 | (ido-final-slash dir) | |
dfebc0ae | 1750 | (not (ido-is-unc-host dir)) |
cb65c373 | 1751 | (file-directory-p dir) |
ea9a3563 | 1752 | (> (nth 7 (file-attributes (file-truename dir))) ido-max-directory-size)))) |
cb65c373 | 1753 | |
789d1bf0 KS |
1754 | (defun ido-set-current-directory (dir &optional subdir no-merge) |
1755 | ;; Set ido's current directory to DIR or DIR/SUBDIR | |
c577a4d2 KS |
1756 | (unless (and ido-enable-tramp-completion |
1757 | (string-match "\\`/[^/]*@\\'" dir)) | |
1758 | (setq dir (ido-final-slash dir t))) | |
789d1bf0 KS |
1759 | (setq ido-use-merged-list nil |
1760 | ido-try-merged-list (not no-merge)) | |
c577a4d2 KS |
1761 | (when subdir |
1762 | (setq dir (concat dir subdir)) | |
1763 | (unless (and ido-enable-tramp-completion | |
1764 | (string-match "\\`/[^/]*@\\'" dir)) | |
1765 | (setq dir (ido-final-slash dir t)))) | |
99fc91fe AK |
1766 | (and ido-completion-buffer |
1767 | (get-buffer ido-completion-buffer) | |
1768 | (kill-buffer ido-completion-buffer)) | |
dfebc0ae KS |
1769 | (cond |
1770 | ((equal dir ido-current-directory) | |
1771 | nil) | |
1772 | ((ido-is-unc-root dir) | |
1773 | (ido-trace "unc" dir) | |
1774 | (setq ido-current-directory dir) | |
1775 | (setq ido-directory-nonreadable nil) | |
1776 | (setq ido-directory-too-big nil) | |
1777 | t) | |
1778 | (t | |
789d1bf0 KS |
1779 | (ido-trace "cd" dir) |
1780 | (setq ido-current-directory dir) | |
99fc91fe AK |
1781 | (and ido-completion-buffer |
1782 | (get-buffer ido-completion-buffer) | |
1783 | (kill-buffer ido-completion-buffer)) | |
866f2239 | 1784 | (setq ido-directory-nonreadable (ido-nonreadable-directory-p dir)) |
cb65c373 KS |
1785 | (setq ido-directory-too-big (and (not ido-directory-nonreadable) |
1786 | (ido-directory-too-big-p dir))) | |
dfebc0ae | 1787 | t))) |
789d1bf0 KS |
1788 | |
1789 | (defun ido-set-current-home (&optional dir) | |
1790 | ;; Set ido's current directory to user's home directory | |
1791 | (ido-set-current-directory (expand-file-name (or dir "~/")))) | |
1792 | ||
1793 | (defun ido-record-command (command arg) | |
04263d23 XF |
1794 | "Add (COMMAND ARG) to `command-history' if `ido-record-commands' is non-nil." |
1795 | (if ido-record-commands ; FIXME: use `when' instead of `if'? | |
789d1bf0 | 1796 | (let ((cmd (list command arg))) |
04263d23 | 1797 | (if (or (not command-history) ; FIXME: ditto |
789d1bf0 KS |
1798 | (not (equal cmd (car command-history)))) |
1799 | (setq command-history (cons cmd command-history)))))) | |
1800 | ||
1801 | (defun ido-make-prompt (item prompt) | |
1802 | ;; Make the prompt for ido-read-internal | |
1803 | (cond | |
1804 | ((and (memq item '(file dir)) ido-current-directory) | |
362cdb61 | 1805 | (let ((dirname (abbreviate-file-name ido-current-directory)) |
a42e9704 KS |
1806 | (max-width (if (and ido-max-file-prompt-width (floatp ido-max-file-prompt-width)) |
1807 | (floor (* (frame-width) ido-max-file-prompt-width)) | |
1808 | ido-max-file-prompt-width)) | |
789d1bf0 | 1809 | (literal (and (boundp 'ido-find-literal) ido-find-literal "(literal) ")) |
310682e6 | 1810 | (vc-off (and ido-saved-vc-hb (not vc-handled-backends) "[-VC] ")) |
789d1bf0 | 1811 | (prefix nil) |
362cdb61 | 1812 | (rule ido-rewrite-file-prompt-rules)) |
789d1bf0 KS |
1813 | (let ((case-fold-search nil)) |
1814 | (while rule | |
1815 | (if (and (consp (car rule)) | |
362cdb61 KS |
1816 | (string-match (car (car rule)) dirname)) |
1817 | (setq dirname | |
789d1bf0 | 1818 | (if (stringp (cdr (car rule))) |
362cdb61 KS |
1819 | (replace-match (cdr (car rule)) t nil dirname) |
1820 | (funcall (cdr (car rule)) dirname)))) | |
789d1bf0 | 1821 | (setq rule (cdr rule)))) |
362cdb61 | 1822 | (run-hooks 'ido-rewrite-file-prompt-functions) |
71296446 | 1823 | (concat prompt |
789d1bf0 KS |
1824 | ; (if ido-process-ignore-lists "" "&") |
1825 | (or literal "") | |
1826 | (or vc-off "") | |
1827 | (or prefix "") | |
362cdb61 | 1828 | (let ((l (length dirname))) |
789d1bf0 | 1829 | (if (and max-width (> max-width 0) (> l max-width)) |
71296446 | 1830 | (let* ((s (substring dirname (- max-width))) |
789d1bf0 KS |
1831 | (i (string-match "/" s))) |
1832 | (concat "..." (if i (substring s i) s))) | |
362cdb61 | 1833 | dirname))))) |
789d1bf0 KS |
1834 | (t prompt))) |
1835 | ||
1836 | ;; Here is very briefly how ido-find-file works: | |
1837 | ;; | |
1838 | ;; (ido-find-file) | |
1839 | ;; (ido-file-internal method) | |
1840 | ;; set ido-current-directory | |
1841 | ;; (ido-read-internal 'file ...) | |
1842 | ;; (while ... | |
1843 | ;; (ido-make-item-list ...) | |
1844 | ;; (ido-set-matches) | |
1845 | ;; (completing-read ... ido-text-init ...) | |
1846 | ;; | |
1847 | ;; ... here user is allowed to type characters and commands | |
1848 | ;; a command may set ido-exit and call (exit-minibuffer) | |
1849 | ;; to make ido-read-internal do advanced tasks (or return) | |
1850 | ;; | |
1851 | ;; ... ido-tidy and ido-exhibit are pre- and post-hooks | |
1852 | ;; which are run before and after each user command. | |
1853 | ;; | |
1854 | ;; return value from completing-read is stored in ido-final-text | |
1855 | ;; - ido-exit may cause further actions to be taken: | |
1856 | ;; 'refresh - repeat loop (make-item-list, set-matches) | |
1857 | ;; 'edit - edit the prompt string, then repeat loop | |
1858 | ;; 'keep - repeat loop but don't (re)make-item-list | |
1859 | ;; 'updir - go up one directory, repeat loop | |
1860 | ;; else set ido-selected based on ido-final-text, | |
1861 | ;; optionally update ido-current-directory and repeat loop, or | |
1862 | ;; exit with the return value of ido-selected (file name) | |
1863 | ;; selected file name is returned from ido-read-internal, | |
1864 | ;; ido-exit and method determines what action is taken | |
1865 | ;; e.g. the file name may be ignored or joined with ido-current-directory, and | |
1866 | ;; the relevant function is called (find-file, write-file, etc). | |
1867 | ||
7690bdea | 1868 | (defun ido-read-internal (item prompt hist &optional default require-match initial) |
a2cf0212 | 1869 | "Perform the `ido-read-buffer' and `ido-read-file-name' functions. |
71296446 | 1870 | Return the name of a buffer or file selected. |
789d1bf0 | 1871 | PROMPT is the prompt to give to the user. |
2d38f869 | 1872 | DEFAULT if given is the default item to start with. |
789d1bf0 KS |
1873 | If REQUIRE-MATCH is non-nil, an existing file must be selected. |
1874 | If INITIAL is non-nil, it specifies the initial input string." | |
1875 | (let | |
1876 | ((ido-cur-item item) | |
1877 | (ido-entry-buffer (current-buffer)) | |
1878 | (ido-process-ignore-lists t) | |
1879 | (ido-process-ignore-lists-inhibit nil) | |
1880 | (ido-set-default-item t) | |
1881 | ido-default-item | |
1882 | ido-selected | |
1883 | ido-final-text | |
1884 | (done nil) | |
1885 | (icomplete-mode nil) ;; prevent icomplete starting up | |
1886 | ;; Exported dynamic variables: | |
1887 | ido-cur-list | |
1888 | ido-ignored-list | |
1889 | (ido-rotate-temp nil) | |
1890 | (ido-keep-item-list nil) | |
1891 | (ido-use-merged-list nil) | |
1892 | (ido-try-merged-list t) | |
1893 | (ido-pre-merge-state nil) | |
1894 | (ido-case-fold ido-case-fold) | |
1895 | (ido-enable-prefix ido-enable-prefix) | |
1896 | (ido-enable-regexp ido-enable-regexp) | |
11c238b3 | 1897 | (ido-show-confirm-message nil) |
789d1bf0 KS |
1898 | ) |
1899 | ||
facf67fd | 1900 | (ido-setup-completion-map) |
789d1bf0 | 1901 | (setq ido-text-init initial) |
3729cc87 KS |
1902 | (setq ido-input-stack nil) |
1903 | ||
1904 | (run-hooks 'ido-setup-hook) | |
1905 | ||
789d1bf0 | 1906 | (while (not done) |
bad111c2 | 1907 | (ido-trace "\n_LOOP_" ido-text-init) |
789d1bf0 KS |
1908 | (setq ido-exit nil) |
1909 | (setq ido-rescan t) | |
1910 | (setq ido-rotate nil) | |
1911 | (setq ido-text "") | |
69beb26d KS |
1912 | (when ido-set-default-item |
1913 | (setq ido-default-item | |
1914 | (cond | |
1915 | ((eq item 'buffer) | |
1916 | (if (bufferp default) (buffer-name default) default)) | |
2d38f869 KS |
1917 | ((stringp default) |
1918 | (if (memq item '(file dir)) | |
1919 | (file-name-nondirectory default) | |
1920 | default)) | |
69beb26d | 1921 | ((eq item 'file) |
71296446 | 1922 | (and ido-enable-last-directory-history |
69beb26d KS |
1923 | (let ((d (assoc ido-current-directory ido-last-directory-list))) |
1924 | (and d (cdr d))))))) | |
1925 | (if (member ido-default-item ido-ignore-item-temp-list) | |
1926 | (setq ido-default-item nil)) | |
5444f278 | 1927 | (ido-trace "new default" ido-default-item) |
155943b9 KS |
1928 | (if ido-default-item |
1929 | (setq ido-initial-position 0)) | |
69beb26d | 1930 | (setq ido-set-default-item nil)) |
789d1bf0 KS |
1931 | |
1932 | (if ido-process-ignore-lists-inhibit | |
1933 | (setq ido-process-ignore-lists nil)) | |
1934 | ||
1935 | (if (and ido-use-merged-list (memq ido-try-merged-list '(t wide)) (not ido-keep-item-list)) | |
1936 | (let ((olist ido-cur-list) | |
1937 | (oign ido-ignored-list) | |
1938 | (omat ido-matches) | |
1939 | (l (ido-make-merged-file-list ido-text-init | |
1940 | (eq ido-use-merged-list 'auto) | |
1941 | (eq ido-try-merged-list 'wide)))) | |
ec441ab5 | 1942 | (ido-trace "merged" l) |
789d1bf0 KS |
1943 | (cond |
1944 | ((not l) | |
1945 | (if (eq ido-try-merged-list 'wide) | |
1946 | (setq ido-pre-merge-state | |
1947 | (list "" ido-current-directory olist oign omat) | |
1948 | ido-cur-list nil | |
1949 | ido-ignored-list nil | |
1950 | ido-matches nil | |
1951 | ido-keep-item-list t | |
1952 | ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil) | |
1953 | ido-use-merged-list nil) | |
1954 | (setq ido-cur-list olist | |
1955 | ido-ignored-list oign | |
1956 | ido-matches omat | |
1957 | ido-keep-item-list t | |
1958 | ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil) | |
1959 | ido-use-merged-list nil))) | |
1960 | ((eq l t) | |
1961 | (setq ido-use-merged-list nil)) | |
ec441ab5 KS |
1962 | ((eq l 'input-pending-p) |
1963 | (setq ido-try-merged-list t | |
1964 | ido-use-merged-list nil)) | |
789d1bf0 KS |
1965 | (t |
1966 | (setq ido-pre-merge-state | |
1967 | (list ido-text-init ido-current-directory olist oign omat)) | |
1968 | (ido-set-current-directory (car (cdr (car l)))) | |
1969 | (if (ido-final-slash ido-text-init) | |
1970 | (setq ido-text-init "")) | |
1971 | (setq ido-cur-list l | |
1972 | ido-ignored-list nil | |
1973 | ido-matches l | |
1974 | ido-rescan nil | |
1975 | ido-keep-item-list t | |
1976 | ido-use-merged-list t) | |
1977 | (ido-trace "Merged" t) | |
1978 | )))) | |
71296446 | 1979 | |
789d1bf0 KS |
1980 | (cond |
1981 | (ido-keep-item-list | |
1982 | (setq ido-keep-item-list nil | |
1983 | ido-rescan nil)) | |
1984 | ((eq ido-cur-item 'file) | |
1985 | (setq ido-ignored-list nil | |
cb65c373 KS |
1986 | ido-cur-list (and (not ido-directory-nonreadable) |
1987 | (not ido-directory-too-big) | |
1988 | (ido-make-file-list ido-default-item)))) | |
789d1bf0 KS |
1989 | ((eq ido-cur-item 'dir) |
1990 | (setq ido-ignored-list nil | |
cb65c373 KS |
1991 | ido-cur-list (and (not ido-directory-nonreadable) |
1992 | (not ido-directory-too-big) | |
1993 | (ido-make-dir-list ido-default-item)))) | |
789d1bf0 KS |
1994 | ((eq ido-cur-item 'buffer) |
1995 | (setq ido-ignored-list nil | |
1996 | ido-cur-list (ido-make-buffer-list ido-default-item))) | |
db9f395b KS |
1997 | ((eq ido-cur-item 'list) |
1998 | (setq ido-ignored-list nil | |
1999 | ido-cur-list (ido-make-choice-list ido-default-item))) | |
789d1bf0 KS |
2000 | (t nil)) |
2001 | (setq ido-rotate-temp nil) | |
2002 | ||
2003 | (if ido-process-ignore-lists-inhibit | |
2004 | (setq ido-process-ignore-lists t | |
2005 | ido-process-ignore-lists-inhibit nil)) | |
2006 | ||
2007 | (ido-set-matches) | |
2008 | (if (and ido-matches (eq ido-try-merged-list 'auto)) | |
2009 | (setq ido-try-merged-list t)) | |
c5b40130 LL |
2010 | (let ((max-mini-window-height (or ido-max-window-height |
2011 | (and (boundp 'max-mini-window-height) | |
2012 | max-mini-window-height))) | |
789d1bf0 KS |
2013 | (ido-completing-read t) |
2014 | (ido-require-match require-match) | |
2015 | (ido-use-mycompletion-depth (1+ (minibuffer-depth))) | |
af896da6 LL |
2016 | (show-paren-mode nil) |
2017 | ;; Postpone history adding till later | |
2018 | (history-add-new-input nil)) | |
789d1bf0 KS |
2019 | ;; prompt the user for the file name |
2020 | (setq ido-exit nil) | |
2021 | (setq ido-final-text | |
2022 | (catch 'ido | |
c5b40130 LL |
2023 | (read-from-minibuffer (ido-make-prompt item prompt) |
2024 | (prog1 ido-text-init | |
2025 | (setq ido-text-init nil)) | |
7690bdea | 2026 | ido-completion-map nil hist)))) |
c5b40130 | 2027 | (ido-trace "read-from-minibuffer" ido-final-text) |
99fc91fe AK |
2028 | (and ido-completion-buffer |
2029 | (get-buffer ido-completion-buffer) | |
2030 | (kill-buffer ido-completion-buffer)) | |
789d1bf0 KS |
2031 | |
2032 | (ido-trace "\n_EXIT_" ido-exit) | |
2033 | ||
2034 | (cond | |
2035 | ((eq ido-exit 'refresh) | |
71296446 | 2036 | (if (and (eq ido-use-merged-list 'auto) |
789d1bf0 KS |
2037 | (or (input-pending-p))) |
2038 | (setq ido-use-merged-list nil | |
2039 | ido-keep-item-list t)) | |
2040 | nil) | |
2041 | ||
2042 | ((eq ido-exit 'done) | |
2043 | (setq done t | |
2044 | ido-selected ido-text | |
2045 | ido-exit nil)) | |
2046 | ||
2047 | ((memq ido-exit '(edit chdir)) | |
71296446 | 2048 | (cond |
789d1bf0 | 2049 | ((memq ido-cur-item '(file dir)) |
3f2b52ad | 2050 | (let* ((read-file-name-function nil) |
789d1bf0 KS |
2051 | (edit (eq ido-exit 'edit)) |
2052 | (d ido-current-directory) | |
2053 | (f ido-text-init) | |
84f6c6d0 | 2054 | (new t)) |
789d1bf0 | 2055 | (setq ido-text-init "") |
84f6c6d0 KS |
2056 | (while new |
2057 | (setq new (if edit | |
3729cc87 KS |
2058 | (condition-case nil |
2059 | (read-file-name (concat prompt "[EDIT] ") | |
2060 | (expand-file-name d) | |
2061 | (concat d f) nil f) | |
2062 | (quit (concat d f))) | |
789d1bf0 | 2063 | f) |
84f6c6d0 KS |
2064 | d (or (file-name-directory new) "/") |
2065 | f (file-name-nondirectory new) | |
789d1bf0 | 2066 | edit t) |
71296446 | 2067 | (if (or |
789d1bf0 KS |
2068 | (file-directory-p d) |
2069 | (and (yes-or-no-p (format "Create directory %s? " d)) | |
71296446 | 2070 | (condition-case nil |
789d1bf0 KS |
2071 | (progn (make-directory d t) t) |
2072 | (error | |
2073 | (message "Could not create directory") | |
2074 | (sit-for 1) | |
2075 | nil)))) | |
2076 | (progn | |
2077 | (ido-set-current-directory d nil (eq ido-exit 'chdir)) | |
2078 | (setq ido-text-init f | |
84f6c6d0 | 2079 | new nil)))))) |
789d1bf0 | 2080 | (t |
3729cc87 KS |
2081 | (setq ido-text-init |
2082 | (condition-case nil | |
2083 | (read-string (concat prompt "[EDIT] ") ido-final-text) | |
2084 | (quit ido-final-text))))) | |
2085 | ||
789d1bf0 KS |
2086 | nil) |
2087 | ||
2088 | ((eq ido-exit 'keep) | |
2089 | (setq ido-keep-item-list t)) | |
2090 | ||
db9f395b | 2091 | ((memq ido-exit '(dired fallback find-file switch-to-buffer insert-buffer insert-file)) |
789d1bf0 KS |
2092 | (setq done t)) |
2093 | ||
3729cc87 | 2094 | ((memq ido-exit '(updir push)) |
789d1bf0 KS |
2095 | ;; cannot go up if already at the root-dir (Unix) or at the |
2096 | ;; root-dir of a certain drive (Windows or MS-DOS). | |
bad111c2 KS |
2097 | (if (ido-is-tramp-root) |
2098 | (when (string-match "\\`\\(/\\([^/]+[:@]\\)*\\)\\([^/]+\\)[:@]\\'" ido-current-directory) | |
2099 | (setq ido-text-init (match-string 3 ido-current-directory)) | |
2100 | (ido-set-current-directory (match-string 1 ido-current-directory)) | |
2101 | (setq ido-set-default-item t)) | |
2102 | (unless (ido-is-root-directory) | |
3729cc87 KS |
2103 | (when (eq ido-exit 'push) |
2104 | (setq ido-input-stack (cons (cons ido-cur-item ido-text) ido-input-stack)) | |
2105 | (setq ido-cur-item 'dir) | |
2106 | (setq ido-text-init (file-name-nondirectory (substring ido-current-directory 0 -1))) | |
2107 | (ido-trace "push" ido-input-stack)) | |
bad111c2 KS |
2108 | (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))) |
2109 | (setq ido-set-default-item t)))) | |
789d1bf0 | 2110 | |
3729cc87 KS |
2111 | ((eq ido-exit 'pop) |
2112 | (ido-trace "pop" ido-input-stack) | |
2113 | (let ((elt (car ido-input-stack))) | |
2114 | (setq ido-input-stack (cdr ido-input-stack)) | |
2115 | (ido-set-current-directory (concat ido-current-directory ido-text)) | |
2116 | (setq ido-cur-item (car elt)) | |
2117 | (setq ido-text-init (cdr elt)))) | |
2118 | ||
2119 | ((eq ido-exit 'pop-all) | |
2120 | (ido-trace "pop-all" ido-input-stack) | |
2121 | (while ido-input-stack | |
2122 | (let ((elt (car ido-input-stack))) | |
2123 | (setq ido-input-stack (cdr ido-input-stack)) | |
2124 | (ido-set-current-directory (concat ido-current-directory ido-text)) | |
2125 | (setq ido-cur-item (car elt)) | |
2126 | (setq ido-text-init (cdr elt))))) | |
2127 | ||
789d1bf0 | 2128 | ;; Handling the require-match must be done in a better way. |
b3da0db5 | 2129 | ((and require-match |
11c238b3 | 2130 | (not (memq require-match '(confirm confirm-after-completion))) |
b3da0db5 KS |
2131 | (not (if ido-directory-too-big |
2132 | (file-exists-p (concat ido-current-directory ido-final-text)) | |
2133 | (ido-existing-item-p)))) | |
a09e21bf | 2134 | (error "Must specify valid item")) |
789d1bf0 KS |
2135 | |
2136 | (t | |
2137 | (setq ido-selected | |
69beb26d KS |
2138 | (if (or (eq ido-exit 'takeprompt) |
2139 | (null ido-matches)) | |
2140 | ido-final-text | |
2141 | ;; else take head of list | |
2142 | (ido-name (car ido-matches)))) | |
789d1bf0 KS |
2143 | |
2144 | (cond | |
2a5095fb | 2145 | ((memq item '(buffer list)) |
789d1bf0 KS |
2146 | (setq done t)) |
2147 | ||
2148 | ((string-equal "./" ido-selected) | |
2149 | nil) | |
2150 | ||
2151 | ((string-equal "../" ido-selected) | |
2152 | ;; cannot go up if already at the root-dir (Unix) or at the | |
2153 | ;; root-dir of a certain drive (Windows or MS-DOS). | |
2154 | (or (ido-is-root-directory) | |
2155 | (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1)))) | |
2156 | (setq ido-set-default-item t)) | |
bad111c2 | 2157 | |
10b19e88 KS |
2158 | ((and (string-match (if ido-enable-tramp-completion ".[:@]\\'" ".:\\'") ido-selected) |
2159 | (ido-is-root-directory) ;; Ange-ftp or Tramp | |
2160 | (not (ido-local-file-exists-p ido-selected))) | |
bad111c2 KS |
2161 | (ido-set-current-directory ido-current-directory ido-selected) |
2162 | (ido-trace "tramp prefix" ido-selected) | |
789d1bf0 KS |
2163 | (if (ido-is-slow-ftp-host) |
2164 | (setq ido-exit 'fallback | |
2165 | done t) | |
2166 | (setq ido-set-default-item t))) | |
dfebc0ae | 2167 | |
6c3e2c3d | 2168 | ((string-match (if (memq system-type '(windows-nt ms-dos)) |
f42d8237 LL |
2169 | "\\`[a-zA-Z]:\\|[/\\][^/\\]" |
2170 | "/[^/]") | |
2171 | ido-selected) | |
789d1bf0 KS |
2172 | (ido-set-current-directory (file-name-directory ido-selected)) |
2173 | (setq ido-set-default-item t)) | |
2174 | ||
2175 | ((string-match "\\`~" ido-selected) | |
2176 | (ido-set-current-home ido-selected)) | |
2177 | ||
2178 | ((ido-final-slash ido-selected) | |
2179 | (if ido-enable-last-directory-history | |
2180 | (let ((x (assoc ido-current-directory ido-last-directory-list))) | |
2181 | (if x | |
2182 | (setcdr x ido-selected) | |
2183 | (setq ido-last-directory-list | |
2184 | (cons (cons ido-current-directory ido-selected) ido-last-directory-list))))) | |
2185 | (ido-set-current-directory ido-current-directory ido-selected) | |
3729cc87 | 2186 | (if ido-input-stack |
11ae5e81 KS |
2187 | ; automatically pop stack elements which match existing files or directories |
2188 | (let (elt) | |
2189 | (while (and (setq elt (car ido-input-stack)) | |
2190 | (file-exists-p (concat ido-current-directory (cdr elt)))) | |
3729cc87 KS |
2191 | (if (setq ido-input-stack (cdr ido-input-stack)) |
2192 | (ido-set-current-directory ido-current-directory (cdr elt)) | |
2193 | (setq ido-text-init (cdr elt))) | |
2194 | (setq ido-cur-item (car elt)))) | |
2195 | (setq ido-set-default-item t))) | |
789d1bf0 KS |
2196 | |
2197 | (t | |
2198 | (setq done t)))))) | |
7690bdea LL |
2199 | (add-to-history (cond |
2200 | ((consp hist) | |
2201 | (or (car hist) 'minibuffer-history)) | |
2202 | (hist hist) | |
2203 | (t 'minibuffer-history)) | |
2204 | ido-selected) | |
789d1bf0 KS |
2205 | ido-selected)) |
2206 | ||
2207 | (defun ido-edit-input () | |
d11320e5 | 2208 | "Edit absolute file name entered so far with Ido; terminate by RET. |
155943b9 | 2209 | If cursor is not at the end of the user input, move to end of input." |
789d1bf0 | 2210 | (interactive) |
155943b9 KS |
2211 | (if (not (eobp)) |
2212 | (end-of-line) | |
2213 | (setq ido-text-init (if ido-matches (ido-name (car ido-matches)) ido-text)) | |
2214 | (setq ido-exit 'edit) | |
2215 | (exit-minibuffer))) | |
789d1bf0 KS |
2216 | |
2217 | ;;; MAIN FUNCTIONS | |
db9f395b | 2218 | (defun ido-buffer-internal (method &optional fallback prompt default initial switch-cmd) |
789d1bf0 KS |
2219 | ;; Internal function for ido-switch-buffer and friends |
2220 | (if (not ido-mode) | |
b2d4c118 KS |
2221 | (progn |
2222 | (run-hook-with-args 'ido-before-fallback-functions | |
2223 | (or fallback 'switch-to-buffer)) | |
2224 | (call-interactively (or fallback 'switch-to-buffer))) | |
db9f395b | 2225 | (let* ((ido-context-switch-command switch-cmd) |
cb65c373 KS |
2226 | (ido-current-directory nil) |
2227 | (ido-directory-nonreadable nil) | |
2228 | (ido-directory-too-big nil) | |
3504a4be LL |
2229 | (ido-enable-virtual-buffers (and ido-use-virtual-buffers |
2230 | (not (eq ido-use-virtual-buffers 'auto)))) | |
11c238b3 KS |
2231 | (require-match (confirm-nonexistent-file-or-buffer)) |
2232 | (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default | |
0523d117 JW |
2233 | require-match initial)) |
2234 | filename) | |
789d1bf0 KS |
2235 | |
2236 | ;; Choose the buffer name: either the text typed in, or the head | |
2237 | ;; of the list of matches | |
2238 | ||
71296446 | 2239 | (cond |
db9f395b | 2240 | ((eq ido-exit 'find-file) |
7d046dbb KS |
2241 | (ido-file-internal |
2242 | (if (memq method '(other-window other-frame)) method ido-default-file-method) | |
2243 | nil nil nil nil ido-text)) | |
789d1bf0 | 2244 | |
db9f395b KS |
2245 | ((eq ido-exit 'insert-file) |
2246 | (ido-file-internal 'insert 'insert-file nil "Insert file: " nil ido-text 'ido-enter-insert-buffer)) | |
2247 | ||
789d1bf0 KS |
2248 | ((eq ido-exit 'fallback) |
2249 | (let ((read-buffer-function nil)) | |
16f462c5 KS |
2250 | (setq this-command (or fallback 'switch-to-buffer)) |
2251 | (run-hook-with-args 'ido-before-fallback-functions this-command) | |
2252 | (call-interactively this-command))) | |
789d1bf0 KS |
2253 | |
2254 | ;; Check buf is non-nil. | |
2255 | ((not buf) nil) | |
69beb26d | 2256 | ((= (length buf) 0) nil) |
789d1bf0 KS |
2257 | |
2258 | ;; View buffer if it exists | |
2259 | ((get-buffer buf) | |
16f462c5 | 2260 | (add-to-history 'buffer-name-history buf) |
789d1bf0 KS |
2261 | (if (eq method 'insert) |
2262 | (progn | |
2263 | (ido-record-command 'insert-buffer buf) | |
2d13e588 KS |
2264 | (push-mark |
2265 | (save-excursion | |
2266 | (insert-buffer-substring (get-buffer buf)) | |
2267 | (point)))) | |
789d1bf0 KS |
2268 | (ido-visit-buffer buf method t))) |
2269 | ||
0523d117 | 2270 | ;; check for a virtual buffer reference |
3504a4be LL |
2271 | ((and ido-enable-virtual-buffers |
2272 | ido-virtual-buffers | |
0523d117 JW |
2273 | (setq filename (assoc buf ido-virtual-buffers))) |
2274 | (ido-visit-buffer (find-file-noselect (cdr filename)) method t)) | |
2275 | ||
2276 | ((and (eq ido-create-new-buffer 'prompt) | |
2277 | (null require-match) | |
2278 | (not (y-or-n-p (format "No buffer matching `%s', create one? " buf)))) | |
2279 | nil) | |
2280 | ||
789d1bf0 | 2281 | ;; buffer doesn't exist |
11c238b3 KS |
2282 | ((and (eq ido-create-new-buffer 'never) |
2283 | (null require-match)) | |
a09e21bf | 2284 | (message "No buffer matching `%s'" buf)) |
789d1bf0 KS |
2285 | |
2286 | ((and (eq ido-create-new-buffer 'prompt) | |
11c238b3 | 2287 | (null require-match) |
789d1bf0 KS |
2288 | (not (y-or-n-p (format "No buffer matching `%s', create one? " buf)))) |
2289 | nil) | |
2290 | ||
2291 | ;; create a new buffer | |
2292 | (t | |
16f462c5 | 2293 | (add-to-history 'buffer-name-history buf) |
789d1bf0 KS |
2294 | (setq buf (get-buffer-create buf)) |
2295 | (if (fboundp 'set-buffer-major-mode) | |
2296 | (set-buffer-major-mode buf)) | |
2297 | (ido-visit-buffer buf method t)))))) | |
2298 | ||
789d1bf0 KS |
2299 | (defun ido-record-work-directory (&optional dir) |
2300 | (when (and (numberp ido-max-work-directory-list) (> ido-max-work-directory-list 0)) | |
2301 | (if (and (setq dir (or dir ido-current-directory)) (> (length dir) 0)) | |
2302 | (let ((items ido-work-directory-list-ignore-regexps) | |
2303 | (case-fold-search nil)) | |
2304 | (while (and items dir) | |
2305 | (if (string-match (car items) dir) | |
2306 | (setq dir nil)) | |
2307 | (setq items (cdr items))) | |
2308 | (if dir | |
2309 | (setq ido-work-directory-list (cons dir (delete dir ido-work-directory-list)))))) | |
2310 | (if (> (length ido-work-directory-list) ido-max-work-directory-list) | |
2311 | (setcdr (nthcdr (1- ido-max-work-directory-list) ido-work-directory-list) nil)))) | |
2312 | ||
2313 | (defun ido-forget-work-directory () | |
2314 | (interactive) | |
2315 | (when (and ido-current-directory ido-work-directory-list) | |
2316 | (setq ido-work-directory-list (delete ido-current-directory ido-work-directory-list)) | |
2317 | (when ido-use-merged-list | |
2318 | (ido-undo-merge-work-directory) | |
2319 | (setq ido-exit 'refresh | |
2320 | ido-try-merged-list t | |
2321 | ido-use-merged-list t | |
2322 | ido-text-init ido-text | |
2323 | ido-rotate-temp t) | |
2324 | (exit-minibuffer)))) | |
71296446 | 2325 | |
789d1bf0 KS |
2326 | (defun ido-record-work-file (name) |
2327 | ;; Save NAME in ido-work-file-list | |
2328 | (when (and (numberp ido-max-work-file-list) (> ido-max-work-file-list 0)) | |
2329 | (or | |
2330 | (and ido-work-file-list (equal (car ido-work-file-list) name)) | |
2331 | (setq ido-work-file-list (cons name (delete name ido-work-file-list)))) | |
2332 | (if (> (length ido-work-file-list) ido-max-work-file-list) | |
2333 | (setcdr (nthcdr (1- ido-max-work-file-list) ido-work-file-list) nil)))) | |
2334 | ||
a70343bd KS |
2335 | (defun ido-expand-directory (dir) |
2336 | ;; Expand DIR or use DEFAULT-DIRECTORY if nil. | |
2337 | ;; Add final slash to result in case it was missing from DEFAULT-DIRECTORY. | |
2338 | (ido-final-slash (expand-file-name (or dir default-directory)) t)) | |
2339 | ||
db9f395b | 2340 | (defun ido-file-internal (method &optional fallback default prompt item initial switch-cmd) |
789d1bf0 | 2341 | ;; Internal function for ido-find-file and friends |
310682e6 KS |
2342 | (unless item |
2343 | (setq item 'file)) | |
94da3cf1 KS |
2344 | (let ((ido-current-directory (ido-expand-directory default)) |
2345 | (ido-context-switch-command switch-cmd) | |
83a12f3a | 2346 | ido-directory-nonreadable ido-directory-too-big |
94da3cf1 KS |
2347 | filename) |
2348 | ||
2349 | (if (or (not ido-mode) (ido-is-slow-ftp-host)) | |
2350 | (setq filename t | |
2351 | ido-exit 'fallback) | |
2352 | (setq ido-directory-nonreadable | |
2353 | (ido-nonreadable-directory-p ido-current-directory) | |
2354 | ido-directory-too-big | |
2355 | (and (not ido-directory-nonreadable) | |
2356 | (ido-directory-too-big-p ido-current-directory)))) | |
2357 | ||
2358 | (when (and (eq item 'file) | |
94912b88 SM |
2359 | (or ido-use-url-at-point ido-use-filename-at-point)) |
2360 | (let (fn) | |
310682e6 | 2361 | (require 'ffap) |
3808c51f CY |
2362 | ;; Duplicate code from ffap-guesser as we want different |
2363 | ;; behavior for files and URLs. | |
310682e6 | 2364 | (cond |
3729cc87 KS |
2365 | ((with-no-warnings |
2366 | (and ido-use-url-at-point | |
2367 | ffap-url-regexp | |
2368 | (ffap-fixup-url (or (ffap-url-at-point) | |
2369 | (ffap-gopher-at-point))))) | |
310682e6 KS |
2370 | (setq ido-exit 'ffap |
2371 | filename t)) | |
2372 | ||
2373 | ((and ido-use-filename-at-point | |
004a00f4 DN |
2374 | (setq fn (with-no-warnings |
2375 | (if (eq ido-use-filename-at-point 'guess) | |
2376 | (ffap-guesser) | |
2377 | (ffap-string-at-point)))) | |
94912b88 | 2378 | (not (string-match "\\`http:/" fn))) |
17d1b51b DG |
2379 | (let ((absolute-fn (expand-file-name fn))) |
2380 | (cond | |
2381 | ((file-directory-p absolute-fn) | |
94912b88 SM |
2382 | (setq ido-current-directory |
2383 | (file-name-as-directory absolute-fn))) | |
17d1b51b DG |
2384 | ((file-directory-p (file-name-directory absolute-fn)) |
2385 | (setq ido-current-directory (file-name-directory absolute-fn)) | |
2386 | (setq initial (file-name-nondirectory absolute-fn))))))))) | |
310682e6 KS |
2387 | |
2388 | (let (ido-saved-vc-hb | |
94912b88 SM |
2389 | (vc-handled-backends (and (boundp 'vc-handled-backends) |
2390 | vc-handled-backends)) | |
789d1bf0 KS |
2391 | (ido-work-directory-index -1) |
2392 | (ido-work-file-index -1) | |
2393 | (ido-find-literal nil)) | |
2394 | ||
2395 | (unless filename | |
310682e6 | 2396 | (setq ido-saved-vc-hb vc-handled-backends) |
d471b4fe | 2397 | (let ((minibuffer-completing-file-name t)) |
94912b88 SM |
2398 | (setq filename |
2399 | (ido-read-internal item | |
2400 | (or prompt "Find file: ") | |
2401 | 'ido-file-history | |
2402 | (and (eq method 'alt-file) buffer-file-name) | |
2403 | (confirm-nonexistent-file-or-buffer) | |
2404 | initial)))) | |
789d1bf0 KS |
2405 | |
2406 | ;; Choose the file name: either the text typed in, or the head | |
2407 | ;; of the list of matches | |
2408 | ||
2409 | (cond | |
2410 | ((eq ido-exit 'fallback) | |
2411 | ;; Need to guard setting of default-directory here, since | |
2412 | ;; we don't want to change directory of current buffer. | |
2413 | (let ((default-directory ido-current-directory) | |
2414 | (read-file-name-function nil)) | |
16f462c5 KS |
2415 | (setq this-command (or fallback 'find-file)) |
2416 | (run-hook-with-args 'ido-before-fallback-functions this-command) | |
2417 | (call-interactively this-command))) | |
789d1bf0 | 2418 | |
db9f395b | 2419 | ((eq ido-exit 'switch-to-buffer) |
7d046dbb | 2420 | (ido-buffer-internal |
94912b88 SM |
2421 | (if (memq method '(other-window other-frame)) |
2422 | method ido-default-buffer-method) | |
7d046dbb | 2423 | nil nil nil ido-text)) |
789d1bf0 | 2424 | |
db9f395b | 2425 | ((eq ido-exit 'insert-buffer) |
94912b88 SM |
2426 | (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " |
2427 | nil ido-text 'ido-enter-insert-file)) | |
db9f395b | 2428 | |
789d1bf0 | 2429 | ((eq ido-exit 'dired) |
a9400458 GM |
2430 | (funcall (cond ((eq method 'other-window) 'dired-other-window) |
2431 | ((eq method 'other-frame) 'dired-other-frame) | |
2432 | (t 'dired)) | |
2433 | (concat ido-current-directory (or ido-text "")))) | |
789d1bf0 | 2434 | |
310682e6 KS |
2435 | ((eq ido-exit 'ffap) |
2436 | (find-file-at-point)) | |
2437 | ||
789d1bf0 KS |
2438 | ((eq method 'alt-file) |
2439 | (ido-record-work-file filename) | |
2440 | (setq default-directory ido-current-directory) | |
2441 | (ido-record-work-directory) | |
2442 | (find-alternate-file filename)) | |
2443 | ||
2444 | ((memq method '(dired list-directory)) | |
2445 | (if (equal filename ".") | |
2446 | (setq filename "")) | |
94912b88 SM |
2447 | (let* ((dirname (ido-final-slash |
2448 | (concat ido-current-directory filename) t)) | |
84f6c6d0 | 2449 | (file (substring dirname 0 -1))) |
789d1bf0 | 2450 | (cond |
84f6c6d0 KS |
2451 | ((file-directory-p dirname) |
2452 | (ido-record-command method dirname) | |
2453 | (ido-record-work-directory dirname) | |
2454 | (funcall method dirname)) | |
789d1bf0 KS |
2455 | ((file-directory-p ido-current-directory) |
2456 | (cond | |
2457 | ((file-exists-p file) | |
2458 | (ido-record-command method ido-current-directory) | |
2459 | (ido-record-work-directory) | |
2460 | (funcall method ido-current-directory) | |
2461 | (if (eq method 'dired) | |
3729cc87 KS |
2462 | (with-no-warnings |
2463 | (dired-goto-file (expand-file-name file))))) | |
789d1bf0 | 2464 | ((string-match "[[*?]" filename) |
84f6c6d0 KS |
2465 | (setq dirname (concat ido-current-directory filename)) |
2466 | (ido-record-command method dirname) | |
789d1bf0 | 2467 | (ido-record-work-directory) |
84f6c6d0 | 2468 | (funcall method dirname)) |
94912b88 SM |
2469 | ((y-or-n-p (format "Directory %s does not exist. Create it? " |
2470 | filename)) | |
84f6c6d0 KS |
2471 | (ido-record-command method dirname) |
2472 | (ido-record-work-directory dirname) | |
2473 | (make-directory-internal dirname) | |
2474 | (funcall method dirname)) | |
789d1bf0 KS |
2475 | (t |
2476 | ;; put make-directory command on history | |
84f6c6d0 | 2477 | (ido-record-command 'make-directory dirname)))) |
789d1bf0 KS |
2478 | (t (error "No such directory"))))) |
2479 | ||
2480 | ((eq method 'write) | |
2481 | (ido-record-work-file filename) | |
2482 | (setq default-directory ido-current-directory) | |
16f462c5 KS |
2483 | (setq filename (concat ido-current-directory filename)) |
2484 | (ido-record-command 'write-file filename) | |
2485 | (add-to-history 'file-name-history filename) | |
789d1bf0 | 2486 | (ido-record-work-directory) |
395542c6 | 2487 | (write-file filename t)) |
789d1bf0 KS |
2488 | |
2489 | ((eq method 'read-only) | |
2490 | (ido-record-work-file filename) | |
2491 | (setq filename (concat ido-current-directory filename)) | |
2492 | (ido-record-command fallback filename) | |
2493 | (ido-record-work-directory) | |
b2d4c118 | 2494 | (run-hook-with-args 'ido-before-fallback-functions fallback) |
789d1bf0 KS |
2495 | (funcall fallback filename)) |
2496 | ||
2497 | ((eq method 'insert) | |
2498 | (ido-record-work-file filename) | |
2499 | (setq filename (concat ido-current-directory filename)) | |
71296446 | 2500 | (ido-record-command |
789d1bf0 KS |
2501 | (if ido-find-literal 'insert-file-literally 'insert-file) |
2502 | filename) | |
16f462c5 | 2503 | (add-to-history 'file-name-history filename) |
789d1bf0 | 2504 | (ido-record-work-directory) |
2d13e588 KS |
2505 | (insert-file-1 filename |
2506 | (if ido-find-literal | |
2507 | #'insert-file-contents-literally | |
2508 | #'insert-file-contents))) | |
789d1bf0 KS |
2509 | |
2510 | (filename | |
2511 | (ido-record-work-file filename) | |
2512 | (setq filename (concat ido-current-directory filename)) | |
2513 | (ido-record-command 'find-file filename) | |
16f462c5 | 2514 | (add-to-history 'file-name-history filename) |
789d1bf0 | 2515 | (ido-record-work-directory) |
94912b88 SM |
2516 | (ido-visit-buffer (find-file-noselect filename nil ido-find-literal) |
2517 | method)))))) | |
789d1bf0 KS |
2518 | |
2519 | (defun ido-existing-item-p () | |
2520 | ;; Return non-nil if there is a matching item | |
2521 | (not (null ido-matches))) | |
2522 | ||
2523 | ;;; COMPLETION CODE | |
2524 | ||
2525 | (defun ido-set-common-completion () | |
2526 | ;; Find common completion of `ido-text' in `ido-matches' | |
2527 | ;; The result is stored in `ido-common-match-string' | |
ccaa42ed JB |
2528 | (let (val) |
2529 | (setq ido-common-match-string nil) | |
789d1bf0 KS |
2530 | (if (and ido-matches |
2531 | (not ido-enable-regexp) ;; testing | |
2532 | (stringp ido-text) | |
2533 | (> (length ido-text) 0)) | |
2534 | (if (setq val (ido-find-common-substring ido-matches ido-text)) | |
2535 | (setq ido-common-match-string val))) | |
2536 | val)) | |
2537 | ||
2538 | (defun ido-complete () | |
2539 | "Try and complete the current pattern amongst the file names." | |
2540 | (interactive) | |
2541 | (let (res) | |
71296446 | 2542 | (cond |
665ed61a KS |
2543 | (ido-incomplete-regexp |
2544 | ;; Do nothing | |
2545 | ) | |
789d1bf0 KS |
2546 | ((and (memq ido-cur-item '(file dir)) |
2547 | (string-match "[$]" ido-text)) | |
2548 | (let ((evar (substitute-in-file-name (concat ido-current-directory ido-text)))) | |
2549 | (if (not (file-exists-p (file-name-directory evar))) | |
337d2b66 | 2550 | (message "Expansion generates non-existing directory name") |
789d1bf0 KS |
2551 | (if (file-directory-p evar) |
2552 | (ido-set-current-directory evar) | |
2553 | (let ((d (or (file-name-directory evar) "/")) | |
2554 | (f (file-name-nondirectory evar))) | |
2555 | (when (file-directory-p d) | |
2556 | (ido-set-current-directory d) | |
2557 | (setq ido-text-init f)))) | |
2558 | (setq ido-exit 'refresh) | |
2559 | (exit-minibuffer)))) | |
2560 | ||
cb65c373 KS |
2561 | (ido-directory-too-big |
2562 | (setq ido-directory-too-big nil) | |
2563 | (setq ido-text-init ido-text) | |
2564 | (setq ido-exit 'refresh) | |
2565 | (exit-minibuffer)) | |
2566 | ||
789d1bf0 KS |
2567 | ((not ido-matches) |
2568 | (when ido-completion-buffer | |
d1a0acac | 2569 | (call-interactively (setq this-command ido-cannot-complete-command)))) |
71296446 | 2570 | |
bad111c2 KS |
2571 | ((and (= 1 (length ido-matches)) |
2572 | (not (and ido-enable-tramp-completion | |
2573 | (string-equal ido-current-directory "/") | |
10b19e88 KS |
2574 | (string-match ".[@:]\\'" (ido-name (car ido-matches))))) |
2575 | (not (ido-local-file-exists-p (ido-name (car ido-matches))))) | |
789d1bf0 | 2576 | ;; only one choice, so select it. |
d81aa76a KS |
2577 | (if (not ido-confirm-unique-completion) |
2578 | (exit-minibuffer) | |
2579 | (setq ido-rescan (not ido-enable-prefix)) | |
2580 | (delete-region (minibuffer-prompt-end) (point)) | |
5a1b28a4 | 2581 | (insert (ido-name (car ido-matches))))) |
71296446 | 2582 | |
789d1bf0 KS |
2583 | (t ;; else there could be some completions |
2584 | (setq res ido-common-match-string) | |
2585 | (if (and (not (memq res '(t nil))) | |
2586 | (not (equal res ido-text))) | |
2587 | ;; found something to complete, so put it in the minibuffer. | |
2588 | (progn | |
2589 | ;; move exact match to front if not in prefix mode | |
2590 | (setq ido-rescan (not ido-enable-prefix)) | |
2591 | (delete-region (minibuffer-prompt-end) (point)) | |
2592 | (insert res)) | |
2593 | ;; else nothing to complete | |
d1a0acac | 2594 | (call-interactively (setq this-command ido-cannot-complete-command)) |
789d1bf0 KS |
2595 | ))))) |
2596 | ||
030fa15b KS |
2597 | (defun ido-complete-space () |
2598 | "Try completion unless inserting the space makes sense." | |
2599 | (interactive) | |
2600 | (if (and (stringp ido-common-match-string) | |
2601 | (stringp ido-text) | |
2602 | (cond | |
2603 | ((> (length ido-common-match-string) (length ido-text)) | |
2604 | (= (aref ido-common-match-string (length ido-text)) ? )) | |
2605 | (ido-matches | |
2606 | (let (insert-space | |
2607 | (re (concat (regexp-quote ido-text) " ")) | |
2608 | (comp ido-matches)) | |
2609 | (while comp | |
2610 | (if (string-match re (ido-name (car comp))) | |
2611 | (setq comp nil insert-space t) | |
2612 | (setq comp (cdr comp)))) | |
2613 | insert-space)) | |
2614 | (t nil))) | |
2615 | (insert " ") | |
2616 | (ido-complete))) | |
2617 | ||
789d1bf0 | 2618 | (defun ido-undo-merge-work-directory (&optional text try refresh) |
d11320e5 | 2619 | "Undo or redo last Ido directory merge operation. |
789d1bf0 KS |
2620 | If no merge has yet taken place, toggle automatic merging option." |
2621 | (interactive) | |
2622 | (cond | |
2623 | (ido-pre-merge-state | |
2624 | (ido-set-current-directory (nth 1 ido-pre-merge-state)) | |
2625 | (setq ido-text-init (or text (car ido-pre-merge-state)) | |
2626 | ido-cur-list (nth 2 ido-pre-merge-state) | |
2627 | ido-ignored-list (nth 3 ido-pre-merge-state) | |
2628 | ido-matches (nth 4 ido-pre-merge-state) | |
2629 | ido-use-merged-list nil | |
2630 | ido-try-merged-list try | |
2631 | ido-keep-item-list (not refresh) | |
2632 | ido-rescan nil | |
2633 | ido-exit 'refresh | |
2634 | ido-pre-merge-state nil) | |
2635 | (exit-minibuffer)) | |
2636 | (text | |
2637 | nil) | |
2638 | (ido-try-merged-list | |
2639 | (setq ido-try-merged-list nil)) | |
2640 | (ido-matches | |
2641 | (setq ido-try-merged-list t)) | |
2642 | ((not ido-use-merged-list) | |
2643 | (ido-merge-work-directories)))) | |
71296446 | 2644 | |
ae9d279d KS |
2645 | ;;; Magic C-f |
2646 | ||
a9dbdece | 2647 | (defun ido-magic-forward-char (arg) |
ae9d279d | 2648 | "Move forward in user input or perform magic action. |
616e8e5f | 2649 | If no user input is present, or at end of input, perform magic actions: |
79164cf4 | 2650 | C-x C-b ... C-f switch to `ido-find-file'. |
d11320e5 JB |
2651 | C-x C-f ... C-f fallback to non-Ido `find-file'. |
2652 | C-x C-d ... C-f fallback to non-Ido brief `dired'. | |
2653 | C-x d ... C-f fallback to non-Ido `dired'." | |
a9dbdece | 2654 | (interactive "P") |
ae9d279d | 2655 | (cond |
a9dbdece KS |
2656 | ((or arg (not (eobp))) |
2657 | (forward-char (min (prefix-numeric-value arg) | |
2658 | (- (point-max) (point))))) | |
cc2691b7 KS |
2659 | ((memq ido-cur-item '(file dir)) |
2660 | (ido-fallback-command)) | |
2661 | (ido-context-switch-command | |
2662 | (call-interactively ido-context-switch-command)) | |
2663 | ((eq ido-cur-item 'buffer) | |
2664 | (ido-enter-find-file)))) | |
ae9d279d KS |
2665 | |
2666 | ;;; Magic C-b | |
2667 | ||
a9dbdece | 2668 | (defun ido-magic-backward-char (arg) |
ae9d279d | 2669 | "Move backward in user input or perform magic action. |
cc2691b7 | 2670 | If no user input is present, or at start of input, perform magic actions: |
a09e21bf JB |
2671 | C-x C-f C-b switch to `ido-switch-buffer'. |
2672 | C-x C-d C-b switch to `ido-switch-buffer'. | |
2673 | C-x d C-b switch to `ido-switch-buffer'. | |
d11320e5 | 2674 | C-x C-b C-b fallback to non-Ido `switch-to-buffer'." |
a9dbdece | 2675 | (interactive "P") |
ae9d279d | 2676 | (cond |
a9dbdece KS |
2677 | ((or arg (> (point) (minibuffer-prompt-end))) |
2678 | (forward-char | |
2679 | (- (min (prefix-numeric-value arg) | |
2680 | (- (point) (minibuffer-prompt-end)))))) | |
155943b9 KS |
2681 | ((eq last-command this-command) |
2682 | (when (and (memq ido-cur-item '(file dir)) | |
2683 | (not (bobp))) | |
2684 | (ido-push-dir))) ; else do nothing | |
ae9d279d | 2685 | ((eq ido-cur-item 'buffer) |
cc2691b7 KS |
2686 | (ido-fallback-command)) |
2687 | (ido-context-switch-command | |
2688 | (call-interactively ido-context-switch-command)) | |
2689 | (t | |
2690 | (ido-enter-switch-buffer)))) | |
ae9d279d KS |
2691 | |
2692 | ;;; Magic C-d | |
2693 | ||
a9dbdece | 2694 | (defun ido-magic-delete-char (arg) |
ae9d279d KS |
2695 | "Delete following char in user input or perform magic action. |
2696 | If at end of user input, perform magic actions: | |
79164cf4 | 2697 | C-x C-f ... C-d enter `dired' on current directory." |
a9dbdece | 2698 | (interactive "P") |
ae9d279d | 2699 | (cond |
a9dbdece KS |
2700 | ((or arg (not (eobp))) |
2701 | (delete-char (min (prefix-numeric-value arg) | |
2702 | (- (point-max) (point))))) | |
ae9d279d KS |
2703 | (ido-context-switch-command |
2704 | nil) | |
2705 | ((memq ido-cur-item '(file dir)) | |
2706 | (ido-enter-dired)))) | |
2707 | ||
2708 | ||
789d1bf0 KS |
2709 | ;;; TOGGLE FUNCTIONS |
2710 | ||
2711 | (defun ido-toggle-case () | |
2712 | "Toggle the value of `ido-case-fold'." | |
2713 | (interactive) | |
2714 | (setq ido-case-fold (not ido-case-fold)) | |
2715 | ;; ask for list to be regenerated. | |
2716 | (setq ido-rescan t)) | |
2717 | ||
2718 | (defun ido-toggle-regexp () | |
2719 | "Toggle the value of `ido-enable-regexp'." | |
2720 | (interactive) | |
2721 | (setq ido-enable-regexp (not ido-enable-regexp)) | |
2722 | ;; ask for list to be regenerated. | |
2723 | (setq ido-rescan t)) | |
2724 | ||
2725 | (defun ido-toggle-prefix () | |
2726 | "Toggle the value of `ido-enable-prefix'." | |
2727 | (interactive) | |
2728 | (setq ido-enable-prefix (not ido-enable-prefix)) | |
2729 | ;; ask for list to be regenerated. | |
2730 | (setq ido-rescan t)) | |
2731 | ||
2732 | (defun ido-toggle-ignore () | |
2733 | "Toggle ignoring files specified with `ido-ignore-files'." | |
2734 | (interactive) | |
155943b9 KS |
2735 | (if (and (not (eobp)) (> (point) (minibuffer-prompt-end))) |
2736 | (goto-char (minibuffer-prompt-end)) | |
2737 | (if ido-directory-too-big | |
2738 | (progn | |
2739 | (message "Reading directory...") | |
2740 | (setq ido-directory-too-big nil)) | |
2741 | (setq ido-process-ignore-lists (not ido-process-ignore-lists))) | |
2742 | (setq ido-text-init ido-text) | |
2743 | (setq ido-exit 'refresh) | |
2744 | (exit-minibuffer))) | |
789d1bf0 KS |
2745 | |
2746 | (defun ido-toggle-vc () | |
d11320e5 | 2747 | "Toggle version control for this file." |
789d1bf0 KS |
2748 | (interactive) |
2749 | (if (and ido-mode (eq ido-cur-item 'file)) | |
2750 | (progn | |
310682e6 KS |
2751 | (setq vc-handled-backends |
2752 | (if vc-handled-backends nil ido-saved-vc-hb)) | |
789d1bf0 KS |
2753 | (setq ido-text-init ido-text) |
2754 | (setq ido-exit 'keep) | |
2755 | (exit-minibuffer)))) | |
2756 | ||
2757 | (defun ido-toggle-literal () | |
2758 | "Toggle literal reading of this file." | |
2759 | (interactive) | |
2760 | (if (and ido-mode (eq ido-cur-item 'file)) | |
2761 | (progn | |
2762 | (setq ido-find-literal (not ido-find-literal)) | |
2763 | (setq ido-text-init ido-text) | |
2764 | (setq ido-exit 'keep) | |
2765 | (exit-minibuffer)))) | |
2766 | ||
c5cbeb12 LL |
2767 | (defun ido-toggle-virtual-buffers () |
2768 | "Toggle the use of virtual buffers. | |
2769 | See `ido-use-virtual-buffers' for explanation of virtual buffer." | |
2770 | (interactive) | |
2771 | (when (and ido-mode (eq ido-cur-item 'buffer)) | |
3504a4be LL |
2772 | (setq ido-enable-virtual-buffers |
2773 | (if ido-enable-virtual-buffers | |
2774 | nil | |
2775 | ;; Use `always' instead of t for `ido-exhibit'. | |
2776 | 'always)) | |
c5cbeb12 LL |
2777 | (setq ido-text-init ido-text) |
2778 | (setq ido-exit 'refresh) | |
2779 | (exit-minibuffer))) | |
2780 | ||
789d1bf0 KS |
2781 | (defun ido-reread-directory () |
2782 | "Read current directory again. | |
2783 | May be useful if cached version is no longer valid, but directory | |
d11320e5 | 2784 | timestamp has not changed (e.g. with FTP or on Windows)." |
789d1bf0 | 2785 | (interactive) |
ff07e0ac | 2786 | (if (and ido-mode (memq ido-cur-item '(file dir))) |
789d1bf0 | 2787 | (progn |
1b00bc64 KS |
2788 | (if (ido-is-unc-root) |
2789 | (setq ido-unc-hosts-cache t) | |
2790 | (ido-remove-cached-dir ido-current-directory)) | |
789d1bf0 KS |
2791 | (setq ido-text-init ido-text) |
2792 | (setq ido-rotate-temp t) | |
2793 | (setq ido-exit 'refresh) | |
2794 | (exit-minibuffer)))) | |
2795 | ||
2796 | (defun ido-exit-minibuffer () | |
2797 | "Exit minibuffer, but make sure we have a match if one is needed." | |
2798 | (interactive) | |
665ed61a | 2799 | (if (and (or (not ido-require-match) |
11c238b3 KS |
2800 | (if (memq ido-require-match '(confirm confirm-after-completion)) |
2801 | (if (or (eq ido-cur-item 'dir) | |
2802 | (eq last-command this-command)) | |
2803 | t | |
2804 | (setq ido-show-confirm-message t) | |
2805 | nil)) | |
665ed61a KS |
2806 | (ido-existing-item-p)) |
2807 | (not ido-incomplete-regexp)) | |
3729cc87 | 2808 | (exit-minibuffer))) |
789d1bf0 KS |
2809 | |
2810 | (defun ido-select-text () | |
2811 | "Select the buffer or file named by the prompt. | |
2812 | If no buffer or file exactly matching the prompt exists, maybe create a new one." | |
2813 | (interactive) | |
2814 | (setq ido-exit 'takeprompt) | |
2815 | (exit-minibuffer)) | |
2816 | ||
2817 | (defun ido-fallback-command () | |
d11320e5 | 2818 | "Fallback to non-Ido version of current command." |
789d1bf0 | 2819 | (interactive) |
4260eddd KS |
2820 | (let ((i (length ido-text))) |
2821 | (while (> i 0) | |
2822 | (push (aref ido-text (setq i (1- i))) unread-command-events))) | |
789d1bf0 KS |
2823 | (setq ido-exit 'fallback) |
2824 | (exit-minibuffer)) | |
2825 | ||
2826 | (defun ido-enter-find-file () | |
616e8e5f | 2827 | "Drop into `find-file' from buffer switching." |
789d1bf0 | 2828 | (interactive) |
db9f395b | 2829 | (setq ido-exit 'find-file) |
789d1bf0 KS |
2830 | (exit-minibuffer)) |
2831 | ||
2832 | (defun ido-enter-switch-buffer () | |
616e8e5f | 2833 | "Drop into `ido-switch-buffer' from file switching." |
789d1bf0 | 2834 | (interactive) |
db9f395b | 2835 | (setq ido-exit 'switch-to-buffer) |
789d1bf0 KS |
2836 | (exit-minibuffer)) |
2837 | ||
2838 | (defun ido-enter-dired () | |
a09e21bf | 2839 | "Drop into `dired' from file switching." |
789d1bf0 KS |
2840 | (interactive) |
2841 | (setq ido-exit 'dired) | |
2842 | (exit-minibuffer)) | |
2843 | ||
db9f395b | 2844 | (defun ido-enter-insert-buffer () |
a09e21bf | 2845 | "Drop into `insert-buffer' from insert file." |
db9f395b KS |
2846 | (interactive) |
2847 | (setq ido-exit 'insert-buffer) | |
2848 | (exit-minibuffer)) | |
2849 | ||
2850 | (defun ido-enter-insert-file () | |
a09e21bf | 2851 | "Drop into `insert-file' from insert buffer." |
db9f395b KS |
2852 | (interactive) |
2853 | (setq ido-exit 'insert-file) | |
2854 | (exit-minibuffer)) | |
2855 | ||
789d1bf0 KS |
2856 | |
2857 | (defun ido-up-directory (&optional clear) | |
2858 | "Go up one directory level." | |
2859 | (interactive "P") | |
2860 | (setq ido-text-init (if clear nil ido-text)) | |
2861 | (setq ido-exit 'updir) | |
2862 | (setq ido-rotate-temp t) | |
2863 | (exit-minibuffer)) | |
2864 | ||
2865 | (defun ido-delete-backward-updir (count) | |
2866 | "Delete char backwards, or at beginning of buffer, go up one level." | |
2867 | (interactive "P") | |
2868 | (cond | |
2869 | ((= (minibuffer-prompt-end) (point)) | |
2870 | (if (not count) | |
2871 | (ido-up-directory t))) | |
2872 | ((and ido-pre-merge-state (string-equal (car ido-pre-merge-state) ido-text)) | |
2873 | (ido-undo-merge-work-directory (substring ido-text 0 -1) t t)) | |
f0a73ccc KS |
2874 | ((eq this-original-command 'viper-backward-char) |
2875 | (funcall this-original-command (prefix-numeric-value count))) | |
2876 | ((eq this-original-command 'viper-del-backward-char-in-insert) | |
2877 | (funcall this-original-command)) | |
789d1bf0 | 2878 | (t |
d355a0b7 | 2879 | (delete-char (- (prefix-numeric-value count)))))) |
789d1bf0 KS |
2880 | |
2881 | (defun ido-delete-backward-word-updir (count) | |
2882 | "Delete all chars backwards, or at beginning of buffer, go up one level." | |
2883 | (interactive "P") | |
2884 | (if (= (minibuffer-prompt-end) (point)) | |
2885 | (if (not count) | |
2886 | (ido-up-directory t)) | |
f0a73ccc KS |
2887 | (if (eq this-original-command 'viper-delete-backward-word) |
2888 | (funcall this-original-command (prefix-numeric-value count)) | |
2889 | (backward-kill-word (prefix-numeric-value count))))) | |
789d1bf0 KS |
2890 | |
2891 | (defun ido-get-work-directory (&optional incr must-match) | |
2892 | (let ((n (length ido-work-directory-list)) | |
2893 | (i ido-work-directory-index) | |
2894 | (j 0) | |
2895 | dir) | |
2896 | (if (or (not ido-text) (= (length ido-text) 0)) | |
2897 | (setq must-match nil)) | |
2898 | (while (< j n) | |
2899 | (setq i (+ i incr) | |
2900 | j (1+ j)) | |
2901 | (if (> incr 0) | |
2902 | (if (>= i n) (setq i 0)) | |
2903 | (if (< i 0) (setq i (1- n)))) | |
2904 | (setq dir (nth i ido-work-directory-list)) | |
2905 | (if (and dir | |
2906 | (not (equal dir ido-current-directory)) | |
2907 | (file-directory-p dir) | |
2908 | (or (not must-match) | |
cb65c373 | 2909 | ;; TODO. check for nonreadable and too-big. |
ec441ab5 | 2910 | (ido-set-matches-1 |
789d1bf0 | 2911 | (if (eq ido-cur-item 'file) |
ec441ab5 KS |
2912 | (ido-make-file-list-1 dir) |
2913 | (ido-make-dir-list-1 dir))))) | |
789d1bf0 KS |
2914 | (setq j n) |
2915 | (setq dir nil))) | |
2916 | (if dir | |
2917 | (setq ido-work-directory-index i)) | |
2918 | dir)) | |
2919 | ||
2920 | (defun ido-prev-work-directory () | |
2921 | "Change to next working directory in list." | |
2922 | (interactive) | |
2923 | (let ((dir (ido-get-work-directory 1 ido-work-directory-match-only))) | |
2924 | (when dir | |
2925 | (ido-set-current-directory dir) | |
2926 | (setq ido-exit 'refresh) | |
2927 | (setq ido-text-init ido-text) | |
2928 | (setq ido-rotate-temp t) | |
2929 | (exit-minibuffer)))) | |
2930 | ||
2931 | (defun ido-next-work-directory () | |
2932 | "Change to previous working directory in list." | |
2933 | (interactive) | |
2934 | (let ((dir (ido-get-work-directory -1 ido-work-directory-match-only))) | |
2935 | (when dir | |
2936 | (ido-set-current-directory dir) | |
2937 | (setq ido-exit 'refresh) | |
2938 | (setq ido-text-init ido-text) | |
2939 | (setq ido-rotate-temp t) | |
2940 | (exit-minibuffer)))) | |
2941 | ||
2942 | (defun ido-merge-work-directories () | |
2943 | "Search (and merge) work directories for files matching the current input string." | |
2944 | (interactive) | |
2945 | (setq ido-use-merged-list t ido-try-merged-list t) | |
2946 | (setq ido-exit 'refresh) | |
2947 | (setq ido-text-init ido-text) | |
2948 | (setq ido-rotate-temp t) | |
2949 | (exit-minibuffer)) | |
2950 | ||
2951 | (defun ido-wide-find-file (&optional file) | |
d11320e5 | 2952 | "Prompt for FILE to search for using `find', starting from current directory." |
789d1bf0 KS |
2953 | (interactive) |
2954 | (unless file | |
b0df3884 KS |
2955 | (let ((enable-recursive-minibuffers t)) |
2956 | (setq file | |
3729cc87 KS |
2957 | (condition-case nil |
2958 | (read-string (concat "Wide find file: " ido-current-directory) ido-text) | |
2959 | (quit ""))))) | |
789d1bf0 KS |
2960 | (when (> (length file) 0) |
2961 | (setq ido-use-merged-list t ido-try-merged-list 'wide) | |
2962 | (setq ido-exit 'refresh) | |
2963 | (setq ido-text-init file) | |
2964 | (setq ido-rotate-temp t) | |
2965 | (exit-minibuffer))) | |
2966 | ||
2967 | (defun ido-wide-find-dir (&optional dir) | |
d11320e5 | 2968 | "Prompt for DIR to search for using `find', starting from current directory." |
789d1bf0 KS |
2969 | (interactive) |
2970 | (unless dir | |
b0df3884 KS |
2971 | (let ((enable-recursive-minibuffers t)) |
2972 | (setq dir | |
3729cc87 KS |
2973 | (condition-case nil |
2974 | (read-string (concat "Wide find directory: " ido-current-directory) ido-text) | |
2975 | (quit ""))))) | |
789d1bf0 KS |
2976 | (when (> (length dir) 0) |
2977 | (setq ido-use-merged-list t ido-try-merged-list 'wide) | |
2978 | (setq ido-exit 'refresh) | |
2979 | (setq ido-text-init (ido-final-slash dir t)) | |
2980 | (setq ido-rotate-temp t) | |
2981 | (exit-minibuffer))) | |
2982 | ||
06b60517 | 2983 | (defun ido-wide-find-dir-or-delete-dir (&optional _dir) |
d11320e5 | 2984 | "Prompt for DIR to search for using `find', starting from current directory. |
ae9d279d KS |
2985 | If input stack is non-empty, delete current directory component." |
2986 | (interactive) | |
2987 | (if ido-input-stack | |
2988 | (ido-delete-backward-word-updir 1) | |
2989 | (ido-wide-find-dir))) | |
2990 | ||
a3f4d4d4 KS |
2991 | (defun ido-take-first-match () |
2992 | "Use first matching item as input text." | |
2993 | (interactive) | |
2994 | (when ido-matches | |
5a1b28a4 | 2995 | (setq ido-text-init (ido-name (car ido-matches))) |
a3f4d4d4 KS |
2996 | (setq ido-exit 'refresh) |
2997 | (exit-minibuffer))) | |
2998 | ||
3729cc87 KS |
2999 | (defun ido-push-dir () |
3000 | "Move to previous directory in file name, push current input on stack." | |
3001 | (interactive) | |
3002 | (setq ido-exit 'push) | |
3003 | (exit-minibuffer)) | |
3004 | ||
a3f4d4d4 KS |
3005 | (defun ido-push-dir-first () |
3006 | "Move to previous directory in file name, push first match on stack." | |
3007 | (interactive) | |
3008 | (if ido-matches | |
5a1b28a4 | 3009 | (setq ido-text (ido-name (car ido-matches)))) |
a3f4d4d4 KS |
3010 | (setq ido-exit 'push) |
3011 | (exit-minibuffer)) | |
3012 | ||
3729cc87 KS |
3013 | (defun ido-pop-dir (arg) |
3014 | "Pop directory from input stack back to input. | |
79164cf4 | 3015 | With \\[universal-argument], pop all elements." |
3729cc87 KS |
3016 | (interactive "P") |
3017 | (when ido-input-stack | |
3018 | (setq ido-exit (if arg 'pop-all 'pop)) | |
3019 | (exit-minibuffer))) | |
3020 | ||
3021 | (defun ido-wide-find-file-or-pop-dir (arg) | |
3022 | (interactive "P") | |
3023 | (if ido-input-stack | |
3024 | (ido-pop-dir arg) | |
3025 | (ido-wide-find-file))) | |
3026 | ||
789d1bf0 KS |
3027 | (defun ido-make-directory (&optional dir) |
3028 | "Prompt for DIR to create in current directory." | |
3029 | (interactive) | |
3030 | (unless dir | |
b0df3884 KS |
3031 | (let ((enable-recursive-minibuffers t)) |
3032 | (setq dir | |
3033 | (read-string (concat "Make directory: " ido-current-directory) ido-text)))) | |
789d1bf0 KS |
3034 | (when (> (length dir) 0) |
3035 | (setq dir (concat ido-current-directory dir)) | |
3036 | (unless (file-exists-p dir) | |
3037 | (make-directory dir t) | |
3038 | (ido-set-current-directory dir) | |
3039 | (setq ido-exit 'refresh) | |
3040 | (setq ido-text-init nil) | |
3041 | (setq ido-rotate-temp t) | |
3042 | (exit-minibuffer)))) | |
3043 | ||
3044 | (defun ido-get-work-file (incr) | |
3045 | (let ((n (length ido-work-file-list)) | |
3046 | (i (+ ido-work-file-index incr)) | |
3047 | name) | |
3048 | (if (> incr 0) | |
3049 | (if (>= i n) (setq i 0)) | |
3050 | (if (< i 0) (setq i (1- n)))) | |
3051 | (setq name (nth i ido-work-file-list)) | |
3052 | (setq ido-work-file-index i) | |
3053 | name)) | |
3054 | ||
3055 | (defun ido-prev-work-file () | |
3056 | "Change to next working file name in list." | |
3057 | (interactive) | |
3058 | (let ((name (ido-get-work-file 1))) | |
3059 | (when name | |
3060 | (setq ido-text-init name) | |
3061 | (setq ido-exit 'refresh) | |
3062 | (exit-minibuffer)))) | |
3063 | ||
3064 | (defun ido-next-work-file () | |
3065 | "Change to previous working file name in list." | |
3066 | (interactive) | |
3067 | (let ((name (ido-get-work-file -1))) | |
3068 | (when name | |
3069 | (setq ido-text-init name) | |
3070 | (setq ido-exit 'refresh) | |
3071 | (exit-minibuffer)))) | |
3072 | ||
3073 | (defun ido-copy-current-file-name (all) | |
3074 | "Insert file name of current buffer. | |
3075 | If repeated, insert text from buffer instead." | |
3076 | (interactive "P") | |
bac4dbd1 KS |
3077 | (let* ((bfname (or (buffer-file-name ido-entry-buffer) |
3078 | (buffer-name ido-entry-buffer))) | |
84f6c6d0 | 3079 | (name (and bfname (file-name-nondirectory bfname)))) |
789d1bf0 | 3080 | (when name |
71296446 JB |
3081 | (setq ido-text-init |
3082 | (if (or all | |
2490c740 | 3083 | (eq last-command this-command) |
84f6c6d0 | 3084 | (not (equal (file-name-directory bfname) ido-current-directory)) |
789d1bf0 KS |
3085 | (not (string-match "\\.[^.]*\\'" name))) |
3086 | name | |
3087 | (substring name 0 (1+ (match-beginning 0))))) | |
3088 | (setq ido-exit 'refresh | |
3089 | ido-try-merged-list nil) | |
3090 | (exit-minibuffer)))) | |
71296446 | 3091 | |
06b60517 | 3092 | (defun ido-copy-current-word (_all) |
362cdb61 | 3093 | "Insert current word (file or directory name) from current buffer." |
789d1bf0 | 3094 | (interactive "P") |
7fdbcd83 | 3095 | (let ((word (with-current-buffer ido-entry-buffer |
06b60517 | 3096 | (let ((p (point)) start-line end-line start-name) |
1b5929b9 KS |
3097 | (if (and mark-active (/= p (mark))) |
3098 | (setq start-name (mark)) | |
3099 | (beginning-of-line) | |
3100 | (setq start-line (point)) | |
3101 | (end-of-line) | |
3102 | (setq end-line (point)) | |
3103 | (goto-char p) | |
3104 | (if (re-search-backward "[^-_a-zA-Z0-9:./\\~@]" start-line 1) | |
3105 | (forward-char 1)) | |
3106 | (setq start-name (point)) | |
3107 | (re-search-forward "[-_a-zA-Z0-9:./\\~@]*" end-line 1) | |
3108 | (if (= start-name (point)) | |
3109 | (setq start-name nil))) | |
3110 | (and start-name | |
3111 | (buffer-substring-no-properties start-name (point))))))) | |
789d1bf0 KS |
3112 | (if (cond |
3113 | ((not word) nil) | |
3114 | ((string-match "\\`[~/]" word) | |
3115 | (setq ido-text-init word | |
3116 | ido-try-merged-list nil | |
3117 | ido-exit 'chdir)) | |
3118 | ((string-match "/" word) | |
3119 | (setq ido-text-init (concat ido-current-directory word) | |
3120 | ido-try-merged-list nil | |
3121 | ido-exit 'chdir)) | |
3122 | (t | |
3123 | (setq ido-text-init word | |
3124 | ido-try-merged-list nil | |
3125 | ido-exit 'refresh))) | |
3126 | (exit-minibuffer)))) | |
3127 | ||
71296446 | 3128 | (defun ido-next-match () |
789d1bf0 KS |
3129 | "Put first element of `ido-matches' at the end of the list." |
3130 | (interactive) | |
3131 | (if ido-matches | |
3132 | (let ((next (cadr ido-matches))) | |
3133 | (setq ido-cur-list (ido-chop ido-cur-list next)) | |
821f936d KS |
3134 | (setq ido-matches (ido-chop ido-matches next)) |
3135 | (setq ido-rescan nil)))) | |
789d1bf0 | 3136 | |
71296446 | 3137 | (defun ido-prev-match () |
789d1bf0 KS |
3138 | "Put last element of `ido-matches' at the front of the list." |
3139 | (interactive) | |
3140 | (if ido-matches | |
3141 | (let ((prev (car (last ido-matches)))) | |
3142 | (setq ido-cur-list (ido-chop ido-cur-list prev)) | |
821f936d KS |
3143 | (setq ido-matches (ido-chop ido-matches prev)) |
3144 | (setq ido-rescan nil)))) | |
789d1bf0 | 3145 | |
71296446 | 3146 | (defun ido-next-match-dir () |
789d1bf0 KS |
3147 | "Find next directory in match list. |
3148 | If work directories have been merged, cycle through directories for | |
3149 | first matching file." | |
3150 | (interactive) | |
3151 | (if ido-use-merged-list | |
3152 | (if ido-matches | |
3153 | (let* ((elt (car ido-matches)) | |
3154 | (dirs (cdr elt))) | |
3155 | (when (> (length dirs) 1) | |
3156 | (setcdr elt (ido-chop dirs (cadr dirs)))) | |
3157 | (setq ido-rescan nil))) | |
3158 | (let ((cnt (length ido-matches)) | |
3159 | (i 1)) | |
3160 | (while (and (< i cnt) (not (ido-final-slash (nth i ido-matches)))) | |
3161 | (setq i (1+ i))) | |
3162 | (if (< i cnt) | |
3163 | (setq ido-cur-list (ido-chop ido-cur-list (nth i ido-matches))))))) | |
3164 | ||
71296446 | 3165 | (defun ido-prev-match-dir () |
789d1bf0 KS |
3166 | "Find previous directory in match list. |
3167 | If work directories have been merged, cycle through directories | |
3168 | for first matching file." | |
3169 | (interactive) | |
3170 | (if ido-use-merged-list | |
3171 | (if ido-matches | |
3172 | (let* ((elt (car ido-matches)) | |
3173 | (dirs (cdr elt))) | |
3174 | (when (> (length dirs) 1) | |
3175 | (setcdr elt (ido-chop dirs (car (last dirs))))) | |
3176 | (setq ido-rescan nil))) | |
3177 | (let* ((cnt (length ido-matches)) | |
3178 | (i (1- cnt))) | |
3179 | (while (and (> i 0) (not (ido-final-slash (nth i ido-matches)))) | |
3180 | (setq i (1- i))) | |
3181 | (if (> i 0) | |
3182 | (setq ido-cur-list (ido-chop ido-cur-list (nth i ido-matches))))))) | |
3183 | ||
71296446 | 3184 | (defun ido-restrict-to-matches () |
08bfde76 KS |
3185 | "Set current item list to the currently matched items." |
3186 | (interactive) | |
3187 | (when ido-matches | |
3188 | (setq ido-cur-list ido-matches | |
3189 | ido-text-init "" | |
3190 | ido-rescan nil | |
3191 | ido-exit 'keep) | |
3192 | (exit-minibuffer))) | |
3193 | ||
789d1bf0 | 3194 | (defun ido-chop (items elem) |
ea78b95b | 3195 | "Remove all elements before ELEM and put them at the end of ITEMS." |
789d1bf0 KS |
3196 | (let ((ret nil) |
3197 | (next nil) | |
3198 | (sofar nil)) | |
3199 | (while (not ret) | |
3200 | (setq next (car items)) | |
ea78b95b | 3201 | (if (equal next elem) |
789d1bf0 KS |
3202 | (setq ret (append items (nreverse sofar))) |
3203 | ;; else | |
3204 | (progn | |
3205 | (setq items (cdr items)) | |
3206 | (setq sofar (cons next sofar))))) | |
3207 | ret)) | |
3208 | ||
3209 | (defun ido-name (item) | |
3210 | ;; Return file name for current item, whether in a normal list | |
3211 | ;; or a merged work directory list. | |
3212 | (if (consp item) (car item) item)) | |
3213 | ||
3214 | ||
3215 | ;;; CREATE LIST OF ALL CURRENT FILES | |
3216 | ||
3217 | (defun ido-all-completions () | |
da6062e6 | 3218 | ;; Return unsorted list of all completions. |
cb65c373 KS |
3219 | (let ((ido-process-ignore-lists nil) |
3220 | (ido-directory-too-big nil)) | |
789d1bf0 KS |
3221 | (cond |
3222 | ((eq ido-cur-item 'file) | |
ec441ab5 | 3223 | (ido-make-file-list-1 ido-current-directory)) |
789d1bf0 | 3224 | ((eq ido-cur-item 'dir) |
ec441ab5 | 3225 | (ido-make-dir-list-1 ido-current-directory)) |
789d1bf0 | 3226 | ((eq ido-cur-item 'buffer) |
ec441ab5 | 3227 | (ido-make-buffer-list-1)) |
db9f395b KS |
3228 | ((eq ido-cur-item 'list) |
3229 | ido-choice-list) | |
789d1bf0 KS |
3230 | (t nil)))) |
3231 | ||
3232 | ||
1de0ae85 KS |
3233 | ;; File list sorting |
3234 | ||
3235 | (defun ido-file-lessp (a b) | |
3236 | ;; Simple compare two file names. | |
3237 | (string-lessp (ido-no-final-slash a) (ido-no-final-slash b))) | |
3238 | ||
3239 | ||
3240 | (defun ido-file-extension-lessp (a b) | |
3241 | ;; Compare file names according to ido-file-extensions-order list. | |
3242 | (let ((n (compare-strings a 0 nil b 0 nil nil)) | |
3243 | lessp p) | |
3244 | (if (eq n t) | |
3245 | nil | |
3246 | (if (< n 0) | |
3247 | (setq n (1- (- n)) | |
3248 | p a a b b p | |
3249 | lessp t) | |
3250 | (setq n (1- n))) | |
3251 | (cond | |
3252 | ((= n 0) | |
3253 | lessp) | |
3254 | ((= (aref a n) ?.) | |
3255 | (ido-file-extension-aux a b n lessp)) | |
3256 | (t | |
3257 | (while (and (> n 2) (/= (aref a n) ?.)) | |
3258 | (setq n (1- n))) | |
3259 | (if (> n 1) | |
3260 | (ido-file-extension-aux a b n lessp) | |
3261 | lessp)))))) | |
3262 | ||
3263 | (defun ido-file-extension-aux (a b n lessp) | |
3264 | (let ((oa (ido-file-extension-order a n)) | |
3265 | (ob (ido-file-extension-order b n))) | |
3266 | (cond | |
1de0ae85 | 3267 | ((and oa ob) |
76a63a6e KS |
3268 | (cond |
3269 | ((= oa ob) | |
3270 | lessp) | |
3271 | (lessp | |
3272 | (> oa ob)) | |
3273 | (t | |
3274 | (< oa ob)))) | |
1de0ae85 KS |
3275 | (oa |
3276 | (not lessp)) | |
3277 | (ob | |
3278 | lessp) | |
3279 | (t | |
3280 | lessp)))) | |
3281 | ||
3282 | (defun ido-file-extension-order (s n) | |
3283 | (let ((l ido-file-extensions-order) | |
3284 | (i 0) o do) | |
3285 | (while l | |
3286 | (cond | |
3287 | ((eq (car l) t) | |
3288 | (setq do i | |
3289 | l (cdr l))) | |
3290 | ((eq (compare-strings s n nil (car l) 0 nil nil) t) | |
3291 | (setq o i | |
3292 | l nil)) | |
3293 | (t | |
3294 | (setq l (cdr l)))) | |
3295 | (setq i (1+ i))) | |
3296 | (or o do))) | |
3297 | ||
789d1bf0 KS |
3298 | |
3299 | (defun ido-sort-merged-list (items promote) | |
3300 | ;; Input is list of ("file" . "dir") cons cells. | |
3301 | ;; Output is sorted list of ("file "dir" ...) lists | |
3302 | (let ((l (sort items (lambda (a b) (string-lessp (car b) (car a))))) | |
06b60517 | 3303 | res a cur) |
789d1bf0 KS |
3304 | (while l |
3305 | (setq a (car l) | |
3306 | l (cdr l)) | |
3307 | (if (and res (string-equal (car (car res)) (car a))) | |
3308 | (progn | |
3309 | (setcdr (car (if cur (cdr res) res)) (cons (cdr a) (cdr (car res)))) | |
3310 | (if (and promote (string-equal ido-current-directory (cdr a))) | |
3311 | (setq cur t))) | |
3312 | (setq res (cons (list (car a) (cdr a)) res) | |
3313 | cur nil))) | |
3314 | res)) | |
3315 | ||
3316 | (defun ido-wide-find-dirs-or-files (dir file &optional prefix finddir) | |
3317 | ;; As ido-run-find-command, but returns a list of cons pairs ("file" . "dir") | |
71296446 | 3318 | (let ((filenames |
001809f6 GM |
3319 | (delq nil |
3320 | (mapcar (lambda (name) | |
3321 | (unless (ido-ignore-item-p name ido-ignore-files t) | |
3322 | name)) | |
3323 | (split-string | |
3324 | (shell-command-to-string | |
3325 | (concat "find " | |
3326 | (shell-quote-argument dir) | |
3327 | (if ido-case-fold " -iname " " -name ") | |
3328 | (shell-quote-argument | |
3329 | (concat (if prefix "" "*") file "*")) | |
3330 | " -type " (if finddir "d" "f") " -print")))))) | |
84f6c6d0 | 3331 | filename d f |
789d1bf0 | 3332 | res) |
84f6c6d0 KS |
3333 | (while filenames |
3334 | (setq filename (car filenames) | |
3335 | filenames (cdr filenames)) | |
b4243e22 | 3336 | (if (and (file-name-absolute-p filename) |
84f6c6d0 KS |
3337 | (file-exists-p filename)) |
3338 | (setq d (file-name-directory filename) | |
3339 | f (file-name-nondirectory filename) | |
789d1bf0 KS |
3340 | res (cons (cons (if finddir (ido-final-slash f t) f) d) res)))) |
3341 | res)) | |
3342 | ||
3343 | (defun ido-flatten-merged-list (items) | |
84d6f465 | 3344 | "Create a list of directory names based on a merged directory list." |
789d1bf0 KS |
3345 | (let (res) |
3346 | (while items | |
3347 | (let* ((item (car items)) | |
3348 | (file (car item)) | |
3349 | (dirs (cdr item))) | |
3350 | (while dirs | |
3351 | (setq res (cons (concat (car dirs) file) res) | |
3352 | dirs (cdr dirs)))) | |
3353 | (setq items (cdr items))) | |
3354 | res)) | |
3355 | ||
ec441ab5 KS |
3356 | |
3357 | (defun ido-make-merged-file-list-1 (text auto wide) | |
789d1bf0 | 3358 | (let (res) |
ec441ab5 KS |
3359 | (if (and (ido-final-slash text) ido-dir-file-cache) |
3360 | (if wide | |
3361 | (setq res (ido-wide-find-dirs-or-files | |
3362 | ido-current-directory (substring text 0 -1) ido-enable-prefix t)) | |
3363 | ;; Use list of cached directories | |
3364 | (let ((re (concat (regexp-quote (substring text 0 -1)) "[^/:]*/\\'")) | |
3365 | (dirs ido-dir-file-cache) | |
3366 | dir b d f) | |
3367 | (if nil ;; simple | |
3368 | (while dirs | |
3369 | (setq dir (car (car dirs)) | |
3370 | dirs (cdr dirs)) | |
3371 | (when (and (string-match re dir) | |
3372 | (not (ido-ignore-item-p dir ido-ignore-directories-merge)) | |
3373 | (file-directory-p dir)) | |
3374 | (setq b (substring dir 0 -1) | |
3375 | f (concat (file-name-nondirectory b) "/") | |
3376 | d (file-name-directory b) | |
3377 | res (cons (cons f d) res)))) | |
789d1bf0 KS |
3378 | (while dirs |
3379 | (setq dir (car dirs) | |
ec441ab5 | 3380 | d (car dir) |
789d1bf0 | 3381 | dirs (cdr dirs)) |
ec441ab5 KS |
3382 | (when (not (ido-ignore-item-p d ido-ignore-directories-merge)) |
3383 | (setq dir (cdr (cdr dir))) | |
3384 | (while dir | |
3385 | (setq f (car dir) | |
3386 | dir (cdr dir)) | |
3387 | (if (and (string-match re f) | |
3388 | (not (ido-ignore-item-p f ido-ignore-directories))) | |
3389 | (setq res (cons (cons f d) res))))) | |
789d1bf0 KS |
3390 | (if (and auto (input-pending-p)) |
3391 | (setq dirs nil | |
3392 | res t)))))) | |
ec441ab5 KS |
3393 | (if wide |
3394 | (setq res (ido-wide-find-dirs-or-files | |
3395 | ido-current-directory text ido-enable-prefix nil)) | |
3396 | (let ((ido-text text) | |
3397 | (dirs ido-work-directory-list) | |
3398 | (must-match (and text (> (length text) 0))) | |
3399 | dir fl) | |
3400 | (if (and auto (not (member ido-current-directory dirs))) | |
3401 | (setq dirs (cons ido-current-directory dirs))) | |
3402 | (while dirs | |
3403 | (setq dir (car dirs) | |
3404 | dirs (cdr dirs)) | |
3405 | (when (and dir (stringp dir) | |
3406 | (or ido-merge-ftp-work-directories | |
3407 | (not (ido-is-ftp-directory dir))) | |
3408 | (file-directory-p dir) | |
3409 | ;; TODO. check for nonreadable and too-big. | |
3410 | (setq fl (if (eq ido-cur-item 'file) | |
3411 | (ido-make-file-list-1 dir t) | |
3412 | (ido-make-dir-list-1 dir t)))) | |
3413 | (if must-match | |
3414 | (setq fl (ido-set-matches-1 fl))) | |
3415 | (if fl | |
3416 | (setq res (nconc fl res)))) | |
3417 | (if (and auto (input-pending-p)) | |
3418 | (setq dirs nil | |
3419 | res t)))))) | |
3420 | res)) | |
3421 | ||
3422 | (defun ido-make-merged-file-list (text auto wide) | |
3423 | (let (res) | |
3424 | (message "Searching for `%s'...." text) | |
3425 | (condition-case nil | |
edc42f56 KS |
3426 | (if (eq t (setq res |
3427 | (while-no-input | |
3428 | (ido-make-merged-file-list-1 text auto wide)))) | |
3429 | (setq res 'input-pending-p)) | |
ec441ab5 KS |
3430 | (quit |
3431 | (setq res t | |
3432 | ido-try-merged-list nil | |
3433 | ido-use-merged-list nil))) | |
3434 | (when (and res (listp res)) | |
3435 | (setq res (ido-sort-merged-list res auto))) | |
9a08196a | 3436 | (when (and (or ido-rotate-temp ido-rotate-file-list-default) |
e20b3173 | 3437 | (listp res) |
9a08196a KS |
3438 | (> (length text) 0)) |
3439 | (let ((elt (assoc text res))) | |
4e85a733 | 3440 | (when (and elt (not (eq elt (car res)))) |
9a08196a KS |
3441 | (setq res (delq elt res)) |
3442 | (setq res (cons elt res))))) | |
789d1bf0 KS |
3443 | (message nil) |
3444 | res)) | |
3445 | ||
ec441ab5 | 3446 | (defun ido-make-buffer-list-1 (&optional frame visible) |
84d6f465 | 3447 | "Return list of non-ignored buffer names." |
71296446 | 3448 | (delq nil |
789d1bf0 KS |
3449 | (mapcar |
3450 | (lambda (x) | |
3451 | (let ((name (buffer-name x))) | |
69beb26d | 3452 | (if (not (or (ido-ignore-item-p name ido-ignore-buffers) (member name visible))) |
789d1bf0 KS |
3453 | name))) |
3454 | (buffer-list frame)))) | |
3455 | ||
3456 | (defun ido-make-buffer-list (default) | |
84d6f465 GM |
3457 | "Return the current list of buffers. |
3458 | Currently visible buffers are put at the end of the list. | |
3459 | The hook `ido-make-buffer-list-hook' is run after the list has been | |
3460 | created to allow the user to further modify the order of the buffer names | |
3461 | in this list. If DEFAULT is non-nil, and corresponds to an existing buffer, | |
3462 | it is put to the start of the list." | |
789d1bf0 | 3463 | (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current)) |
ec441ab5 | 3464 | (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers))) |
789d1bf0 KS |
3465 | (if ido-temp-list |
3466 | (nconc ido-temp-list ido-current-buffers) | |
3467 | (setq ido-temp-list ido-current-buffers)) | |
e0143335 | 3468 | (if default |
3504a4be LL |
3469 | (setq ido-temp-list |
3470 | (cons default (delete default ido-temp-list)))) | |
3471 | (if (bound-and-true-p ido-enable-virtual-buffers) | |
dff0fdc3 | 3472 | (ido-add-virtual-buffers-to-list)) |
789d1bf0 KS |
3473 | (run-hooks 'ido-make-buffer-list-hook) |
3474 | ido-temp-list)) | |
3475 | ||
0523d117 JW |
3476 | (defun ido-add-virtual-buffers-to-list () |
3477 | "Add recently visited files, and bookmark files, to the buffer list. | |
3478 | This is to make them appear as if they were \"virtual buffers\"." | |
3479 | ;; If no buffers matched, and virtual buffers are being used, then | |
3480 | ;; consult the list of past visited files, to see if we can find | |
3481 | ;; the file which the user might thought was still open. | |
9caf8a8f | 3482 | (unless recentf-mode (recentf-mode 1)) |
0523d117 | 3483 | (setq ido-virtual-buffers nil) |
9caf8a8f JB |
3484 | (let (name) |
3485 | (dolist (head recentf-list) | |
c28b9050 LL |
3486 | (setq name (file-name-nondirectory head)) |
3487 | ;; In case HEAD is a directory with trailing /. See bug#14552. | |
3488 | (when (equal name "") | |
3489 | (setq name (file-name-nondirectory (directory-file-name head)))) | |
3490 | (when (equal name "") | |
3491 | (setq name head)) | |
3492 | (and (not (equal name "")) | |
3493 | (null (get-file-buffer head)) | |
9caf8a8f | 3494 | (not (assoc name ido-virtual-buffers)) |
2a07afc5 | 3495 | (not (member name ido-temp-list)) |
9caf8a8f JB |
3496 | (not (ido-ignore-item-p name ido-ignore-buffers)) |
3497 | ;;(file-exists-p head) | |
3498 | (push (cons name head) ido-virtual-buffers)))) | |
0523d117 JW |
3499 | (when ido-virtual-buffers |
3500 | (if ido-use-faces | |
3501 | (dolist (comp ido-virtual-buffers) | |
3502 | (put-text-property 0 (length (car comp)) | |
3503 | 'face 'ido-virtual | |
3504 | (car comp)))) | |
3505 | (setq ido-temp-list | |
3506 | (nconc ido-temp-list | |
3507 | (nreverse (mapcar #'car ido-virtual-buffers)))))) | |
3508 | ||
db9f395b | 3509 | (defun ido-make-choice-list (default) |
84d6f465 GM |
3510 | "Return the current list of choices. |
3511 | If DEFAULT is non-nil, and corresponds to an element of choices, | |
3512 | it is put to the start of the list." | |
db9f395b KS |
3513 | (let ((ido-temp-list ido-choice-list)) |
3514 | (if default | |
3515 | (progn | |
3516 | (setq ido-temp-list | |
3517 | (delete default ido-temp-list)) | |
3518 | (setq ido-temp-list | |
3519 | (cons default ido-temp-list)))) | |
3520 | ; (run-hooks 'ido-make-choice-list-hook) | |
3521 | ido-temp-list)) | |
3522 | ||
789d1bf0 | 3523 | (defun ido-to-end (items) |
84d6f465 | 3524 | "Move the elements from ITEMS to the end of `ido-temp-list'." |
db99576a | 3525 | (mapc |
71296446 | 3526 | (lambda (elem) |
789d1bf0 KS |
3527 | (setq ido-temp-list (delq elem ido-temp-list))) |
3528 | items) | |
3529 | (if ido-temp-list | |
3530 | (nconc ido-temp-list items) | |
3531 | (setq ido-temp-list items))) | |
3532 | ||
ec441ab5 | 3533 | (defun ido-file-name-all-completions-1 (dir) |
a70343bd | 3534 | (cond |
866f2239 | 3535 | ((ido-nonreadable-directory-p dir) '()) |
cb65c373 KS |
3536 | ;; do not check (ido-directory-too-big-p dir) here. |
3537 | ;; Caller must have done that if necessary. | |
c577a4d2 | 3538 | |
a70343bd | 3539 | ((and ido-enable-tramp-completion |
c577a4d2 KS |
3540 | (string-match "\\`/[^/]+[:@]\\'" dir)) |
3541 | ;; Strip method:user@host: part of tramp completions. | |
3542 | ;; Tramp completions do not include leading slash. | |
d9e43b70 | 3543 | (let* ((len (1- (length dir))) |
5f2b693f | 3544 | (non-essential t) |
d9e43b70 MA |
3545 | (compl |
3546 | (or (file-name-all-completions "" dir) | |
3547 | ;; work around bug in ange-ftp. | |
3548 | ;; /ftp:user@host: => nil | |
3549 | ;; /ftp:user@host:./ => ok | |
3550 | (and | |
3551 | (not (string= "/ftp:" dir)) | |
ad74a69e MA |
3552 | (file-remote-p dir) |
3553 | ;; tramp-ftp-file-name-p is available only when tramp | |
3554 | ;; has been loaded. | |
d9e43b70 MA |
3555 | (fboundp 'tramp-ftp-file-name-p) |
3556 | (funcall 'tramp-ftp-file-name-p dir) | |
3557 | (string-match ":\\'" dir) | |
3558 | (file-name-all-completions "" (concat dir "./")))))) | |
c577a4d2 KS |
3559 | (if (and compl |
3560 | (> (length (car compl)) len) | |
3561 | (string= (substring (car compl) 0 len) (substring dir 1))) | |
a70343bd KS |
3562 | (mapcar (lambda (c) (substring c len)) compl) |
3563 | compl))) | |
3564 | (t | |
3565 | (file-name-all-completions "" dir)))) | |
bad111c2 | 3566 | |
789d1bf0 | 3567 | (defun ido-file-name-all-completions (dir) |
84d6f465 GM |
3568 | "Return name of all files in DIR. |
3569 | Uses and updates `ido-dir-file-cache'." | |
dfebc0ae KS |
3570 | (cond |
3571 | ((ido-is-unc-root dir) | |
3572 | (mapcar | |
3573 | (lambda (host) | |
3574 | (if (string-match "/\\'" host) host (concat host "/"))) | |
4c2ee078 | 3575 | (ido-unc-hosts t))) |
dfebc0ae KS |
3576 | ((and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0) |
3577 | (stringp dir) (> (length dir) 0) | |
3578 | (ido-may-cache-directory dir)) | |
3579 | (let* ((cached (assoc dir ido-dir-file-cache)) | |
71296446 | 3580 | (ctime (nth 1 cached)) |
789d1bf0 | 3581 | (ftp (ido-is-ftp-directory dir)) |
dfebc0ae KS |
3582 | (unc (ido-is-unc-host dir)) |
3583 | (attr (if (or ftp unc) nil (file-attributes dir))) | |
789d1bf0 KS |
3584 | (mtime (nth 5 attr)) |
3585 | valid) | |
3586 | (when cached ; should we use the cached entry ? | |
dfebc0ae KS |
3587 | (cond |
3588 | (ftp | |
3589 | (setq valid (and (eq (car ctime) 'ftp) | |
3590 | (ido-cache-ftp-valid (cdr ctime))))) | |
3591 | (unc | |
3592 | (setq valid (and (eq (car ctime) 'unc) | |
3593 | (ido-cache-unc-valid (cdr ctime))))) | |
3594 | (t | |
789d1bf0 KS |
3595 | (if attr |
3596 | (setq valid (and (= (car ctime) (car mtime)) | |
dfebc0ae KS |
3597 | (= (car (cdr ctime)) (car (cdr mtime)))))))) |
3598 | (unless valid | |
3599 | (setq ido-dir-file-cache (delq cached ido-dir-file-cache) | |
3600 | cached nil))) | |
789d1bf0 | 3601 | (unless cached |
dfebc0ae KS |
3602 | (cond |
3603 | (unc | |
3604 | (setq mtime (cons 'unc (ido-time-stamp)))) | |
3605 | ((and ftp (file-readable-p dir)) | |
3606 | (setq mtime (cons 'ftp (ido-time-stamp))))) | |
789d1bf0 | 3607 | (if mtime |
ec441ab5 | 3608 | (setq cached (cons dir (cons mtime (ido-file-name-all-completions-1 dir))) |
789d1bf0 KS |
3609 | ido-dir-file-cache (cons cached ido-dir-file-cache))) |
3610 | (if (> (length ido-dir-file-cache) ido-max-dir-file-cache) | |
3611 | (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil))) | |
3612 | (and cached | |
dfebc0ae KS |
3613 | (cdr (cdr cached))))) |
3614 | (t | |
3615 | (ido-file-name-all-completions-1 dir)))) | |
789d1bf0 KS |
3616 | |
3617 | (defun ido-remove-cached-dir (dir) | |
84d6f465 | 3618 | "Remove DIR from `ido-dir-file-cache'." |
789d1bf0 KS |
3619 | (if (and ido-dir-file-cache |
3620 | (stringp dir) (> (length dir) 0)) | |
3621 | (let ((cached (assoc dir ido-dir-file-cache))) | |
3622 | (if cached | |
3623 | (setq ido-dir-file-cache (delq cached ido-dir-file-cache)))))) | |
3624 | ||
3625 | ||
ec441ab5 | 3626 | (defun ido-make-file-list-1 (dir &optional merged) |
84d6f465 GM |
3627 | "Return list of non-ignored files in DIR |
3628 | If MERGED is non-nil, each file is cons'ed with DIR." | |
dfebc0ae KS |
3629 | (and (or (ido-is-tramp-root dir) (ido-is-unc-root dir) |
3630 | (file-directory-p dir)) | |
001809f6 GM |
3631 | (delq nil |
3632 | (mapcar | |
3633 | (lambda (name) | |
3634 | (if (not (ido-ignore-item-p name ido-ignore-files t)) | |
3635 | (if merged (cons name dir) name))) | |
3636 | (ido-file-name-all-completions dir))))) | |
789d1bf0 KS |
3637 | |
3638 | (defun ido-make-file-list (default) | |
84d6f465 GM |
3639 | "Return the current list of files. |
3640 | Currently visible files are put at the end of the list. | |
3641 | The hook `ido-make-file-list-hook' is run after the list has been | |
3642 | created to allow the user to further modify the order of the file names | |
3643 | in this list." | |
ec441ab5 | 3644 | (let ((ido-temp-list (ido-make-file-list-1 ido-current-directory))) |
1de0ae85 KS |
3645 | (setq ido-temp-list (sort ido-temp-list |
3646 | (if ido-file-extensions-order | |
3647 | #'ido-file-extension-lessp | |
3648 | #'ido-file-lessp))) | |
c577a4d2 KS |
3649 | (unless (ido-is-tramp-root ido-current-directory) |
3650 | (let ((default-directory ido-current-directory)) | |
3651 | (ido-to-end ;; move ftp hosts and visited files to end | |
3652 | (delq nil (mapcar | |
10b19e88 KS |
3653 | (lambda (x) (if (or (and (string-match ".:\\'" x) |
3654 | (not (ido-local-file-exists-p x))) | |
c577a4d2 | 3655 | (and (not (ido-final-slash x)) |
10b19e88 KS |
3656 | (let (file-name-handler-alist) |
3657 | (get-file-buffer x)))) x)) | |
c577a4d2 | 3658 | ido-temp-list))))) |
789d1bf0 | 3659 | (ido-to-end ;; move . files to end |
71296446 | 3660 | (delq nil (mapcar |
789d1bf0 KS |
3661 | (lambda (x) (if (string-equal (substring x 0 1) ".") x)) |
3662 | ido-temp-list))) | |
3663 | (if (and default (member default ido-temp-list)) | |
3664 | (if (or ido-rotate-temp ido-rotate-file-list-default) | |
3665 | (unless (equal default (car ido-temp-list)) | |
3666 | (let ((l ido-temp-list) k) | |
3667 | (while (and l (cdr l) (not (equal default (car (cdr l))))) | |
3668 | (setq l (cdr l))) | |
3669 | (setq k (cdr l)) | |
3670 | (setcdr l nil) | |
3671 | (nconc k ido-temp-list) | |
3672 | (setq ido-temp-list k))) | |
71296446 | 3673 | (setq ido-temp-list |
789d1bf0 | 3674 | (delete default ido-temp-list)) |
71296446 | 3675 | (setq ido-temp-list |
789d1bf0 KS |
3676 | (cons default ido-temp-list)))) |
3677 | (when ido-show-dot-for-dired | |
3678 | (setq ido-temp-list (delete "." ido-temp-list)) | |
3679 | (setq ido-temp-list (cons "." ido-temp-list))) | |
3680 | (run-hooks 'ido-make-file-list-hook) | |
3681 | ido-temp-list)) | |
3682 | ||
ec441ab5 | 3683 | (defun ido-make-dir-list-1 (dir &optional merged) |
84d6f465 GM |
3684 | "Return list of non-ignored subdirs in DIR. |
3685 | If MERGED is non-nil, each subdir is cons'ed with DIR." | |
bad111c2 | 3686 | (and (or (ido-is-tramp-root dir) (file-directory-p dir)) |
71296446 | 3687 | (delq nil |
789d1bf0 KS |
3688 | (mapcar |
3689 | (lambda (name) | |
3690 | (and (ido-final-slash name) (not (ido-ignore-item-p name ido-ignore-directories)) | |
3691 | (if merged (cons name dir) name))) | |
3692 | (ido-file-name-all-completions dir))))) | |
3693 | ||
3694 | (defun ido-make-dir-list (default) | |
84d6f465 GM |
3695 | "Return the current list of directories. |
3696 | The hook `ido-make-dir-list-hook' is run after the list has been | |
3697 | created to allow the user to further modify the order of the | |
3698 | directory names in this list." | |
ec441ab5 | 3699 | (let ((ido-temp-list (ido-make-dir-list-1 ido-current-directory))) |
1de0ae85 | 3700 | (setq ido-temp-list (sort ido-temp-list #'ido-file-lessp)) |
789d1bf0 | 3701 | (ido-to-end ;; move . files to end |
71296446 | 3702 | (delq nil (mapcar |
789d1bf0 KS |
3703 | (lambda (x) (if (string-equal (substring x 0 1) ".") x)) |
3704 | ido-temp-list))) | |
3705 | (if (and default (member default ido-temp-list)) | |
3706 | (if (or ido-rotate-temp ido-rotate-file-list-default) | |
3707 | (unless (equal default (car ido-temp-list)) | |
3708 | (let ((l ido-temp-list) k) | |
3709 | (while (and l (cdr l) (not (equal default (car (cdr l))))) | |
3710 | (setq l (cdr l))) | |
3711 | (setq k (cdr l)) | |
3712 | (setcdr l nil) | |
3713 | (nconc k ido-temp-list) | |
3714 | (setq ido-temp-list k))) | |
71296446 | 3715 | (setq ido-temp-list |
789d1bf0 | 3716 | (delete default ido-temp-list)) |
71296446 | 3717 | (setq ido-temp-list |
789d1bf0 KS |
3718 | (cons default ido-temp-list)))) |
3719 | (setq ido-temp-list (delete "." ido-temp-list)) | |
3729cc87 KS |
3720 | (unless ido-input-stack |
3721 | (setq ido-temp-list (cons "." ido-temp-list))) | |
789d1bf0 KS |
3722 | (run-hooks 'ido-make-dir-list-hook) |
3723 | ido-temp-list)) | |
3724 | ||
3725 | ;; List of the files visible in the current frame. | |
3726 | (defvar ido-bufs-in-frame) | |
3727 | ||
3728 | (defun ido-get-buffers-in-frames (&optional current) | |
84d6f465 GM |
3729 | "Return the list of buffers that are visible in the current frame. |
3730 | If optional argument CURRENT is given, restrict searching to the current | |
3731 | frame, rather than all frames, regardless of value of `ido-all-frames'." | |
789d1bf0 KS |
3732 | (let ((ido-bufs-in-frame nil)) |
3733 | (walk-windows 'ido-get-bufname nil | |
71296446 | 3734 | (if current |
789d1bf0 KS |
3735 | nil |
3736 | ido-all-frames)) | |
3737 | ido-bufs-in-frame)) | |
3738 | ||
3739 | (defun ido-get-bufname (win) | |
84d6f465 | 3740 | "Used by `ido-get-buffers-in-frames' to walk through all windows." |
789d1bf0 | 3741 | (let ((buf (buffer-name (window-buffer win)))) |
69beb26d KS |
3742 | (unless (or (member buf ido-bufs-in-frame) |
3743 | (member buf ido-ignore-item-temp-list)) | |
3744 | ;; Only add buf if it is not already in list. | |
3745 | ;; This prevents same buf in two different windows being | |
3746 | ;; put into the list twice. | |
3747 | (setq ido-bufs-in-frame | |
3748 | (cons buf ido-bufs-in-frame))))) | |
789d1bf0 KS |
3749 | |
3750 | ;;; FIND MATCHING ITEMS | |
3751 | ||
ec441ab5 | 3752 | (defun ido-set-matches-1 (items &optional do-full) |
84d6f465 | 3753 | "Return list of matches in ITEMS." |
789d1bf0 | 3754 | (let* ((case-fold-search ido-case-fold) |
bad111c2 KS |
3755 | (slash (and (not ido-enable-prefix) (ido-final-slash ido-text))) |
3756 | (text (if slash (substring ido-text 0 -1) ido-text)) | |
5444f278 KS |
3757 | (rex0 (if ido-enable-regexp text (regexp-quote text))) |
3758 | (rexq (concat rex0 (if slash ".*/" ""))) | |
789d1bf0 | 3759 | (re (if ido-enable-prefix (concat "\\`" rexq) rexq)) |
a8c14da8 | 3760 | (full-re (and do-full |
9c1228c3 LL |
3761 | (not (and (eq ido-cur-item 'buffer) |
3762 | ido-buffer-disable-smart-matches)) | |
a8c14da8 LL |
3763 | (not ido-enable-regexp) |
3764 | (not (string-match "\$\\'" rex0)) | |
5444f278 KS |
3765 | (concat "\\`" rex0 (if slash "/" "") "\\'"))) |
3766 | (suffix-re (and do-full slash | |
9c1228c3 LL |
3767 | (not (and (eq ido-cur-item 'buffer) |
3768 | ido-buffer-disable-smart-matches)) | |
a8c14da8 LL |
3769 | (not ido-enable-regexp) |
3770 | (not (string-match "\$\\'" rex0)) | |
5444f278 | 3771 | (concat rex0 "/\\'"))) |
789d1bf0 KS |
3772 | (prefix-re (and full-re (not ido-enable-prefix) |
3773 | (concat "\\`" rexq))) | |
6d8b6cbd KS |
3774 | (non-prefix-dot (or (not ido-enable-dot-prefix) |
3775 | (not ido-process-ignore-lists) | |
3776 | ido-enable-prefix | |
3777 | (= (length ido-text) 0))) | |
5444f278 | 3778 | full-matches suffix-matches prefix-matches matches) |
665ed61a KS |
3779 | (setq ido-incomplete-regexp nil) |
3780 | (condition-case error | |
db99576a | 3781 | (mapc |
665ed61a KS |
3782 | (lambda (item) |
3783 | (let ((name (ido-name item))) | |
5444f278 KS |
3784 | (if (and (or non-prefix-dot |
3785 | (if (= (aref ido-text 0) ?.) | |
3786 | (= (aref name 0) ?.) | |
3787 | (/= (aref name 0) ?.))) | |
3788 | (string-match re name)) | |
3789 | (cond | |
39449da0 | 3790 | ((and (eq ido-cur-item 'buffer) |
3d37467b KS |
3791 | (or (not (stringp ido-default-item)) |
3792 | (not (string= name ido-default-item))) | |
39449da0 KS |
3793 | (string= name (buffer-name ido-entry-buffer))) |
3794 | (setq matches (cons item matches))) | |
5444f278 KS |
3795 | ((and full-re (string-match full-re name)) |
3796 | (setq full-matches (cons item full-matches))) | |
3797 | ((and suffix-re (string-match suffix-re name)) | |
3798 | (setq suffix-matches (cons item suffix-matches))) | |
3799 | ((and prefix-re (string-match prefix-re name)) | |
3800 | (setq prefix-matches (cons item prefix-matches))) | |
3801 | (t (setq matches (cons item matches)))))) | |
3802 | t) | |
665ed61a KS |
3803 | items) |
3804 | (invalid-regexp | |
3805 | (setq ido-incomplete-regexp t | |
3806 | ;; Consider the invalid regexp message internally as a | |
3807 | ;; special-case single match, and handle appropriately | |
3808 | ;; elsewhere. | |
3809 | matches (cdr error)))) | |
5444f278 KS |
3810 | (when prefix-matches |
3811 | (ido-trace "prefix match" prefix-matches) | |
9940702b | 3812 | ;; Bug#2042. |
5444f278 KS |
3813 | (setq matches (nconc prefix-matches matches))) |
3814 | (when suffix-matches | |
3815 | (ido-trace "suffix match" (list text suffix-re suffix-matches)) | |
3816 | (setq matches (nconc suffix-matches matches))) | |
3817 | (when full-matches | |
3818 | (ido-trace "full match" (list text full-re full-matches)) | |
3819 | (setq matches (nconc full-matches matches))) | |
789d1bf0 KS |
3820 | (when (and (null matches) |
3821 | ido-enable-flex-matching | |
3822 | (> (length ido-text) 1) | |
3823 | (not ido-enable-regexp)) | |
05a859c1 LL |
3824 | (setq re (concat (regexp-quote (string (aref ido-text 0))) |
3825 | (mapconcat (lambda (c) | |
3826 | (concat "[^" (string c) "]*" | |
3827 | (regexp-quote (string c)))) | |
3828 | (substring ido-text 1) ""))) | |
789d1bf0 KS |
3829 | (if ido-enable-prefix |
3830 | (setq re (concat "\\`" re))) | |
db99576a | 3831 | (mapc |
789d1bf0 KS |
3832 | (lambda (item) |
3833 | (let ((name (ido-name item))) | |
3834 | (if (string-match re name) | |
3835 | (setq matches (cons item matches))))) | |
3836 | items)) | |
c7a8fcac | 3837 | (delete-consecutive-dups matches t))) |
71296446 | 3838 | |
789d1bf0 KS |
3839 | |
3840 | (defun ido-set-matches () | |
84d6f465 | 3841 | "Set `ido-matches' to the list of items matching prompt." |
789d1bf0 | 3842 | (when ido-rescan |
ec441ab5 | 3843 | (setq ido-matches (ido-set-matches-1 (reverse ido-cur-list) (not ido-rotate)) |
789d1bf0 | 3844 | ido-rotate nil))) |
71296446 | 3845 | |
789d1bf0 | 3846 | (defun ido-ignore-item-p (name re-list &optional ignore-ext) |
84d6f465 | 3847 | "Return t if the buffer or file NAME should be ignored." |
69beb26d KS |
3848 | (or (member name ido-ignore-item-temp-list) |
3849 | (and | |
3850 | ido-process-ignore-lists re-list | |
d6049c78 KS |
3851 | (save-match-data |
3852 | (let ((ext-list (and ignore-ext ido-ignore-extensions | |
789d1bf0 | 3853 | completion-ignored-extensions)) |
d6049c78 KS |
3854 | (case-fold-search ido-case-fold) |
3855 | ignorep nextstr | |
3856 | (flen (length name)) slen) | |
3857 | (while ext-list | |
3858 | (setq nextstr (car ext-list)) | |
3859 | (if (cond | |
3860 | ((stringp nextstr) | |
3861 | (and (>= flen (setq slen (length nextstr))) | |
3862 | (string-equal (substring name (- flen slen)) nextstr))) | |
bf8b0f8b | 3863 | ((functionp nextstr) (funcall nextstr name)) |
d6049c78 KS |
3864 | (t nil)) |
3865 | (setq ignorep t | |
3866 | ext-list nil | |
3867 | re-list nil) | |
3868 | (setq ext-list (cdr ext-list)))) | |
3869 | (while re-list | |
3870 | (setq nextstr (car re-list)) | |
3871 | (if (cond | |
3872 | ((stringp nextstr) (string-match nextstr name)) | |
bf8b0f8b | 3873 | ((functionp nextstr) (funcall nextstr name)) |
d6049c78 KS |
3874 | (t nil)) |
3875 | (setq ignorep t | |
3876 | re-list nil) | |
3877 | (setq re-list (cdr re-list)))) | |
3878 | ;; return the result | |
3879 | (if ignorep | |
3880 | (setq ido-ignored-list (cons name ido-ignored-list))) | |
3881 | ignorep))))) | |
789d1bf0 KS |
3882 | |
3883 | ;; Private variable used by `ido-word-matching-substring'. | |
3884 | (defvar ido-change-word-sub) | |
3885 | ||
3886 | (defun ido-find-common-substring (items subs) | |
84d6f465 | 3887 | "Return common string following SUBS in each element of ITEMS." |
789d1bf0 KS |
3888 | (let (res |
3889 | alist | |
3890 | ido-change-word-sub) | |
3891 | (setq ido-change-word-sub | |
3892 | (if ido-enable-regexp | |
3893 | subs | |
3894 | (regexp-quote subs))) | |
9066a4d0 | 3895 | (setq res (mapcar #'ido-word-matching-substring items)) |
789d1bf0 | 3896 | (setq res (delq nil res)) ;; remove any nil elements (shouldn't happen) |
9066a4d0 | 3897 | (setq alist (mapcar #'ido-makealist res)) ;; could use an OBARRAY |
789d1bf0 KS |
3898 | |
3899 | ;; try-completion returns t if there is an exact match. | |
9066a4d0 KS |
3900 | (let* ((completion-ignore-case ido-case-fold) |
3901 | (comp (try-completion subs alist))) | |
3902 | (if (eq comp t) | |
3903 | subs | |
3904 | comp)))) | |
789d1bf0 KS |
3905 | |
3906 | (defun ido-word-matching-substring (word) | |
84d6f465 GM |
3907 | "Return part of WORD before first match to `ido-change-word-sub'. |
3908 | If `ido-change-word-sub' cannot be found in WORD, return nil." | |
71296446 | 3909 | (let ((case-fold-search ido-case-fold)) |
789d1bf0 KS |
3910 | (let ((m (string-match ido-change-word-sub (ido-name word)))) |
3911 | (if m | |
3912 | (substring (ido-name word) m) | |
3913 | ;; else no match | |
3914 | nil)))) | |
3915 | ||
3916 | (defun ido-makealist (res) | |
84d6f465 | 3917 | "Return dotted pair (RES . 1)." |
789d1bf0 KS |
3918 | (cons res 1)) |
3919 | ||
d5e63715 | 3920 | (defun ido-choose-completion-string (choice &rest ignored) |
789d1bf0 KS |
3921 | (when (ido-active) |
3922 | ;; Insert the completion into the buffer where completion was requested. | |
99fc91fe AK |
3923 | (and ido-completion-buffer |
3924 | (get-buffer ido-completion-buffer) | |
3925 | (kill-buffer ido-completion-buffer)) | |
789d1bf0 KS |
3926 | (cond |
3927 | ((ido-active t) ;; ido-use-merged-list | |
3928 | (setq ido-current-directory "" | |
3929 | ido-text choice | |
3930 | ido-exit 'done)) | |
3931 | ((not (ido-final-slash choice)) | |
3932 | (setq ido-text choice | |
3933 | ido-exit 'done)) | |
3934 | (t | |
3935 | (ido-set-current-directory ido-current-directory choice) | |
3936 | (setq ido-exit 'refresh))) | |
3937 | (exit-minibuffer) | |
3938 | t)) | |
3939 | ||
3940 | (defun ido-completion-help () | |
d11320e5 | 3941 | "Show possible completions in a \"*File Completions*\" buffer." |
789d1bf0 KS |
3942 | (interactive) |
3943 | (setq ido-rescan nil) | |
99fc91fe AK |
3944 | (let ((temp-buf (and ido-completion-buffer |
3945 | (get-buffer ido-completion-buffer))) | |
789d1bf0 KS |
3946 | display-it full-list) |
3947 | (if (and (eq last-command this-command) temp-buf) | |
3948 | ;; scroll buffer | |
3949 | (let (win (buf (current-buffer))) | |
3950 | (display-buffer temp-buf nil nil) | |
3951 | (set-buffer temp-buf) | |
3952 | (setq win (get-buffer-window temp-buf)) | |
3953 | (if (pos-visible-in-window-p (point-max) win) | |
c05b0612 KS |
3954 | (if (or ido-completion-buffer-all-completions |
3955 | (boundp 'ido-completion-buffer-full)) | |
789d1bf0 | 3956 | (set-window-start win (point-min)) |
3729cc87 KS |
3957 | (with-no-warnings |
3958 | (set (make-local-variable 'ido-completion-buffer-full) t)) | |
789d1bf0 KS |
3959 | (setq full-list t |
3960 | display-it t)) | |
3961 | (scroll-other-window)) | |
3962 | (set-buffer buf)) | |
3963 | (setq display-it t)) | |
99fc91fe | 3964 | (if (and ido-completion-buffer display-it) |
789d1bf0 | 3965 | (with-output-to-temp-buffer ido-completion-buffer |
1de0ae85 | 3966 | (let ((completion-list (sort |
789d1bf0 | 3967 | (cond |
c05b0612 | 3968 | (ido-directory-too-big |
1fd1a9f2 | 3969 | (message "Reading directory...") |
c05b0612 KS |
3970 | (setq ido-directory-too-big nil |
3971 | ido-ignored-list nil | |
3972 | ido-cur-list (ido-all-completions) | |
3973 | ido-rescan t) | |
3974 | (ido-set-matches) | |
3975 | (or ido-matches ido-cur-list)) | |
789d1bf0 KS |
3976 | (ido-use-merged-list |
3977 | (ido-flatten-merged-list (or ido-matches ido-cur-list))) | |
3978 | ((or full-list ido-completion-buffer-all-completions) | |
3979 | (ido-all-completions)) | |
3980 | (t | |
1de0ae85 KS |
3981 | (copy-sequence (or ido-matches ido-cur-list)))) |
3982 | #'ido-file-lessp))) | |
1518d6e3 | 3983 | (if (featurep 'xemacs) |
789d1bf0 KS |
3984 | ;; XEmacs extents are put on by default, doesn't seem to be |
3985 | ;; any way of switching them off. | |
ad9dcd70 SM |
3986 | (display-completion-list |
3987 | completion-list | |
3988 | :help-string "ido " | |
3989 | :activate-callback | |
3990 | (lambda (&rest _) (message "Doesn't work yet, sorry!"))) | |
789d1bf0 KS |
3991 | ;; else running Emacs |
3992 | ;;(add-hook 'completion-setup-hook 'completion-setup-function) | |
3993 | (display-completion-list completion-list))))))) | |
3994 | ||
3995 | ;;; KILL CURRENT BUFFER | |
3996 | (defun ido-kill-buffer-at-head () | |
155943b9 KS |
3997 | "Kill the buffer at the head of `ido-matches'. |
3998 | If cursor is not at the end of the user input, delete to end of input." | |
789d1bf0 | 3999 | (interactive) |
155943b9 | 4000 | (if (not (eobp)) |
79ef5763 | 4001 | (delete-region (point) (line-end-position)) |
155943b9 | 4002 | (let ((enable-recursive-minibuffers t) |
e0143335 LL |
4003 | (buf (ido-name (car ido-matches))) |
4004 | (nextbuf (cadr ido-matches))) | |
5c90fde0 LL |
4005 | (cond |
4006 | ((get-buffer buf) | |
e0143335 | 4007 | ;; If next match names a buffer use the buffer object; buffer |
5c90fde0 | 4008 | ;; name may be changed by packages such as uniquify. |
e0143335 LL |
4009 | (when (and nextbuf (get-buffer nextbuf)) |
4010 | (setq nextbuf (get-buffer nextbuf))) | |
4011 | (if (null (kill-buffer buf)) | |
4012 | ;; Buffer couldn't be killed. | |
155943b9 | 4013 | (setq ido-rescan t) |
e0143335 LL |
4014 | ;; Else `kill-buffer' succeeds so re-make the buffer list |
4015 | ;; taking into account packages like uniquify may rename | |
4016 | ;; buffers. | |
4017 | (if (bufferp nextbuf) | |
4018 | (setq nextbuf (buffer-name nextbuf))) | |
4019 | (setq ido-default-item nextbuf | |
4020 | ido-text-init ido-text | |
4021 | ido-exit 'refresh) | |
5c90fde0 LL |
4022 | (exit-minibuffer))) |
4023 | ;; Handle virtual buffers | |
4024 | ((assoc buf ido-virtual-buffers) | |
4025 | (setq recentf-list | |
4026 | (delete (cdr (assoc buf ido-virtual-buffers)) recentf-list)) | |
4027 | (setq ido-cur-list (delete buf ido-cur-list)) | |
4028 | (setq ido-rescan t)))))) | |
789d1bf0 KS |
4029 | |
4030 | ;;; DELETE CURRENT FILE | |
4031 | (defun ido-delete-file-at-head () | |
155943b9 | 4032 | "Delete the file at the head of `ido-matches'. |
e01aa29c | 4033 | Trash the file if `delete-by-moving-to-trash' is non-nil. |
155943b9 | 4034 | If cursor is not at the end of the user input, delete to end of input." |
789d1bf0 | 4035 | (interactive) |
155943b9 | 4036 | (if (not (eobp)) |
79ef5763 | 4037 | (delete-region (point) (line-end-position)) |
155943b9 KS |
4038 | (let ((enable-recursive-minibuffers t) |
4039 | (file (ido-name (car ido-matches)))) | |
4040 | (if file | |
4041 | (setq file (concat ido-current-directory file))) | |
4042 | (when (and file | |
4043 | (file-exists-p file) | |
4044 | (not (file-directory-p file)) | |
4045 | (file-writable-p ido-current-directory) | |
e01aa29c LL |
4046 | (or delete-by-moving-to-trash |
4047 | (yes-or-no-p (concat "Delete " file "? ")))) | |
4048 | (delete-file file 'trash) | |
155943b9 KS |
4049 | ;; Check if file still exists. |
4050 | (if (file-exists-p file) | |
4051 | ;; file could not be deleted | |
4052 | (setq ido-rescan t) | |
4053 | ;; else file was killed so remove name from list. | |
4054 | (setq ido-cur-list (delq (car ido-matches) ido-cur-list))))))) | |
789d1bf0 KS |
4055 | |
4056 | ||
4057 | ;;; VISIT CHOSEN BUFFER | |
4058 | (defun ido-visit-buffer (buffer method &optional record) | |
a11ad595 | 4059 | "Switch to BUFFER according to METHOD. |
616e8e5f | 4060 | Record command in `command-history' if optional RECORD is non-nil." |
930f852e KS |
4061 | (if (bufferp buffer) |
4062 | (setq buffer (buffer-name buffer))) | |
789d1bf0 KS |
4063 | (let (win newframe) |
4064 | (cond | |
4065 | ((eq method 'kill) | |
4066 | (if record | |
4067 | (ido-record-command 'kill-buffer buffer)) | |
e0143335 | 4068 | (kill-buffer buffer)) |
789d1bf0 | 4069 | |
a11ad595 | 4070 | ((eq method 'other-window) |
789d1bf0 KS |
4071 | (if record |
4072 | (ido-record-command 'switch-to-buffer buffer)) | |
4073 | (switch-to-buffer-other-window buffer)) | |
4074 | ||
4075 | ((eq method 'display) | |
4076 | (display-buffer buffer)) | |
4077 | ||
a11ad595 | 4078 | ((eq method 'other-frame) |
1518d6e3 | 4079 | (switch-to-buffer-other-frame buffer) |
a11ad595 KS |
4080 | (select-frame-set-input-focus (selected-frame))) |
4081 | ||
4082 | ((and (memq method '(raise-frame maybe-frame)) | |
4083 | window-system | |
4084 | (setq win (ido-buffer-window-other-frame buffer)) | |
4085 | (or (eq method 'raise-frame) | |
4086 | (y-or-n-p "Jump to frame? "))) | |
4087 | (setq newframe (window-frame win)) | |
4088 | (select-frame-set-input-focus newframe) | |
4089 | (select-window win)) | |
4090 | ||
4091 | ;; (eq method 'selected-window) | |
4092 | (t | |
4093 | ;; No buffer in other frames... | |
4094 | (if record | |
4095 | (ido-record-command 'switch-to-buffer buffer)) | |
4096 | (switch-to-buffer buffer) | |
1518d6e3 | 4097 | )))) |
789d1bf0 KS |
4098 | |
4099 | ||
a11ad595 | 4100 | (defun ido-buffer-window-other-frame (buffer) |
84d6f465 GM |
4101 | "Return window pointer if BUFFER is visible in another frame. |
4102 | If BUFFER is visible in the current frame, return nil." | |
789d1bf0 KS |
4103 | (let ((blist (ido-get-buffers-in-frames 'current))) |
4104 | ;;If the buffer is visible in current frame, return nil | |
69beb26d | 4105 | (if (member buffer blist) |
789d1bf0 KS |
4106 | nil |
4107 | ;; maybe in other frame or icon | |
4108 | (get-buffer-window buffer 0) ; better than 'visible | |
4109 | ))) | |
4110 | ||
4111 | ||
4112 | ;;; ----------- IDONIZED FUNCTIONS ------------ | |
4113 | ||
4114 | ;;;###autoload | |
4115 | (defun ido-switch-buffer () | |
4116 | "Switch to another buffer. | |
4117 | The buffer is displayed according to `ido-default-buffer-method' -- the | |
4118 | default is to show it in the same window, unless it is already visible | |
4119 | in another frame. | |
4120 | ||
4121 | As you type in a string, all of the buffers matching the string are | |
d11320e5 | 4122 | displayed if substring-matching is used (default). Look at |
616e8e5f JB |
4123 | `ido-enable-prefix' and `ido-toggle-prefix'. When you have found the |
4124 | buffer you want, it can then be selected. As you type, most keys have | |
facf67fd | 4125 | their normal keybindings, except for the following: \\<ido-buffer-completion-map> |
789d1bf0 | 4126 | |
d11320e5 JB |
4127 | RET\tSelect the buffer at the front of the list of matches. |
4128 | \tIf the list is empty, possibly prompt to create new buffer. | |
4129 | ||
4130 | \\[ido-select-text]\tUse the current input string verbatim. | |
4131 | ||
4132 | \\[ido-next-match]\tPut the first element at the end of the list. | |
4133 | \\[ido-prev-match]\tPut the last element at the start of the list. | |
4134 | \\[ido-complete]\tComplete a common suffix to the current string that matches | |
4135 | \tall buffers. If there is only one match, select that buffer. | |
4136 | \tIf there is no common suffix, show a list of all matching buffers | |
4137 | \tin a separate window. | |
4138 | \\[ido-edit-input]\tEdit input string. | |
4139 | \\[ido-fallback-command]\tFallback to non-ido version of current command. | |
4140 | \\[ido-toggle-regexp]\tToggle regexp searching. | |
4141 | \\[ido-toggle-prefix]\tToggle between substring and prefix matching. | |
4142 | \\[ido-toggle-case]\tToggle case-sensitive searching of buffer names. | |
4143 | \\[ido-completion-help]\tShow list of matching buffers in separate window. | |
4144 | \\[ido-enter-find-file]\tDrop into `ido-find-file'. | |
4145 | \\[ido-kill-buffer-at-head]\tKill buffer at head of buffer list. | |
4146 | \\[ido-toggle-ignore]\tToggle ignoring buffers listed in `ido-ignore-buffers'." | |
789d1bf0 KS |
4147 | (interactive) |
4148 | (ido-buffer-internal ido-default-buffer-method)) | |
4149 | ||
4150 | ;;;###autoload | |
4151 | (defun ido-switch-buffer-other-window () | |
4152 | "Switch to another buffer and show it in another window. | |
4153 | The buffer name is selected interactively by typing a substring. | |
74a5d578 | 4154 | For details of keybindings, see `ido-switch-buffer'." |
789d1bf0 | 4155 | (interactive) |
a11ad595 | 4156 | (ido-buffer-internal 'other-window 'switch-to-buffer-other-window)) |
789d1bf0 KS |
4157 | |
4158 | ;;;###autoload | |
4159 | (defun ido-display-buffer () | |
4160 | "Display a buffer in another window but don't select it. | |
4161 | The buffer name is selected interactively by typing a substring. | |
74a5d578 | 4162 | For details of keybindings, see `ido-switch-buffer'." |
789d1bf0 | 4163 | (interactive) |
db9f395b | 4164 | (ido-buffer-internal 'display 'display-buffer nil nil nil 'ignore)) |
789d1bf0 KS |
4165 | |
4166 | ;;;###autoload | |
4167 | (defun ido-kill-buffer () | |
4168 | "Kill a buffer. | |
4169 | The buffer name is selected interactively by typing a substring. | |
74a5d578 | 4170 | For details of keybindings, see `ido-switch-buffer'." |
789d1bf0 | 4171 | (interactive) |
d11320e5 JB |
4172 | (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " |
4173 | (buffer-name (current-buffer)) nil 'ignore)) | |
789d1bf0 KS |
4174 | |
4175 | ;;;###autoload | |
4176 | (defun ido-insert-buffer () | |
4177 | "Insert contents of a buffer in current buffer after point. | |
4178 | The buffer name is selected interactively by typing a substring. | |
74a5d578 | 4179 | For details of keybindings, see `ido-switch-buffer'." |
789d1bf0 | 4180 | (interactive) |
d11320e5 JB |
4181 | (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " |
4182 | nil nil 'ido-enter-insert-file)) | |
789d1bf0 KS |
4183 | |
4184 | ;;;###autoload | |
4185 | (defun ido-switch-buffer-other-frame () | |
4186 | "Switch to another buffer and show it in another frame. | |
4187 | The buffer name is selected interactively by typing a substring. | |
74a5d578 | 4188 | For details of keybindings, see `ido-switch-buffer'." |
789d1bf0 KS |
4189 | (interactive) |
4190 | (if ido-mode | |
a11ad595 | 4191 | (ido-buffer-internal 'other-frame) |
789d1bf0 KS |
4192 | (call-interactively 'switch-to-buffer-other-frame))) |
4193 | ||
4194 | ;;;###autoload | |
4195 | (defun ido-find-file-in-dir (dir) | |
4196 | "Switch to another file starting from DIR." | |
4197 | (interactive "DDir: ") | |
72a75b41 | 4198 | (setq dir (file-name-as-directory dir)) |
db9f395b | 4199 | (ido-file-internal ido-default-file-method nil dir nil nil nil 'ignore)) |
789d1bf0 KS |
4200 | |
4201 | ;;;###autoload | |
4202 | (defun ido-find-file () | |
4203 | "Edit file with name obtained via minibuffer. | |
4204 | The file is displayed according to `ido-default-file-method' -- the | |
d11320e5 JB |
4205 | default is to show it in the same window, unless it is already visible |
4206 | in another frame. | |
789d1bf0 | 4207 | |
616e8e5f JB |
4208 | The file name is selected interactively by typing a substring. As you |
4209 | type in a string, all of the filenames matching the string are displayed | |
d11320e5 | 4210 | if substring-matching is used (default). Look at `ido-enable-prefix' and |
616e8e5f JB |
4211 | `ido-toggle-prefix'. When you have found the filename you want, it can |
4212 | then be selected. As you type, most keys have their normal keybindings, | |
facf67fd | 4213 | except for the following: \\<ido-file-completion-map> |
789d1bf0 | 4214 | |
d11320e5 JB |
4215 | RET\tSelect the file at the front of the list of matches. |
4216 | \tIf the list is empty, possibly prompt to create new file. | |
4217 | ||
4218 | \\[ido-select-text]\tUse the current input string verbatim. | |
4219 | ||
4220 | \\[ido-next-match]\tPut the first element at the end of the list. | |
4221 | \\[ido-prev-match]\tPut the last element at the start of the list. | |
4222 | \\[ido-complete]\tComplete a common suffix to the current string that matches | |
4223 | \tall files. If there is only one match, select that file. | |
4224 | \tIf there is no common suffix, show a list of all matching files | |
4225 | \tin a separate window. | |
4226 | \\[ido-magic-delete-char]\tOpen the specified directory in Dired mode. | |
4227 | \\[ido-edit-input]\tEdit input string (including directory). | |
4228 | \\[ido-prev-work-directory]\tGo to previous directory in work directory history. | |
4229 | \\[ido-next-work-directory]\tGo to next directory in work directory history. | |
4230 | \\[ido-merge-work-directories]\tSearch for file in the work directory history. | |
4231 | \\[ido-forget-work-directory]\tRemove current directory from the work directory history. | |
4232 | \\[ido-prev-work-file]\tCycle to previous file in work file history. | |
4233 | \\[ido-next-work-file]\tCycle to next file in work file history. | |
4234 | \\[ido-wide-find-file-or-pop-dir]\tPrompt for a file and use find to locate it. | |
4235 | \\[ido-wide-find-dir-or-delete-dir]\tPrompt for a directory and use find to locate it. | |
4236 | \\[ido-make-directory]\tPrompt for a directory to create in current directory. | |
4237 | \\[ido-fallback-command]\tFallback to non-Ido version of current command. | |
4238 | \\[ido-toggle-regexp]\tToggle regexp searching. | |
4239 | \\[ido-toggle-prefix]\tToggle between substring and prefix matching. | |
4240 | \\[ido-toggle-case]\tToggle case-sensitive searching of file names. | |
4241 | \\[ido-toggle-literal]\tToggle literal reading of this file. | |
4242 | \\[ido-completion-help]\tShow list of matching files in separate window. | |
4243 | \\[ido-toggle-ignore]\tToggle ignoring files listed in `ido-ignore-files'." | |
789d1bf0 KS |
4244 | |
4245 | (interactive) | |
4246 | (ido-file-internal ido-default-file-method)) | |
4247 | ||
4248 | ;;;###autoload | |
4249 | (defun ido-find-file-other-window () | |
4250 | "Switch to another file and show it in another window. | |
4251 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4252 | For details of keybindings, see `ido-find-file'." |
789d1bf0 | 4253 | (interactive) |
a11ad595 | 4254 | (ido-file-internal 'other-window 'find-file-other-window)) |
789d1bf0 KS |
4255 | |
4256 | ;;;###autoload | |
4257 | (defun ido-find-alternate-file () | |
4258 | "Switch to another file and show it in another window. | |
4259 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4260 | For details of keybindings, see `ido-find-file'." |
789d1bf0 KS |
4261 | (interactive) |
4262 | (ido-file-internal 'alt-file 'find-alternate-file nil "Find alternate file: ")) | |
4263 | ||
4264 | ;;;###autoload | |
4265 | (defun ido-find-file-read-only () | |
4266 | "Edit file read-only with name obtained via minibuffer. | |
4267 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4268 | For details of keybindings, see `ido-find-file'." |
789d1bf0 KS |
4269 | (interactive) |
4270 | (ido-file-internal 'read-only 'find-file-read-only nil "Find file read-only: ")) | |
4271 | ||
4272 | ;;;###autoload | |
4273 | (defun ido-find-file-read-only-other-window () | |
4274 | "Edit file read-only in other window with name obtained via minibuffer. | |
4275 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4276 | For details of keybindings, see `ido-find-file'." |
789d1bf0 | 4277 | (interactive) |
d11320e5 JB |
4278 | (ido-file-internal 'read-only 'find-file-read-only-other-window nil |
4279 | "Find file read-only other window: ")) | |
789d1bf0 KS |
4280 | |
4281 | ;;;###autoload | |
4282 | (defun ido-find-file-read-only-other-frame () | |
4283 | "Edit file read-only in other frame with name obtained via minibuffer. | |
4284 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4285 | For details of keybindings, see `ido-find-file'." |
789d1bf0 | 4286 | (interactive) |
d11320e5 JB |
4287 | (ido-file-internal 'read-only 'find-file-read-only-other-frame nil |
4288 | "Find file read-only other frame: ")) | |
789d1bf0 KS |
4289 | |
4290 | ;;;###autoload | |
4291 | (defun ido-display-file () | |
4292 | "Display a file in another window but don't select it. | |
4293 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4294 | For details of keybindings, see `ido-find-file'." |
789d1bf0 | 4295 | (interactive) |
db9f395b | 4296 | (ido-file-internal 'display nil nil nil nil nil 'ignore)) |
789d1bf0 KS |
4297 | |
4298 | ;;;###autoload | |
4299 | (defun ido-find-file-other-frame () | |
4300 | "Switch to another file and show it in another frame. | |
4301 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4302 | For details of keybindings, see `ido-find-file'." |
789d1bf0 | 4303 | (interactive) |
a11ad595 | 4304 | (ido-file-internal 'other-frame 'find-file-other-frame)) |
789d1bf0 KS |
4305 | |
4306 | ;;;###autoload | |
4307 | (defun ido-write-file () | |
4308 | "Write current buffer to a file. | |
4309 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4310 | For details of keybindings, see `ido-find-file'." |
789d1bf0 KS |
4311 | (interactive) |
4312 | (let ((ido-process-ignore-lists t) | |
4313 | (ido-work-directory-match-only nil) | |
4314 | (ido-ignore-files (cons "[^/]\\'" ido-ignore-files)) | |
4315 | (ido-report-no-match nil) | |
d81aa76a | 4316 | (ido-confirm-unique-completion t) |
789d1bf0 | 4317 | (ido-auto-merge-work-directories-length -1)) |
db9f395b | 4318 | (ido-file-internal 'write 'write-file nil "Write file: " nil nil 'ignore))) |
789d1bf0 KS |
4319 | |
4320 | ;;;###autoload | |
4321 | (defun ido-insert-file () | |
4322 | "Insert contents of file in current buffer. | |
4323 | The file name is selected interactively by typing a substring. | |
74a5d578 | 4324 | For details of keybindings, see `ido-find-file'." |
789d1bf0 | 4325 | (interactive) |
db9f395b | 4326 | (ido-file-internal 'insert 'insert-file nil "Insert file: " nil nil 'ido-enter-insert-buffer)) |
789d1bf0 KS |
4327 | |
4328 | ;;;###autoload | |
4329 | (defun ido-dired () | |
d11320e5 | 4330 | "Call `dired' the Ido way. |
789d1bf0 | 4331 | The directory is selected interactively by typing a substring. |
74a5d578 | 4332 | For details of keybindings, see `ido-find-file'." |
789d1bf0 KS |
4333 | (interactive) |
4334 | (let ((ido-report-no-match nil) | |
4335 | (ido-auto-merge-work-directories-length -1)) | |
4336 | (ido-file-internal 'dired 'dired nil "Dired: " 'dir))) | |
4337 | ||
4338 | (defun ido-list-directory () | |
d11320e5 | 4339 | "Call `list-directory' the Ido way. |
789d1bf0 | 4340 | The directory is selected interactively by typing a substring. |
74a5d578 | 4341 | For details of keybindings, see `ido-find-file'." |
789d1bf0 KS |
4342 | (interactive) |
4343 | (let ((ido-report-no-match nil) | |
4344 | (ido-auto-merge-work-directories-length -1)) | |
4345 | (ido-file-internal 'list-directory 'list-directory nil "List directory: " 'dir))) | |
4346 | ||
4347 | ;;; XEmacs hack for showing default buffer | |
4348 | ||
4349 | ;; The first time we enter the minibuffer, Emacs puts up the default | |
4350 | ;; buffer to switch to, but XEmacs doesn't -- presumably there is a | |
4351 | ;; subtle difference in the two versions of post-command-hook. The | |
4352 | ;; default is shown for both whenever we delete all of our text | |
4353 | ;; though, indicating its just a problem the first time we enter the | |
4354 | ;; function. To solve this, we use another entry hook for emacs to | |
4355 | ;; show the default the first time we enter the minibuffer. | |
4356 | ||
4357 | ||
4358 | ;;; ICOMPLETE TYPE CODE | |
4359 | ||
4360 | (defun ido-initiate-auto-merge (buffer) | |
4361 | (ido-trace "\n*merge timeout*" buffer) | |
4362 | (setq ido-auto-merge-timer nil) | |
4363 | (when (and (buffer-live-p buffer) | |
cba9a3a5 | 4364 | (ido-active) |
789d1bf0 KS |
4365 | (boundp 'ido-eoinput) ido-eoinput) |
4366 | (let ((contents (buffer-substring-no-properties (minibuffer-prompt-end) ido-eoinput))) | |
4367 | (ido-trace "request merge") | |
4368 | (setq ido-use-merged-list 'auto | |
4369 | ido-text-init contents | |
4370 | ido-rotate-temp t | |
4371 | ido-exit 'refresh) | |
7fdbcd83 | 4372 | (with-current-buffer buffer |
789d1bf0 KS |
4373 | (ido-tidy)) |
4374 | (throw 'ido contents)))) | |
4375 | ||
4376 | (defun ido-exhibit () | |
d11320e5 | 4377 | "Post command hook for Ido." |
789d1bf0 KS |
4378 | ;; Find matching files and display a list in the minibuffer. |
4379 | ;; Copied from `icomplete-exhibit' with two changes: | |
4380 | ;; 1. It prints a default file name when there is no text yet entered. | |
4381 | ;; 2. It calls my completion routine rather than the standard completion. | |
4382 | ||
cba9a3a5 | 4383 | (when (ido-active) |
bad111c2 KS |
4384 | (let ((contents (buffer-substring-no-properties (minibuffer-prompt-end) (point-max))) |
4385 | (buffer-undo-list t) | |
4386 | try-single-dir-match | |
4387 | refresh) | |
789d1bf0 | 4388 | |
5444f278 KS |
4389 | (when ido-trace-enable |
4390 | (ido-trace "\nexhibit" this-command) | |
4391 | (ido-trace "dir" ido-current-directory) | |
4392 | (ido-trace "contents" contents) | |
4393 | (ido-trace "list" ido-cur-list) | |
4394 | (ido-trace "matches" ido-matches) | |
4395 | (ido-trace "rescan" ido-rescan)) | |
789d1bf0 | 4396 | |
bad111c2 KS |
4397 | (save-excursion |
4398 | (goto-char (point-max)) | |
4399 | ;; Register the end of input, so we know where the extra stuff (match-status info) begins: | |
4400 | (unless (boundp 'ido-eoinput) | |
4401 | ;; In case it got wiped out by major mode business: | |
4402 | (make-local-variable 'ido-eoinput)) | |
4403 | (setq ido-eoinput (point)) | |
4404 | ||
4405 | ;; Handle explicit directory changes | |
4406 | (cond | |
db9f395b | 4407 | ((memq ido-cur-item '(buffer list)) |
bad111c2 KS |
4408 | ) |
4409 | ||
4410 | ((= (length contents) 0) | |
4411 | ) | |
4412 | ||
4413 | ((= (length contents) 1) | |
dfebc0ae KS |
4414 | (cond |
4415 | ((and (ido-is-tramp-root) (string-equal contents "/")) | |
bad111c2 KS |
4416 | (ido-set-current-directory ido-current-directory contents) |
4417 | (setq refresh t)) | |
4c2ee078 | 4418 | ((and (ido-unc-hosts) (string-equal contents "/") |
dfebc0ae KS |
4419 | (let ((ido-enable-tramp-completion nil)) |
4420 | (ido-is-root-directory))) | |
4421 | (ido-set-current-directory "//") | |
4422 | (setq refresh t)) | |
4423 | )) | |
bad111c2 | 4424 | |
10b19e88 KS |
4425 | ((and (string-match (if ido-enable-tramp-completion ".[:@]\\'" ".:\\'") contents) |
4426 | (ido-is-root-directory) ;; Ange-ftp or tramp | |
4427 | (not (ido-local-file-exists-p contents))) | |
bad111c2 KS |
4428 | (ido-set-current-directory ido-current-directory contents) |
4429 | (when (ido-is-slow-ftp-host) | |
4430 | (setq ido-exit 'fallback) | |
4431 | (exit-minibuffer)) | |
4432 | (setq refresh t)) | |
4433 | ||
4434 | ((ido-final-slash contents) ;; xxx/ | |
4435 | (ido-trace "final slash" contents) | |
71296446 | 4436 | (cond |
bad111c2 KS |
4437 | ((string-equal contents "~/") |
4438 | (ido-set-current-home) | |
4439 | (setq refresh t)) | |
4440 | ((string-equal contents "../") | |
4441 | (ido-up-directory t) | |
4442 | (setq refresh t)) | |
4443 | ((string-equal contents "./") | |
4444 | (setq refresh t)) | |
1c36d72a | 4445 | ((string-match "\\`~[-_a-zA-Z0-9]+[$]?/\\'" contents) |
bad111c2 KS |
4446 | (ido-trace "new home" contents) |
4447 | (ido-set-current-home contents) | |
4448 | (setq refresh t)) | |
4449 | ((string-match "[$][A-Za-z0-9_]+/\\'" contents) | |
4450 | (let ((exp (condition-case () | |
4451 | (expand-file-name | |
4452 | (substitute-in-file-name (substring contents 0 -1)) | |
4453 | ido-current-directory) | |
4454 | (error nil)))) | |
4455 | (ido-trace contents exp) | |
4456 | (when (and exp (file-directory-p exp)) | |
4457 | (ido-set-current-directory (file-name-directory exp)) | |
4458 | (setq ido-text-init (file-name-nondirectory exp)) | |
4459 | (setq refresh t)))) | |
4460 | ((and (memq system-type '(windows-nt ms-dos)) | |
4461 | (string-equal (substring contents 1) ":/")) | |
4462 | (ido-set-current-directory (file-name-directory contents)) | |
4463 | (setq refresh t)) | |
4464 | ((string-equal (substring contents -2 -1) "/") | |
71296446 | 4465 | (ido-set-current-directory |
bad111c2 KS |
4466 | (if (memq system-type '(windows-nt ms-dos)) |
4467 | (expand-file-name "/" ido-current-directory) | |
4468 | "/")) | |
4469 | (setq refresh t)) | |
cb65c373 | 4470 | ((and (or ido-directory-nonreadable ido-directory-too-big) |
a70343bd | 4471 | (file-directory-p (concat ido-current-directory (file-name-directory contents)))) |
d81aa76a | 4472 | (ido-set-current-directory |
a70343bd KS |
4473 | (concat ido-current-directory (file-name-directory contents))) |
4474 | (setq refresh t)) | |
bad111c2 KS |
4475 | (t |
4476 | (ido-trace "try single dir") | |
4477 | (setq try-single-dir-match t)))) | |
4478 | ||
4479 | ((and (string-equal (substring contents -2 -1) "/") | |
4480 | (not (string-match "[$]" contents))) | |
4481 | (ido-set-current-directory | |
4482 | (cond | |
4483 | ((= (length contents) 2) | |
4484 | "/") | |
4485 | (ido-matches | |
5a1b28a4 | 4486 | (concat ido-current-directory (ido-name (car ido-matches)))) |
bad111c2 KS |
4487 | (t |
4488 | (concat ido-current-directory (substring contents 0 -1))))) | |
4489 | (setq ido-text-init (substring contents -1)) | |
4490 | (setq refresh t)) | |
4491 | ||
4492 | ((and (not ido-use-merged-list) | |
4493 | (not (ido-final-slash contents)) | |
4494 | (eq ido-try-merged-list t) | |
4495 | (numberp ido-auto-merge-work-directories-length) | |
4496 | (> ido-auto-merge-work-directories-length 0) | |
4497 | (= (length contents) ido-auto-merge-work-directories-length) | |
4498 | (not (and ido-auto-merge-inhibit-characters-regexp | |
4499 | (string-match ido-auto-merge-inhibit-characters-regexp contents))) | |
4500 | (not (input-pending-p))) | |
4501 | (setq ido-use-merged-list 'auto | |
4502 | ido-text-init contents | |
4503 | ido-rotate-temp t) | |
4504 | (setq refresh t)) | |
4505 | ||
4506 | (t nil)) | |
4507 | ||
4508 | (when refresh | |
4509 | (ido-trace "refresh on /" ido-text-init) | |
4510 | (setq ido-exit 'refresh) | |
4511 | (exit-minibuffer)) | |
789d1bf0 | 4512 | |
5702da69 | 4513 | (when (and ido-enter-matching-directory |
bad111c2 | 4514 | ido-matches |
5702da69 KS |
4515 | (or (eq ido-enter-matching-directory 'first) |
4516 | (null (cdr ido-matches))) | |
5a1b28a4 | 4517 | (ido-final-slash (ido-name (car ido-matches))) |
bad111c2 | 4518 | (or try-single-dir-match |
5702da69 | 4519 | (eq ido-enter-matching-directory t))) |
bad111c2 | 4520 | (ido-trace "single match" (car ido-matches)) |
71296446 | 4521 | (ido-set-current-directory |
5a1b28a4 | 4522 | (concat ido-current-directory (ido-name (car ido-matches)))) |
bad111c2 KS |
4523 | (setq ido-exit 'refresh) |
4524 | (exit-minibuffer)) | |
4525 | ||
97ead0e5 LL |
4526 | ;; Update the list of matches |
4527 | (setq ido-text contents) | |
4528 | (ido-set-matches) | |
4529 | (ido-trace "new " ido-matches) | |
4530 | ||
3504a4be LL |
4531 | (when (and (boundp 'ido-enable-virtual-buffers) |
4532 | (not (eq ido-enable-virtual-buffers 'always)) | |
4533 | (eq ido-cur-item 'buffer) | |
4534 | (eq ido-use-virtual-buffers 'auto)) | |
4535 | ||
4536 | (when (and (not ido-enable-virtual-buffers) | |
4537 | (not ido-matches)) | |
4538 | (setq ido-text-init ido-text) | |
4539 | (setq ido-enable-virtual-buffers t) | |
4540 | (setq ido-exit 'refresh) | |
4541 | (exit-minibuffer)) | |
4542 | ||
4543 | ;; If input matches real buffers turn off virtual buffers. | |
4544 | (when (and ido-enable-virtual-buffers | |
4545 | ido-matches | |
4546 | (ido-set-matches-1 (ido-make-buffer-list-1))) | |
4547 | (setq ido-enable-virtual-buffers nil) | |
4548 | (setq ido-text-init ido-text) | |
4549 | (setq ido-exit 'refresh) | |
4550 | (exit-minibuffer))) | |
4551 | ||
bad111c2 | 4552 | (when (and (not ido-matches) |
a70343bd | 4553 | (not ido-directory-nonreadable) |
cb65c373 | 4554 | (not ido-directory-too-big) |
bad111c2 | 4555 | ;; ido-rescan ? |
789d1bf0 KS |
4556 | ido-process-ignore-lists |
4557 | ido-ignored-list) | |
bad111c2 KS |
4558 | (let ((ido-process-ignore-lists nil) |
4559 | (ido-rotate ido-rotate) | |
4560 | (ido-cur-list ido-ignored-list)) | |
4561 | (ido-trace "try all" ido-ignored-list) | |
4562 | (ido-set-matches)) | |
4563 | (when ido-matches | |
4564 | (ido-trace "found " ido-matches) | |
4565 | (setq ido-rescan t) | |
4566 | (setq ido-process-ignore-lists-inhibit t) | |
4567 | (setq ido-text-init ido-text) | |
4568 | (setq ido-exit 'refresh) | |
4569 | (exit-minibuffer))) | |
4570 | ||
4571 | (when (and | |
4572 | ido-rescan | |
4573 | (not ido-matches) | |
4574 | (memq ido-cur-item '(file dir)) | |
4575 | (not (ido-is-root-directory)) | |
4576 | (> (length contents) 1) | |
a70343bd | 4577 | (not (string-match "[$]" contents)) |
cb65c373 KS |
4578 | (not ido-directory-nonreadable) |
4579 | (not ido-directory-too-big)) | |
bad111c2 KS |
4580 | (ido-trace "merge?") |
4581 | (if ido-use-merged-list | |
4582 | (ido-undo-merge-work-directory contents nil) | |
4583 | (when (and (eq ido-try-merged-list t) | |
4584 | (numberp ido-auto-merge-work-directories-length) | |
4585 | (= ido-auto-merge-work-directories-length 0) | |
4586 | (not (and ido-auto-merge-inhibit-characters-regexp | |
4587 | (string-match ido-auto-merge-inhibit-characters-regexp contents))) | |
4588 | (not (input-pending-p))) | |
4589 | (ido-trace "\n*start timer*") | |
4590 | (setq ido-auto-merge-timer | |
4591 | (run-with-timer ido-auto-merge-delay-time nil 'ido-initiate-auto-merge (current-buffer)))))) | |
71296446 | 4592 | |
bad111c2 | 4593 | (setq ido-rescan t) |
789d1bf0 | 4594 | |
71296446 | 4595 | (if (and ido-use-merged-list |
bad111c2 KS |
4596 | ido-matches |
4597 | (not (string-equal (car (cdr (car ido-matches))) ido-current-directory))) | |
4598 | (progn | |
4599 | (ido-set-current-directory (car (cdr (car ido-matches)))) | |
4600 | (setq ido-use-merged-list t | |
4601 | ido-exit 'keep | |
4602 | ido-text-init ido-text) | |
4603 | (exit-minibuffer))) | |
4604 | ||
4605 | ;; Insert the match-status information: | |
4606 | (ido-set-common-completion) | |
c5b40130 | 4607 | (let ((inf (ido-completions contents))) |
11c238b3 | 4608 | (setq ido-show-confirm-message nil) |
bad111c2 KS |
4609 | (ido-trace "inf" inf) |
4610 | (insert inf)) | |
4611 | )))) | |
789d1bf0 | 4612 | |
c5b40130 | 4613 | (defun ido-completions (name) |
84d6f465 GM |
4614 | "Return the string that is displayed after the user's text. |
4615 | Modified from `icomplete-completions'." | |
789d1bf0 KS |
4616 | (let* ((comps ido-matches) |
4617 | (ind (and (consp (car comps)) (> (length (cdr (car comps))) 1) | |
4618 | ido-merged-indicator)) | |
4619 | first) | |
4620 | ||
4621 | (if (and ind ido-use-faces) | |
ccba8bb6 | 4622 | (put-text-property 0 1 'face 'ido-indicator ind)) |
71296446 | 4623 | |
789d1bf0 KS |
4624 | (if (and ido-use-faces comps) |
4625 | (let* ((fn (ido-name (car comps))) | |
4626 | (ln (length fn))) | |
4627 | (setq first (format "%s" fn)) | |
4628 | (put-text-property 0 ln 'face | |
4629 | (if (= (length comps) 1) | |
665ed61a KS |
4630 | (if ido-incomplete-regexp |
4631 | 'ido-incomplete-regexp | |
4632 | 'ido-only-match) | |
ccba8bb6 | 4633 | 'ido-first-match) |
789d1bf0 KS |
4634 | first) |
4635 | (if ind (setq first (concat first ind))) | |
4636 | (setq comps (cons first (cdr comps))))) | |
4637 | ||
4638 | (cond ((null comps) | |
a70343bd | 4639 | (cond |
11c238b3 | 4640 | (ido-show-confirm-message |
5b54c385 | 4641 | (or (nth 10 ido-decorations) " [Confirm]")) |
a70343bd KS |
4642 | (ido-directory-nonreadable |
4643 | (or (nth 8 ido-decorations) " [Not readable]")) | |
cb65c373 KS |
4644 | (ido-directory-too-big |
4645 | (or (nth 9 ido-decorations) " [Too big]")) | |
a70343bd KS |
4646 | (ido-report-no-match |
4647 | (nth 6 ido-decorations)) ;; [No match] | |
4648 | (t ""))) | |
665ed61a KS |
4649 | (ido-incomplete-regexp |
4650 | (concat " " (car comps))) | |
789d1bf0 | 4651 | ((null (cdr comps)) ;one match |
665ed61a KS |
4652 | (concat (if (if (not ido-enable-regexp) |
4653 | (= (length (ido-name (car comps))) (length name)) | |
4654 | ;; We can't rely on the length of the input | |
4655 | ;; for regexps, so explicitly check for a | |
4656 | ;; complete match | |
4657 | (string-match name (ido-name (car comps))) | |
4658 | (string-equal (match-string 0 (ido-name (car comps))) | |
4659 | (ido-name (car comps)))) | |
4660 | "" | |
632556e4 SM |
4661 | ;; When there is only one match, show the matching file |
4662 | ;; name in full, wrapped in [ ... ]. | |
4663 | (concat | |
4664 | (or (nth 11 ido-decorations) (nth 4 ido-decorations)) | |
4665 | (ido-name (car comps)) | |
4666 | (or (nth 12 ido-decorations) (nth 5 ido-decorations)))) | |
789d1bf0 KS |
4667 | (if (not ido-use-faces) (nth 7 ido-decorations)))) ;; [Matched] |
4668 | (t ;multiple matches | |
4669 | (let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999)) | |
4670 | (alternatives | |
4671 | (apply | |
71296446 | 4672 | #'concat |
789d1bf0 | 4673 | (cdr (apply |
9066a4d0 KS |
4674 | #'nconc |
4675 | (mapcar | |
4676 | (lambda (com) | |
4677 | (setq com (ido-name com)) | |
4678 | (setq items (1- items)) | |
4679 | (cond | |
4680 | ((< items 0) ()) | |
4681 | ((= items 0) (list (nth 3 ido-decorations))) ; " | ..." | |
4682 | (t | |
4683 | (list (or ido-separator (nth 2 ido-decorations)) ; " | " | |
4684 | (let ((str (substring com 0))) | |
4685 | (if (and ido-use-faces | |
4686 | (not (string= str first)) | |
4687 | (ido-final-slash str)) | |
ccba8bb6 | 4688 | (put-text-property 0 (length str) 'face 'ido-subdir str)) |
9066a4d0 KS |
4689 | str))))) |
4690 | comps)))))) | |
789d1bf0 KS |
4691 | |
4692 | (concat | |
4693 | ;; put in common completion item -- what you get by pressing tab | |
9066a4d0 KS |
4694 | (if (and (stringp ido-common-match-string) |
4695 | (> (length ido-common-match-string) (length name))) | |
789d1bf0 KS |
4696 | (concat (nth 4 ido-decorations) ;; [ ... ] |
4697 | (substring ido-common-match-string (length name)) | |
4698 | (nth 5 ido-decorations))) | |
4699 | ;; list all alternatives | |
4700 | (nth 0 ido-decorations) ;; { ... } | |
4701 | alternatives | |
4702 | (nth 1 ido-decorations))))))) | |
4703 | ||
4704 | (defun ido-minibuffer-setup () | |
d11320e5 | 4705 | "Minibuffer setup hook for Ido." |
789d1bf0 | 4706 | ;; Copied from `icomplete-minibuffer-setup-hook'. |
cba9a3a5 | 4707 | (when (ido-active) |
789d1bf0 KS |
4708 | (add-hook 'pre-command-hook 'ido-tidy nil t) |
4709 | (add-hook 'post-command-hook 'ido-exhibit nil t) | |
1518d6e3 | 4710 | (when (featurep 'xemacs) |
789d1bf0 KS |
4711 | (ido-exhibit) |
4712 | (goto-char (point-min))) | |
155943b9 KS |
4713 | (run-hooks 'ido-minibuffer-setup-hook) |
4714 | (when ido-initial-position | |
4715 | (goto-char (+ (minibuffer-prompt-end) ido-initial-position)) | |
4716 | (setq ido-initial-position nil)))) | |
789d1bf0 KS |
4717 | |
4718 | (defun ido-tidy () | |
d11320e5 | 4719 | "Pre command hook for Ido." |
789d1bf0 KS |
4720 | ;; Remove completions display, if any, prior to new user input. |
4721 | ;; Copied from `icomplete-tidy'." | |
4722 | ||
4723 | (when ido-auto-merge-timer | |
4724 | (ido-trace "\n*cancel timer*" this-command) | |
4725 | (cancel-timer ido-auto-merge-timer) | |
4726 | (setq ido-auto-merge-timer nil)) | |
4727 | ||
c744a3b9 LL |
4728 | (when (ido-active) |
4729 | (if (bound-and-true-p ido-eoinput) | |
4730 | (if (> ido-eoinput (point-max)) | |
4731 | ;; Oops, got rug pulled out from under us - reinit: | |
4732 | (setq ido-eoinput (point-max)) | |
4733 | (let ((inhibit-read-only t) | |
4734 | (buffer-undo-list t)) | |
4735 | (delete-region ido-eoinput (point-max)))) | |
4736 | ||
4737 | ;; Reestablish the local variable 'cause minibuffer-setup is weird: | |
4738 | (make-local-variable 'ido-eoinput) | |
4739 | (setq ido-eoinput 1)))) | |
789d1bf0 KS |
4740 | |
4741 | (defun ido-summary-buffers-to-end () | |
4742 | ;; Move the summaries to the end of the buffer list. | |
4743 | ;; This is an example function which can be hooked on to | |
4744 | ;; `ido-make-buffer-list-hook'. Any buffer matching the regexps | |
4745 | ;; `Summary' or `output\*$'are put to the end of the list. | |
71296446 JB |
4746 | (let ((summaries (delq nil (mapcar |
4747 | (lambda (x) | |
4748 | (if (or | |
789d1bf0 KS |
4749 | (string-match "Summary" x) |
4750 | (string-match "output\\*\\'" x)) | |
4751 | x)) | |
4752 | ido-temp-list)))) | |
4753 | (ido-to-end summaries))) | |
4754 | ||
4755 | ;;; Helper functions for other programs | |
4756 | ||
ae9d279d | 4757 | (put 'ibuffer-find-file 'ido 'find-file) |
6c0674ee | 4758 | (put 'dired 'ido 'dir) |
76ce3ae6 | 4759 | (put 'dired-other-window 'ido 'dir) |
7bcb455b | 4760 | (put 'dired-other-frame 'ido 'dir) |
6c0674ee LL |
4761 | ;; See http://debbugs.gnu.org/11954 for reasons. |
4762 | (put 'dired-do-copy 'ido 'ignore) | |
4763 | (put 'dired-do-rename 'ido 'ignore) | |
84263efb | 4764 | |
cb65c373 KS |
4765 | ;;;###autoload |
4766 | (defun ido-read-buffer (prompt &optional default require-match) | |
4767 | "Ido replacement for the built-in `read-buffer'. | |
4768 | Return the name of a buffer selected. | |
4769 | PROMPT is the prompt to give to the user. DEFAULT if given is the default | |
4770 | buffer to be selected, which will go to the front of the list. | |
616e8e5f | 4771 | If REQUIRE-MATCH is non-nil, an existing buffer must be selected." |
cb65c373 KS |
4772 | (let* ((ido-current-directory nil) |
4773 | (ido-directory-nonreadable nil) | |
4774 | (ido-directory-too-big nil) | |
4775 | (ido-context-switch-command 'ignore) | |
4776 | (buf (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match))) | |
4777 | (if (eq ido-exit 'fallback) | |
4778 | (let ((read-buffer-function nil)) | |
b2d4c118 | 4779 | (run-hook-with-args 'ido-before-fallback-functions 'read-buffer) |
cb65c373 KS |
4780 | (read-buffer prompt default require-match)) |
4781 | buf))) | |
4782 | ||
789d1bf0 KS |
4783 | ;;;###autoload |
4784 | (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate) | |
cb65c373 KS |
4785 | "Ido replacement for the built-in `read-file-name'. |
4786 | Read file name, prompting with PROMPT and completing in directory DIR. | |
789d1bf0 | 4787 | See `read-file-name' for additional parameters." |
db9f395b KS |
4788 | (let (filename) |
4789 | (cond | |
4790 | ((or (eq predicate 'file-directory-p) | |
58fbe886 LL |
4791 | (eq (and (symbolp this-command) |
4792 | (get this-command 'ido)) 'dir) | |
db9f395b KS |
4793 | (memq this-command ido-read-file-name-as-directory-commands)) |
4794 | (setq filename | |
5550a72c | 4795 | (ido-read-directory-name prompt dir default-filename mustmatch initial))) |
58fbe886 LL |
4796 | ((and (not (eq (and (symbolp this-command) |
4797 | (get this-command 'ido)) 'ignore)) | |
db9f395b KS |
4798 | (not (memq this-command ido-read-file-name-non-ido)) |
4799 | (or (null predicate) (eq predicate 'file-exists-p))) | |
4800 | (let* (ido-saved-vc-hb | |
ae9d279d | 4801 | (ido-context-switch-command |
58fbe886 LL |
4802 | (if (eq (and (symbolp this-command) |
4803 | (get this-command 'ido)) 'find-file) | |
4804 | nil 'ignore)) | |
db9f395b | 4805 | (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends)) |
83a12f3a | 4806 | (minibuffer-completing-file-name t) |
db9f395b KS |
4807 | (ido-current-directory (ido-expand-directory dir)) |
4808 | (ido-directory-nonreadable (not (file-readable-p ido-current-directory))) | |
cb65c373 KS |
4809 | (ido-directory-too-big (and (not ido-directory-nonreadable) |
4810 | (ido-directory-too-big-p ido-current-directory))) | |
db9f395b | 4811 | (ido-work-directory-index -1) |
fcbc95a9 KS |
4812 | (ido-show-dot-for-dired (and ido-show-dot-for-dired |
4813 | (not default-filename))) | |
db9f395b KS |
4814 | (ido-work-file-index -1) |
4815 | (ido-find-literal nil)) | |
4816 | (setq ido-exit nil) | |
4817 | (setq filename | |
a43d577e LL |
4818 | (ido-read-internal 'file prompt 'ido-file-history |
4819 | (cond ; Bug#11861. | |
4820 | ((stringp default-filename) default-filename) | |
4821 | ((consp default-filename) (car default-filename)) | |
4822 | ((and (not default-filename) initial) | |
4823 | (expand-file-name initial dir)) | |
4824 | (buffer-file-name buffer-file-name)) | |
4825 | mustmatch initial)) | |
5550a72c | 4826 | (setq dir ido-current-directory) ; See bug#1516. |
db9f395b KS |
4827 | (cond |
4828 | ((eq ido-exit 'fallback) | |
4829 | (setq filename 'fallback)) | |
ae9d279d KS |
4830 | ((eq ido-exit 'dired) |
4831 | (setq filename ido-current-directory)) | |
db9f395b KS |
4832 | (filename |
4833 | (setq filename | |
4834 | (concat ido-current-directory filename)))))) | |
4835 | (t | |
4836 | (setq filename 'fallback))) | |
4837 | (if (eq filename 'fallback) | |
4838 | (let ((read-file-name-function nil)) | |
b2d4c118 | 4839 | (run-hook-with-args 'ido-before-fallback-functions 'read-file-name) |
db9f395b KS |
4840 | (read-file-name prompt dir default-filename mustmatch initial predicate)) |
4841 | filename))) | |
789d1bf0 KS |
4842 | |
4843 | ;;;###autoload | |
4844 | (defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial) | |
cb65c373 KS |
4845 | "Ido replacement for the built-in `read-directory-name'. |
4846 | Read directory name, prompting with PROMPT and completing in directory DIR. | |
4847 | See `read-directory-name' for additional parameters." | |
a70343bd | 4848 | (let* (filename |
83a12f3a | 4849 | (minibuffer-completing-file-name t) |
db9f395b | 4850 | (ido-context-switch-command 'ignore) |
a70343bd KS |
4851 | ido-saved-vc-hb |
4852 | (ido-current-directory (ido-expand-directory dir)) | |
4853 | (ido-directory-nonreadable (not (file-readable-p ido-current-directory))) | |
cb65c373 KS |
4854 | (ido-directory-too-big (and (not ido-directory-nonreadable) |
4855 | (ido-directory-too-big-p ido-current-directory))) | |
a70343bd KS |
4856 | (ido-work-directory-index -1) |
4857 | (ido-work-file-index -1)) | |
a43d577e LL |
4858 | (setq filename (ido-read-internal |
4859 | 'dir prompt 'ido-file-history | |
4860 | (or default-dirname ; Bug#11861. | |
4861 | (if initial | |
4862 | (expand-file-name initial ido-current-directory) | |
4863 | ido-current-directory)) | |
4864 | mustmatch initial)) | |
5550a72c LL |
4865 | (cond |
4866 | ((eq ido-exit 'fallback) | |
4867 | (let ((read-file-name-function nil)) | |
4868 | (run-hook-with-args 'ido-before-fallback-functions 'read-directory-name) | |
4869 | (read-directory-name prompt ido-current-directory | |
4870 | default-dirname mustmatch initial))) | |
4871 | ((equal filename ".") ido-current-directory) | |
4872 | (t (concat ido-current-directory filename))))) | |
789d1bf0 | 4873 | |
db9f395b | 4874 | ;;;###autoload |
06b60517 JB |
4875 | (defun ido-completing-read (prompt choices &optional _predicate require-match |
4876 | initial-input hist def _inherit-input-method) | |
cb65c373 | 4877 | "Ido replacement for the built-in `completing-read'. |
d11320e5 | 4878 | Read a string in the minibuffer with Ido-style completion. |
db9f395b KS |
4879 | PROMPT is a string to prompt with; normally it ends in a colon and a space. |
4880 | CHOICES is a list of strings which are the possible completions. | |
d11320e5 | 4881 | PREDICATE and INHERIT-INPUT-METHOD are currently ignored; they are included |
3ec03f7e | 4882 | to be compatible with `completing-read'. |
db9f395b KS |
4883 | If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless |
4884 | the input is (or completes to) an element of CHOICES or is null. | |
4885 | If the input is null, `ido-completing-read' returns DEF, or an empty | |
4886 | string if DEF is nil, regardless of the value of REQUIRE-MATCH. | |
4887 | If INITIAL-INPUT is non-nil, insert it in the minibuffer initially, | |
4888 | with point positioned at the end. | |
4889 | HIST, if non-nil, specifies a history list. | |
4890 | DEF, if non-nil, is the default value." | |
4891 | (let ((ido-current-directory nil) | |
4892 | (ido-directory-nonreadable nil) | |
cb65c373 | 4893 | (ido-directory-too-big nil) |
db9f395b | 4894 | (ido-context-switch-command 'ignore) |
c7a8fcac | 4895 | (ido-choice-list choices)) |
bd794450 | 4896 | ;; Initialize ido before invoking ido-read-internal |
0fdd1db7 | 4897 | (ido-common-initialization) |
db9f395b KS |
4898 | (ido-read-internal 'list prompt hist def require-match initial-input))) |
4899 | ||
4e3e159b JB |
4900 | (defun ido-unload-function () |
4901 | "Unload the Ido library." | |
4902 | (ido-mode -1) | |
4903 | (setq minor-mode-map-alist (assq-delete-all 'ido-mode minor-mode-map-alist)) | |
4904 | ;; continue standard unloading | |
4905 | nil) | |
4906 | ||
403dae9d | 4907 | (provide 'ido) |
db9f395b | 4908 | |
789d1bf0 | 4909 | ;;; ido.el ends here |