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