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