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