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