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