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