1 ;;; ido.el --- interactively do things with buffers and files.
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Kim F. Storm <storm@cua.dk>
7 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
8 ;; Keywords: extensions convenience
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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.
32 ;; Interactive substring matching
33 ;; ------------------------------
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.
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.
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.
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
56 ;; Buffer: {123456 | 123}
59 ;; Buffer: 2[3]{123456 | 123}
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
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].
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.
72 ;; Buffer: 23{123456 | 123}
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.
79 ;; However, if I type 4, I only have one match left:
80 ;; Buffer: 234[123456]
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.
86 ;; If I want to create a new buffer named "234", I press C-j instead of
89 ;; If instead, I type "a":
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".
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).
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.
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.
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.
115 ;; To go up to the parent directory, delete any partial file name
116 ;; already specified (e.g. using [backspace]) and hit [backspace].
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
123 ;; to inhibit the ido substring matching for ftp access.
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.
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)
133 ;; Hidden buffers and files
134 ;; ------------------------
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
143 ;; You can toggle display of the hidden buffers and files with C-a.
145 ;; Additional functionality
146 ;; ------------------------
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.
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.
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.
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.
171 ;; You can toggle prefix matching with C-p.
175 ;; If you have again two Buffers "123456" and "123" then hitting "2" does
176 ;; not match because "2" is not a PREFIX in any of the buffer-names.
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.
186 ;; The flexible matching implies that any item which simply contains all
187 ;; of the entered characters in the specified sequence will match.
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.
199 ;; There is limited provision for regexp matching within ido,
200 ;; enabled through `ido-enable-regexp' (toggle with C-t).
201 ;; This allows you to type `[ch]$' for example and see all file names
202 ;; ending in `c' or `h'.
204 ;; Note: ido-style completion is inhibited when you enable regexp matching.
210 ;; Customize the `ido' group to change the `ido' functionality.
212 ;; To modify the keybindings, use the ido-setup-hook. For example:
213 ;;(add-hook 'ido-setup-hook 'ido-my-keys)
215 ;;(defun ido-my-keys ()
216 ;; "Add my keybindings for ido."
217 ;; (define-key ido-completion-map " " 'ido-next-match)
220 ;; Seeing all the matching buffers or files
221 ;; ----------------------------------------
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
228 ;; resizing behavior, set the variable `ido-max-window-height'.
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.
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
239 ;; Changing the list of files
240 ;; --------------------------
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:
247 ;; (add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end)
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
252 ;; end of the list (these are created by AUCTeX when compiling.)
253 ;; Other functions could be made available which alter the list of
254 ;; matching files (either deleting or rearranging elements.)
259 ;; The highlighting of matching items is controlled via ido-use-faces.
260 ;; The faces used are ido-first-match, ido-only-match and
262 ;; Colouring of the matching item was suggested by
263 ;; Carsten Dominik (dominik@strw.leidenuniv.nl).
265 ;; Replacement for read-buffer and read-file-name
266 ;; ----------------------------------------------
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'.
272 ;; To use ido for all buffer and file selections in Emacs, customize the
273 ;; variable `ido-everywhere'.
275 ;; Using ido-like behavior in other lisp packages
276 ;; -----------------------------------------------
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.
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.
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.
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
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.
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.
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.
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.
325 (defvar cua-inhibit-cua-keys
)
326 (defvar recentf-list
)
330 ;; These are some things you might want to change.
332 (defun ido-fractionp (n)
333 (and (numberp n
) (> n
0.0) (<= n
1.0)))
336 "Switch between files using substrings."
340 :link
'(emacs-commentary-link :tag
"Commentary" "ido.el")
341 :link
'(emacs-library-link :tag
"Lisp File" "ido.el"))
344 (defcustom ido-mode nil
345 "Determines for which functional group \(buffer and files) ido behavior
346 should be enabled. The following values are possible:
347 - `buffer': Turn only on ido buffer behavior \(switching, killing,
349 - `file': Turn only on ido file behavior \(finding, writing, inserting...)
350 - `both': Turn on ido buffer and file behavior.
351 - `nil': Turn off any ido switching.
353 Setting this variable directly does not take effect;
354 use either \\[customize] or the function `ido-mode'."
355 :set
#'(lambda (symbol value
)
357 :initialize
'custom-initialize-default
359 :link
'(emacs-commentary-link "ido.el")
360 :set-after
'(ido-save-directory-list-file
361 ;; This will clear ido-unc-hosts-cache, so set it
362 ;; before loading history file.
364 :type
'(choice (const :tag
"Turn on only buffer" buffer
)
365 (const :tag
"Turn on only file" file
)
366 (const :tag
"Turn on both buffer and file" both
)
367 (const :tag
"Switch off all" nil
))
370 (defcustom ido-case-fold case-fold-search
371 "Non-nil if searching of buffer and file names should ignore case."
375 (defcustom ido-ignore-buffers
377 "List of regexps or functions matching buffer names to ignore.
378 For example, traditional behavior is not to list buffers whose names begin
379 with a space, for which the regexp is `\\` '. See the source file for
380 example functions that filter buffer names."
381 :type
'(repeat (choice regexp function
))
384 (defcustom ido-ignore-files
385 '("\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./")
386 "List of regexps or functions matching file names to ignore.
387 For example, traditional behavior is not to list files whose names begin
388 with a #, for which the regexp is `\\`#'. See the source file for
389 example functions that filter filenames."
390 :type
'(repeat (choice regexp function
))
393 (defcustom ido-ignore-extensions t
394 "Non-nil means ignore files in `completion-ignored-extensions' list."
398 (defcustom ido-show-dot-for-dired nil
399 "Non-nil means to always put . as the first item in file name lists.
400 This allows the current directory to be opened immediately with `dired'."
404 (defcustom ido-file-extensions-order nil
405 "List of file extensions specifying preferred order of file selections.
406 Each element is either a string with `.' as the first char, an empty
407 string matching files without extension, or t which is the default order
408 for files with an unlisted file extension."
409 :type
'(repeat (choice string
410 (const :tag
"Default order" t
)))
413 (defcustom ido-ignore-directories
414 '("\\`CVS/" "\\`\\.\\./" "\\`\\./")
415 "List of regexps or functions matching sub-directory names to ignore."
416 :type
'(repeat (choice regexp function
))
419 (defcustom ido-ignore-directories-merge nil
420 "List of regexps or functions matching directory names to ignore during merge.
421 Directory names matched by one of the regexps in this list are not inserted
422 in merged file and directory lists."
423 :type
'(repeat (choice regexp function
))
426 ;; Examples for setting the value of ido-ignore-buffers
427 ;;(defun ido-ignore-c-mode (name)
428 ;; "Ignore all c mode buffers -- example function for ido."
429 ;; (with-current-buffer name
430 ;; (derived-mode-p 'c-mode)))
432 ;;(setq ido-ignore-buffers '("^ " ido-ignore-c-mode))
434 ;; Examples for setting the value of ido-ignore-files
435 ;;(setq ido-ignore-files '("^ " "\\.c\\'" "\\.h\\'"))
437 (defcustom ido-default-file-method
'raise-frame
438 "How to visit a new file when using `ido-find-file'.
440 `selected-window' Show new file in selected window
441 `other-window' Show new file in another window (same frame)
442 `display' Display file in another window without selecting to it
443 `other-frame' Show new file in another frame
444 `maybe-frame' If a file is visible in another frame, prompt to ask if you
445 you want to see the file in the same window of the current
446 frame or in the other frame
447 `raise-frame' If a file is visible in another frame, raise that
448 frame; otherwise, visit the file in the same window"
449 :type
'(choice (const :tag
"Visit in selected window" selected-window
)
450 (const :tag
"Visit in other window" other-window
)
451 (const :tag
"Display (no select) in other window" display
)
452 (const :tag
"Visit in other frame" other-frame
)
453 (const :tag
"Ask to visit in other frame" maybe-frame
)
454 (const :tag
"Raise frame if already visited" raise-frame
))
457 (defcustom ido-default-buffer-method
'raise-frame
458 "How to switch to new buffer when using `ido-switch-buffer'.
459 See `ido-default-file-method' for details."
460 :type
'(choice (const :tag
"Show in selected window" selected-window
)
461 (const :tag
"Show in other window" other-window
)
462 (const :tag
"Display (no select) in other window" display
)
463 (const :tag
"Show in other frame" other-frame
)
464 (const :tag
"Ask to show in other frame" maybe-frame
)
465 (const :tag
"Raise frame if already shown" raise-frame
))
466 :type
'(choice (const selected-window
)
474 (defcustom ido-enable-flex-matching nil
475 "Non-nil means that `ido' will do flexible string matching.
476 Flexible matching means that if the entered string does not
477 match any item, any item containing the entered characters
478 in the given sequence will match."
483 (defcustom ido-enable-regexp nil
484 "Non-nil means that `ido' will do regexp matching.
485 Value can be toggled within `ido' using `ido-toggle-regexp'."
489 (defcustom ido-enable-prefix nil
490 "Non-nil means only match if the entered text is a prefix of file name.
491 This behavior is like the standard Emacs completion.
492 If nil, match if the entered text is an arbitrary substring.
493 Value can be toggled within `ido' using `ido-toggle-prefix'."
497 (defcustom ido-enable-dot-prefix nil
498 "Non-nil means to match leading dot as prefix.
499 I.e. hidden files and buffers will match only if you type a dot
500 as first char even if `ido-enable-prefix' is nil."
504 (defcustom ido-confirm-unique-completion nil
505 "Non-nil means that even a unique completion must be confirmed.
506 This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer]
507 even when there is only one unique completion."
511 (defcustom ido-cannot-complete-command
'ido-completion-help
512 "Command run when `ido-complete' can't complete any more.
513 The most useful values are `ido-completion-help', which pops up a
514 window with completion alternatives, or `ido-next-match' or
515 `ido-prev-match', which cycle the buffer list."
520 (defcustom ido-record-commands t
521 "Non-nil means that `ido' will record commands in command history.
522 Note that the non-ido equivalent command is recorded."
526 (defcustom ido-max-prospects
12
527 "Non-zero means that the prospect list will be limited to that number of items.
528 For a long list of prospects, building the full list for the minibuffer can take a
529 non-negligible amount of time; setting this variable reduces that time."
533 (defcustom ido-max-file-prompt-width
0.35
534 "Non-zero means that the prompt string be limited to that number of characters.
535 If value is a floating point number, it specifies a fraction of the frame width."
537 (integer :tag
"Characters" :value
20)
538 (restricted-sexp :tag
"Fraction of frame width"
540 :match-alternatives
(ido-fractionp)))
543 (defcustom ido-max-window-height nil
544 "Non-nil specifies a value to override `max-mini-window-height'."
546 (const :tag
"Don't override" nil
)
547 (integer :tag
"Number of lines" :value
1)
549 :tag
"Fraction of window height"
551 :match-alternatives
(ido-fractionp)))
554 (defcustom ido-enable-last-directory-history t
555 "Non-nil means that `ido' will remember latest selected directory names.
556 See `ido-last-directory-list' and `ido-save-directory-list-file'."
560 (defcustom ido-max-work-directory-list
50
561 "Maximum number of working directories to record.
562 This is the list of directories where files have most recently been opened.
563 See `ido-work-directory-list' and `ido-save-directory-list-file'."
567 (defcustom ido-work-directory-list-ignore-regexps nil
568 "List of regexps matching directories which should not be recorded.
569 Directory names matched by one of the regexps in this list are not inserted in
570 the `ido-work-directory-list' list."
571 :type
'(repeat regexp
)
575 (defcustom ido-use-filename-at-point nil
576 "Non-nil means that ido shall look for a filename at point.
577 May use `ffap-guesser' to guess whether text at point is a filename.
578 If found, use that as the starting point for filename selection."
580 (const :tag
"Disabled" nil
)
581 (const :tag
"Guess filename" guess
)
582 (other :tag
"Use literal filename" t
))
586 (defcustom ido-use-url-at-point nil
587 "Non-nil means that ido shall look for a URL at point.
588 If found, call `find-file-at-point' to visit it."
593 (defcustom ido-enable-tramp-completion t
594 "Non-nil means that ido shall perform tramp method and server name completion.
595 A tramp file name uses the following syntax: /method:user@host:filename."
599 (defcustom ido-record-ftp-work-directories t
600 "Non-nil means record ftp file names in the work directory list."
604 (defcustom ido-merge-ftp-work-directories nil
605 "If nil, merging ignores ftp file names in the work directory list."
609 (defcustom ido-cache-ftp-work-directory-time
1.0
610 "Maximum time to cache contents of an ftp directory (in hours).
611 Use C-l in prompt to refresh list.
612 If zero, ftp directories are not cached."
616 (defcustom ido-slow-ftp-hosts nil
617 "List of slow ftp hosts where ido prompting should not be used.
618 If an ftp host is on this list, ido automatically switches to the non-ido
619 equivalent function, e.g. `find-file' rather than `ido-find-file'."
620 :type
'(repeat string
)
623 (defcustom ido-slow-ftp-host-regexps nil
624 "List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')."
625 :type
'(repeat regexp
)
628 (defvar ido-unc-hosts-cache t
629 "Cached value from `ido-unc-hosts' function.")
631 (defcustom ido-unc-hosts nil
632 "List of known UNC host names to complete after initial //.
633 If value is a function, that function is called to search network for
634 hosts on first use of UNC path."
635 :type
'(choice (repeat :tag
"List of UNC host names" string
)
636 (function-item :tag
"Use `NET VIEW'"
637 :value ido-unc-hosts-net-view
)
638 (function :tag
"Your own function"))
639 :set
#'(lambda (symbol value
)
641 (setq ido-unc-hosts-cache t
))
644 (defcustom ido-downcase-unc-hosts t
645 "Non-nil if UNC host names should be downcased."
649 (defcustom ido-ignore-unc-host-regexps nil
650 "List of regexps matching UNC hosts to ignore.
651 Case is ignored if `ido-downcase-unc-hosts' is set."
652 :type
'(repeat regexp
)
655 (defcustom ido-cache-unc-host-shares-time
8.0
656 "Maximum time to cache shares of an UNC host (in hours).
657 Use C-l in prompt to refresh list.
658 If zero, UNC host shares are not cached."
662 (defcustom ido-max-work-file-list
10
663 "Maximum number of names of recently opened files to record.
664 This is the list of the file names (sans directory) which have most recently
665 been opened. See `ido-work-file-list' and `ido-save-directory-list-file'."
669 (defcustom ido-work-directory-match-only t
670 "Non-nil means to skip non-matching directories in the directory history.
671 When some text is already entered at the `ido-find-file' prompt, using
672 \\[ido-prev-work-directory] or \\[ido-next-work-directory] will skip directories
673 without any matching entries."
677 (defcustom ido-auto-merge-work-directories-length
0
678 "Automatically switch to merged work directories during file name input.
679 The value is number of characters to type before switching to merged mode.
680 If zero, the switch happens when no matches are found in the current directory.
681 Automatic merging is disabled if the value is negative."
685 (defcustom ido-auto-merge-delay-time
0.70
686 "Delay in seconds to wait for more input before doing auto merge."
690 (defcustom ido-auto-merge-inhibit-characters-regexp
"[][*?~]"
691 "Regexp matching characters which should inhibit automatic merging.
692 When a (partial) file name matches this regexp, merging is inhibited."
696 (defcustom ido-merged-indicator
"^"
697 "The string appended to first choice if it has multiple directory choices."
701 (defcustom ido-max-dir-file-cache
100
702 "Maximum number of working directories to be cached.
703 This is the size of the cache of `file-name-all-completions' results.
704 Each cache entry is time stamped with the modification time of the
705 directory. Some systems, like Windows, have unreliable directory
706 modification times, so you may choose to disable caching on such
707 systems, or explicitly refresh the cache contents using the command
708 `ido-reread-directory' command (C-l) in the minibuffer.
709 See also `ido-dir-file-cache' and `ido-save-directory-list-file'."
713 (defcustom ido-max-directory-size
30000
714 "Maximum size (in bytes) for directories to use ido completion.
715 If you enter a directory with a size larger than this size, ido will
716 not provide the normal completion. To show the completions, use C-a."
717 :type
'(choice (const :tag
"No limit" nil
)
718 (integer :tag
"Size in bytes" 30000))
721 (defcustom ido-rotate-file-list-default nil
722 "Non-nil means that `ido' will always rotate file list to get default in front."
726 (defcustom ido-enter-matching-directory
'only
727 "Additional methods to enter sub-directory of first/only matching item.
728 If value is 'first, enter first matching sub-directory when typing a slash.
729 If value is 'only, typing a slash only enters the sub-directory if it is
730 the only matching item.
731 If value is t, automatically enter a sub-directory when it is the only
732 matching item, even without typing a slash."
733 :type
'(choice (const :tag
"Never" nil
)
734 (const :tag
"Slash enters first directory" first
)
735 (const :tag
"Slash enters first and only directory" only
)
736 (other :tag
"Always enter unique directory" t
))
739 (defcustom ido-create-new-buffer
'prompt
740 "Specify whether a new buffer is created if no buffer matches substring.
741 Choices are 'always to create new buffers unconditionally, 'prompt to
742 ask user whether to create buffer, or 'never to never create new buffer."
743 :type
'(choice (const always
)
748 (defcustom ido-setup-hook nil
749 "Hook run after the ido variables and keymap have been setup.
750 The dynamic variable `ido-cur-item' contains the current type of item that
751 is read by ido; possible values are file, dir, buffer, and list.
752 Additional keys can be defined in `ido-completion-map'."
756 (defcustom ido-separator nil
757 "String used by ido to separate the alternatives in the minibuffer.
758 Obsolete. Set 3rd element of `ido-decorations' instead."
759 :type
'(choice string
(const nil
))
762 (defcustom ido-decorations
'( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")
763 "List of strings used by ido to display the alternatives in the minibuffer.
764 There are 11 elements in this list:
765 1st and 2nd elements are used as brackets around the prospect list,
766 3rd element is the separator between prospects (ignored if `ido-separator' is set),
767 4th element is the string inserted at the end of a truncated list of prospects,
768 5th and 6th elements are used as brackets around the common match string which
769 can be completed using TAB,
770 7th element is the string displayed when there are no matches, and
771 8th element is displayed if there is a single match (and faces are not used),
772 9th element is displayed when the current directory is non-readable,
773 10th element is displayed when directory exceeds `ido-max-directory-size',
774 11th element is displayed to confirm creating new file or buffer."
775 :type
'(repeat string
)
778 (defcustom ido-use-virtual-buffers nil
779 "If non-nil, refer to past buffers as well as existing ones.
780 Essentially it works as follows: Say you are visiting a file and
781 the buffer gets cleaned up by mignight.el. Later, you want to
782 switch to that buffer, but find it's no longer open. With
783 virtual buffers enabled, the buffer name stays in the buffer
784 list (using the ido-virtual face, and always at the end), and if
785 you select it, it opens the file back up again. This allows you
786 to think less about whether recently opened files are still open
787 or not. Most of the time you can quit Emacs, restart, and then
788 switch to a file buffer that was previously open as if it still
790 This feature relies upon the `recentf' package, which will be
791 enabled if this variable is configured to a non-nil value."
796 (defcustom ido-use-faces t
797 "Non-nil means use ido faces to highlighting first match, only match and
798 subdirs in the alternatives."
802 (defface ido-first-match
'((t (:bold t
)))
803 "Face used by ido for highlighting first match."
806 (defface ido-only-match
'((((class color
))
807 (:foreground
"ForestGreen"))
809 "Face used by ido for highlighting only match."
812 (defface ido-subdir
'((((min-colors 88) (class color
))
813 (:foreground
"red1"))
817 "Face used by ido for highlighting subdirs in the alternatives."
820 (defface ido-virtual
'((t (:inherit font-lock-builtin-face
)))
821 "Face used by ido for matching virtual buffer names."
825 (defface ido-indicator
'((((min-colors 88) (class color
))
826 (:foreground
"yellow1"
830 (:foreground
"yellow"
833 (t (:inverse-video t
)))
834 "Face used by ido for highlighting its indicators."
837 (defface ido-incomplete-regexp
839 (:inherit font-lock-warning-face
)))
840 "Ido face for indicating incomplete regexps."
843 (defcustom ido-make-file-list-hook nil
844 "List of functions to run when the list of matching files is created.
845 Each function on the list may modify the dynamically bound variable
846 `ido-temp-list' which contains the current list of matching files."
850 (defcustom ido-make-dir-list-hook nil
851 "List of functions to run when the list of matching directories is created.
852 Each function on the list may modify the dynamically bound variable
853 `ido-temp-list' which contains the current list of matching directories."
857 (defcustom ido-make-buffer-list-hook nil
858 "List of functions to run when the list of matching buffers is created.
859 Each function on the list may modify the dynamically bound variable
860 `ido-temp-list' which contains the current list of matching buffer names."
864 (defcustom ido-rewrite-file-prompt-functions nil
865 "List of functions to run when the find-file prompt is created.
866 Each function on the list may modify the following dynamically bound
868 dirname - the (abbreviated) directory name
869 to be modified by the hook functions
870 max-width - the max width of the resulting dirname; nil means no limit
871 prompt - the basic prompt (e.g. \"Find File: \")
872 literal - the string shown if doing \"literal\" find; set to nil to omit
873 vc-off - the string shown if version control is inhibited; set to nil to omit
874 prefix - either nil or a fixed prefix for the dirname
876 The following variables are available, but should not be changed:
877 `ido-current-directory' - the unabbreviated directory name
878 item - equals `file' or `dir' depending on the current mode."
882 (defvar ido-rewrite-file-prompt-rules nil
883 "*Alist of rewriting rules for directory names in ido prompts.
884 A list of elements of the form (FROM . TO) or (FROM . FUNC), each
885 meaning to rewrite the directory name if matched by FROM by either
886 substituting the matched string by TO or calling the function FUNC
887 with the current directory name as its only argument and using the
888 return value as the new directory name. In addition, each FUNC may
889 also modify the dynamic variables described for the variable
890 `ido-rewrite-file-prompt-functions'.")
892 (defcustom ido-completion-buffer
"*Ido Completions*"
893 "Name of completion buffer used by ido.
894 Set to nil to disable completion buffers popping up."
898 (defcustom ido-completion-buffer-all-completions nil
899 "Non-nil means to show all completions in completion buffer.
900 Otherwise, only the current list of matches is shown."
904 (defvar ido-all-frames
'visible
905 "*Argument to pass to `walk-windows' when finding visible files.
906 See documentation of `walk-windows' for useful values.")
908 (defcustom ido-minibuffer-setup-hook nil
909 "Ido-specific customization of minibuffer setup.
911 This hook is run during minibuffer setup if `ido' is active.
912 It is intended for use in customizing ido for interoperation
913 with other packages. For instance:
915 \(add-hook 'ido-minibuffer-setup-hook
918 \(make-local-variable 'max-mini-window-height)
919 \(setq max-mini-window-height 3))))
921 will constrain Emacs to a maximum minibuffer height of 3 lines when
922 ido is running. Copied from `icomplete-minibuffer-setup-hook'."
926 (defcustom ido-save-directory-list-file
(convert-standard-filename "~/.ido.last")
927 "File in which the ido state is saved between invocations.
928 Variables stored are: `ido-last-directory-list', `ido-work-directory-list',
929 `ido-work-file-list', and `ido-dir-file-cache'.
930 Must be set before enabling ido mode."
934 (defcustom ido-read-file-name-as-directory-commands
'()
935 "List of commands which uses `read-file-name' to read a directory name.
936 When `ido-everywhere' is non-nil, the commands in this list will read
937 the directory using `ido-read-directory-name'."
938 :type
'(repeat symbol
)
941 (defcustom ido-read-file-name-non-ido
'()
942 "List of commands which shall not read file names the ido way.
943 When `ido-everywhere' is non-nil, the commands in this list will read
944 the file name using normal `read-file-name' style."
945 :type
'(repeat symbol
)
948 (defcustom ido-before-fallback-functions
'()
949 "List of functions to call before calling a fallback command.
950 The fallback command is passed as an argument to the functions."
954 ;;; Internal Variables
956 ;; Persistent variables
958 (defvar ido-completion-map nil
959 "Currently active keymap for ido commands.")
961 (defvar ido-common-completion-map nil
962 "Keymap for all ido commands.")
964 (defvar ido-file-completion-map nil
965 "Keymap for ido file commands.")
967 (defvar ido-file-dir-completion-map nil
968 "Keymap for ido file and directory commands.")
970 (defvar ido-buffer-completion-map nil
971 "Keymap for ido buffer commands.")
973 (defvar ido-file-history nil
974 "History of files selected using `ido-find-file'.")
976 (defvar ido-buffer-history nil
977 "History of buffers selected using `ido-switch-buffer'.")
979 (defvar ido-last-directory-list nil
980 "List of last selected directory names.
981 See `ido-enable-last-directory-history' for details.")
983 (defvar ido-work-directory-list nil
984 "List of actual working directory names.
985 The current directory is inserted at the front of this list whenever a
986 file is opened with `ido-find-file' and family.")
988 (defvar ido-work-file-list nil
989 "List of actual work file names.
990 Opening a file with `ido-find-file' and similar functions
991 inserts the current file name (relative to its containing directory)
992 at the front of this list.")
994 (defvar ido-dir-file-cache nil
995 "List of `file-name-all-completions' results.
996 Each element in the list is of the form (DIR (MTIME) FILE...).")
998 (defvar ido-ignore-item-temp-list nil
999 "List of items to ignore in current ido invocation.
1000 Intended to be let-bound by functions which call ido repeatedly.
1001 Should never be set permanently.")
1003 ;; Temporary storage
1005 (defvar ido-eoinput
1
1006 "Point where minibuffer input ends and completion info begins.
1007 Copied from `icomplete-eoinput'.")
1008 (make-variable-buffer-local 'ido-eoinput
)
1010 (defvar ido-common-match-string nil
1011 "Stores the string that is common to all matching files.")
1013 (defvar ido-rescan nil
1014 "Non-nil means we need to regenerate the list of matching items.")
1016 (defvar ido-rotate nil
1017 "Non-nil means we are rotating list of matches.")
1019 (defvar ido-text nil
1020 "Stores the users string as it is typed in.")
1022 (defvar ido-text-init nil
1023 "The initial string for the users string it is typed in.")
1025 (defvar ido-input-stack nil
1026 "Stores the users strings when user hits M-b/M-f.")
1028 (defvar ido-matches nil
1029 "List of files currently matching `ido-text'.")
1031 (defvar ido-report-no-match t
1032 "Report [No Match] when no completions matches `ido-text'.")
1034 (defvar ido-exit nil
1035 "Flag to monitor how `ido-find-file' exits.
1036 If equal to `takeprompt', we use the prompt as the file name to be
1039 (defvar ido-current-directory nil
1040 "Current directory for `ido-find-file'.")
1042 (defvar ido-auto-merge-timer nil
1043 "Delay timer for auto merge.")
1045 (defvar ido-use-mycompletion-depth
0
1046 "Non-nil means use `ido' completion feedback.
1047 Is set by ido functions to the current `minibuffer-depth',
1048 so that it doesn't interfere with other minibuffer usage.")
1050 (defvar ido-incomplete-regexp nil
1051 "Non-nil if an incomplete regexp is entered.")
1053 (defvar ido-initial-position nil
1054 "Non-nil means to explicitly cursor on entry to minibuffer.
1055 Value is an integer which is number of chars to right of prompt.")
1057 (defvar ido-virtual-buffers nil
1058 "List of virtual buffers, that is, past visited files.
1059 This is a copy of `recentf-list', pared down and with faces applied.
1060 Only used if `ido-use-virtual-buffers' is non-nil.")
1062 ;;; Variables with dynamic bindings.
1063 ;;; Declared here to keep the byte compiler quiet.
1065 ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list).
1066 (defvar ido-cur-item
)
1068 ;;; Stores the current default item
1069 (defvar ido-default-item
)
1071 ;; Stores the current list of items that will be searched through.
1072 ;; The list is ordered, so that the most interesting item comes first,
1073 ;; although by default, the files visible in the current frame are put
1074 ;; at the end of the list.
1075 (defvar ido-cur-list nil
)
1077 ;; Stores the choice list for ido-completing-read
1078 (defvar ido-choice-list nil
)
1080 ;; Stores the list of items which are ignored when building
1081 ;; `ido-cur-list'. It is in no specific order.
1082 (defvar ido-ignored-list
)
1084 ;; Remember if current directory is non-readable (so we cannot do completion).
1085 (defvar ido-directory-nonreadable
)
1087 ;; Remember if current directory is 'huge' (so we don't want to do completion).
1088 (defvar ido-directory-too-big
)
1090 ;; Keep current item list if non-nil.
1091 (defvar ido-keep-item-list
)
1093 ;; Process ido-ignore-* lists.
1094 (defvar ido-process-ignore-lists
)
1096 ;; Don't process ido-ignore- lists once.
1097 (defvar ido-process-ignore-lists-inhibit
)
1099 ;; Buffer from which ido was entered.
1100 (defvar ido-entry-buffer
)
1102 ;; Non-nil if matching file must be selected.
1103 (defvar ido-require-match
)
1105 ;; Non-nil if we should add [confirm] to prompt
1106 (defvar ido-show-confirm-message
)
1108 ;; Stores a temporary version of the file list being created.
1109 (defvar ido-temp-list
)
1111 ;; Non-nil if default list element should be rotated into place.
1112 (defvar ido-rotate-temp
)
1114 ;; Stores current index in ido-work-directory-list.
1115 (defvar ido-work-directory-index
)
1117 ;; Stores current index in ido-work-file-list.
1118 (defvar ido-work-file-index
)
1120 ;; Set when merged work directory list is in use.
1121 (defvar ido-use-merged-list
)
1123 ;; Set when merged work directory list not yet built.
1124 (defvar ido-try-merged-list
)
1126 ;; Saved state prior to last work directory merge.
1127 ;; Value is a list (ido-text dir cur-list ignored-list matches).
1128 (defvar ido-pre-merge-state
)
1130 ;; Original value of vc-handled-backends for use in ido-toggle-vc.
1131 (defvar ido-saved-vc-hb
)
1133 ;; Stores temporary state of literal find file.
1134 (defvar ido-find-literal
)
1136 ;; Set to 'ignore to inhibit switching between find-file/switch-buffer.
1137 (defvar ido-context-switch-command
)
1141 (defun ido-active (&optional merge
)
1144 (and (boundp 'ido-completing-read
)
1145 (or (featurep 'xemacs
)
1146 (= ido-use-mycompletion-depth
(minibuffer-depth))))))
1148 (defvar ido-trace-enable nil
)
1150 (defun ido-trace (p &optional s retval
)
1151 (if ido-trace-enable
1152 (let ((b (get-buffer-create " *IDO Trace*"))
1153 (deactivate-mark deactivate-mark
))
1157 (insert p
": " (if (stringp s
) s
(format "%S" s
)) "\n")))))
1160 (defun ido-toggle-trace (arg)
1162 (setq ido-trace-enable
(or arg
(not ido-trace-enable
)))
1163 (if ido-trace-enable
1164 (message "IDO trace on"))
1165 (let ((b (get-buffer " *IDO Trace*")))
1167 (if ido-trace-enable
1169 (pop-to-buffer b t t
)
1170 (setq truncate-lines t
)))))
1172 (defun ido-local-file-exists-p (file)
1173 "Tell if FILE exists locally."
1174 (let (file-name-handler-alist)
1175 (file-exists-p file
)))
1177 (defun ido-unc-hosts (&optional query
)
1178 "Return list of UNC host names."
1181 ((listp ido-unc-hosts
)
1182 ido-unc-hosts
) ;; static list or nil
1183 ((listp ido-unc-hosts-cache
)
1184 ido-unc-hosts-cache
) ;; result of net search
1185 ((and query
(fboundp ido-unc-hosts
))
1186 (message (propertize "Searching for UNC hosts..." 'face
'highlight
))
1187 (setq ido-unc-hosts-cache
(funcall ido-unc-hosts
))
1189 ido-unc-hosts-cache
)
1191 (setq ido-unc-hosts-cache nil
))
1192 (t (fboundp ido-unc-hosts
)))))
1194 (let ((case-fold-search ido-downcase-unc-hosts
)
1195 res host re-list re
)
1197 (setq host
(car hosts
)
1199 re-list
(and ido-process-ignore-lists
1200 ido-ignore-unc-host-regexps
))
1202 (setq re
(car re-list
)
1203 re-list
(cdr re-list
))
1204 (if (string-match re host
)
1208 (when ido-downcase-unc-hosts
1209 (setq host
(downcase host
)))
1210 (setq res
(cons host res
))))
1211 (setq hosts
(sort res
#'string
<))))
1214 (defun ido-unc-hosts-net-view ()
1215 "Query network for list of UNC host names using `NET VIEW'."
1218 (shell-command "net view" t
)
1219 (goto-char (point-min))
1220 (while (re-search-forward "^\\\\\\\\\\([[:graph:]]+\\)" nil t
)
1221 (setq hosts
(cons (match-string 1) hosts
))))
1224 (defun ido-is-tramp-root (&optional dir
)
1225 (and ido-enable-tramp-completion
1226 (string-match "\\`/[^/]+[@:]\\'"
1227 (or dir ido-current-directory
))))
1229 (defun ido-is-unc-root (&optional dir
)
1230 (and (ido-unc-hosts)
1232 (or dir ido-current-directory
))))
1234 (defun ido-is-unc-host (&optional dir
)
1235 (and (ido-unc-hosts)
1236 (string-match "\\`//[^/]+/\\'"
1237 (or dir ido-current-directory
))))
1239 (defun ido-is-root-directory (&optional dir
)
1240 (setq dir
(or dir ido-current-directory
))
1242 (string-equal "/" dir
)
1243 (and (memq system-type
'(windows-nt ms-dos
))
1244 (string-match "\\`[a-zA-Z]:[/\\]\\'" dir
))
1245 (if ido-enable-tramp-completion
1246 (ido-is-tramp-root dir
)
1247 (string-match "\\`/[^:/][^:/]+:\\'" dir
))))
1249 (defun ido-is-ftp-directory (&optional dir
)
1251 (if ido-enable-tramp-completion
1252 "\\`/[^/:][^/:]+:" ;; like tramp-file-name-regexp-unified, but doesn't match single drive letters
1253 "\\`/[^/:][^/:]+:/")
1254 (or dir ido-current-directory
)))
1256 (defun ido-is-slow-ftp-host (&optional dir
)
1257 (and (or ido-slow-ftp-hosts ido-slow-ftp-host-regexps
)
1258 (setq dir
(or dir ido-current-directory
))
1259 ;; (featurep 'ange-ftp)
1260 ;; (ange-ftp-ftp-name dir)
1262 (if ido-enable-tramp-completion
1263 "\\`/\\([^/]+[@:]\\)*\\([^@/:][^@/:]+\\):"
1264 "\\`/\\([^/:]*@\\)?\\([^@/:][^@/:]+\\):/")
1266 (let ((host (substring dir
(match-beginning 2) (match-end 2))))
1267 (or (member host ido-slow-ftp-hosts
)
1268 (let ((re ido-slow-ftp-host-regexps
))
1269 (while (and re
(not (string-match (car re
) host
)))
1273 (defun ido-time-stamp (&optional time
)
1274 ;; Time is a floating point number (fractions of 1 hour)
1275 (setq time
(or time
(current-time)))
1276 (/ (+ (* (car time
) 65536.0) (car (cdr time
))) 3600.0))
1278 (defun ido-cache-ftp-valid (&optional time
)
1279 (and (numberp ido-cache-ftp-work-directory-time
)
1280 (> ido-cache-ftp-work-directory-time
0)
1282 (< (- (ido-time-stamp) time
) ido-cache-ftp-work-directory-time
))))
1284 (defun ido-cache-unc-valid (&optional time
)
1285 (and (numberp ido-cache-unc-host-shares-time
)
1286 (> ido-cache-unc-host-shares-time
0)
1288 (< (- (ido-time-stamp) time
) ido-cache-unc-host-shares-time
))))
1290 (defun ido-may-cache-directory (&optional dir
)
1291 (setq dir
(or dir ido-current-directory
))
1293 ((ido-directory-too-big-p dir
)
1295 ((and (ido-is-root-directory dir
)
1296 (or ido-enable-tramp-completion
1297 (memq system-type
'(windows-nt ms-dos
))))
1299 ((ido-is-unc-host dir
)
1300 (ido-cache-unc-valid))
1301 ((ido-is-ftp-directory dir
)
1302 (ido-cache-ftp-valid))
1305 (defun ido-pp (list &optional sep
)
1306 (let ((print-level nil
) (eval-expression-print-level nil
)
1307 (print-length nil
) (eval-expression-print-length nil
))
1308 (insert "\n;; ----- " (symbol-name list
) " -----\n(\n ")
1309 (setq list
(symbol-value list
))
1311 (let* ((elt (car list
))
1312 (s (if (consp elt
) (car elt
) elt
)))
1313 (if (and (stringp s
) (= (length s
) 0))
1316 (prin1 elt
(current-buffer)))
1317 (if (and (setq list
(cdr list
)) s
)
1318 (insert (or sep
"\n ")))))
1321 (defun ido-save-history ()
1322 "Save ido history and cache information between sessions."
1324 (when (and ido-last-directory-list ido-save-directory-list-file
)
1325 (let ((buf (get-buffer-create " *ido session*"))
1326 (version-control 'never
))
1328 (with-current-buffer buf
1330 (insert ";;; -*- coding: utf-8 -*-\n")
1331 (setq buffer-file-coding-system
'utf-8
)
1332 (ido-pp 'ido-last-directory-list
)
1333 (ido-pp 'ido-work-directory-list
)
1334 (ido-pp 'ido-work-file-list
)
1335 (ido-pp 'ido-dir-file-cache
"\n\n ")
1336 (if (listp ido-unc-hosts-cache
)
1337 (ido-pp 'ido-unc-hosts-cache
)
1338 (insert "\n;; ----- ido-unc-hosts-cache -----\nt\n"))
1339 (write-file ido-save-directory-list-file nil
))
1340 (kill-buffer buf
)))))
1342 (defun ido-load-history (&optional arg
)
1343 "Load ido history and cache information from previous session.
1344 With prefix argument, reload history unconditionally."
1346 (if (or arg
(and ido-save-directory-list-file
(not ido-last-directory-list
)))
1347 (let ((file (expand-file-name ido-save-directory-list-file
))
1349 (when (file-readable-p file
)
1350 (setq buf
(get-buffer-create " *ido session*"))
1352 (with-current-buffer buf
1354 (insert-file-contents file
)
1356 (setq ido-last-directory-list
(read (current-buffer))
1357 ido-work-directory-list
(read (current-buffer))
1358 ido-work-file-list
(read (current-buffer))
1359 ido-dir-file-cache
(read (current-buffer))
1360 ido-unc-hosts-cache
(read (current-buffer)))
1362 (kill-buffer buf
)))))
1365 (defun ido-wash-history ()
1366 "Clean-up ido history and cache information.
1367 Removes badly formatted data and ignored directories."
1369 ;; Check format of each of our lists, discard bogus elements
1370 (setq ido-last-directory-list
1371 (and (listp ido-last-directory-list
)
1372 (let ((l ido-last-directory-list
) r
)
1374 (if (and (consp (car l
))
1375 (stringp (car (car l
)))
1376 (stringp (cdr (car l
))))
1377 (setq r
(cons (car l
) r
)))
1380 (setq ido-work-directory-list
1381 (and (listp ido-work-directory-list
)
1382 (let ((l ido-work-directory-list
) r
)
1384 (if (and (stringp (car l
))
1385 (or ido-record-ftp-work-directories
1386 (not (ido-is-ftp-directory (car l
)))))
1387 (setq r
(cons (car l
) r
)))
1390 (setq ido-work-file-list
1391 (and (listp ido-work-file-list
)
1392 (let ((l ido-work-file-list
) r
)
1394 (if (stringp (car l
))
1395 (setq r
(cons (car l
) r
)))
1398 (setq ido-dir-file-cache
1399 (and (listp ido-dir-file-cache
)
1400 (let ((l ido-dir-file-cache
) r
)
1402 (if (and (listp (car l
))
1403 (> (length (car l
)) 2)
1404 (let ((dir (car (car l
)))
1405 (time (car (cdr (car l
))))
1406 (files (cdr (cdr (car l
)))))
1411 ((integerp (car time
))
1412 (and (/= (car time
) 0)
1413 (integerp (car (cdr time
)))
1414 (/= (car (cdr time
)) 0)
1415 (ido-may-cache-directory dir
)))
1416 ((eq (car time
) 'ftp
)
1417 (and (numberp (cdr time
))
1418 (ido-is-ftp-directory dir
)
1419 (ido-cache-ftp-valid (cdr time
))))
1420 ((eq (car time
) 'unc
)
1421 (and (numberp (cdr time
))
1422 (ido-is-unc-host dir
)
1423 (ido-cache-unc-valid (cdr time
))))
1425 (let ((s files
) (ok t
))
1427 (if (stringp (car s
))
1429 (setq s nil ok nil
)))
1431 (setq r
(cons (car l
) r
)))
1435 ;; Remove ignored directories from work directory list
1436 ;; according to ido-work-directory-list-ignore-regexps
1437 (if ido-work-directory-list
1438 (let ((dirs (reverse ido-work-directory-list
)))
1439 (setq ido-work-directory-list nil
)
1441 (ido-record-work-directory (car dirs
))
1442 (setq dirs
(cdr dirs
)))))
1443 ;; Get rid of text properties
1444 (let ((l ido-last-directory-list
) e
)
1446 (setq e
(car l
) l
(cdr l
))
1447 (set-text-properties 0 (length (car e
)) nil
(car e
))
1448 (set-text-properties 0 (length (cdr e
)) nil
(cdr e
))))
1449 (let ((l ido-work-directory-list
) e
)
1451 (setq e
(car l
) l
(cdr l
))
1452 (set-text-properties 0 (length e
) nil e
)))
1453 (let ((l ido-work-file-list
) e
)
1455 (setq e
(car l
) l
(cdr l
))
1456 (set-text-properties 0 (length e
) nil e
)))
1457 (let ((l ido-dir-file-cache
) e d
)
1459 (setq e
(car l
) l
(cdr l
))
1462 (setq d
(car e
) e
(cdr e
))
1464 (set-text-properties 0 (length d
) nil d
)))))))
1467 (defun ido-kill-emacs-hook ()
1468 ;; ido kill emacs hook
1471 (define-minor-mode ido-everywhere
1472 "Toggle using ido speed-ups everywhere file and directory names are read.
1473 With ARG, turn ido speed-up on if arg is positive, off otherwise."
1476 (when (get 'ido-everywhere
'file
)
1477 (setq read-file-name-function
(car (get 'ido-everywhere
'file
)))
1478 (put 'ido-everywhere
'file nil
))
1479 (when (get 'ido-everywhere
'buffer
)
1480 (setq read-buffer-function
(car (get 'ido-everywhere
'buffer
)))
1481 (put 'ido-everywhere
'buffer nil
))
1482 (when ido-everywhere
1483 (when (memq ido-mode
'(both file
))
1484 (put 'ido-everywhere
'file
(cons read-file-name-function nil
))
1485 (setq read-file-name-function
'ido-read-file-name
))
1486 (when (memq ido-mode
'(both buffer
))
1487 (put 'ido-everywhere
'buffer
(cons read-buffer-function nil
))
1488 (setq read-buffer-function
'ido-read-buffer
))))
1490 (defvar ido-minor-mode-map-entry nil
)
1493 (defun ido-mode (&optional arg
)
1494 "Toggle ido speed-ups on or off.
1495 With ARG, turn ido speed-up on if arg is positive, off otherwise.
1496 Turning on ido-mode will remap (via a minor-mode keymap) the default
1497 keybindings for the `find-file' and `switch-to-buffer' families of
1498 commands to the ido versions of these functions.
1499 However, if ARG arg equals 'files, remap only commands for files, or
1500 if it equals 'buffers, remap only commands for buffer switching.
1501 This function also adds a hook to the minibuffer."
1505 ((null arg
) (if ido-mode nil
'both
))
1507 ((eq arg
'files
) 'file
)
1508 ((eq arg
'buffers
) 'buffer
)
1509 ((memq arg
'(file buffer both
)) arg
)
1510 ((> (prefix-numeric-value arg
) 0) 'both
)
1513 (ido-everywhere (if ido-everywhere
1 -
1))
1515 (ido-init-completion-maps))
1518 (add-hook 'minibuffer-setup-hook
'ido-minibuffer-setup
)
1519 (add-hook 'choose-completion-string-functions
'ido-choose-completion-string
)
1522 (add-hook 'kill-emacs-hook
'ido-kill-emacs-hook
)
1524 (let ((map (make-sparse-keymap)))
1525 (when (memq ido-mode
'(file both
))
1526 (define-key map
[remap find-file
] 'ido-find-file
)
1527 (define-key map
[remap find-file-read-only
] 'ido-find-file-read-only
)
1528 (define-key map
[remap find-alternate-file
] 'ido-find-alternate-file
)
1529 (define-key map
[remap write-file
] 'ido-write-file
)
1530 (define-key map
[remap insert-file
] 'ido-insert-file
)
1531 (define-key map
[remap list-directory
] 'ido-list-directory
)
1532 (define-key map
[remap dired
] 'ido-dired
)
1533 (define-key map
[remap find-file-other-window
]
1534 'ido-find-file-other-window
)
1535 (define-key map
[remap find-file-read-only-other-window
]
1536 'ido-find-file-read-only-other-window
)
1537 (define-key map
[remap find-file-other-frame
]
1538 'ido-find-file-other-frame
)
1539 (define-key map
[remap find-file-read-only-other-frame
]
1540 'ido-find-file-read-only-other-frame
))
1542 (when (memq ido-mode
'(buffer both
))
1543 (define-key map
[remap switch-to-buffer
] 'ido-switch-buffer
)
1544 (define-key map
[remap switch-to-buffer-other-window
]
1545 'ido-switch-buffer-other-window
)
1546 (define-key map
[remap switch-to-buffer-other-frame
]
1547 'ido-switch-buffer-other-frame
)
1548 (define-key map
[remap insert-buffer
] 'ido-insert-buffer
)
1549 (define-key map
[remap kill-buffer
] 'ido-kill-buffer
)
1550 (define-key map
[remap display-buffer
] 'ido-display-buffer
))
1552 (if ido-minor-mode-map-entry
1553 (setcdr ido-minor-mode-map-entry map
)
1554 (setq ido-minor-mode-map-entry
(cons 'ido-mode map
))
1555 (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry
))))
1557 (message "Ido mode %s" (if ido-mode
"enabled" "disabled")))
1561 (defun ido-init-completion-maps ()
1562 "Set up the completion keymaps used by `ido'."
1565 (let ((map (make-sparse-keymap)))
1566 (define-key map
"\C-a" 'ido-toggle-ignore
)
1567 (define-key map
"\C-c" 'ido-toggle-case
)
1568 (define-key map
"\C-e" 'ido-edit-input
)
1569 (define-key map
"\t" 'ido-complete
)
1570 (define-key map
" " 'ido-complete-space
)
1571 (define-key map
"\C-j" 'ido-select-text
)
1572 (define-key map
"\C-m" 'ido-exit-minibuffer
)
1573 (define-key map
"\C-p" 'ido-toggle-prefix
)
1574 (define-key map
"\C-r" 'ido-prev-match
)
1575 (define-key map
"\C-s" 'ido-next-match
)
1576 (define-key map
"\C-t" 'ido-toggle-regexp
)
1577 (define-key map
"\C-z" 'ido-undo-merge-work-directory
)
1578 (define-key map
[(control ?\s
)] 'ido-restrict-to-matches
)
1579 (define-key map
[(meta ?\s
)] 'ido-take-first-match
)
1580 (define-key map
[(control ?
@)] 'ido-restrict-to-matches
)
1581 (define-key map
[right] 'ido-next-match)
1582 (define-key map [left] 'ido-prev-match)
1583 (define-key map "?" 'ido-completion-help)
1585 (define-key map "\C-b" 'ido-magic-backward-char)
1586 (define-key map "\C-f" 'ido-magic-forward-char)
1587 (define-key map "\C-d" 'ido-magic-delete-char)
1588 (set-keymap-parent map minibuffer-local-map)
1589 (setq ido-common-completion-map map))
1591 ;; File and directory map
1592 (let ((map (make-sparse-keymap)))
1593 (define-key map "\C-x\C-b" 'ido-enter-switch-buffer)
1594 (define-key map "\C-x\C-f" 'ido-fallback-command)
1595 (define-key map "\C-x\C-d" 'ido-enter-dired)
1596 (define-key map [down] 'ido-next-match-dir)
1597 (define-key map [up] 'ido-prev-match-dir)
1598 (define-key map [(meta up)] 'ido-prev-work-directory)
1599 (define-key map [(meta down)] 'ido-next-work-directory)
1600 (define-key map [backspace] 'ido-delete-backward-updir)
1601 (define-key map "\d" 'ido-delete-backward-updir)
1602 (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS
1603 (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir) ; M-DEL
1605 (define-key map [(control backspace)] 'ido-up-directory)
1606 (define-key map "\C-l" 'ido-reread-directory)
1607 (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
1608 (define-key map [(meta ?b)] 'ido-push-dir)
1609 (define-key map [(meta ?v)] 'ido-push-dir-first)
1610 (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
1611 (define-key map [(meta ?k)] 'ido-forget-work-directory)
1612 (define-key map [(meta ?m)] 'ido-make-directory)
1613 (define-key map [(meta ?n)] 'ido-next-work-directory)
1614 (define-key map [(meta ?o)] 'ido-prev-work-file)
1615 (define-key map [(meta control ?o)] 'ido-next-work-file)
1616 (define-key map [(meta ?p)] 'ido-prev-work-directory)
1617 (define-key map [(meta ?s)] 'ido-merge-work-directories)
1618 (set-keymap-parent map ido-common-completion-map)
1619 (setq ido-file-dir-completion-map map))
1622 (let ((map (make-sparse-keymap)))
1623 (define-key map "\C-k" 'ido-delete-file-at-head)
1624 (define-key map "\C-o" 'ido-copy-current-word)
1625 (define-key map "\C-w" 'ido-copy-current-file-name)
1626 (define-key map [(meta ?l)] 'ido-toggle-literal)
1627 (define-key map "\C-v" 'ido-toggle-vc)
1628 (set-keymap-parent map ido-file-dir-completion-map)
1629 (setq ido-file-completion-map map))
1632 (let ((map (make-sparse-keymap)))
1633 (define-key map "\C-x\C-f" 'ido-enter-find-file)
1634 (define-key map "\C-x\C-b" 'ido-fallback-command)
1635 (define-key map "\C-k" 'ido-kill-buffer-at-head)
1636 (set-keymap-parent map ido-common-completion-map)
1637 (setq ido-buffer-completion-map map)))
1640 (defun ido-setup-completion-map ()
1641 "Set up the keymap for `ido'."
1643 ;; generated every time so that it can inherit new functions.
1644 (let ((map (make-sparse-keymap))
1645 (viper-p (if (boundp 'viper-mode) viper-mode)))
1648 (define-key map [remap viper-intercept-ESC-key] 'ignore))
1651 ((memq ido-cur-item '(file dir))
1652 (when ido-context-switch-command
1653 (define-key map "\C-x\C-b" ido-context-switch-command)
1654 (define-key map "\C-x\C-d" 'ignore))
1656 (define-key map [remap viper-backward-char] 'ido-delete-backward-updir)
1657 (define-key map [remap viper-del-backward-char-in-insert] 'ido-delete-backward-updir)
1658 (define-key map [remap viper-delete-backward-word] 'ido-delete-backward-word-updir))
1659 (set-keymap-parent map
1660 (if (eq ido-cur-item 'file)
1661 ido-file-completion-map
1662 ido-file-dir-completion-map)))
1664 ((eq ido-cur-item 'buffer)
1665 (when ido-context-switch-command
1666 (define-key map "\C-x\C-f" ido-context-switch-command))
1667 (set-keymap-parent map ido-buffer-completion-map))
1670 (set-keymap-parent map ido-common-completion-map)))
1672 (setq ido-completion-map map)))
1674 (defun ido-final-slash (dir &optional fix-it)
1675 ;; return DIR if DIR has final slash.
1676 ;; else if FIX-IT is non-nil, return DIR/
1678 (setq dir (ido-name dir))
1680 ((string-match "/\\'" dir) dir)
1681 ((ido-is-tramp-root dir) dir)
1682 (fix-it (concat dir "/"))
1685 (defun ido-no-final-slash (s)
1686 ;; Remove optional final slash from string S
1687 (let ((l (1- (length s))))
1688 (if (and (> l 0) (eq (aref s l) ?/))
1692 (defun ido-nonreadable-directory-p (dir)
1693 ;; Return t if dir is a directory, but not readable
1694 ;; Do not check for non-readable directories via tramp, as this causes a premature
1695 ;; connect on incomplete tramp paths (after entring just method:).
1696 (let ((ido-enable-tramp-completion nil))
1697 (and (ido-final-slash dir)
1698 (not (ido-is-unc-host dir))
1699 (file-directory-p dir)
1700 (not (file-readable-p dir)))))
1702 (defun ido-directory-too-big-p (dir)
1703 ;; Return t if dir is a directory, but too big to show
1704 ;; Do not check for non-readable directories via tramp, as this causes a premature
1705 ;; connect on incomplete tramp paths (after entring just method:).
1706 (let ((ido-enable-tramp-completion nil))
1707 (and (numberp ido-max-directory-size)
1708 (ido-final-slash dir)
1709 (not (ido-is-unc-host dir))
1710 (file-directory-p dir)
1711 (> (nth 7 (file-attributes dir)) ido-max-directory-size))))
1713 (defun ido-set-current-directory (dir &optional subdir no-merge)
1714 ;; Set ido's current directory to DIR or DIR/SUBDIR
1715 (unless (and ido-enable-tramp-completion
1716 (string-match "\\`/[^/]*@\\'" dir))
1717 (setq dir (ido-final-slash dir t)))
1718 (setq ido-use-merged-list nil
1719 ido-try-merged-list (not no-merge))
1721 (setq dir (concat dir subdir))
1722 (unless (and ido-enable-tramp-completion
1723 (string-match "\\`/[^/]*@\\'" dir))
1724 (setq dir (ido-final-slash dir t))))
1725 (if (get-buffer ido-completion-buffer)
1726 (kill-buffer ido-completion-buffer))
1728 ((equal dir ido-current-directory)
1730 ((ido-is-unc-root dir)
1731 (ido-trace "unc" dir)
1732 (setq ido-current-directory dir)
1733 (setq ido-directory-nonreadable nil)
1734 (setq ido-directory-too-big nil)
1737 (ido-trace "cd" dir)
1738 (setq ido-current-directory dir)
1739 (if (get-buffer ido-completion-buffer)
1740 (kill-buffer ido-completion-buffer))
1741 (setq ido-directory-nonreadable (ido-nonreadable-directory-p dir))
1742 (setq ido-directory-too-big (and (not ido-directory-nonreadable)
1743 (ido-directory-too-big-p dir)))
1746 (defun ido-set-current-home (&optional dir)
1747 ;; Set ido's current directory to user's home directory
1748 (ido-set-current-directory (expand-file-name (or dir "~/"))))
1750 (defun ido-record-command (command arg)
1751 ;; Add (command arg) to command-history if ido-record-commands is t
1752 (if ido-record-commands
1753 (let ((cmd (list command arg)))
1754 (if (or (not command-history)
1755 (not (equal cmd (car command-history))))
1756 (setq command-history (cons cmd command-history))))))
1758 (defun ido-make-prompt (item prompt)
1759 ;; Make the prompt for ido-read-internal
1761 ((and (memq item '(file dir)) ido-current-directory)
1762 (let ((dirname (abbreviate-file-name ido-current-directory))
1763 (max-width (if (and ido-max-file-prompt-width (floatp ido-max-file-prompt-width))
1764 (floor (* (frame-width) ido-max-file-prompt-width))
1765 ido-max-file-prompt-width))
1766 (literal (and (boundp 'ido-find-literal) ido-find-literal "(literal) "))
1767 (vc-off (and ido-saved-vc-hb (not vc-handled-backends) "[-VC] "))
1769 (rule ido-rewrite-file-prompt-rules))
1770 (let ((case-fold-search nil))
1772 (if (and (consp (car rule))
1773 (string-match (car (car rule)) dirname))
1775 (if (stringp (cdr (car rule)))
1776 (replace-match (cdr (car rule)) t nil dirname)
1777 (funcall (cdr (car rule)) dirname))))
1778 (setq rule (cdr rule))))
1779 (run-hooks 'ido-rewrite-file-prompt-functions)
1781 ; (if ido-process-ignore-lists "" "&")
1785 (let ((l (length dirname)))
1786 (if (and max-width (> max-width 0) (> l max-width))
1787 (let* ((s (substring dirname (- max-width)))
1788 (i (string-match "/" s)))
1789 (concat "..." (if i (substring s i) s)))
1793 ;; Here is very briefly how ido-find-file works:
1796 ;; (ido-file-internal method)
1797 ;; set ido-current-directory
1798 ;; (ido-read-internal 'file ...)
1800 ;; (ido-make-item-list ...)
1801 ;; (ido-set-matches)
1802 ;; (completing-read ... ido-text-init ...)
1804 ;; ... here user is allowed to type characters and commands
1805 ;; a command may set ido-exit and call (exit-minibuffer)
1806 ;; to make ido-read-internal do advanced tasks (or return)
1808 ;; ... ido-tidy and ido-exhibit are pre- and post-hooks
1809 ;; which are run before and after each user command.
1811 ;; return value from completing-read is stored in ido-final-text
1812 ;; - ido-exit may cause further actions to be taken:
1813 ;; 'refresh - repeat loop (make-item-list, set-matches)
1814 ;; 'edit - edit the prompt string, then repeat loop
1815 ;; 'keep - repeat loop but don't (re)make-item-list
1816 ;; 'updir - go up one directory, repeat loop
1817 ;; else set ido-selected based on ido-final-text,
1818 ;; optionally update ido-current-directory and repeat loop, or
1819 ;; exit with the return value of ido-selected (file name)
1820 ;; selected file name is returned from ido-read-internal,
1821 ;; ido-exit and method determines what action is taken
1822 ;; e.g. the file name may be ignored or joined with ido-current-directory, and
1823 ;; the relevant function is called (find-file, write-file, etc).
1825 (defun ido-read-internal (item prompt history &optional default require-match initial)
1826 "Perform the `ido-read-buffer' and `ido-read-file-name' functions.
1827 Return the name of a buffer or file selected.
1828 PROMPT is the prompt to give to the user.
1829 DEFAULT if given is the default item to start with.
1830 If REQUIRE-MATCH is non-nil, an existing file must be selected.
1831 If INITIAL is non-nil, it specifies the initial input string."
1833 ((ido-cur-item item)
1834 (ido-entry-buffer (current-buffer))
1835 (ido-process-ignore-lists t)
1836 (ido-process-ignore-lists-inhibit nil)
1837 (ido-set-default-item t)
1842 (icomplete-mode nil) ;; prevent icomplete starting up
1843 ;; Exported dynamic variables:
1846 (ido-rotate-temp nil)
1847 (ido-keep-item-list nil)
1848 (ido-use-merged-list nil)
1849 (ido-try-merged-list t)
1850 (ido-pre-merge-state nil)
1851 (ido-case-fold ido-case-fold)
1852 (ido-enable-prefix ido-enable-prefix)
1853 (ido-enable-regexp ido-enable-regexp)
1854 (ido-show-confirm-message nil)
1857 (ido-setup-completion-map)
1858 (setq ido-text-init initial)
1859 (setq ido-input-stack nil)
1861 (run-hooks 'ido-setup-hook)
1864 (ido-trace "\n_LOOP_" ido-text-init)
1867 (setq ido-rotate nil)
1869 (when ido-set-default-item
1870 (setq ido-default-item
1873 (if (bufferp default) (buffer-name default) default))
1875 (if (memq item '(file dir))
1876 (file-name-nondirectory default)
1879 (and ido-enable-last-directory-history
1880 (let ((d (assoc ido-current-directory ido-last-directory-list)))
1881 (and d (cdr d)))))))
1882 (if (member ido-default-item ido-ignore-item-temp-list)
1883 (setq ido-default-item nil))
1884 (ido-trace "new default" ido-default-item)
1885 (if ido-default-item
1886 (setq ido-initial-position 0))
1887 (setq ido-set-default-item nil))
1889 (if ido-process-ignore-lists-inhibit
1890 (setq ido-process-ignore-lists nil))
1892 (if (and ido-use-merged-list (memq ido-try-merged-list '(t wide)) (not ido-keep-item-list))
1893 (let ((olist ido-cur-list)
1894 (oign ido-ignored-list)
1896 (l (ido-make-merged-file-list ido-text-init
1897 (eq ido-use-merged-list 'auto)
1898 (eq ido-try-merged-list 'wide))))
1899 (ido-trace "merged" l)
1902 (if (eq ido-try-merged-list 'wide)
1903 (setq ido-pre-merge-state
1904 (list "" ido-current-directory olist oign omat)
1906 ido-ignored-list nil
1908 ido-keep-item-list t
1909 ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil)
1910 ido-use-merged-list nil)
1911 (setq ido-cur-list olist
1912 ido-ignored-list oign
1914 ido-keep-item-list t
1915 ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil)
1916 ido-use-merged-list nil)))
1918 (setq ido-use-merged-list nil))
1919 ((eq l 'input-pending-p)
1920 (setq ido-try-merged-list t
1921 ido-use-merged-list nil))
1923 (setq ido-pre-merge-state
1924 (list ido-text-init ido-current-directory olist oign omat))
1925 (ido-set-current-directory (car (cdr (car l))))
1926 (if (ido-final-slash ido-text-init)
1927 (setq ido-text-init ""))
1928 (setq ido-cur-list l
1929 ido-ignored-list nil
1932 ido-keep-item-list t
1933 ido-use-merged-list t)
1934 (ido-trace "Merged" t)
1939 (setq ido-keep-item-list nil
1941 ((eq ido-cur-item 'file)
1942 (setq ido-ignored-list nil
1943 ido-cur-list (and (not ido-directory-nonreadable)
1944 (not ido-directory-too-big)
1945 (ido-make-file-list ido-default-item))))
1946 ((eq ido-cur-item 'dir)
1947 (setq ido-ignored-list nil
1948 ido-cur-list (and (not ido-directory-nonreadable)
1949 (not ido-directory-too-big)
1950 (ido-make-dir-list ido-default-item))))
1951 ((eq ido-cur-item 'buffer)
1952 (setq ido-ignored-list nil
1953 ido-cur-list (ido-make-buffer-list ido-default-item)))
1954 ((eq ido-cur-item 'list)
1955 (setq ido-ignored-list nil
1956 ido-cur-list (ido-make-choice-list ido-default-item)))
1958 (setq ido-rotate-temp nil)
1960 (if ido-process-ignore-lists-inhibit
1961 (setq ido-process-ignore-lists t
1962 ido-process-ignore-lists-inhibit nil))
1965 (if (and ido-matches (eq ido-try-merged-list 'auto))
1966 (setq ido-try-merged-list t))
1968 ((minibuffer-local-completion-map
1969 (if (memq ido-cur-item '(file dir))
1970 minibuffer-local-completion-map
1971 ido-completion-map))
1972 (minibuffer-local-filename-completion-map
1973 (if (memq ido-cur-item '(file dir))
1975 minibuffer-local-filename-completion-map))
1976 (max-mini-window-height (or ido-max-window-height
1977 (and (boundp 'max-mini-window-height) max-mini-window-height)))
1978 (ido-completing-read t)
1979 (ido-require-match require-match)
1980 (ido-use-mycompletion-depth (1+ (minibuffer-depth)))
1981 (show-paren-mode nil))
1982 ;; prompt the user for the file name
1984 (setq ido-final-text
1987 (ido-make-prompt item prompt)
1988 '(("dummy" . 1)) nil nil ; table predicate require-match
1989 (prog1 ido-text-init (setq ido-text-init nil)) ;initial-contents
1991 (ido-trace "completing-read" ido-final-text)
1992 (if (get-buffer ido-completion-buffer)
1993 (kill-buffer ido-completion-buffer))
1995 (ido-trace "\n_EXIT_" ido-exit)
1998 ((eq ido-exit 'refresh)
1999 (if (and (eq ido-use-merged-list 'auto)
2000 (or (input-pending-p)))
2001 (setq ido-use-merged-list nil
2002 ido-keep-item-list t))
2005 ((eq ido-exit 'done)
2007 ido-selected ido-text
2010 ((memq ido-exit '(edit chdir))
2012 ((memq ido-cur-item '(file dir))
2013 (let* ((read-file-name-function nil)
2014 (edit (eq ido-exit 'edit))
2015 (d ido-current-directory)
2018 (setq ido-text-init "")
2022 (read-file-name (concat prompt "[EDIT] ")
2023 (expand-file-name d)
2025 (quit (concat d f)))
2027 d (or (file-name-directory new) "/")
2028 f (file-name-nondirectory new)
2031 (file-directory-p d)
2032 (and (yes-or-no-p (format "Create directory %s? " d))
2034 (progn (make-directory d t) t)
2036 (message "Could not create directory")
2040 (ido-set-current-directory d nil (eq ido-exit 'chdir))
2041 (setq ido-text-init f
2046 (read-string (concat prompt "[EDIT] ") ido-final-text)
2047 (quit ido-final-text)))))
2051 ((eq ido-exit 'keep)
2052 (setq ido-keep-item-list t))
2054 ((memq ido-exit '(dired fallback find-file switch-to-buffer insert-buffer insert-file))
2057 ((memq ido-exit '(updir push))
2058 ;; cannot go up if already at the root-dir (Unix) or at the
2059 ;; root-dir of a certain drive (Windows or MS-DOS).
2060 (if (ido-is-tramp-root)
2061 (when (string-match "\\`\\(/\\([^/]+[:@]\\)*\\)\\([^/]+\\)[:@]\\'" ido-current-directory)
2062 (setq ido-text-init (match-string 3 ido-current-directory))
2063 (ido-set-current-directory (match-string 1 ido-current-directory))
2064 (setq ido-set-default-item t))
2065 (unless (ido-is-root-directory)
2066 (when (eq ido-exit 'push)
2067 (setq ido-input-stack (cons (cons ido-cur-item ido-text) ido-input-stack))
2068 (setq ido-cur-item 'dir)
2069 (setq ido-text-init (file-name-nondirectory (substring ido-current-directory 0 -1)))
2070 (ido-trace "push" ido-input-stack))
2071 (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1)))
2072 (setq ido-set-default-item t))))
2075 (ido-trace "pop" ido-input-stack)
2076 (let ((elt (car ido-input-stack)))
2077 (setq ido-input-stack (cdr ido-input-stack))
2078 (ido-set-current-directory (concat ido-current-directory ido-text))
2079 (setq ido-cur-item (car elt))
2080 (setq ido-text-init (cdr elt))))
2082 ((eq ido-exit 'pop-all)
2083 (ido-trace "pop-all" ido-input-stack)
2084 (while ido-input-stack
2085 (let ((elt (car ido-input-stack)))
2086 (setq ido-input-stack (cdr ido-input-stack))
2087 (ido-set-current-directory (concat ido-current-directory ido-text))
2088 (setq ido-cur-item (car elt))
2089 (setq ido-text-init (cdr elt)))))
2091 ;; Handling the require-match must be done in a better way.
2093 (not (memq require-match '(confirm confirm-after-completion)))
2094 (not (if ido-directory-too-big
2095 (file-exists-p (concat ido-current-directory ido-final-text))
2096 (ido-existing-item-p))))
2097 (error "Must specify valid item"))
2101 (if (or (eq ido-exit 'takeprompt)
2104 ;; else take head of list
2105 (ido-name (car ido-matches))))
2108 ((memq item '(buffer list))
2111 ((string-equal "./" ido-selected)
2114 ((string-equal "../" ido-selected)
2115 ;; cannot go up if already at the root-dir (Unix) or at the
2116 ;; root-dir of a certain drive (Windows or MS-DOS).
2117 (or (ido-is-root-directory)
2118 (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))))
2119 (setq ido-set-default-item t))
2121 ((and (string-match (if ido-enable-tramp-completion ".[:@]\\'" ".:\\'") ido-selected)
2122 (ido-is-root-directory) ;; Ange-ftp or Tramp
2123 (not (ido-local-file-exists-p ido-selected)))
2124 (ido-set-current-directory ido-current-directory ido-selected)
2125 (ido-trace "tramp prefix" ido-selected)
2126 (if (ido-is-slow-ftp-host)
2127 (setq ido-exit 'fallback
2129 (setq ido-set-default-item t)))
2131 ((or (string-match "[/\\][^/\\]" ido-selected)
2132 (and (memq system-type '(windows-nt ms-dos))
2133 (string-match "\\`[a-zA-Z]:" ido-selected)))
2134 (ido-set-current-directory (file-name-directory ido-selected))
2135 (setq ido-set-default-item t))
2137 ((string-match "\\`~" ido-selected)
2138 (ido-set-current-home ido-selected))
2140 ((ido-final-slash ido-selected)
2141 (if ido-enable-last-directory-history
2142 (let ((x (assoc ido-current-directory ido-last-directory-list)))
2144 (setcdr x ido-selected)
2145 (setq ido-last-directory-list
2146 (cons (cons ido-current-directory ido-selected) ido-last-directory-list)))))
2147 (ido-set-current-directory ido-current-directory ido-selected)
2149 ; automatically pop stack elements which match existing files or directories
2151 (while (and (setq elt (car ido-input-stack))
2152 (file-exists-p (concat ido-current-directory (cdr elt))))
2153 (if (setq ido-input-stack (cdr ido-input-stack))
2154 (ido-set-current-directory ido-current-directory (cdr elt))
2155 (setq ido-text-init (cdr elt)))
2156 (setq ido-cur-item (car elt))))
2157 (setq ido-set-default-item t)))
2163 (defun ido-edit-input ()
2164 "Edit absolute file name entered so far with ido; terminate by RET.
2165 If cursor is not at the end of the user input, move to end of input."
2169 (setq ido-text-init (if ido-matches (ido-name (car ido-matches)) ido-text))
2170 (setq ido-exit 'edit)
2174 (defun ido-buffer-internal (method &optional fallback prompt default initial switch-cmd)
2175 ;; Internal function for ido-switch-buffer and friends
2178 (run-hook-with-args 'ido-before-fallback-functions
2179 (or fallback 'switch-to-buffer))
2180 (call-interactively (or fallback 'switch-to-buffer)))
2181 (let* ((ido-context-switch-command switch-cmd)
2182 (ido-current-directory nil)
2183 (ido-directory-nonreadable nil)
2184 (ido-directory-too-big nil)
2185 (require-match (confirm-nonexistent-file-or-buffer))
2186 (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default
2187 require-match initial))
2190 ;; Choose the buffer name: either the text typed in, or the head
2191 ;; of the list of matches
2194 ((eq ido-exit 'find-file)
2196 (if (memq method '(other-window other-frame)) method ido-default-file-method)
2197 nil nil nil nil ido-text))
2199 ((eq ido-exit 'insert-file)
2200 (ido-file-internal 'insert 'insert-file nil "Insert file: " nil ido-text 'ido-enter-insert-buffer))
2202 ((eq ido-exit 'fallback)
2203 (let ((read-buffer-function nil))
2204 (setq this-command (or fallback 'switch-to-buffer))
2205 (run-hook-with-args 'ido-before-fallback-functions this-command)
2206 (call-interactively this-command)))
2208 ;; Check buf is non-nil.
2210 ((= (length buf) 0) nil)
2212 ;; View buffer if it exists
2214 (add-to-history 'buffer-name-history buf)
2215 (if (eq method 'insert)
2217 (ido-record-command 'insert-buffer buf)
2220 (insert-buffer-substring (get-buffer buf))
2222 (ido-visit-buffer buf method t)))
2224 ;; check for a virtual buffer reference
2225 ((and ido-use-virtual-buffers ido-virtual-buffers
2226 (setq filename (assoc buf ido-virtual-buffers)))
2227 (ido-visit-buffer (find-file-noselect (cdr filename)) method t))
2229 ((and (eq ido-create-new-buffer 'prompt)
2230 (null require-match)
2231 (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
2234 ;; buffer doesn't exist
2235 ((and (eq ido-create-new-buffer 'never)
2236 (null require-match))
2237 (message "No buffer matching `%s'" buf))
2239 ((and (eq ido-create-new-buffer 'prompt)
2240 (null require-match)
2241 (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
2244 ;; create a new buffer
2246 (add-to-history 'buffer-name-history buf)
2247 (setq buf (get-buffer-create buf))
2248 (if (fboundp 'set-buffer-major-mode)
2249 (set-buffer-major-mode buf))
2250 (ido-visit-buffer buf method t))))))
2252 (defun ido-record-work-directory (&optional dir)
2253 (when (and (numberp ido-max-work-directory-list) (> ido-max-work-directory-list 0))
2254 (if (and (setq dir (or dir ido-current-directory)) (> (length dir) 0))
2255 (let ((items ido-work-directory-list-ignore-regexps)
2256 (case-fold-search nil))
2257 (while (and items dir)
2258 (if (string-match (car items) dir)
2260 (setq items (cdr items)))
2262 (setq ido-work-directory-list (cons dir (delete dir ido-work-directory-list))))))
2263 (if (> (length ido-work-directory-list) ido-max-work-directory-list)
2264 (setcdr (nthcdr (1- ido-max-work-directory-list) ido-work-directory-list) nil))))
2266 (defun ido-forget-work-directory ()
2268 (when (and ido-current-directory ido-work-directory-list)
2269 (setq ido-work-directory-list (delete ido-current-directory ido-work-directory-list))
2270 (when ido-use-merged-list
2271 (ido-undo-merge-work-directory)
2272 (setq ido-exit 'refresh
2273 ido-try-merged-list t
2274 ido-use-merged-list t
2275 ido-text-init ido-text
2277 (exit-minibuffer))))
2279 (defun ido-record-work-file (name)
2280 ;; Save NAME in ido-work-file-list
2281 (when (and (numberp ido-max-work-file-list) (> ido-max-work-file-list 0))
2283 (and ido-work-file-list (equal (car ido-work-file-list) name))
2284 (setq ido-work-file-list (cons name (delete name ido-work-file-list))))
2285 (if (> (length ido-work-file-list) ido-max-work-file-list)
2286 (setcdr (nthcdr (1- ido-max-work-file-list) ido-work-file-list) nil))))
2288 (defun ido-expand-directory (dir)
2289 ;; Expand DIR or use DEFAULT-DIRECTORY if nil.
2290 ;; Add final slash to result in case it was missing from DEFAULT-DIRECTORY.
2291 (ido-final-slash (expand-file-name (or dir default-directory)) t))
2293 (defun ido-file-internal (method &optional fallback default prompt item initial switch-cmd)
2294 ;; Internal function for ido-find-file and friends
2297 (let ((ido-current-directory (ido-expand-directory default))
2298 (ido-context-switch-command switch-cmd)
2299 ido-directory-nonreadable ido-directory-too-big
2302 (if (or (not ido-mode) (ido-is-slow-ftp-host))
2305 (setq ido-directory-nonreadable
2306 (ido-nonreadable-directory-p ido-current-directory)
2307 ido-directory-too-big
2308 (and (not ido-directory-nonreadable)
2309 (ido-directory-too-big-p ido-current-directory))))
2311 (when (and (eq item 'file)
2312 (or ido-use-url-at-point ido-use-filename-at-point))
2315 ;; Duplicate code from ffap-guesser as we want different
2316 ;; behavior for files and URLs.
2319 (and ido-use-url-at-point
2321 (ffap-fixup-url (or (ffap-url-at-point)
2322 (ffap-gopher-at-point)))))
2323 (setq ido-exit 'ffap
2326 ((and ido-use-filename-at-point
2327 (setq fn (with-no-warnings
2328 (if (eq ido-use-filename-at-point 'guess)
2330 (ffap-string-at-point))))
2331 (not (string-match "^http:/" fn))
2332 (let ((absolute-fn (expand-file-name fn)))
2333 (setq d (if (file-directory-p absolute-fn)
2334 (file-name-as-directory absolute-fn)
2335 (file-name-directory absolute-fn))))
2336 (file-directory-p d))
2337 (setq ido-current-directory d)
2338 (setq initial (file-name-nondirectory fn))))))
2340 (let (ido-saved-vc-hb
2341 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
2342 (ido-work-directory-index -1)
2343 (ido-work-file-index -1)
2344 (ido-find-literal nil))
2347 (setq ido-saved-vc-hb vc-handled-backends)
2348 (let ((minibuffer-completing-file-name t))
2349 (setq filename (ido-read-internal item
2350 (or prompt "Find file: ")
2352 (and (eq method 'alt-file) buffer-file-name)
2353 (confirm-nonexistent-file-or-buffer) initial))))
2355 ;; Choose the file name: either the text typed in, or the head
2356 ;; of the list of matches
2359 ((eq ido-exit 'fallback)
2360 ;; Need to guard setting of default-directory here, since
2361 ;; we don't want to change directory of current buffer.
2362 (let ((default-directory ido-current-directory)
2363 (read-file-name-function nil))
2364 (setq this-command (or fallback 'find-file))
2365 (run-hook-with-args 'ido-before-fallback-functions this-command)
2366 (call-interactively this-command)))
2368 ((eq ido-exit 'switch-to-buffer)
2369 (ido-buffer-internal
2370 (if (memq method '(other-window other-frame)) method ido-default-buffer-method)
2371 nil nil nil ido-text))
2373 ((eq ido-exit 'insert-buffer)
2374 (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil ido-text 'ido-enter-insert-file))
2376 ((eq ido-exit 'dired)
2377 (dired (concat ido-current-directory (or ido-text ""))))
2379 ((eq ido-exit 'ffap)
2380 (find-file-at-point))
2382 ((eq method 'alt-file)
2383 (ido-record-work-file filename)
2384 (setq default-directory ido-current-directory)
2385 (ido-record-work-directory)
2386 (find-alternate-file filename))
2388 ((memq method '(dired list-directory))
2389 (if (equal filename ".")
2391 (let* ((dirname (ido-final-slash (concat ido-current-directory filename) t))
2392 (file (substring dirname 0 -1)))
2394 ((file-directory-p dirname)
2395 (ido-record-command method dirname)
2396 (ido-record-work-directory dirname)
2397 (funcall method dirname))
2398 ((file-directory-p ido-current-directory)
2400 ((file-exists-p file)
2401 (ido-record-command method ido-current-directory)
2402 (ido-record-work-directory)
2403 (funcall method ido-current-directory)
2404 (if (eq method 'dired)
2406 (dired-goto-file (expand-file-name file)))))
2407 ((string-match "[[*?]" filename)
2408 (setq dirname (concat ido-current-directory filename))
2409 (ido-record-command method dirname)
2410 (ido-record-work-directory)
2411 (funcall method dirname))
2412 ((y-or-n-p (format "Directory %s does not exist. Create it? " filename))
2413 (ido-record-command method dirname)
2414 (ido-record-work-directory dirname)
2415 (make-directory-internal dirname)
2416 (funcall method dirname))
2418 ;; put make-directory command on history
2419 (ido-record-command 'make-directory dirname))))
2420 (t (error "No such directory")))))
2423 (ido-record-work-file filename)
2424 (setq default-directory ido-current-directory)
2425 (setq filename (concat ido-current-directory filename))
2426 (ido-record-command 'write-file filename)
2427 (add-to-history 'file-name-history filename)
2428 (ido-record-work-directory)
2429 (write-file filename))
2431 ((eq method 'read-only)
2432 (ido-record-work-file filename)
2433 (setq filename (concat ido-current-directory filename))
2434 (ido-record-command fallback filename)
2435 (ido-record-work-directory)
2436 (run-hook-with-args 'ido-before-fallback-functions fallback)
2437 (funcall fallback filename))
2439 ((eq method 'insert)
2440 (ido-record-work-file filename)
2441 (setq filename (concat ido-current-directory filename))
2443 (if ido-find-literal 'insert-file-literally 'insert-file)
2445 (add-to-history 'file-name-history filename)
2446 (ido-record-work-directory)
2447 (insert-file-1 filename
2448 (if ido-find-literal
2449 #'insert-file-contents-literally
2450 #'insert-file-contents)))
2453 (ido-record-work-file filename)
2454 (setq filename (concat ido-current-directory filename))
2455 (ido-record-command 'find-file filename)
2456 (add-to-history 'file-name-history filename)
2457 (ido-record-work-directory)
2458 (ido-visit-buffer (find-file-noselect filename nil ido-find-literal) method))))))
2460 (defun ido-existing-item-p ()
2461 ;; Return non-nil if there is a matching item
2462 (not (null ido-matches)))
2466 (defun ido-set-common-completion ()
2467 ;; Find common completion of `ido-text' in `ido-matches'
2468 ;; The result is stored in `ido-common-match-string'
2470 (setq ido-common-match-string nil)
2471 (if (and ido-matches
2472 (not ido-enable-regexp) ;; testing
2474 (> (length ido-text) 0))
2475 (if (setq val (ido-find-common-substring ido-matches ido-text))
2476 (setq ido-common-match-string val)))
2479 (defun ido-complete ()
2480 "Try and complete the current pattern amongst the file names."
2484 (ido-incomplete-regexp
2487 ((and (memq ido-cur-item '(file dir))
2488 (string-match "[$]" ido-text))
2489 (let ((evar (substitute-in-file-name (concat ido-current-directory ido-text))))
2490 (if (not (file-exists-p (file-name-directory evar)))
2491 (message "Expansion generates non-existing directory name")
2492 (if (file-directory-p evar)
2493 (ido-set-current-directory evar)
2494 (let ((d (or (file-name-directory evar) "/"))
2495 (f (file-name-nondirectory evar)))
2496 (when (file-directory-p d)
2497 (ido-set-current-directory d)
2498 (setq ido-text-init f))))
2499 (setq ido-exit 'refresh)
2500 (exit-minibuffer))))
2502 (ido-directory-too-big
2503 (setq ido-directory-too-big nil)
2504 (setq ido-text-init ido-text)
2505 (setq ido-exit 'refresh)
2509 (when ido-completion-buffer
2510 (call-interactively (setq this-command ido-cannot-complete-command))))
2512 ((and (= 1 (length ido-matches))
2513 (not (and ido-enable-tramp-completion
2514 (string-equal ido-current-directory "/")
2515 (string-match ".[@:]\\'" (ido-name (car ido-matches)))))
2516 (not (ido-local-file-exists-p (ido-name (car ido-matches)))))
2517 ;; only one choice, so select it.
2518 (if (not ido-confirm-unique-completion)
2520 (setq ido-rescan (not ido-enable-prefix))
2521 (delete-region (minibuffer-prompt-end) (point))
2522 (insert (ido-name (car ido-matches)))))
2524 (t ;; else there could be some completions
2525 (setq res ido-common-match-string)
2526 (if (and (not (memq res '(t nil)))
2527 (not (equal res ido-text)))
2528 ;; found something to complete, so put it in the minibuffer.
2530 ;; move exact match to front if not in prefix mode
2531 (setq ido-rescan (not ido-enable-prefix))
2532 (delete-region (minibuffer-prompt-end) (point))
2534 ;; else nothing to complete
2535 (call-interactively (setq this-command ido-cannot-complete-command))
2538 (defun ido-complete-space ()
2539 "Try completion unless inserting the space makes sense."
2541 (if (and (stringp ido-common-match-string)
2544 ((> (length ido-common-match-string) (length ido-text))
2545 (= (aref ido-common-match-string (length ido-text)) ? ))
2548 (re (concat (regexp-quote ido-text) " "))
2551 (if (string-match re (ido-name (car comp)))
2552 (setq comp nil insert-space t)
2553 (setq comp (cdr comp))))
2559 (defun ido-undo-merge-work-directory (&optional text try refresh)
2560 "Undo or redo last ido directory merge operation.
2561 If no merge has yet taken place, toggle automatic merging option."
2564 (ido-pre-merge-state
2565 (ido-set-current-directory (nth 1 ido-pre-merge-state))
2566 (setq ido-text-init (or text (car ido-pre-merge-state))
2567 ido-cur-list (nth 2 ido-pre-merge-state)
2568 ido-ignored-list (nth 3 ido-pre-merge-state)
2569 ido-matches (nth 4 ido-pre-merge-state)
2570 ido-use-merged-list nil
2571 ido-try-merged-list try
2572 ido-keep-item-list (not refresh)
2575 ido-pre-merge-state nil)
2579 (ido-try-merged-list
2580 (setq ido-try-merged-list nil))
2582 (setq ido-try-merged-list t))
2583 ((not ido-use-merged-list)
2584 (ido-merge-work-directories))))
2588 (defun ido-magic-forward-char (arg)
2589 "Move forward in user input or perform magic action.
2590 If no user input is present, or at end of input, perform magic actions:
2591 C-x C-b ... C-f switch to `ido-find-file'.
2592 C-x C-f ... C-f fallback to non-ido `find-file'.
2593 C-x C-d ... C-f fallback to non-ido brief `dired'.
2594 C-x d ... C-f fallback to non-ido `dired'."
2597 ((or arg (not (eobp)))
2598 (forward-char (min (prefix-numeric-value arg)
2599 (- (point-max) (point)))))
2600 ((memq ido-cur-item '(file dir))
2601 (ido-fallback-command))
2602 (ido-context-switch-command
2603 (call-interactively ido-context-switch-command))
2604 ((eq ido-cur-item 'buffer)
2605 (ido-enter-find-file))))
2609 (defun ido-magic-backward-char (arg)
2610 "Move backward in user input or perform magic action.
2611 If no user input is present, or at start of input, perform magic actions:
2612 C-x C-f C-b switch to `ido-switch-buffer'.
2613 C-x C-d C-b switch to `ido-switch-buffer'.
2614 C-x d C-b switch to `ido-switch-buffer'.
2615 C-x C-b C-b fallback to non-ido `switch-to-buffer'."
2618 ((or arg (> (point) (minibuffer-prompt-end)))
2620 (- (min (prefix-numeric-value arg)
2621 (- (point) (minibuffer-prompt-end))))))
2622 ((eq last-command this-command)
2623 (when (and (memq ido-cur-item '(file dir))
2625 (ido-push-dir))) ; else do nothing
2626 ((eq ido-cur-item 'buffer)
2627 (ido-fallback-command))
2628 (ido-context-switch-command
2629 (call-interactively ido-context-switch-command))
2631 (ido-enter-switch-buffer))))
2635 (defun ido-magic-delete-char (arg)
2636 "Delete following char in user input or perform magic action.
2637 If at end of user input, perform magic actions:
2638 C-x C-f ... C-d enter `dired' on current directory."
2641 ((or arg (not (eobp)))
2642 (delete-char (min (prefix-numeric-value arg)
2643 (- (point-max) (point)))))
2644 (ido-context-switch-command
2646 ((memq ido-cur-item '(file dir))
2647 (ido-enter-dired))))
2650 ;;; TOGGLE FUNCTIONS
2652 (defun ido-toggle-case ()
2653 "Toggle the value of `ido-case-fold'."
2655 (setq ido-case-fold (not ido-case-fold))
2656 ;; ask for list to be regenerated.
2657 (setq ido-rescan t))
2659 (defun ido-toggle-regexp ()
2660 "Toggle the value of `ido-enable-regexp'."
2662 (setq ido-enable-regexp (not ido-enable-regexp))
2663 ;; ask for list to be regenerated.
2664 (setq ido-rescan t))
2666 (defun ido-toggle-prefix ()
2667 "Toggle the value of `ido-enable-prefix'."
2669 (setq ido-enable-prefix (not ido-enable-prefix))
2670 ;; ask for list to be regenerated.
2671 (setq ido-rescan t))
2673 (defun ido-toggle-ignore ()
2674 "Toggle ignoring files specified with `ido-ignore-files'."
2676 (if (and (not (eobp)) (> (point) (minibuffer-prompt-end)))
2677 (goto-char (minibuffer-prompt-end))
2678 (if ido-directory-too-big
2680 (message "Reading directory...")
2681 (setq ido-directory-too-big nil))
2682 (setq ido-process-ignore-lists (not ido-process-ignore-lists)))
2683 (setq ido-text-init ido-text)
2684 (setq ido-exit 'refresh)
2687 (defun ido-toggle-vc ()
2688 "Disable version control for this file."
2690 (if (and ido-mode (eq ido-cur-item 'file))
2692 (setq vc-handled-backends
2693 (if vc-handled-backends nil ido-saved-vc-hb))
2694 (setq ido-text-init ido-text)
2695 (setq ido-exit 'keep)
2696 (exit-minibuffer))))
2698 (defun ido-toggle-literal ()
2699 "Toggle literal reading of this file."
2701 (if (and ido-mode (eq ido-cur-item 'file))
2703 (setq ido-find-literal (not ido-find-literal))
2704 (setq ido-text-init ido-text)
2705 (setq ido-exit 'keep)
2706 (exit-minibuffer))))
2708 (defun ido-reread-directory ()
2709 "Read current directory again.
2710 May be useful if cached version is no longer valid, but directory
2711 timestamp has not changed (e.g. with ftp or on Windows)."
2713 (if (and ido-mode (memq ido-cur-item '(file dir)))
2715 (if (ido-is-unc-root)
2716 (setq ido-unc-hosts-cache t)
2717 (ido-remove-cached-dir ido-current-directory))
2718 (setq ido-text-init ido-text)
2719 (setq ido-rotate-temp t)
2720 (setq ido-exit 'refresh)
2721 (exit-minibuffer))))
2723 (defun ido-exit-minibuffer ()
2724 "Exit minibuffer, but make sure we have a match if one is needed."
2726 (if (and (or (not ido-require-match)
2727 (if (memq ido-require-match '(confirm confirm-after-completion))
2728 (if (or (eq ido-cur-item 'dir)
2729 (eq last-command this-command))
2731 (setq ido-show-confirm-message t)
2733 (ido-existing-item-p))
2734 (not ido-incomplete-regexp))
2737 (defun ido-select-text ()
2738 "Select the buffer or file named by the prompt.
2739 If no buffer or file exactly matching the prompt exists, maybe create a new one."
2741 (setq ido-exit 'takeprompt)
2744 (defun ido-fallback-command ()
2745 "Fallback to non-ido version of current command."
2747 (let ((i (length ido-text)))
2749 (push (aref ido-text (setq i (1- i))) unread-command-events)))
2750 (setq ido-exit 'fallback)
2753 (defun ido-enter-find-file ()
2754 "Drop into `find-file' from buffer switching."
2756 (setq ido-exit 'find-file)
2759 (defun ido-enter-switch-buffer ()
2760 "Drop into `ido-switch-buffer' from file switching."
2762 (setq ido-exit 'switch-to-buffer)
2765 (defun ido-enter-dired ()
2766 "Drop into `dired' from file switching."
2768 (setq ido-exit 'dired)
2771 (defun ido-enter-insert-buffer ()
2772 "Drop into `insert-buffer' from insert file."
2774 (setq ido-exit 'insert-buffer)
2777 (defun ido-enter-insert-file ()
2778 "Drop into `insert-file' from insert buffer."
2780 (setq ido-exit 'insert-file)
2784 (defun ido-up-directory (&optional clear)
2785 "Go up one directory level."
2787 (setq ido-text-init (if clear nil ido-text))
2788 (setq ido-exit 'updir)
2789 (setq ido-rotate-temp t)
2792 (defun ido-delete-backward-updir (count)
2793 "Delete char backwards, or at beginning of buffer, go up one level."
2796 ((= (minibuffer-prompt-end) (point))
2798 (ido-up-directory t)))
2799 ((and ido-pre-merge-state (string-equal (car ido-pre-merge-state) ido-text))
2800 (ido-undo-merge-work-directory (substring ido-text 0 -1) t t))
2801 ((eq this-original-command 'viper-backward-char)
2802 (funcall this-original-command (prefix-numeric-value count)))
2803 ((eq this-original-command 'viper-del-backward-char-in-insert)
2804 (funcall this-original-command))
2806 (delete-backward-char (prefix-numeric-value count)))))
2808 (defun ido-delete-backward-word-updir (count)
2809 "Delete all chars backwards, or at beginning of buffer, go up one level."
2811 (if (= (minibuffer-prompt-end) (point))
2813 (ido-up-directory t))
2814 (if (eq this-original-command 'viper-delete-backward-word)
2815 (funcall this-original-command (prefix-numeric-value count))
2816 (backward-kill-word (prefix-numeric-value count)))))
2818 (defun ido-get-work-directory (&optional incr must-match)
2819 (let ((n (length ido-work-directory-list))
2820 (i ido-work-directory-index)
2823 (if (or (not ido-text) (= (length ido-text) 0))
2824 (setq must-match nil))
2829 (if (>= i n) (setq i 0))
2830 (if (< i 0) (setq i (1- n))))
2831 (setq dir (nth i ido-work-directory-list))
2833 (not (equal dir ido-current-directory))
2834 (file-directory-p dir)
2835 (or (not must-match)
2836 ;; TODO. check for nonreadable and too-big.
2838 (if (eq ido-cur-item 'file)
2839 (ido-make-file-list-1 dir)
2840 (ido-make-dir-list-1 dir)))))
2844 (setq ido-work-directory-index i))
2847 (defun ido-prev-work-directory ()
2848 "Change to next working directory in list."
2850 (let ((dir (ido-get-work-directory 1 ido-work-directory-match-only)))
2852 (ido-set-current-directory dir)
2853 (setq ido-exit 'refresh)
2854 (setq ido-text-init ido-text)
2855 (setq ido-rotate-temp t)
2856 (exit-minibuffer))))
2858 (defun ido-next-work-directory ()
2859 "Change to previous working directory in list."
2861 (let ((dir (ido-get-work-directory -1 ido-work-directory-match-only)))
2863 (ido-set-current-directory dir)
2864 (setq ido-exit 'refresh)
2865 (setq ido-text-init ido-text)
2866 (setq ido-rotate-temp t)
2867 (exit-minibuffer))))
2869 (defun ido-merge-work-directories ()
2870 "Search (and merge) work directories for files matching the current input string."
2872 (setq ido-use-merged-list t ido-try-merged-list t)
2873 (setq ido-exit 'refresh)
2874 (setq ido-text-init ido-text)
2875 (setq ido-rotate-temp t)
2878 (defun ido-wide-find-file (&optional file)
2879 "Prompt for FILE to search for using find, starting from current directory."
2882 (let ((enable-recursive-minibuffers t))
2885 (read-string (concat "Wide find file: " ido-current-directory) ido-text)
2887 (when (> (length file) 0)
2888 (setq ido-use-merged-list t ido-try-merged-list 'wide)
2889 (setq ido-exit 'refresh)
2890 (setq ido-text-init file)
2891 (setq ido-rotate-temp t)
2894 (defun ido-wide-find-dir (&optional dir)
2895 "Prompt for DIR to search for using find, starting from current directory."
2898 (let ((enable-recursive-minibuffers t))
2901 (read-string (concat "Wide find directory: " ido-current-directory) ido-text)
2903 (when (> (length dir) 0)
2904 (setq ido-use-merged-list t ido-try-merged-list 'wide)
2905 (setq ido-exit 'refresh)
2906 (setq ido-text-init (ido-final-slash dir t))
2907 (setq ido-rotate-temp t)
2910 (defun ido-wide-find-dir-or-delete-dir (&optional dir)
2911 "Prompt for DIR to search for using find, starting from current directory.
2912 If input stack is non-empty, delete current directory component."
2915 (ido-delete-backward-word-updir 1)
2916 (ido-wide-find-dir)))
2918 (defun ido-take-first-match ()
2919 "Use first matching item as input text."
2922 (setq ido-text-init (ido-name (car ido-matches)))
2923 (setq ido-exit 'refresh)
2926 (defun ido-push-dir ()
2927 "Move to previous directory in file name, push current input on stack."
2929 (setq ido-exit 'push)
2932 (defun ido-push-dir-first ()
2933 "Move to previous directory in file name, push first match on stack."
2936 (setq ido-text (ido-name (car ido-matches))))
2937 (setq ido-exit 'push)
2940 (defun ido-pop-dir (arg)
2941 "Pop directory from input stack back to input.
2942 With \\[universal-argument], pop all elements."
2944 (when ido-input-stack
2945 (setq ido-exit (if arg 'pop-all 'pop))
2948 (defun ido-wide-find-file-or-pop-dir (arg)
2952 (ido-wide-find-file)))
2954 (defun ido-make-directory (&optional dir)
2955 "Prompt for DIR to create in current directory."
2958 (let ((enable-recursive-minibuffers t))
2960 (read-string (concat "Make directory: " ido-current-directory) ido-text))))
2961 (when (> (length dir) 0)
2962 (setq dir (concat ido-current-directory dir))
2963 (unless (file-exists-p dir)
2964 (make-directory dir t)
2965 (ido-set-current-directory dir)
2966 (setq ido-exit 'refresh)
2967 (setq ido-text-init nil)
2968 (setq ido-rotate-temp t)
2969 (exit-minibuffer))))
2971 (defun ido-get-work-file (incr)
2972 (let ((n (length ido-work-file-list))
2973 (i (+ ido-work-file-index incr))
2976 (if (>= i n) (setq i 0))
2977 (if (< i 0) (setq i (1- n))))
2978 (setq name (nth i ido-work-file-list))
2979 (setq ido-work-file-index i)
2982 (defun ido-prev-work-file ()
2983 "Change to next working file name in list."
2985 (let ((name (ido-get-work-file 1)))
2987 (setq ido-text-init name)
2988 (setq ido-exit 'refresh)
2989 (exit-minibuffer))))
2991 (defun ido-next-work-file ()
2992 "Change to previous working file name in list."
2994 (let ((name (ido-get-work-file -1)))
2996 (setq ido-text-init name)
2997 (setq ido-exit 'refresh)
2998 (exit-minibuffer))))
3000 (defun ido-copy-current-file-name (all)
3001 "Insert file name of current buffer.
3002 If repeated, insert text from buffer instead."
3004 (let* ((bfname (or (buffer-file-name ido-entry-buffer)
3005 (buffer-name ido-entry-buffer)))
3006 (name (and bfname (file-name-nondirectory bfname))))
3010 (eq last-command this-command)
3011 (not (equal (file-name-directory bfname) ido-current-directory))
3012 (not (string-match "\\.[^.]*\\'" name)))
3014 (substring name 0 (1+ (match-beginning 0)))))
3015 (setq ido-exit 'refresh
3016 ido-try-merged-list nil)
3017 (exit-minibuffer))))
3019 (defun ido-copy-current-word (all)
3020 "Insert current word (file or directory name) from current buffer."
3022 (let ((word (with-current-buffer ido-entry-buffer
3023 (let ((p (point)) start-line end-line start-name name)
3024 (if (and mark-active (/= p (mark)))
3025 (setq start-name (mark))
3027 (setq start-line (point))
3029 (setq end-line (point))
3031 (if (re-search-backward "[^-_a-zA-Z0-9:./\\~@]" start-line 1)
3033 (setq start-name (point))
3034 (re-search-forward "[-_a-zA-Z0-9:./\\~@]*" end-line 1)
3035 (if (= start-name (point))
3036 (setq start-name nil)))
3038 (buffer-substring-no-properties start-name (point)))))))
3041 ((string-match "\\`[~/]" word)
3042 (setq ido-text-init word
3043 ido-try-merged-list nil
3045 ((string-match "/" word)
3046 (setq ido-text-init (concat ido-current-directory word)
3047 ido-try-merged-list nil
3050 (setq ido-text-init word
3051 ido-try-merged-list nil
3052 ido-exit 'refresh)))
3053 (exit-minibuffer))))
3055 (defun ido-next-match ()
3056 "Put first element of `ido-matches' at the end of the list."
3059 (let ((next (cadr ido-matches)))
3060 (setq ido-cur-list (ido-chop ido-cur-list next))
3062 (setq ido-rotate t))))
3064 (defun ido-prev-match ()
3065 "Put last element of `ido-matches' at the front of the list."
3068 (let ((prev (car (last ido-matches))))
3069 (setq ido-cur-list (ido-chop ido-cur-list prev))
3071 (setq ido-rotate t))))
3073 (defun ido-next-match-dir ()
3074 "Find next directory in match list.
3075 If work directories have been merged, cycle through directories for
3076 first matching file."
3078 (if ido-use-merged-list
3080 (let* ((elt (car ido-matches))
3082 (when (> (length dirs) 1)
3083 (setcdr elt (ido-chop dirs (cadr dirs))))
3084 (setq ido-rescan nil)))
3085 (let ((cnt (length ido-matches))
3087 (while (and (< i cnt) (not (ido-final-slash (nth i ido-matches))))
3090 (setq ido-cur-list (ido-chop ido-cur-list (nth i ido-matches)))))))
3092 (defun ido-prev-match-dir ()
3093 "Find previous directory in match list.
3094 If work directories have been merged, cycle through directories
3095 for first matching file."
3097 (if ido-use-merged-list
3099 (let* ((elt (car ido-matches))
3101 (when (> (length dirs) 1)
3102 (setcdr elt (ido-chop dirs (car (last dirs)))))
3103 (setq ido-rescan nil)))
3104 (let* ((cnt (length ido-matches))
3106 (while (and (> i 0) (not (ido-final-slash (nth i ido-matches))))
3109 (setq ido-cur-list (ido-chop ido-cur-list (nth i ido-matches)))))))
3111 (defun ido-restrict-to-matches ()
3112 "Set current item list to the currently matched items."
3115 (setq ido-cur-list ido-matches
3121 (defun ido-chop (items elem)
3122 "Remove all elements before ELEM and put them at the end of ITEMS."
3127 (setq next (car items))
3128 (if (equal next elem)
3129 (setq ret (append items (nreverse sofar)))
3132 (setq items (cdr items))
3133 (setq sofar (cons next sofar)))))
3136 (defun ido-name (item)
3137 ;; Return file name for current item, whether in a normal list
3138 ;; or a merged work directory list.
3139 (if (consp item) (car item) item))
3142 ;;; CREATE LIST OF ALL CURRENT FILES
3144 (defun ido-all-completions ()
3145 ;; Return unsorted list of all competions.
3146 (let ((ido-process-ignore-lists nil)
3147 (ido-directory-too-big nil))
3149 ((eq ido-cur-item 'file)
3150 (ido-make-file-list-1 ido-current-directory))
3151 ((eq ido-cur-item 'dir)
3152 (ido-make-dir-list-1 ido-current-directory))
3153 ((eq ido-cur-item 'buffer)
3154 (ido-make-buffer-list-1))
3155 ((eq ido-cur-item 'list)
3160 ;; File list sorting
3162 (defun ido-file-lessp (a b)
3163 ;; Simple compare two file names.
3164 (string-lessp (ido-no-final-slash a) (ido-no-final-slash b)))
3167 (defun ido-file-extension-lessp (a b)
3168 ;; Compare file names according to ido-file-extensions-order list.
3169 (let ((n (compare-strings a 0 nil b 0 nil nil))
3182 (ido-file-extension-aux a b n lessp))
3184 (while (and (> n 2) (/= (aref a n) ?.))
3187 (ido-file-extension-aux a b n lessp)
3190 (defun ido-file-extension-aux (a b n lessp)
3191 (let ((oa (ido-file-extension-order a n))
3192 (ob (ido-file-extension-order b n)))
3209 (defun ido-file-extension-order (s n)
3210 (let ((l ido-file-extensions-order)
3217 ((eq (compare-strings s n nil (car l) 0 nil nil) t)
3226 (defun ido-sort-merged-list (items promote)
3227 ;; Input is list of ("file" . "dir") cons cells.
3228 ;; Output is sorted list of ("file "dir" ...) lists
3229 (let ((l (sort items (lambda (a b) (string-lessp (car b) (car a)))))
3234 (if (and res (string-equal (car (car res)) (car a)))
3236 (setcdr (car (if cur (cdr res) res)) (cons (cdr a) (cdr (car res))))
3237 (if (and promote (string-equal ido-current-directory (cdr a)))
3239 (setq res (cons (list (car a) (cdr a)) res)
3243 (defun ido-wide-find-dirs-or-files (dir file &optional prefix finddir)
3244 ;; As ido-run-find-command, but returns a list of cons pairs ("file" . "dir")
3247 (shell-command-to-string
3249 (shell-quote-argument dir)
3251 (shell-quote-argument
3252 (concat (if prefix "" "*") file "*"))
3253 " -type " (if finddir "d" "f") " -print"))))
3257 (setq filename (car filenames)
3258 filenames (cdr filenames))
3259 (if (and (string-match "^/" filename)
3260 (file-exists-p filename))
3261 (setq d (file-name-directory filename)
3262 f (file-name-nondirectory filename)
3263 res (cons (cons (if finddir (ido-final-slash f t) f) d) res))))
3266 (defun ido-flatten-merged-list (items)
3267 ;; Create a list of directory names based on a merged directory list.
3270 (let* ((item (car items))
3274 (setq res (cons (concat (car dirs) file) res)
3276 (setq items (cdr items)))
3280 (defun ido-make-merged-file-list-1 (text auto wide)
3282 (if (and (ido-final-slash text) ido-dir-file-cache)
3284 (setq res (ido-wide-find-dirs-or-files
3285 ido-current-directory (substring text 0 -1) ido-enable-prefix t))
3286 ;; Use list of cached directories
3287 (let ((re (concat (regexp-quote (substring text 0 -1)) "[^/:]*/\\'"))
3288 (dirs ido-dir-file-cache)
3292 (setq dir (car (car dirs))
3294 (when (and (string-match re dir)
3295 (not (ido-ignore-item-p dir ido-ignore-directories-merge))
3296 (file-directory-p dir))
3297 (setq b (substring dir 0 -1)
3298 f (concat (file-name-nondirectory b) "/")
3299 d (file-name-directory b)
3300 res (cons (cons f d) res))))
3302 (setq dir (car dirs)
3305 (when (not (ido-ignore-item-p d ido-ignore-directories-merge))
3306 (setq dir (cdr (cdr dir)))
3310 (if (and (string-match re f)
3311 (not (ido-ignore-item-p f ido-ignore-directories)))
3312 (setq res (cons (cons f d) res)))))
3313 (if (and auto (input-pending-p))
3317 (setq res (ido-wide-find-dirs-or-files
3318 ido-current-directory text ido-enable-prefix nil))
3319 (let ((ido-text text)
3320 (dirs ido-work-directory-list)
3321 (must-match (and text (> (length text) 0)))
3323 (if (and auto (not (member ido-current-directory dirs)))
3324 (setq dirs (cons ido-current-directory dirs)))
3326 (setq dir (car dirs)
3328 (when (and dir (stringp dir)
3329 (or ido-merge-ftp-work-directories
3330 (not (ido-is-ftp-directory dir)))
3331 (file-directory-p dir)
3332 ;; TODO. check for nonreadable and too-big.
3333 (setq fl (if (eq ido-cur-item 'file)
3334 (ido-make-file-list-1 dir t)
3335 (ido-make-dir-list-1 dir t))))
3337 (setq fl (ido-set-matches-1 fl)))
3339 (setq res (nconc fl res))))
3340 (if (and auto (input-pending-p))
3345 (defun ido-make-merged-file-list (text auto wide)
3347 (message "Searching for `%s'...." text)
3351 (ido-make-merged-file-list-1 text auto wide))))
3352 (setq res 'input-pending-p))
3355 ido-try-merged-list nil
3356 ido-use-merged-list nil)))
3357 (when (and res (listp res))
3358 (setq res (ido-sort-merged-list res auto)))
3359 (when (and (or ido-rotate-temp ido-rotate-file-list-default)
3361 (> (length text) 0))
3362 (let ((elt (assoc text res)))
3363 (when (and elt (not (eq elt (car res))))
3364 (setq res (delq elt res))
3365 (setq res (cons elt res)))))
3369 (defun ido-make-buffer-list-1 (&optional frame visible)
3370 ;; Return list of non-ignored buffer names
3374 (let ((name (buffer-name x)))
3375 (if (not (or (ido-ignore-item-p name ido-ignore-buffers) (member name visible)))
3377 (buffer-list frame))))
3379 (defun ido-make-buffer-list (default)
3380 ;; Return the current list of buffers.
3381 ;; Currently visible buffers are put at the end of the list.
3382 ;; The hook `ido-make-buffer-list-hook' is run after the list has been
3383 ;; created to allow the user to further modify the order of the buffer names
3384 ;; in this list. If DEFAULT is non-nil, and corresponds to an existing buffer,
3385 ;; it is put to the start of the list.
3386 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current))
3387 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers)))
3389 (nconc ido-temp-list ido-current-buffers)
3390 (setq ido-temp-list ido-current-buffers))
3391 (when (and default (buffer-live-p (get-buffer default)))
3393 (cons default (delete default ido-temp-list))))
3394 (if ido-use-virtual-buffers
3395 (ido-add-virtual-buffers-to-list))
3396 (run-hooks 'ido-make-buffer-list-hook)
3399 (defun ido-add-virtual-buffers-to-list ()
3400 "Add recently visited files, and bookmark files, to the buffer list.
3401 This is to make them appear as if they were \"virtual buffers\"."
3402 ;; If no buffers matched, and virtual buffers are being used, then
3403 ;; consult the list of past visited files, to see if we can find
3404 ;; the file which the user might thought was still open.
3405 (unless recentf-mode (recentf-mode 1))
3406 (setq ido-virtual-buffers nil)
3408 (dolist (head recentf-list)
3409 (and (setq name (file-name-nondirectory head))
3410 (null (get-file-buffer head))
3411 (not (assoc name ido-virtual-buffers))
3412 (not (member name ido-temp-list))
3413 (not (ido-ignore-item-p name ido-ignore-buffers))
3414 ;;(file-exists-p head)
3415 (push (cons name head) ido-virtual-buffers))))
3416 (when ido-virtual-buffers
3418 (dolist (comp ido-virtual-buffers)
3419 (put-text-property 0 (length (car comp))
3423 (nconc ido-temp-list
3424 (nreverse (mapcar #'car ido-virtual-buffers))))))
3426 (defun ido-make-choice-list (default)
3427 ;; Return the current list of choices.
3428 ;; If DEFAULT is non-nil, and corresponds to an element of choices,
3429 ;; it is put to the start of the list.
3430 (let ((ido-temp-list ido-choice-list))
3434 (delete default ido-temp-list))
3436 (cons default ido-temp-list))))
3437 ; (run-hooks 'ido-make-choice-list-hook)
3440 (defun ido-to-end (items)
3441 ;; Move the elements from ITEMS to the end of `ido-temp-list'
3444 (setq ido-temp-list (delq elem ido-temp-list)))
3447 (nconc ido-temp-list items)
3448 (setq ido-temp-list items)))
3450 (declare-function tramp-tramp-file-p "tramp" (name))
3452 (defun ido-file-name-all-completions-1 (dir)
3454 ((ido-nonreadable-directory-p dir) '())
3455 ;; do not check (ido-directory-too-big-p dir) here.
3456 ;; Caller must have done that if necessary.
3458 ((and ido-enable-tramp-completion
3459 (or (fboundp 'tramp-completion-mode-p)
3460 (require 'tramp nil t))
3461 (string-match "\\`/[^/]+[:@]\\'" dir))
3462 ;; Strip method:user@host: part of tramp completions.
3463 ;; Tramp completions do not include leading slash.
3464 (let* ((len (1- (length dir)))
3467 (or (file-name-all-completions "" dir)
3468 ;; work around bug in ange-ftp.
3469 ;; /ftp:user@host: => nil
3470 ;; /ftp:user@host:./ => ok
3472 (not (string= "/ftp:" dir))
3473 (tramp-tramp-file-p dir)
3474 (fboundp 'tramp-ftp-file-name-p)
3475 (funcall 'tramp-ftp-file-name-p dir)
3476 (string-match ":\\'" dir)
3477 (file-name-all-completions "" (concat dir "./"))))))
3479 (> (length (car compl)) len)
3480 (string= (substring (car compl) 0 len) (substring dir 1)))
3481 (mapcar (lambda (c) (substring c len)) compl)
3484 (file-name-all-completions "" dir))))
3486 (defun ido-file-name-all-completions (dir)
3487 ;; Return name of all files in DIR
3488 ;; Uses and updates ido-dir-file-cache
3490 ((ido-is-unc-root dir)
3493 (if (string-match "/\\'" host) host (concat host "/")))
3495 ((and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0)
3496 (stringp dir) (> (length dir) 0)
3497 (ido-may-cache-directory dir))
3498 (let* ((cached (assoc dir ido-dir-file-cache))
3499 (ctime (nth 1 cached))
3500 (ftp (ido-is-ftp-directory dir))
3501 (unc (ido-is-unc-host dir))
3502 (attr (if (or ftp unc) nil (file-attributes dir)))
3503 (mtime (nth 5 attr))
3505 (when cached ; should we use the cached entry ?
3508 (setq valid (and (eq (car ctime) 'ftp)
3509 (ido-cache-ftp-valid (cdr ctime)))))
3511 (setq valid (and (eq (car ctime) 'unc)
3512 (ido-cache-unc-valid (cdr ctime)))))
3515 (setq valid (and (= (car ctime) (car mtime))
3516 (= (car (cdr ctime)) (car (cdr mtime))))))))
3518 (setq ido-dir-file-cache (delq cached ido-dir-file-cache)
3523 (setq mtime (cons 'unc (ido-time-stamp))))
3524 ((and ftp (file-readable-p dir))
3525 (setq mtime (cons 'ftp (ido-time-stamp)))))
3527 (setq cached (cons dir (cons mtime (ido-file-name-all-completions-1 dir)))
3528 ido-dir-file-cache (cons cached ido-dir-file-cache)))
3529 (if (> (length ido-dir-file-cache) ido-max-dir-file-cache)
3530 (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil)))
3532 (cdr (cdr cached)))))
3534 (ido-file-name-all-completions-1 dir))))
3536 (defun ido-remove-cached-dir (dir)
3537 ;; Remove dir from ido-dir-file-cache
3538 (if (and ido-dir-file-cache
3539 (stringp dir) (> (length dir) 0))
3540 (let ((cached (assoc dir ido-dir-file-cache)))
3542 (setq ido-dir-file-cache (delq cached ido-dir-file-cache))))))
3545 (defun ido-make-file-list-1 (dir &optional merged)
3546 ;; Return list of non-ignored files in DIR
3547 ;; If MERGED is non-nil, each file is cons'ed with DIR
3548 (and (or (ido-is-tramp-root dir) (ido-is-unc-root dir)
3549 (file-directory-p dir))
3553 (if (not (ido-ignore-item-p name ido-ignore-files t))
3554 (if merged (cons name dir) name)))
3555 (ido-file-name-all-completions dir)))))
3557 (defun ido-make-file-list (default)
3558 ;; Return the current list of files.
3559 ;; Currently visible files are put at the end of the list.
3560 ;; The hook `ido-make-file-list-hook' is run after the list has been
3561 ;; created to allow the user to further modify the order of the file names
3563 (let ((ido-temp-list (ido-make-file-list-1 ido-current-directory)))
3564 (setq ido-temp-list (sort ido-temp-list
3565 (if ido-file-extensions-order
3566 #'ido-file-extension-lessp
3568 (unless (ido-is-tramp-root ido-current-directory)
3569 (let ((default-directory ido-current-directory))
3570 (ido-to-end ;; move ftp hosts and visited files to end
3572 (lambda (x) (if (or (and (string-match ".:\\'" x)
3573 (not (ido-local-file-exists-p x)))
3574 (and (not (ido-final-slash x))
3575 (let (file-name-handler-alist)
3576 (get-file-buffer x)))) x))
3578 (ido-to-end ;; move . files to end
3580 (lambda (x) (if (string-equal (substring x 0 1) ".") x))
3582 (if (and default (member default ido-temp-list))
3583 (if (or ido-rotate-temp ido-rotate-file-list-default)
3584 (unless (equal default (car ido-temp-list))
3585 (let ((l ido-temp-list) k)
3586 (while (and l (cdr l) (not (equal default (car (cdr l)))))
3590 (nconc k ido-temp-list)
3591 (setq ido-temp-list k)))
3593 (delete default ido-temp-list))
3595 (cons default ido-temp-list))))
3596 (when ido-show-dot-for-dired
3597 (setq ido-temp-list (delete "." ido-temp-list))
3598 (setq ido-temp-list (cons "." ido-temp-list)))
3599 (run-hooks 'ido-make-file-list-hook)
3602 (defun ido-make-dir-list-1 (dir &optional merged)
3603 ;; Return list of non-ignored subdirs in DIR
3604 ;; If MERGED is non-nil, each subdir is cons'ed with DIR
3605 (and (or (ido-is-tramp-root dir) (file-directory-p dir))
3609 (and (ido-final-slash name) (not (ido-ignore-item-p name ido-ignore-directories))
3610 (if merged (cons name dir) name)))
3611 (ido-file-name-all-completions dir)))))
3613 (defun ido-make-dir-list (default)
3614 ;; Return the current list of directories.
3615 ;; The hook `ido-make-dir-list-hook' is run after the list has been
3616 ;; created to allow the user to further modify the order of the
3617 ;; directory names in this list.
3618 (let ((ido-temp-list (ido-make-dir-list-1 ido-current-directory)))
3619 (setq ido-temp-list (sort ido-temp-list #'ido-file-lessp))
3620 (ido-to-end ;; move . files to end
3622 (lambda (x) (if (string-equal (substring x 0 1) ".") x))
3624 (if (and default (member default ido-temp-list))
3625 (if (or ido-rotate-temp ido-rotate-file-list-default)
3626 (unless (equal default (car ido-temp-list))
3627 (let ((l ido-temp-list) k)
3628 (while (and l (cdr l) (not (equal default (car (cdr l)))))
3632 (nconc k ido-temp-list)
3633 (setq ido-temp-list k)))
3635 (delete default ido-temp-list))
3637 (cons default ido-temp-list))))
3638 (setq ido-temp-list (delete "." ido-temp-list))
3639 (unless ido-input-stack
3640 (setq ido-temp-list (cons "." ido-temp-list)))
3641 (run-hooks 'ido-make-dir-list-hook)
3644 ;; List of the files visible in the current frame.
3645 (defvar ido-bufs-in-frame)
3647 (defun ido-get-buffers-in-frames (&optional current)
3648 ;; Return the list of buffers that are visible in the current frame.
3649 ;; If optional argument `current' is given, restrict searching to the
3650 ;; current frame, rather than all frames, regardless of value of
3651 ;; `ido-all-frames'.
3652 (let ((ido-bufs-in-frame nil))
3653 (walk-windows 'ido-get-bufname nil
3659 (defun ido-get-bufname (win)
3660 ;; Used by `ido-get-buffers-in-frames' to walk through all windows
3661 (let ((buf (buffer-name (window-buffer win))))
3662 (unless (or (member buf ido-bufs-in-frame)
3664 (member buf ido-ignore-item-temp-list))
3665 ;; Only add buf if it is not already in list.
3666 ;; This prevents same buf in two different windows being
3667 ;; put into the list twice.
3668 (setq ido-bufs-in-frame
3669 (cons buf ido-bufs-in-frame)))))
3671 ;;; FIND MATCHING ITEMS
3673 (defun ido-set-matches-1 (items &optional do-full)
3674 ;; Return list of matches in items
3675 (let* ((case-fold-search ido-case-fold)
3676 (slash (and (not ido-enable-prefix) (ido-final-slash ido-text)))
3677 (text (if slash (substring ido-text 0 -1) ido-text))
3678 (rex0 (if ido-enable-regexp text (regexp-quote text)))
3679 (rexq (concat rex0 (if slash ".*/" "")))
3680 (re (if ido-enable-prefix (concat "\\`" rexq) rexq))
3681 (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
3682 (concat "\\`" rex0 (if slash "/" "") "\\'")))
3683 (suffix-re (and do-full slash
3684 (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
3685 (concat rex0 "/\\'")))
3686 (prefix-re (and full-re (not ido-enable-prefix)
3687 (concat "\\`" rexq)))
3688 (non-prefix-dot (or (not ido-enable-dot-prefix)
3689 (not ido-process-ignore-lists)
3691 (= (length ido-text) 0)))
3692 full-matches suffix-matches prefix-matches matches)
3693 (setq ido-incomplete-regexp nil)
3694 (condition-case error
3697 (let ((name (ido-name item)))
3698 (if (and (or non-prefix-dot
3699 (if (= (aref ido-text 0) ?.)
3700 (= (aref name 0) ?.)
3701 (/= (aref name 0) ?.)))
3702 (string-match re name))
3704 ((and (eq ido-cur-item 'buffer)
3705 (or (not (stringp ido-default-item))
3706 (not (string= name ido-default-item)))
3707 (string= name (buffer-name ido-entry-buffer)))
3708 (setq matches (cons item matches)))
3709 ((and full-re (string-match full-re name))
3710 (setq full-matches (cons item full-matches)))
3711 ((and suffix-re (string-match suffix-re name))
3712 (setq suffix-matches (cons item suffix-matches)))
3713 ((and prefix-re (string-match prefix-re name))
3714 (setq prefix-matches (cons item prefix-matches)))
3715 (t (setq matches (cons item matches))))))
3719 (setq ido-incomplete-regexp t
3720 ;; Consider the invalid regexp message internally as a
3721 ;; special-case single match, and handle appropriately
3723 matches (cdr error))))
3724 (when prefix-matches
3725 (ido-trace "prefix match" prefix-matches)
3727 (setq matches (nconc prefix-matches matches)))
3728 (when suffix-matches
3729 (ido-trace "suffix match" (list text suffix-re suffix-matches))
3730 (setq matches (nconc suffix-matches matches)))
3732 (ido-trace "full match" (list text full-re full-matches))
3733 (setq matches (nconc full-matches matches)))
3734 (when (and (null matches)
3735 ido-enable-flex-matching
3736 (> (length ido-text) 1)
3737 (not ido-enable-regexp))
3738 (setq re (mapconcat #'regexp-quote (split-string ido-text "") ".*"))
3739 (if ido-enable-prefix
3740 (setq re (concat "\\`" re)))
3743 (let ((name (ido-name item)))
3744 (if (string-match re name)
3745 (setq matches (cons item matches)))))
3750 (defun ido-set-matches ()
3751 ;; Set `ido-matches' to the list of items matching prompt
3753 (setq ido-matches (ido-set-matches-1 (reverse ido-cur-list) (not ido-rotate))
3756 (defun ido-ignore-item-p (name re-list &optional ignore-ext)
3757 ;; Return t if the buffer or file NAME should be ignored.
3758 (or (member name ido-ignore-item-temp-list)
3760 ido-process-ignore-lists re-list
3762 (let ((ext-list (and ignore-ext ido-ignore-extensions
3763 completion-ignored-extensions))
3764 (case-fold-search ido-case-fold)
3766 (flen (length name)) slen)
3768 (setq nextstr (car ext-list))
3771 (and (>= flen (setq slen (length nextstr)))
3772 (string-equal (substring name (- flen slen)) nextstr)))
3773 ((functionp nextstr) (funcall nextstr name))
3778 (setq ext-list (cdr ext-list))))
3780 (setq nextstr (car re-list))
3782 ((stringp nextstr) (string-match nextstr name))
3783 ((functionp nextstr) (funcall nextstr name))
3787 (setq re-list (cdr re-list))))
3788 ;; return the result
3790 (setq ido-ignored-list (cons name ido-ignored-list)))
3793 ;; Private variable used by `ido-word-matching-substring'.
3794 (defvar ido-change-word-sub)
3796 (defun ido-find-common-substring (items subs)
3797 ;; Return common string following SUBS in each element of ITEMS.
3800 ido-change-word-sub)
3801 (setq ido-change-word-sub
3802 (if ido-enable-regexp
3804 (regexp-quote subs)))
3805 (setq res (mapcar #'ido-word-matching-substring items))
3806 (setq res (delq nil res)) ;; remove any nil elements (shouldn't happen)
3807 (setq alist (mapcar #'ido-makealist res)) ;; could use an OBARRAY
3809 ;; try-completion returns t if there is an exact match.
3810 (let* ((completion-ignore-case ido-case-fold)
3811 (comp (try-completion subs alist)))
3816 (defun ido-word-matching-substring (word)
3817 ;; Return part of WORD before 1st match to `ido-change-word-sub'.
3818 ;; If `ido-change-word-sub' cannot be found in WORD, return nil.
3819 (let ((case-fold-search ido-case-fold))
3820 (let ((m (string-match ido-change-word-sub (ido-name word))))
3822 (substring (ido-name word) m)
3826 (defun ido-makealist (res)
3827 ;; Return dotted pair (RES . 1).
3830 (defun ido-choose-completion-string (choice &rest ignored)
3832 ;; Insert the completion into the buffer where completion was requested.
3833 (if (get-buffer ido-completion-buffer)
3834 (kill-buffer ido-completion-buffer))
3836 ((ido-active t) ;; ido-use-merged-list
3837 (setq ido-current-directory ""
3840 ((not (ido-final-slash choice))
3841 (setq ido-text choice
3844 (ido-set-current-directory ido-current-directory choice)
3845 (setq ido-exit 'refresh)))
3849 (defun ido-completion-help ()
3850 "Show possible completions in a *File Completions* buffer."
3852 (setq ido-rescan nil)
3853 (let ((temp-buf (get-buffer ido-completion-buffer))
3854 display-it full-list)
3855 (if (and (eq last-command this-command) temp-buf)
3857 (let (win (buf (current-buffer)))
3858 (display-buffer temp-buf nil nil)
3859 (set-buffer temp-buf)
3860 (setq win (get-buffer-window temp-buf))
3861 (if (pos-visible-in-window-p (point-max) win)
3862 (if (or ido-completion-buffer-all-completions
3863 (boundp 'ido-completion-buffer-full))
3864 (set-window-start win (point-min))
3866 (set (make-local-variable 'ido-completion-buffer-full) t))
3869 (scroll-other-window))
3871 (setq display-it t))
3873 (with-output-to-temp-buffer ido-completion-buffer
3874 (let ((completion-list (sort
3876 (ido-directory-too-big
3877 (message "Reading directory...")
3878 (setq ido-directory-too-big nil
3879 ido-ignored-list nil
3880 ido-cur-list (ido-all-completions)
3883 (or ido-matches ido-cur-list))
3884 (ido-use-merged-list
3885 (ido-flatten-merged-list (or ido-matches ido-cur-list)))
3886 ((or full-list ido-completion-buffer-all-completions)
3887 (ido-all-completions))
3889 (copy-sequence (or ido-matches ido-cur-list))))
3891 (if (featurep 'xemacs)
3892 ;; XEmacs extents are put on by default, doesn't seem to be
3893 ;; any way of switching them off.
3894 ;; This obscure code avoids a byte compiler warning in Emacs.
3895 (let ((f 'display-completion-list))
3896 (funcall f completion-list
3899 '(lambda (x y z) (message "Doesn't work yet, sorry!"))))
3900 ;; else running Emacs
3901 ;;(add-hook 'completion-setup-hook 'completion-setup-function)
3902 (display-completion-list completion-list)))))))
3904 (defun ido-kill-buffer-internal (buf)
3905 "Kill buffer BUF and rebuild ido's buffer list if needed."
3906 (if (not (kill-buffer buf))
3907 ;; buffer couldn't be killed.
3909 ;; else buffer was killed so remove name from list.
3910 (setq ido-cur-list (delq buf ido-cur-list))
3911 ;; Some packages, like uniquify.el, may rename buffers when one
3912 ;; is killed, so we need to test this condition to avoid using
3913 ;; an outdated list of buffer names. We don't want to always
3914 ;; rebuild the list of buffers, as this alters the previous
3915 ;; buffer order that the user was seeing on the prompt. However,
3916 ;; when we rebuild the list, we try to keep the previous second
3917 ;; buffer as the first one.
3919 (dolist (b ido-cur-list)
3920 (unless (get-buffer b)
3921 (setq ido-cur-list (ido-make-buffer-list (cadr ido-matches)))
3923 (throw 'update nil))))))
3925 ;;; KILL CURRENT BUFFER
3926 (defun ido-kill-buffer-at-head ()
3927 "Kill the buffer at the head of `ido-matches'.
3928 If cursor is not at the end of the user input, delete to end of input."
3931 (delete-region (point) (line-end-position))
3932 (let ((enable-recursive-minibuffers t)
3933 (buf (ido-name (car ido-matches))))
3935 (ido-kill-buffer-internal buf)
3936 ;; Check if buffer still exists.
3937 (if (get-buffer buf)
3938 ;; buffer couldn't be killed.
3940 ;; else buffer was killed so remove name from list.
3941 (setq ido-cur-list (delq buf ido-cur-list)))))))
3943 ;;; DELETE CURRENT FILE
3944 (defun ido-delete-file-at-head ()
3945 "Delete the file at the head of `ido-matches'.
3946 If cursor is not at the end of the user input, delete to end of input."
3949 (delete-region (point) (line-end-position))
3950 (let ((enable-recursive-minibuffers t)
3951 (file (ido-name (car ido-matches))))
3953 (setq file (concat ido-current-directory file)))
3955 (file-exists-p file)
3956 (not (file-directory-p file))
3957 (file-writable-p ido-current-directory)
3958 (yes-or-no-p (concat "Delete " file "? ")))
3960 ;; Check if file still exists.
3961 (if (file-exists-p file)
3962 ;; file could not be deleted
3964 ;; else file was killed so remove name from list.
3965 (setq ido-cur-list (delq (car ido-matches) ido-cur-list)))))))
3968 ;;; VISIT CHOSEN BUFFER
3969 (defun ido-visit-buffer (buffer method &optional record)
3970 "Switch to BUFFER according to METHOD.
3971 Record command in `command-history' if optional RECORD is non-nil."
3972 (if (bufferp buffer)
3973 (setq buffer (buffer-name buffer)))
3978 (ido-record-command 'kill-buffer buffer))
3979 (ido-kill-buffer-internal buffer))
3981 ((eq method 'other-window)
3983 (ido-record-command 'switch-to-buffer buffer))
3984 (switch-to-buffer-other-window buffer))
3986 ((eq method 'display)
3987 (display-buffer buffer))
3989 ((eq method 'other-frame)
3990 (switch-to-buffer-other-frame buffer)
3991 (select-frame-set-input-focus (selected-frame)))
3993 ((and (memq method '(raise-frame maybe-frame))
3995 (setq win (ido-buffer-window-other-frame buffer))
3996 (or (eq method 'raise-frame)
3997 (y-or-n-p "Jump to frame? ")))
3998 (setq newframe (window-frame win))
3999 (select-frame-set-input-focus newframe)
4000 (select-window win))
4002 ;; (eq method 'selected-window)
4004 ;; No buffer in other frames...
4006 (ido-record-command 'switch-to-buffer buffer))
4007 (switch-to-buffer buffer)
4011 (defun ido-buffer-window-other-frame (buffer)
4012 ;; Return window pointer if BUFFER is visible in another frame.
4013 ;; If BUFFER is visible in the current frame, return nil.
4014 (let ((blist (ido-get-buffers-in-frames 'current)))
4015 ;;If the buffer is visible in current frame, return nil
4016 (if (member buffer blist)
4018 ;; maybe in other frame or icon
4019 (get-buffer-window buffer 0) ; better than 'visible
4023 ;;; ----------- IDONIZED FUNCTIONS ------------
4026 (defun ido-switch-buffer ()
4027 "Switch to another buffer.
4028 The buffer is displayed according to `ido-default-buffer-method' -- the
4029 default is to show it in the same window, unless it is already visible
4032 As you type in a string, all of the buffers matching the string are
4033 displayed if substring-matching is used \(default). Look at
4034 `ido-enable-prefix' and `ido-toggle-prefix'. When you have found the
4035 buffer you want, it can then be selected. As you type, most keys have
4036 their normal keybindings, except for the following: \\<ido-buffer-completion-map>
4038 RET Select the buffer at the front of the list of matches. If the
4039 list is empty, possibly prompt to create new buffer.
4041 \\[ido-select-text] Select the current prompt as the buffer.
4042 If no buffer is found, prompt for a new one.
4044 \\[ido-next-match] Put the first element at the end of the list.
4045 \\[ido-prev-match] Put the last element at the start of the list.
4046 \\[ido-complete] Complete a common suffix to the current string that
4047 matches all buffers. If there is only one match, select that buffer.
4048 If there is no common suffix, show a list of all matching buffers
4049 in a separate window.
4050 \\[ido-edit-input] Edit input string.
4051 \\[ido-fallback-command] Fallback to non-ido version of current command.
4052 \\[ido-toggle-regexp] Toggle regexp searching.
4053 \\[ido-toggle-prefix] Toggle between substring and prefix matching.
4054 \\[ido-toggle-case] Toggle case-sensitive searching of buffer names.
4055 \\[ido-completion-help] Show list of matching buffers in separate window.
4056 \\[ido-enter-find-file] Drop into `ido-find-file'.
4057 \\[ido-kill-buffer-at-head] Kill buffer at head of buffer list.
4058 \\[ido-toggle-ignore] Toggle ignoring buffers listed in `ido-ignore-buffers'."
4060 (ido-buffer-internal ido-default-buffer-method))
4063 (defun ido-switch-buffer-other-window ()
4064 "Switch to another buffer and show it in another window.
4065 The buffer name is selected interactively by typing a substring.
4066 For details of keybindings, see `ido-switch-buffer'."
4068 (ido-buffer-internal 'other-window 'switch-to-buffer-other-window))
4071 (defun ido-display-buffer ()
4072 "Display a buffer in another window but don't select it.
4073 The buffer name is selected interactively by typing a substring.
4074 For details of keybindings, see `ido-switch-buffer'."
4076 (ido-buffer-internal 'display 'display-buffer nil nil nil 'ignore))
4079 (defun ido-kill-buffer ()
4081 The buffer name is selected interactively by typing a substring.
4082 For details of keybindings, see `ido-switch-buffer'."
4084 (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " (buffer-name (current-buffer)) nil 'ignore))
4087 (defun ido-insert-buffer ()
4088 "Insert contents of a buffer in current buffer after point.
4089 The buffer name is selected interactively by typing a substring.
4090 For details of keybindings, see `ido-switch-buffer'."
4092 (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil nil 'ido-enter-insert-file))
4095 (defun ido-switch-buffer-other-frame ()
4096 "Switch to another buffer and show it in another frame.
4097 The buffer name is selected interactively by typing a substring.
4098 For details of keybindings, see `ido-switch-buffer'."
4101 (ido-buffer-internal 'other-frame)
4102 (call-interactively 'switch-to-buffer-other-frame)))
4105 (defun ido-find-file-in-dir (dir)
4106 "Switch to another file starting from DIR."
4107 (interactive "DDir: ")
4108 (setq dir (file-name-as-directory dir))
4109 (ido-file-internal ido-default-file-method nil dir nil nil nil 'ignore))
4112 (defun ido-find-file ()
4113 "Edit file with name obtained via minibuffer.
4114 The file is displayed according to `ido-default-file-method' -- the
4115 default is to show it in the same window, unless it is already
4116 visible in another frame.
4118 The file name is selected interactively by typing a substring. As you
4119 type in a string, all of the filenames matching the string are displayed
4120 if substring-matching is used \(default). Look at `ido-enable-prefix' and
4121 `ido-toggle-prefix'. When you have found the filename you want, it can
4122 then be selected. As you type, most keys have their normal keybindings,
4123 except for the following: \\<ido-file-completion-map>
4125 RET Select the file at the front of the list of matches. If the
4126 list is empty, possibly prompt to create new file.
4128 \\[ido-select-text] Select the current prompt as the buffer or file.
4129 If no buffer or file is found, prompt for a new one.
4131 \\[ido-next-match] Put the first element at the end of the list.
4132 \\[ido-prev-match] Put the last element at the start of the list.
4133 \\[ido-complete] Complete a common suffix to the current string that
4134 matches all files. If there is only one match, select that file.
4135 If there is no common suffix, show a list of all matching files
4136 in a separate window.
4137 \\[ido-edit-input] Edit input string (including directory).
4138 \\[ido-prev-work-directory] or \\[ido-next-work-directory] go to previous/next directory in work directory history.
4139 \\[ido-merge-work-directories] search for file in the work directory history.
4140 \\[ido-forget-work-directory] removes current directory from the work directory history.
4141 \\[ido-prev-work-file] or \\[ido-next-work-file] cycle through the work file history.
4142 \\[ido-wide-find-file-or-pop-dir] and \\[ido-wide-find-dir-or-delete-dir] prompts and uses find to locate files or directories.
4143 \\[ido-make-directory] prompts for a directory to create in current directory.
4144 \\[ido-fallback-command] Fallback to non-ido version of current command.
4145 \\[ido-toggle-regexp] Toggle regexp searching.
4146 \\[ido-toggle-prefix] Toggle between substring and prefix matching.
4147 \\[ido-toggle-case] Toggle case-sensitive searching of file names.
4148 \\[ido-toggle-vc] Toggle version control for this file.
4149 \\[ido-toggle-literal] Toggle literal reading of this file.
4150 \\[ido-completion-help] Show list of matching files in separate window.
4151 \\[ido-toggle-ignore] Toggle ignoring files listed in `ido-ignore-files'."
4154 (ido-file-internal ido-default-file-method))
4157 (defun ido-find-file-other-window ()
4158 "Switch to another file and show it in another window.
4159 The file name is selected interactively by typing a substring.
4160 For details of keybindings, see `ido-find-file'."
4162 (ido-file-internal 'other-window 'find-file-other-window))
4165 (defun ido-find-alternate-file ()
4166 "Switch to another file and show it in another window.
4167 The file name is selected interactively by typing a substring.
4168 For details of keybindings, see `ido-find-file'."
4170 (ido-file-internal 'alt-file 'find-alternate-file nil "Find alternate file: "))
4173 (defun ido-find-file-read-only ()
4174 "Edit file read-only with name obtained via minibuffer.
4175 The file name is selected interactively by typing a substring.
4176 For details of keybindings, see `ido-find-file'."
4178 (ido-file-internal 'read-only 'find-file-read-only nil "Find file read-only: "))
4181 (defun ido-find-file-read-only-other-window ()
4182 "Edit file read-only in other window with name obtained via minibuffer.
4183 The file name is selected interactively by typing a substring.
4184 For details of keybindings, see `ido-find-file'."
4186 (ido-file-internal 'read-only 'find-file-read-only-other-window nil "Find file read-only other window: "))
4189 (defun ido-find-file-read-only-other-frame ()
4190 "Edit file read-only in other frame with name obtained via minibuffer.
4191 The file name is selected interactively by typing a substring.
4192 For details of keybindings, see `ido-find-file'."
4194 (ido-file-internal 'read-only 'find-file-read-only-other-frame nil "Find file read-only other frame: "))
4197 (defun ido-display-file ()
4198 "Display a file in another window but don't select it.
4199 The file name is selected interactively by typing a substring.
4200 For details of keybindings, see `ido-find-file'."
4202 (ido-file-internal 'display nil nil nil nil nil 'ignore))
4205 (defun ido-find-file-other-frame ()
4206 "Switch to another file and show it in another frame.
4207 The file name is selected interactively by typing a substring.
4208 For details of keybindings, see `ido-find-file'."
4210 (ido-file-internal 'other-frame 'find-file-other-frame))
4213 (defun ido-write-file ()
4214 "Write current buffer to a file.
4215 The file name is selected interactively by typing a substring.
4216 For details of keybindings, see `ido-find-file'."
4218 (let ((ido-process-ignore-lists t)
4219 (ido-work-directory-match-only nil)
4220 (ido-ignore-files (cons "[^/]\\'" ido-ignore-files))
4221 (ido-report-no-match nil)
4222 (ido-confirm-unique-completion t)
4223 (ido-auto-merge-work-directories-length -1))
4224 (ido-file-internal 'write 'write-file nil "Write file: " nil nil 'ignore)))
4227 (defun ido-insert-file ()
4228 "Insert contents of file in current buffer.
4229 The file name is selected interactively by typing a substring.
4230 For details of keybindings, see `ido-find-file'."
4232 (ido-file-internal 'insert 'insert-file nil "Insert file: " nil nil 'ido-enter-insert-buffer))
4236 "Call `dired' the ido way.
4237 The directory is selected interactively by typing a substring.
4238 For details of keybindings, see `ido-find-file'."
4240 (let ((ido-report-no-match nil)
4241 (ido-auto-merge-work-directories-length -1))
4242 (ido-file-internal 'dired 'dired nil "Dired: " 'dir)))
4244 (defun ido-list-directory ()
4245 "Call `list-directory' the ido way.
4246 The directory is selected interactively by typing a substring.
4247 For details of keybindings, see `ido-find-file'."
4249 (let ((ido-report-no-match nil)
4250 (ido-auto-merge-work-directories-length -1))
4251 (ido-file-internal 'list-directory 'list-directory nil "List directory: " 'dir)))
4253 ;;; XEmacs hack for showing default buffer
4255 ;; The first time we enter the minibuffer, Emacs puts up the default
4256 ;; buffer to switch to, but XEmacs doesn't -- presumably there is a
4257 ;; subtle difference in the two versions of post-command-hook. The
4258 ;; default is shown for both whenever we delete all of our text
4259 ;; though, indicating its just a problem the first time we enter the
4260 ;; function. To solve this, we use another entry hook for emacs to
4261 ;; show the default the first time we enter the minibuffer.
4264 ;;; ICOMPLETE TYPE CODE
4266 (defun ido-initiate-auto-merge (buffer)
4267 (ido-trace "\n*merge timeout*" buffer)
4268 (setq ido-auto-merge-timer nil)
4269 (when (and (buffer-live-p buffer)
4271 (boundp 'ido-eoinput) ido-eoinput)
4272 (let ((contents (buffer-substring-no-properties (minibuffer-prompt-end) ido-eoinput)))
4273 (ido-trace "request merge")
4274 (setq ido-use-merged-list 'auto
4275 ido-text-init contents
4278 (with-current-buffer buffer
4280 (throw 'ido contents))))
4282 (defun ido-exhibit ()
4283 "Post command hook for `ido'."
4284 ;; Find matching files and display a list in the minibuffer.
4285 ;; Copied from `icomplete-exhibit' with two changes:
4286 ;; 1. It prints a default file name when there is no text yet entered.
4287 ;; 2. It calls my completion routine rather than the standard completion.
4290 (let ((contents (buffer-substring-no-properties (minibuffer-prompt-end) (point-max)))
4291 (buffer-undo-list t)
4292 try-single-dir-match
4295 (when ido-trace-enable
4296 (ido-trace "\nexhibit" this-command)
4297 (ido-trace "dir" ido-current-directory)
4298 (ido-trace "contents" contents)
4299 (ido-trace "list" ido-cur-list)
4300 (ido-trace "matches" ido-matches)
4301 (ido-trace "rescan" ido-rescan))
4304 (goto-char (point-max))
4305 ;; Register the end of input, so we know where the extra stuff (match-status info) begins:
4306 (unless (boundp 'ido-eoinput)
4307 ;; In case it got wiped out by major mode business:
4308 (make-local-variable 'ido-eoinput))
4309 (setq ido-eoinput (point))
4311 ;; Handle explicit directory changes
4313 ((memq ido-cur-item '(buffer list))
4316 ((= (length contents) 0)
4319 ((= (length contents) 1)
4321 ((and (ido-is-tramp-root) (string-equal contents "/"))
4322 (ido-set-current-directory ido-current-directory contents)
4324 ((and (ido-unc-hosts) (string-equal contents "/")
4325 (let ((ido-enable-tramp-completion nil))
4326 (ido-is-root-directory)))
4327 (ido-set-current-directory "//")
4331 ((and (string-match (if ido-enable-tramp-completion ".[:@]\\'" ".:\\'") contents)
4332 (ido-is-root-directory) ;; Ange-ftp or tramp
4333 (not (ido-local-file-exists-p contents)))
4334 (ido-set-current-directory ido-current-directory contents)
4335 (when (ido-is-slow-ftp-host)
4336 (setq ido-exit 'fallback)
4340 ((ido-final-slash contents) ;; xxx/
4341 (ido-trace "final slash" contents)
4343 ((string-equal contents "~/")
4344 (ido-set-current-home)
4346 ((string-equal contents "../")
4347 (ido-up-directory t)
4349 ((string-equal contents "./")
4351 ((string-match "\\`~[-_a-zA-Z0-9]+[$]?/\\'" contents)
4352 (ido-trace "new home" contents)
4353 (ido-set-current-home contents)
4355 ((string-match "[$][A-Za-z0-9_]+/\\'" contents)
4356 (let ((exp (condition-case ()
4358 (substitute-in-file-name (substring contents 0 -1))
4359 ido-current-directory)
4361 (ido-trace contents exp)
4362 (when (and exp (file-directory-p exp))
4363 (ido-set-current-directory (file-name-directory exp))
4364 (setq ido-text-init (file-name-nondirectory exp))
4366 ((and (memq system-type '(windows-nt ms-dos))
4367 (string-equal (substring contents 1) ":/"))
4368 (ido-set-current-directory (file-name-directory contents))
4370 ((string-equal (substring contents -2 -1) "/")
4371 (ido-set-current-directory
4372 (if (memq system-type '(windows-nt ms-dos))
4373 (expand-file-name "/" ido-current-directory)
4376 ((and (or ido-directory-nonreadable ido-directory-too-big)
4377 (file-directory-p (concat ido-current-directory (file-name-directory contents))))
4378 (ido-set-current-directory
4379 (concat ido-current-directory (file-name-directory contents)))
4382 (ido-trace "try single dir")
4383 (setq try-single-dir-match t))))
4385 ((and (string-equal (substring contents -2 -1) "/")
4386 (not (string-match "[$]" contents)))
4387 (ido-set-current-directory
4389 ((= (length contents) 2)
4392 (concat ido-current-directory (ido-name (car ido-matches))))
4394 (concat ido-current-directory (substring contents 0 -1)))))
4395 (setq ido-text-init (substring contents -1))
4398 ((and (not ido-use-merged-list)
4399 (not (ido-final-slash contents))
4400 (eq ido-try-merged-list t)
4401 (numberp ido-auto-merge-work-directories-length)
4402 (> ido-auto-merge-work-directories-length 0)
4403 (= (length contents) ido-auto-merge-work-directories-length)
4404 (not (and ido-auto-merge-inhibit-characters-regexp
4405 (string-match ido-auto-merge-inhibit-characters-regexp contents)))
4406 (not (input-pending-p)))
4407 (setq ido-use-merged-list 'auto
4408 ido-text-init contents
4415 (ido-trace "refresh on /" ido-text-init)
4416 (setq ido-exit 'refresh)
4419 ;; Update the list of matches
4420 (setq ido-text contents)
4422 (ido-trace "new " ido-matches)
4424 (when (and ido-enter-matching-directory
4426 (or (eq ido-enter-matching-directory 'first)
4427 (null (cdr ido-matches)))
4428 (ido-final-slash (ido-name (car ido-matches)))
4429 (or try-single-dir-match
4430 (eq ido-enter-matching-directory t)))
4431 (ido-trace "single match" (car ido-matches))
4432 (ido-set-current-directory
4433 (concat ido-current-directory (ido-name (car ido-matches))))
4434 (setq ido-exit 'refresh)
4437 (when (and (not ido-matches)
4438 (not ido-directory-nonreadable)
4439 (not ido-directory-too-big)
4441 ido-process-ignore-lists
4443 (let ((ido-process-ignore-lists nil)
4444 (ido-rotate ido-rotate)
4445 (ido-cur-list ido-ignored-list))
4446 (ido-trace "try all" ido-ignored-list)
4449 (ido-trace "found " ido-matches)
4451 (setq ido-process-ignore-lists-inhibit t)
4452 (setq ido-text-init ido-text)
4453 (setq ido-exit 'refresh)
4459 (memq ido-cur-item '(file dir))
4460 (not (ido-is-root-directory))
4461 (> (length contents) 1)
4462 (not (string-match "[$]" contents))
4463 (not ido-directory-nonreadable)
4464 (not ido-directory-too-big))
4465 (ido-trace "merge?")
4466 (if ido-use-merged-list
4467 (ido-undo-merge-work-directory contents nil)
4468 (when (and (eq ido-try-merged-list t)
4469 (numberp ido-auto-merge-work-directories-length)
4470 (= ido-auto-merge-work-directories-length 0)
4471 (not (and ido-auto-merge-inhibit-characters-regexp
4472 (string-match ido-auto-merge-inhibit-characters-regexp contents)))
4473 (not (input-pending-p)))
4474 (ido-trace "\n*start timer*")
4475 (setq ido-auto-merge-timer
4476 (run-with-timer ido-auto-merge-delay-time nil 'ido-initiate-auto-merge (current-buffer))))))
4480 (if (and ido-use-merged-list
4482 (not (string-equal (car (cdr (car ido-matches))) ido-current-directory)))
4484 (ido-set-current-directory (car (cdr (car ido-matches))))
4485 (setq ido-use-merged-list t
4487 ido-text-init ido-text)
4490 ;; Insert the match-status information:
4491 (ido-set-common-completion)
4492 (let ((inf (ido-completions
4494 minibuffer-completion-table
4495 minibuffer-completion-predicate
4496 (not minibuffer-completion-confirm))))
4497 (setq ido-show-confirm-message nil)
4498 (ido-trace "inf" inf)
4502 (defun ido-completions (name candidates predicate require-match)
4503 ;; Return the string that is displayed after the user's text.
4504 ;; Modified from `icomplete-completions'.
4506 (let* ((comps ido-matches)
4507 (ind (and (consp (car comps)) (> (length (cdr (car comps))) 1)
4508 ido-merged-indicator))
4511 (if (and ind ido-use-faces)
4512 (put-text-property 0 1 'face 'ido-indicator ind))
4514 (if (and ido-use-faces comps)
4515 (let* ((fn (ido-name (car comps)))
4517 (setq first (format "%s" fn))
4518 (put-text-property 0 ln 'face
4519 (if (= (length comps) 1)
4520 (if ido-incomplete-regexp
4521 'ido-incomplete-regexp
4525 (if ind (setq first (concat first ind)))
4526 (setq comps (cons first (cdr comps)))))
4530 (ido-show-confirm-message
4531 (or (nth 10 ido-decorations) " [Confirm]"))
4532 (ido-directory-nonreadable
4533 (or (nth 8 ido-decorations) " [Not readable]"))
4534 (ido-directory-too-big
4535 (or (nth 9 ido-decorations) " [Too big]"))
4536 (ido-report-no-match
4537 (nth 6 ido-decorations)) ;; [No match]
4539 (ido-incomplete-regexp
4540 (concat " " (car comps)))
4541 ((null (cdr comps)) ;one match
4542 (concat (if (if (not ido-enable-regexp)
4543 (= (length (ido-name (car comps))) (length name))
4544 ;; We can't rely on the length of the input
4545 ;; for regexps, so explicitly check for a
4547 (string-match name (ido-name (car comps)))
4548 (string-equal (match-string 0 (ido-name (car comps)))
4549 (ido-name (car comps))))
4551 ;; when there is one match, show the matching file name in full
4552 (concat (nth 4 ido-decorations) ;; [ ... ]
4553 (ido-name (car comps))
4554 (nth 5 ido-decorations)))
4555 (if (not ido-use-faces) (nth 7 ido-decorations)))) ;; [Matched]
4556 (t ;multiple matches
4557 (let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999))
4565 (setq com (ido-name com))
4566 (setq items (1- items))
4569 ((= items 0) (list (nth 3 ido-decorations))) ; " | ..."
4571 (list (or ido-separator (nth 2 ido-decorations)) ; " | "
4572 (let ((str (substring com 0)))
4573 (if (and ido-use-faces
4574 (not (string= str first))
4575 (ido-final-slash str))
4576 (put-text-property 0 (length str) 'face 'ido-subdir str))
4581 ;; put in common completion item -- what you get by pressing tab
4582 (if (and (stringp ido-common-match-string)
4583 (> (length ido-common-match-string) (length name)))
4584 (concat (nth 4 ido-decorations) ;; [ ... ]
4585 (substring ido-common-match-string (length name))
4586 (nth 5 ido-decorations)))
4587 ;; list all alternatives
4588 (nth 0 ido-decorations) ;; { ... }
4590 (nth 1 ido-decorations)))))))
4592 (defun ido-minibuffer-setup ()
4593 "Minibuffer setup hook for `ido'."
4594 ;; Copied from `icomplete-minibuffer-setup-hook'.
4596 (add-hook 'pre-command-hook 'ido-tidy nil t)
4597 (add-hook 'post-command-hook 'ido-exhibit nil t)
4598 (setq cua-inhibit-cua-keys t)
4599 (when (featurep 'xemacs)
4601 (goto-char (point-min)))
4602 (run-hooks 'ido-minibuffer-setup-hook)
4603 (when ido-initial-position
4604 (goto-char (+ (minibuffer-prompt-end) ido-initial-position))
4605 (setq ido-initial-position nil))))
4608 "Pre command hook for `ido'."
4609 ;; Remove completions display, if any, prior to new user input.
4610 ;; Copied from `icomplete-tidy'."
4612 (when ido-auto-merge-timer
4613 (ido-trace "\n*cancel timer*" this-command)
4614 (cancel-timer ido-auto-merge-timer)
4615 (setq ido-auto-merge-timer nil))
4618 (if (and (boundp 'ido-eoinput)
4621 (if (> ido-eoinput (point-max))
4622 ;; Oops, got rug pulled out from under us - reinit:
4623 (setq ido-eoinput (point-max))
4624 (let ((buffer-undo-list t))
4625 (delete-region ido-eoinput (point-max))))
4627 ;; Reestablish the local variable 'cause minibuffer-setup is weird:
4628 (make-local-variable 'ido-eoinput)
4629 (setq ido-eoinput 1))))
4631 (defun ido-summary-buffers-to-end ()
4632 ;; Move the summaries to the end of the buffer list.
4633 ;; This is an example function which can be hooked on to
4634 ;; `ido-make-buffer-list-hook'. Any buffer matching the regexps
4635 ;; `Summary' or `output\*$'are put to the end of the list.
4636 (let ((summaries (delq nil (mapcar
4639 (string-match "Summary" x)
4640 (string-match "output\\*\\'" x))
4643 (ido-to-end summaries)))
4645 ;;; Helper functions for other programs
4647 (put 'dired-do-rename 'ido 'ignore)
4648 (put 'ibuffer-find-file 'ido 'find-file)
4649 (put 'dired-other-window 'ido 'dir)
4652 (defun ido-read-buffer (prompt &optional default require-match)
4653 "Ido replacement for the built-in `read-buffer'.
4654 Return the name of a buffer selected.
4655 PROMPT is the prompt to give to the user. DEFAULT if given is the default
4656 buffer to be selected, which will go to the front of the list.
4657 If REQUIRE-MATCH is non-nil, an existing buffer must be selected."
4658 (let* ((ido-current-directory nil)
4659 (ido-directory-nonreadable nil)
4660 (ido-directory-too-big nil)
4661 (ido-context-switch-command 'ignore)
4662 (buf (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match)))
4663 (if (eq ido-exit 'fallback)
4664 (let ((read-buffer-function nil))
4665 (run-hook-with-args 'ido-before-fallback-functions 'read-buffer)
4666 (read-buffer prompt default require-match))
4670 (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
4671 "Ido replacement for the built-in `read-file-name'.
4672 Read file name, prompting with PROMPT and completing in directory DIR.
4673 See `read-file-name' for additional parameters."
4676 ((or (eq predicate 'file-directory-p)
4677 (eq (get this-command 'ido) 'dir)
4678 (memq this-command ido-read-file-name-as-directory-commands))
4680 (ido-read-directory-name prompt dir default-filename mustmatch initial))
4681 (if (eq ido-exit 'fallback)
4682 (setq filename 'fallback)))
4683 ((and (not (eq (get this-command 'ido) 'ignore))
4684 (not (memq this-command ido-read-file-name-non-ido))
4685 (or (null predicate) (eq predicate 'file-exists-p)))
4686 (let* (ido-saved-vc-hb
4687 (ido-context-switch-command
4688 (if (eq (get this-command 'ido) 'find-file) nil 'ignore))
4689 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
4690 (minibuffer-completing-file-name t)
4691 (ido-current-directory (ido-expand-directory dir))
4692 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
4693 (ido-directory-too-big (and (not ido-directory-nonreadable)
4694 (ido-directory-too-big-p ido-current-directory)))
4695 (ido-work-directory-index -1)
4696 (ido-show-dot-for-dired (and ido-show-dot-for-dired
4697 (not default-filename)))
4698 (ido-work-file-index -1)
4699 (ido-find-literal nil))
4702 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial))
4704 ((eq ido-exit 'fallback)
4705 (setq filename 'fallback))
4706 ((eq ido-exit 'dired)
4707 (setq filename ido-current-directory))
4710 (concat ido-current-directory filename))))))
4712 (setq filename 'fallback)))
4713 (if (eq filename 'fallback)
4714 (let ((read-file-name-function nil))
4715 (run-hook-with-args 'ido-before-fallback-functions 'read-file-name)
4716 (read-file-name prompt dir default-filename mustmatch initial predicate))
4720 (defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial)
4721 "Ido replacement for the built-in `read-directory-name'.
4722 Read directory name, prompting with PROMPT and completing in directory DIR.
4723 See `read-directory-name' for additional parameters."
4725 (minibuffer-completing-file-name t)
4726 (ido-context-switch-command 'ignore)
4728 (ido-current-directory (ido-expand-directory dir))
4729 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
4730 (ido-directory-too-big (and (not ido-directory-nonreadable)
4731 (ido-directory-too-big-p ido-current-directory)))
4732 (ido-work-directory-index -1)
4733 (ido-work-file-index -1))
4735 (ido-read-internal 'dir prompt 'ido-file-history default-dirname mustmatch initial))
4737 (if (and (stringp filename) (string-equal filename "."))
4738 ido-current-directory
4739 (concat ido-current-directory filename)))))
4742 (defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def)
4743 "Ido replacement for the built-in `completing-read'.
4744 Read a string in the minibuffer with ido-style completion.
4745 PROMPT is a string to prompt with; normally it ends in a colon and a space.
4746 CHOICES is a list of strings which are the possible completions.
4747 PREDICATE is currently ignored; it is included to be compatible
4748 with `completing-read'.
4749 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
4750 the input is (or completes to) an element of CHOICES or is null.
4751 If the input is null, `ido-completing-read' returns DEF, or an empty
4752 string if DEF is nil, regardless of the value of REQUIRE-MATCH.
4753 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially,
4754 with point positioned at the end.
4755 HIST, if non-nil, specifies a history list.
4756 DEF, if non-nil, is the default value."
4757 (let ((ido-current-directory nil)
4758 (ido-directory-nonreadable nil)
4759 (ido-directory-too-big nil)
4760 (ido-context-switch-command 'ignore)
4761 (ido-choice-list choices))
4762 (ido-read-internal 'list prompt hist def require-match initial-input)))
4764 (defun ido-unload-function ()
4765 "Unload the Ido library."
4767 (setq minor-mode-map-alist (assq-delete-all 'ido-mode minor-mode-map-alist))
4768 ;; continue standard unloading
4773 ;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
4774 ;;; ido.el ends here