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