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