Replace Lisp calls to delete-backward-char by delete-char.
[bpt/emacs.git] / lisp / ido.el
index d4a8478..d34893d 100644 (file)
@@ -1,7 +1,7 @@
 ;;; ido.el --- interactively do things with buffers and files.
 
 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
 ;; to show you more of the matching files (depending on the setting
 ;; of the variables `resize-mini-windows' and `max-mini-window-height').
 ;; If you want ido to behave differently from the default minibuffer
-;; resizing behaviour, set the variable `ido-max-window-height'.
+;; resizing behavior, set the variable `ido-max-window-height'.
 ;;
 ;; Also, to improve the responsiveness of ido, the maximum number of
 ;; matching items is limited to 12, but you can increase or removed
 ;; To use ido for all buffer and file selections in Emacs, customize the
 ;; variable `ido-everywhere'.
 
-;; Using ido-like behaviour in other lisp packages
+;; Using ido-like behavior in other lisp packages
 ;; -----------------------------------------------
 
 ;; If you don't want to rely on the `ido-everywhere' functionality,
 
 ;;; Code:
 
-(provide 'ido)
-
-(defvar cua-inhibit-cua-keys)
+(defvar recentf-list)
 
 ;;; User Variables
 ;;
@@ -355,7 +353,7 @@ Setting this variable directly does not take effect;
 use either \\[customize] or the function `ido-mode'."
   :set #'(lambda (symbol value)
           (ido-mode value))
-  :initialize 'custom-initialize-set
+  :initialize 'custom-initialize-default
   :require 'ido
   :link '(emacs-commentary-link "ido.el")
   :set-after '(ido-save-directory-list-file
@@ -368,33 +366,23 @@ use either \\[customize] or the function `ido-mode'."
                  (const :tag "Switch off all" nil))
   :group 'ido)
 
-(defcustom ido-everywhere nil
-  "Use ido everywhere for reading file names and directories.
-Setting this variable directly does not work.  Use `customize' or
-call the function `ido-everywhere'."
-  :set #'(lambda (symbol value)
-          (ido-everywhere (if value 1 -1)))
-  :initialize 'custom-initialize-default
-  :type 'boolean
-  :group 'ido)
-
 (defcustom ido-case-fold case-fold-search
-  "*Non-nil if searching of buffer and file names should ignore case."
+  "Non-nil if searching of buffer and file names should ignore case."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-ignore-buffers
   '("\\` ")
-  "*List of regexps or functions matching buffer names to ignore.
+  "List of regexps or functions matching buffer names to ignore.
 For example, traditional behavior is not to list buffers whose names begin
 with a space, for which the regexp is `\\` '.  See the source file for
-example functions that filter buffernames."
+example functions that filter buffer names."
   :type '(repeat (choice regexp function))
   :group 'ido)
 
 (defcustom ido-ignore-files
   '("\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./")
-  "*List of regexps or functions matching file names to ignore.
+  "List of regexps or functions matching file names to ignore.
 For example, traditional behavior is not to list files whose names begin
 with a #, for which the regexp is `\\`#'.  See the source file for
 example functions that filter filenames."
@@ -402,18 +390,18 @@ example functions that filter filenames."
   :group 'ido)
 
 (defcustom ido-ignore-extensions t
-  "*Non-nil means ignore files in `completion-ignored-extensions' list."
+  "Non-nil means ignore files in `completion-ignored-extensions' list."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-show-dot-for-dired nil
-  "*Non-nil means to always put . as the first item in file name lists.
+  "Non-nil means to always put . as the first item in file name lists.
 This allows the current directory to be opened immediately with `dired'."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-file-extensions-order nil
-  "*List of file extensions specifying preferred order of file selections.
+  "List of file extensions specifying preferred order of file selections.
 Each element is either a string with `.' as the first char, an empty
 string matching files without extension, or t which is the default order
 for files with an unlisted file extension."
@@ -423,12 +411,12 @@ for files with an unlisted file extension."
 
 (defcustom ido-ignore-directories
   '("\\`CVS/" "\\`\\.\\./" "\\`\\./")
-  "*List of regexps or functions matching sub-directory names to ignore."
+  "List of regexps or functions matching sub-directory names to ignore."
   :type '(repeat (choice regexp function))
   :group 'ido)
 
 (defcustom ido-ignore-directories-merge nil
-  "*List of regexps or functions matching directory names to ignore during merge.
+  "List of regexps or functions matching directory names to ignore during merge.
 Directory names matched by one of the regexps in this list are not inserted
 in merged file and directory lists."
   :type '(repeat (choice regexp function))
@@ -446,7 +434,7 @@ in merged file and directory lists."
 ;;(setq ido-ignore-files '("^ " "\\.c\\'" "\\.h\\'"))
 
 (defcustom ido-default-file-method  'raise-frame
-  "*How to visit a new file when using `ido-find-file'.
+  "How to visit a new file when using `ido-find-file'.
 Possible values:
 `selected-window' Show new file in selected window
 `other-window'   Show new file in another window (same frame)
@@ -466,7 +454,7 @@ Possible values:
     :group 'ido)
 
 (defcustom ido-default-buffer-method  'raise-frame
-  "*How to switch to new buffer when using `ido-switch-buffer'.
+  "How to switch to new buffer when using `ido-switch-buffer'.
 See `ido-default-file-method' for details."
     :type '(choice (const :tag "Show in selected window" selected-window)
                   (const :tag "Show in other window" other-window)
@@ -483,7 +471,7 @@ See `ido-default-file-method' for details."
     :group 'ido)
 
 (defcustom ido-enable-flex-matching nil
-  "*Non-nil means that `ido' will do flexible string matching.
+  "Non-nil means that `ido' will do flexible string matching.
 Flexible matching means that if the entered string does not
 match any item, any item containing the entered characters
 in the given sequence will match."
@@ -492,35 +480,35 @@ in the given sequence will match."
 
 
 (defcustom ido-enable-regexp nil
-  "*Non-nil means that `ido' will do regexp matching.
+  "Non-nil means that `ido' will do regexp matching.
 Value can be toggled within `ido' using `ido-toggle-regexp'."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-enable-prefix nil
-  "*Non-nil means only match if the entered text is a prefix of file name.
-This behavior is like the standard emacs-completion.
+  "Non-nil means only match if the entered text is a prefix of file name.
+This behavior is like the standard Emacs completion.
 If nil, match if the entered text is an arbitrary substring.
 Value can be toggled within `ido' using `ido-toggle-prefix'."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-enable-dot-prefix nil
-  "*Non-nil means to match leading dot as prefix.
+  "Non-nil means to match leading dot as prefix.
 I.e. hidden files and buffers will match only if you type a dot
 as first char even if `ido-enable-prefix' is nil."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-confirm-unique-completion nil
-  "*Non-nil means that even a unique completion must be confirmed.
+  "Non-nil means that even a unique completion must be confirmed.
 This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer]
 even when there is only one unique completion."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-cannot-complete-command 'ido-completion-help
-  "*Command run when `ido-complete' can't complete any more.
+  "Command run when `ido-complete' can't complete any more.
 The most useful values are `ido-completion-help', which pops up a
 window with completion alternatives, or `ido-next-match' or
 `ido-prev-match', which cycle the buffer list."
@@ -529,20 +517,20 @@ window with completion alternatives, or `ido-next-match' or
 
 
 (defcustom ido-record-commands t
-  "*Non-nil means that `ido' will record commands in command history.
+  "Non-nil means that `ido' will record commands in command history.
 Note that the non-ido equivalent command is recorded."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-max-prospects 12
-  "*Non-zero means that the prospect list will be limited to than number of items.
+  "Non-zero means that the prospect list will be limited to that number of items.
 For a long list of prospects, building the full list for the minibuffer can take a
 non-negligible amount of time; setting this variable reduces that time."
   :type 'integer
   :group 'ido)
 
 (defcustom ido-max-file-prompt-width 0.35
-  "*Non-zero means that the prompt string be limited to than number of characters.
+  "Non-zero means that the prompt string be limited to that number of characters.
 If value is a floating point number, it specifies a fraction of the frame width."
   :type '(choice
          (integer :tag "Characters" :value 20)
@@ -552,7 +540,7 @@ If value is a floating point number, it specifies a fraction of the frame width.
   :group 'ido)
 
 (defcustom ido-max-window-height nil
-  "*Non-nil specifies a value to override `max-mini-window-height'."
+  "Non-nil specifies a value to override `max-mini-window-height'."
   :type '(choice
          (const :tag "Don't override" nil)
          (integer :tag "Number of lines" :value 1)
@@ -563,20 +551,20 @@ If value is a floating point number, it specifies a fraction of the frame width.
   :group 'ido)
 
 (defcustom ido-enable-last-directory-history t
-  "*Non-nil means that `ido' will remember latest selected directory names.
+  "Non-nil means that `ido' will remember latest selected directory names.
 See `ido-last-directory-list' and `ido-save-directory-list-file'."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-max-work-directory-list 50
-  "*Maximum number of working directories to record.
+  "Maximum number of working directories to record.
 This is the list of directories where files have most recently been opened.
 See `ido-work-directory-list' and `ido-save-directory-list-file'."
   :type 'integer
   :group 'ido)
 
 (defcustom ido-work-directory-list-ignore-regexps nil
-  "*List of regexps matching directories which should not be recorded.
+  "List of regexps matching directories which should not be recorded.
 Directory names matched by one of the regexps in this list are not inserted in
 the `ido-work-directory-list' list."
   :type '(repeat regexp)
@@ -584,7 +572,7 @@ the `ido-work-directory-list' list."
 
 
 (defcustom ido-use-filename-at-point nil
-  "*Non-nil means that ido shall look for a filename at point.
+  "Non-nil means that ido shall look for a filename at point.
 May use `ffap-guesser' to guess whether text at point is a filename.
 If found, use that as the starting point for filename selection."
   :type '(choice
@@ -595,44 +583,44 @@ If found, use that as the starting point for filename selection."
 
 
 (defcustom ido-use-url-at-point nil
-  "*Non-nil means that ido shall look for a URL at point.
+  "Non-nil means that ido shall look for a URL at point.
 If found, call `find-file-at-point' to visit it."
   :type 'boolean
   :group 'ido)
 
 
 (defcustom ido-enable-tramp-completion t
-  "*Non-nil means that ido shall perform tramp method and server name completion.
+  "Non-nil means that ido shall perform tramp method and server name completion.
 A tramp file name uses the following syntax: /method:user@host:filename."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-record-ftp-work-directories t
-  "*Non-nil means record ftp file names in the work directory list."
+  "Non-nil means record ftp file names in the work directory list."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-merge-ftp-work-directories nil
-  "*If nil means merging ignores ftp file names in the work directory list."
+  "If nil, merging ignores ftp file names in the work directory list."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-cache-ftp-work-directory-time 1.0
-  "*Maximum time to cache contents of an ftp directory (in hours).
+  "Maximum time to cache contents of an ftp directory (in hours).
 Use C-l in prompt to refresh list.
 If zero, ftp directories are not cached."
   :type 'number
   :group 'ido)
 
 (defcustom ido-slow-ftp-hosts nil
-  "*List of slow ftp hosts where ido prompting should not be used.
+  "List of slow ftp hosts where ido prompting should not be used.
 If an ftp host is on this list, ido automatically switches to the non-ido
 equivalent function, e.g. `find-file' rather than `ido-find-file'."
   :type '(repeat string)
   :group 'ido)
 
 (defcustom ido-slow-ftp-host-regexps nil
-  "*List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')."
+  "List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')."
   :type '(repeat regexp)
   :group 'ido)
 
@@ -640,7 +628,7 @@ equivalent function, e.g. `find-file' rather than `ido-find-file'."
   "Cached value from `ido-unc-hosts' function.")
 
 (defcustom ido-unc-hosts nil
-  "*List of known UNC host names to complete after initial //.
+  "List of known UNC host names to complete after initial //.
 If value is a function, that function is called to search network for
 hosts on first use of UNC path."
   :type '(choice (repeat :tag "List of UNC host names" string)
@@ -653,32 +641,32 @@ hosts on first use of UNC path."
   :group 'ido)
 
 (defcustom ido-downcase-unc-hosts t
-  "*Non-nil if UNC host names should be downcased."
+  "Non-nil if UNC host names should be downcased."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-ignore-unc-host-regexps nil
-  "*List of regexps matching UNC hosts to ignore.
+  "List of regexps matching UNC hosts to ignore.
 Case is ignored if `ido-downcase-unc-hosts' is set."
   :type '(repeat regexp)
   :group 'ido)
 
 (defcustom ido-cache-unc-host-shares-time 8.0
-  "*Maximum time to cache shares of an UNC host (in hours).
+  "Maximum time to cache shares of an UNC host (in hours).
 Use C-l in prompt to refresh list.
 If zero, UNC host shares are not cached."
   :type 'number
   :group 'ido)
 
 (defcustom ido-max-work-file-list 10
-  "*Maximum number of names of recently opened files to record.
-This is the list the file names (sans directory) which have most recently
+  "Maximum number of names of recently opened files to record.
+This is the list of the file names (sans directory) which have most recently
 been opened.  See `ido-work-file-list' and `ido-save-directory-list-file'."
   :type 'integer
   :group 'ido)
 
 (defcustom ido-work-directory-match-only t
-  "*Non-nil means to skip non-matching directories in the directory history.
+  "Non-nil means to skip non-matching directories in the directory history.
 When some text is already entered at the `ido-find-file' prompt, using
 \\[ido-prev-work-directory] or \\[ido-next-work-directory] will skip directories
 without any matching entries."
@@ -686,7 +674,7 @@ without any matching entries."
   :group 'ido)
 
 (defcustom ido-auto-merge-work-directories-length 0
-  "*Automatically switch to merged work directories during file name input.
+  "Automatically switch to merged work directories during file name input.
 The value is number of characters to type before switching to merged mode.
 If zero, the switch happens when no matches are found in the current directory.
 Automatic merging is disabled if the value is negative."
@@ -694,12 +682,12 @@ Automatic merging is disabled if the value is negative."
   :group 'ido)
 
 (defcustom ido-auto-merge-delay-time 0.70
-  "*Delay in seconds to wait for more input before doing auto merge."
+  "Delay in seconds to wait for more input before doing auto merge."
   :type 'number
   :group 'ido)
 
 (defcustom ido-auto-merge-inhibit-characters-regexp "[][*?~]"
-  "*Regexp matching characters which should inhibit automatic merging.
+  "Regexp matching characters which should inhibit automatic merging.
 When a (partial) file name matches this regexp, merging is inhibited."
   :type 'regexp
   :group 'ido)
@@ -710,7 +698,7 @@ When a (partial) file name matches this regexp, merging is inhibited."
   :group 'ido)
 
 (defcustom ido-max-dir-file-cache 100
-  "*Maximum number of working directories to be cached.
+  "Maximum number of working directories to be cached.
 This is the size of the cache of `file-name-all-completions' results.
 Each cache entry is time stamped with the modification time of the
 directory.  Some systems, like Windows, have unreliable directory
@@ -722,7 +710,7 @@ See also `ido-dir-file-cache' and `ido-save-directory-list-file'."
   :group 'ido)
 
 (defcustom ido-max-directory-size 30000
-  "*Maximum size (in bytes) for directories to use ido completion.
+  "Maximum size (in bytes) for directories to use ido completion.
 If you enter a directory with a size larger than this size, ido will
 not provide the normal completion.  To show the completions, use C-a."
   :type '(choice (const :tag "No limit" nil)
@@ -730,12 +718,12 @@ not provide the normal completion.  To show the completions, use C-a."
   :group 'ido)
 
 (defcustom ido-rotate-file-list-default nil
-  "*Non-nil means that `ido' will always rotate file list to get default in front."
+  "Non-nil means that `ido' will always rotate file list to get default in front."
   :type 'boolean
   :group 'ido)
 
 (defcustom ido-enter-matching-directory 'only
-  "*Additional methods to enter sub-directory of first/only matching item.
+  "Additional methods to enter sub-directory of first/only matching item.
 If value is 'first, enter first matching sub-directory when typing a slash.
 If value is 'only, typing a slash only enters the sub-directory if it is
 the only matching item.
@@ -748,7 +736,7 @@ matching item, even without typing a slash."
   :group 'ido)
 
 (defcustom ido-create-new-buffer 'prompt
-  "*Specify whether a new buffer is created if no buffer matches substring.
+  "Specify whether a new buffer is created if no buffer matches substring.
 Choices are 'always to create new buffers unconditionally, 'prompt to
 ask user whether to create buffer, or 'never to never create new buffer."
   :type '(choice (const always)
@@ -757,22 +745,22 @@ ask user whether to create buffer, or 'never to never create new buffer."
   :group 'ido)
 
 (defcustom ido-setup-hook  nil
-  "*Hook run after the ido variables and keymap have been setup.
+  "Hook run after the ido variables and keymap have been setup.
 The dynamic variable `ido-cur-item' contains the current type of item that
-is read by ido, possible values are file, dir, buffer, and list.
+is read by ido; possible values are file, dir, buffer, and list.
 Additional keys can be defined in `ido-completion-map'."
   :type 'hook
   :group 'ido)
 
 (defcustom ido-separator nil
-  "*String used by ido to separate the alternatives in the minibuffer.
+  "String used by ido to separate the alternatives in the minibuffer.
 Obsolete.  Set 3rd element of `ido-decorations' instead."
   :type '(choice string (const nil))
   :group 'ido)
 
-(defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]")
-  "*List of strings used by ido to display the alternatives in the minibuffer.
-There are 10 elements in this list:
+(defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")
+  "List of strings used by ido to display the alternatives in the minibuffer.
+There are 11 elements in this list:
 1st and 2nd elements are used as brackets around the prospect list,
 3rd element is the separator between prospects (ignored if `ido-separator' is set),
 4th element is the string inserted at the end of a truncated list of prospects,
@@ -781,24 +769,43 @@ can be completed using TAB,
 7th element is the string displayed when there are no matches, and
 8th element is displayed if there is a single match (and faces are not used),
 9th element is displayed when the current directory is non-readable,
-10th element is displayed when directory exceeds `ido-max-directory-size'."
+10th element is displayed when directory exceeds `ido-max-directory-size',
+11th element is displayed to confirm creating new file or buffer."
   :type '(repeat string)
   :group 'ido)
 
+(defcustom ido-use-virtual-buffers nil
+  "If non-nil, refer to past buffers as well as existing ones.
+Essentially it works as follows: Say you are visiting a file and
+the buffer gets cleaned up by mignight.el.  Later, you want to
+switch to that buffer, but find it's no longer open.  With
+virtual buffers enabled, the buffer name stays in the buffer
+list (using the ido-virtual face, and always at the end), and if
+you select it, it opens the file back up again.  This allows you
+to think less about whether recently opened files are still open
+or not.  Most of the time you can quit Emacs, restart, and then
+switch to a file buffer that was previously open as if it still
+were.
+    This feature relies upon the `recentf' package, which will be
+enabled if this variable is configured to a non-nil value."
+  :version "24.1"
+  :type 'boolean
+  :group 'ido)
+
 (defcustom ido-use-faces t
-  "*Non-nil means use ido faces to highlighting first match, only match and
+  "Non-nil means use ido faces to highlighting first match, only match and
 subdirs in the alternatives."
   :type 'boolean
   :group 'ido)
 
 (defface ido-first-match  '((t (:bold t)))
-  "*Face used by ido for highlighting first match."
+  "Face used by ido for highlighting first match."
   :group 'ido)
 
 (defface ido-only-match  '((((class color))
                                  (:foreground "ForestGreen"))
                                 (t (:italic t)))
-  "*Face used by ido for highlighting only match."
+  "Face used by ido for highlighting only match."
   :group 'ido)
 
 (defface ido-subdir  '((((min-colors 88) (class color))
@@ -806,7 +813,12 @@ subdirs in the alternatives."
                            (((class color))
                              (:foreground "red"))
                             (t (:underline t)))
-  "*Face used by ido for highlighting subdirs in the alternatives."
+  "Face used by ido for highlighting subdirs in the alternatives."
+  :group 'ido)
+
+(defface ido-virtual '((t (:inherit font-lock-builtin-face)))
+  "Face used by ido for matching virtual buffer names."
+  :version "24.1"
   :group 'ido)
 
 (defface ido-indicator  '((((min-colors 88) (class color))
@@ -818,7 +830,7 @@ subdirs in the alternatives."
                                 :background "red"
                                 :width condensed))
                               (t (:inverse-video t)))
-  "*Face used by ido for highlighting its indicators."
+  "Face used by ido for highlighting its indicators."
   :group 'ido)
 
 (defface ido-incomplete-regexp
@@ -828,28 +840,28 @@ subdirs in the alternatives."
   :group 'ido)
 
 (defcustom ido-make-file-list-hook  nil
-  "*List of functions to run when the list of matching files is created.
+  "List of functions to run when the list of matching files is created.
 Each function on the list may modify the dynamically bound variable
 `ido-temp-list' which contains the current list of matching files."
   :type 'hook
   :group 'ido)
 
 (defcustom ido-make-dir-list-hook  nil
-  "*List of functions to run when the list of matching directories is created.
+  "List of functions to run when the list of matching directories is created.
 Each function on the list may modify the dynamically bound variable
 `ido-temp-list' which contains the current list of matching directories."
   :type 'hook
   :group 'ido)
 
 (defcustom ido-make-buffer-list-hook  nil
-  "*List of functions to run when the list of matching buffers is created.
+  "List of functions to run when the list of matching buffers is created.
 Each function on the list may modify the dynamically bound variable
 `ido-temp-list' which contains the current list of matching buffer names."
   :type 'hook
   :group 'ido)
 
 (defcustom ido-rewrite-file-prompt-functions nil
-  "*List of functions to run when the find-file prompt is created.
+  "List of functions to run when the find-file prompt is created.
 Each function on the list may modify the following dynamically bound
 variables:
   dirname   - the (abbreviated) directory name
@@ -857,7 +869,7 @@ variables:
   max-width - the max width of the resulting dirname; nil means no limit
   prompt    - the basic prompt (e.g. \"Find File: \")
   literal   - the string shown if doing \"literal\" find; set to nil to omit
-  vc-off    - the string shown if version control is inhibited; set to nit to omit
+  vc-off    - the string shown if version control is inhibited; set to nil to omit
   prefix    - either nil or a fixed prefix for the dirname
 
 The following variables are available, but should not be changed:
@@ -877,13 +889,13 @@ also modify the dynamic variables described for the variable
 `ido-rewrite-file-prompt-functions'.")
 
 (defcustom ido-completion-buffer "*Ido Completions*"
-  "*Name of completion buffer used by ido.
+  "Name of completion buffer used by ido.
 Set to nil to disable completion buffers popping up."
   :type 'string
   :group 'ido)
 
 (defcustom ido-completion-buffer-all-completions nil
-  "*Non-nil means to show all completions in completion buffer.
+  "Non-nil means to show all completions in completion buffer.
 Otherwise, only the current list of matches is shown."
   :type 'boolean
   :group 'ido)
@@ -893,7 +905,7 @@ Otherwise, only the current list of matches is shown."
 See documentation of `walk-windows' for useful values.")
 
 (defcustom ido-minibuffer-setup-hook nil
-  "*Ido-specific customization of minibuffer setup.
+  "Ido-specific customization of minibuffer setup.
 
 This hook is run during minibuffer setup if `ido' is active.
 It is intended for use in customizing ido for interoperation
@@ -910,7 +922,7 @@ ido is running.  Copied from `icomplete-minibuffer-setup-hook'."
   :type 'hook
   :group 'ido)
 
-(defcustom ido-save-directory-list-file "~/.ido.last"
+(defcustom ido-save-directory-list-file (convert-standard-filename "~/.ido.last")
   "File in which the ido state is saved between invocations.
 Variables stored are: `ido-last-directory-list', `ido-work-directory-list',
 `ido-work-file-list', and `ido-dir-file-cache'.
@@ -1041,6 +1053,11 @@ so that it doesn't interfere with other minibuffer usage.")
   "Non-nil means to explicitly cursor on entry to minibuffer.
 Value is an integer which is number of chars to right of prompt.")
 
+(defvar ido-virtual-buffers nil
+  "List of virtual buffers, that is, past visited files.
+This is a copy of `recentf-list', pared down and with faces applied.
+Only used if `ido-use-virtual-buffers' is non-nil.")
+
 ;;; Variables with dynamic bindings.
 ;;; Declared here to keep the byte compiler quiet.
 
@@ -1053,11 +1070,11 @@ Value is an integer which is number of chars to right of prompt.")
 ;; Stores the current list of items that will be searched through.
 ;; The list is ordered, so that the most interesting item comes first,
 ;; although by default, the files visible in the current frame are put
-;; at the end of the list.  Created by `ido-make-item-list'.
-(defvar ido-cur-list)
+;; at the end of the list.
+(defvar ido-cur-list nil)
 
 ;; Stores the choice list for ido-completing-read
-(defvar ido-choice-list)
+(defvar ido-choice-list nil)
 
 ;; Stores the list of items which are ignored when building
 ;; `ido-cur-list'.  It is in no specific order.
@@ -1084,6 +1101,9 @@ Value is an integer which is number of chars to right of prompt.")
 ;; Non-nil if matching file must be selected.
 (defvar ido-require-match)
 
+;; Non-nil if we should add [confirm] to prompt
+(defvar ido-show-confirm-message)
+
 ;; Stores a temporary version of the file list being created.
 (defvar ido-temp-list)
 
@@ -1447,6 +1467,25 @@ Removes badly formatted data and ignored directories."
   ;; ido kill emacs hook
   (ido-save-history))
 
+(define-minor-mode ido-everywhere
+  "Toggle using ido speed-ups everywhere file and directory names are read.
+With ARG, turn ido speed-up on if arg is positive, off otherwise."
+  :global t
+  :group 'ido
+  (when (get 'ido-everywhere 'file)
+    (setq read-file-name-function (car (get 'ido-everywhere 'file)))
+    (put 'ido-everywhere 'file nil))
+  (when (get 'ido-everywhere 'buffer)
+    (setq read-buffer-function (car (get 'ido-everywhere 'buffer)))
+    (put 'ido-everywhere 'buffer nil))
+  (when ido-everywhere
+    (when (memq ido-mode '(both file))
+      (put 'ido-everywhere 'file (cons read-file-name-function nil))
+      (setq read-file-name-function 'ido-read-file-name))
+    (when (memq ido-mode '(both buffer))
+      (put 'ido-everywhere 'buffer (cons read-buffer-function nil))
+      (setq read-buffer-function 'ido-read-buffer))))
+
 (defvar ido-minor-mode-map-entry nil)
 
 ;;;###autoload
@@ -1490,15 +1529,21 @@ This function also adds a hook to the minibuffer."
        (define-key map [remap insert-file] 'ido-insert-file)
        (define-key map [remap list-directory] 'ido-list-directory)
        (define-key map [remap dired] 'ido-dired)
-       (define-key map [remap find-file-other-window] 'ido-find-file-other-window)
-       (define-key map [remap find-file-read-only-other-window] 'ido-find-file-read-only-other-window)
-       (define-key map [remap find-file-other-frame] 'ido-find-file-other-frame)
-       (define-key map [remap find-file-read-only-other-frame] 'ido-find-file-read-only-other-frame))
+       (define-key map [remap find-file-other-window]
+          'ido-find-file-other-window)
+       (define-key map [remap find-file-read-only-other-window]
+          'ido-find-file-read-only-other-window)
+       (define-key map [remap find-file-other-frame]
+          'ido-find-file-other-frame)
+       (define-key map [remap find-file-read-only-other-frame]
+          'ido-find-file-read-only-other-frame))
 
       (when (memq ido-mode '(buffer both))
        (define-key map [remap switch-to-buffer] 'ido-switch-buffer)
-       (define-key map [remap switch-to-buffer-other-window] 'ido-switch-buffer-other-window)
-       (define-key map [remap switch-to-buffer-other-frame] 'ido-switch-buffer-other-frame)
+       (define-key map [remap switch-to-buffer-other-window]
+          'ido-switch-buffer-other-window)
+       (define-key map [remap switch-to-buffer-other-frame]
+          'ido-switch-buffer-other-frame)
        (define-key map [remap insert-buffer] 'ido-insert-buffer)
        (define-key map [remap kill-buffer] 'ido-kill-buffer)
        (define-key map [remap display-buffer] 'ido-display-buffer))
@@ -1506,29 +1551,9 @@ This function also adds a hook to the minibuffer."
       (if ido-minor-mode-map-entry
          (setcdr ido-minor-mode-map-entry map)
        (setq ido-minor-mode-map-entry (cons 'ido-mode map))
-       (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry)))))
+       (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry))))
 
-
-(defun ido-everywhere (arg)
-  "Toggle using ido speed-ups everywhere file and directory names are read.
-With ARG, turn ido speed-up on if arg is positive, off otherwise."
-  (interactive "P")
-  (setq ido-everywhere (if arg
-                          (> (prefix-numeric-value arg) 0)
-                        (not ido-everywhere)))
-  (when (get 'ido-everywhere 'file)
-    (setq read-file-name-function (car (get 'ido-everywhere 'file)))
-    (put 'ido-everywhere 'file nil))
-  (when (get 'ido-everywhere 'buffer)
-    (setq read-buffer-function (car (get 'ido-everywhere 'buffer)))
-    (put 'ido-everywhere 'buffer nil))
-  (when ido-everywhere
-    (when (memq ido-mode '(both file))
-      (put 'ido-everywhere 'file (cons read-file-name-function nil))
-      (setq read-file-name-function 'ido-read-file-name))
-    (when (memq ido-mode '(both buffer))
-      (put 'ido-everywhere 'buffer (cons read-buffer-function nil))
-      (setq read-buffer-function 'ido-read-buffer))))
+  (message "Ido mode %s" (if ido-mode "enabled" "disabled")))
 
 
 ;;; IDO KEYMAP
@@ -1598,7 +1623,6 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise."
     (define-key map "\C-o" 'ido-copy-current-word)
     (define-key map "\C-w" 'ido-copy-current-file-name)
     (define-key map [(meta ?l)] 'ido-toggle-literal)
-    (define-key map "\C-v" 'ido-toggle-vc)
     (set-keymap-parent map ido-file-dir-completion-map)
     (setq ido-file-completion-map map))
 
@@ -1607,6 +1631,7 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise."
     (define-key map "\C-x\C-f" 'ido-enter-find-file)
     (define-key map "\C-x\C-b" 'ido-fallback-command)
     (define-key map "\C-k" 'ido-kill-buffer-at-head)
+    (define-key map "\C-o" 'ido-toggle-virtual-buffers)
     (set-keymap-parent map ido-common-completion-map)
     (setq ido-buffer-completion-map map)))
 
@@ -1825,6 +1850,7 @@ If INITIAL is non-nil, it specifies the initial input string."
        (ido-case-fold ido-case-fold)
        (ido-enable-prefix ido-enable-prefix)
        (ido-enable-regexp ido-enable-regexp)
+       (ido-show-confirm-message nil)
        )
 
     (ido-setup-completion-map)
@@ -2063,6 +2089,7 @@ If INITIAL is non-nil, it specifies the initial input string."
 
        ;; Handling the require-match must be done in a better way.
        ((and require-match
+            (not (memq require-match '(confirm confirm-after-completion)))
             (not (if ido-directory-too-big
                      (file-exists-p (concat ido-current-directory ido-final-text))
                    (ido-existing-item-p))))
@@ -2154,14 +2181,22 @@ If cursor is not at the end of the user input, move to end of input."
           (ido-current-directory nil)
           (ido-directory-nonreadable nil)
           (ido-directory-too-big nil)
-          (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default nil initial)))
+          (ido-use-virtual-buffers (if (eq method 'kill)
+                                       nil    ;; Don't consider virtual buffers for killing
+                                     ido-use-virtual-buffers))
+          (require-match (confirm-nonexistent-file-or-buffer))
+          (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default
+                                  require-match initial))
+          filename)
 
       ;; Choose the buffer name: either the text typed in, or the head
       ;; of the list of matches
 
       (cond
        ((eq ido-exit 'find-file)
-       (ido-file-internal ido-default-file-method nil nil nil nil ido-text))
+       (ido-file-internal
+        (if (memq method '(other-window other-frame)) method ido-default-file-method)
+        nil nil nil nil ido-text))
 
        ((eq ido-exit 'insert-file)
        (ido-file-internal 'insert 'insert-file nil "Insert file: " nil ido-text 'ido-enter-insert-buffer))
@@ -2188,11 +2223,23 @@ If cursor is not at the end of the user input, move to end of input."
                 (point))))
          (ido-visit-buffer buf method t)))
 
+       ;; check for a virtual buffer reference
+       ((and ido-use-virtual-buffers ido-virtual-buffers
+            (setq filename (assoc buf ido-virtual-buffers)))
+       (ido-visit-buffer (find-file-noselect (cdr filename)) method t))
+
+       ((and (eq ido-create-new-buffer 'prompt)
+            (null require-match)
+            (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
+       nil)
+
        ;; buffer doesn't exist
-       ((eq ido-create-new-buffer 'never)
+       ((and (eq ido-create-new-buffer 'never)
+            (null require-match))
        (message "No buffer matching `%s'" buf))
 
        ((and (eq ido-create-new-buffer 'prompt)
+            (null require-match)
             (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
        nil)
 
@@ -2267,7 +2314,8 @@ If cursor is not at the end of the user input, move to end of input."
           (or ido-use-url-at-point ido-use-filename-at-point))
       (let (fn d)
        (require 'ffap)
-       ;; Duplicate code from ffap-guesser as we want different behaviour for files and URLs.
+       ;; Duplicate code from ffap-guesser as we want different
+       ;; behavior for files and URLs.
        (cond
         ((with-no-warnings
            (and ido-use-url-at-point
@@ -2283,7 +2331,10 @@ If cursor is not at the end of the user input, move to end of input."
                              (ffap-guesser)
                            (ffap-string-at-point))))
               (not (string-match "^http:/" fn))
-              (setq d (file-name-directory fn))
+              (let ((absolute-fn (expand-file-name fn)))
+                (setq d (if (file-directory-p absolute-fn)
+                            (file-name-as-directory absolute-fn)
+                          (file-name-directory absolute-fn))))
               (file-directory-p d))
          (setq ido-current-directory d)
          (setq initial (file-name-nondirectory fn))))))
@@ -2301,7 +2352,7 @@ If cursor is not at the end of the user input, move to end of input."
                                            (or prompt "Find file: ")
                                            'ido-file-history
                                            (and (eq method 'alt-file) buffer-file-name)
-                                           nil initial))))
+                                           (confirm-nonexistent-file-or-buffer) initial))))
 
       ;; Choose the file name: either the text typed in, or the head
       ;; of the list of matches
@@ -2317,7 +2368,9 @@ If cursor is not at the end of the user input, move to end of input."
          (call-interactively this-command)))
 
        ((eq ido-exit 'switch-to-buffer)
-       (ido-buffer-internal ido-default-buffer-method nil nil nil ido-text))
+       (ido-buffer-internal
+        (if (memq method '(other-window other-frame)) method ido-default-buffer-method)
+        nil nil nil ido-text))
 
        ((eq ido-exit 'insert-buffer)
        (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil ido-text 'ido-enter-insert-file))
@@ -2358,7 +2411,7 @@ If cursor is not at the end of the user input, move to end of input."
              (ido-record-command method dirname)
              (ido-record-work-directory)
              (funcall method dirname))
-            ((y-or-n-p (format "Directory %s does not exist. Create it? " filename))
+            ((y-or-n-p (format "Directory %s does not exist.  Create it? " filename))
              (ido-record-command method dirname)
              (ido-record-work-directory dirname)
              (make-directory-internal dirname)
@@ -2537,10 +2590,10 @@ If no merge has yet taken place, toggle automatic merging option."
 (defun ido-magic-forward-char (arg)
   "Move forward in user input or perform magic action.
 If no user input is present, or at end of input, perform magic actions:
-C-x C-b ... C-f  switch to ido-find-file.
-C-x C-f ... C-f  fallback to non-ido find-file.
-C-x C-d ... C-f  fallback to non-ido brief dired.
-C-x d ... C-f    fallback to non-ido dired."
+C-x C-b ... C-f  switch to `ido-find-file'.
+C-x C-f ... C-f  fallback to non-ido `find-file'.
+C-x C-d ... C-f  fallback to non-ido brief `dired'.
+C-x d ... C-f    fallback to non-ido `dired'."
   (interactive "P")
   (cond
    ((or arg (not (eobp)))
@@ -2584,7 +2637,7 @@ C-x C-b C-b  fallback to non-ido `switch-to-buffer'."
 (defun ido-magic-delete-char (arg)
   "Delete following char in user input or perform magic action.
 If at end of user input, perform magic actions:
-C-x C-f ... C-d  enter dired on current directory."
+C-x C-f ... C-d  enter `dired' on current directory."
   (interactive "P")
   (cond
    ((or arg (not (eobp)))
@@ -2654,6 +2707,16 @@ C-x C-f ... C-d  enter dired on current directory."
        (setq ido-exit 'keep)
        (exit-minibuffer))))
 
+(defun ido-toggle-virtual-buffers ()
+  "Toggle the use of virtual buffers.
+See `ido-use-virtual-buffers' for explanation of virtual buffer."
+  (interactive)
+  (when (and ido-mode (eq ido-cur-item 'buffer))
+    (setq ido-use-virtual-buffers (not ido-use-virtual-buffers))
+    (setq ido-text-init ido-text)
+    (setq ido-exit 'refresh)
+    (exit-minibuffer)))
+
 (defun ido-reread-directory ()
   "Read current directory again.
 May be useful if cached version is no longer valid, but directory
@@ -2673,6 +2736,12 @@ timestamp has not changed (e.g. with ftp or on Windows)."
   "Exit minibuffer, but make sure we have a match if one is needed."
   (interactive)
   (if (and (or (not ido-require-match)
+              (if (memq ido-require-match '(confirm confirm-after-completion))
+                  (if (or (eq ido-cur-item 'dir)
+                          (eq last-command this-command))
+                      t
+                    (setq ido-show-confirm-message t)
+                    nil))
                (ido-existing-item-p))
            (not ido-incomplete-regexp))
       (exit-minibuffer)))
@@ -2746,7 +2815,7 @@ If no buffer or file exactly matching the prompt exists, maybe create a new one.
    ((eq this-original-command 'viper-del-backward-char-in-insert)
     (funcall this-original-command))
    (t
-    (delete-backward-char (prefix-numeric-value count)))))
+    (delete-char (- (prefix-numeric-value count))))))
 
 (defun ido-delete-backward-word-updir (count)
   "Delete all chars backwards, or at beginning of buffer, go up one level."
@@ -2882,7 +2951,7 @@ If input stack is non-empty, delete current directory component."
 
 (defun ido-pop-dir (arg)
   "Pop directory from input stack back to input.
-With \\[universal-argument], pop all element."
+With \\[universal-argument], pop all elements."
   (interactive "P")
   (when ido-input-stack
     (setq ido-exit (if arg 'pop-all 'pop))
@@ -2962,8 +3031,7 @@ If repeated, insert text from buffer instead."
 (defun ido-copy-current-word (all)
   "Insert current word (file or directory name) from current buffer."
   (interactive "P")
-  (let ((word (save-excursion
-               (set-buffer ido-entry-buffer)
+  (let ((word (with-current-buffer ido-entry-buffer
                (let ((p (point)) start-line end-line start-name name)
                  (if (and mark-active (/= p (mark)))
                      (setq start-name (mark))
@@ -3332,15 +3400,41 @@ for first matching file."
     (if ido-temp-list
        (nconc ido-temp-list ido-current-buffers)
       (setq ido-temp-list ido-current-buffers))
-    (if default
-       (progn
-         (setq ido-temp-list
-               (delete default ido-temp-list))
-         (setq ido-temp-list
-               (cons default ido-temp-list))))
+    (when (and default (buffer-live-p (get-buffer default)))
+      (setq ido-temp-list
+           (cons default (delete default ido-temp-list))))
+    (if ido-use-virtual-buffers
+       (ido-add-virtual-buffers-to-list))
     (run-hooks 'ido-make-buffer-list-hook)
     ido-temp-list))
 
+(defun ido-add-virtual-buffers-to-list ()
+  "Add recently visited files, and bookmark files, to the buffer list.
+This is to make them appear as if they were \"virtual buffers\"."
+  ;; If no buffers matched, and virtual buffers are being used, then
+  ;; consult the list of past visited files, to see if we can find
+  ;; the file which the user might thought was still open.
+  (unless recentf-mode (recentf-mode 1))
+  (setq ido-virtual-buffers nil)
+  (let (name)
+    (dolist (head recentf-list)
+      (and (setq name (file-name-nondirectory head))
+           (null (get-file-buffer head))
+           (not (assoc name ido-virtual-buffers))
+           (not (member name ido-temp-list))
+           (not (ido-ignore-item-p name ido-ignore-buffers))
+           ;;(file-exists-p head)
+           (push (cons name head) ido-virtual-buffers))))
+  (when ido-virtual-buffers
+    (if ido-use-faces
+       (dolist (comp ido-virtual-buffers)
+         (put-text-property 0 (length (car comp))
+                            'face 'ido-virtual
+                            (car comp))))
+    (setq ido-temp-list
+         (nconc ido-temp-list
+                (nreverse (mapcar #'car ido-virtual-buffers))))))
+
 (defun ido-make-choice-list (default)
   ;; Return the current list of choices.
   ;; If DEFAULT is non-nil, and corresponds to an element of choices,
@@ -3380,7 +3474,7 @@ for first matching file."
     ;; Strip method:user@host: part of tramp completions.
     ;; Tramp completions do not include leading slash.
     (let* ((len (1- (length dir)))
-          (tramp-completion-mode t)
+          (non-essential t)
           (compl
            (or (file-name-all-completions "" dir)
                ;; work around bug in ange-ftp.
@@ -3578,6 +3672,7 @@ for first matching file."
   ;; Used by `ido-get-buffers-in-frames' to walk through all windows
   (let ((buf (buffer-name (window-buffer win))))
        (unless (or (member buf ido-bufs-in-frame)
+                   (minibufferp buf)
                    (member buf ido-ignore-item-temp-list))
          ;; Only add buf if it is not already in list.
          ;; This prevents same buf in two different windows being
@@ -3640,6 +3735,7 @@ for first matching file."
              matches (cdr error))))
     (when prefix-matches
       (ido-trace "prefix match" prefix-matches)
+      ;; Bug#2042.
       (setq matches (nconc prefix-matches matches)))
     (when suffix-matches
       (ido-trace "suffix match" (list text suffix-re suffix-matches))
@@ -3743,7 +3839,7 @@ for first matching file."
   ;; Return dotted pair (RES . 1).
   (cons res 1))
 
-(defun ido-choose-completion-string (choice buffer mini-p base-size)
+(defun ido-choose-completion-string (choice &rest ignored)
   (when (ido-active)
     ;; Insert the completion into the buffer where completion was requested.
     (if (get-buffer ido-completion-buffer)
@@ -3817,6 +3913,27 @@ for first matching file."
              ;;(add-hook 'completion-setup-hook 'completion-setup-function)
              (display-completion-list completion-list)))))))
 
+(defun ido-kill-buffer-internal (buf)
+  "Kill buffer BUF and rebuild ido's buffer list if needed."
+  (if (not (kill-buffer buf))
+      ;; buffer couldn't be killed.
+      (setq ido-rescan t)
+    ;; else buffer was killed so remove name from list.
+    (setq ido-cur-list (delq buf ido-cur-list))
+    ;; Some packages, like uniquify.el, may rename buffers when one
+    ;; is killed, so we need to test this condition to avoid using
+    ;; an outdated list of buffer names. We don't want to always
+    ;; rebuild the list of buffers, as this alters the previous
+    ;; buffer order that the user was seeing on the prompt. However,
+    ;; when we rebuild the list, we try to keep the previous second
+    ;; buffer as the first one.
+    (catch 'update
+      (dolist (b ido-cur-list)
+       (unless (get-buffer b)
+         (setq ido-cur-list (ido-make-buffer-list (cadr ido-matches)))
+         (setq ido-rescan t)
+         (throw 'update nil))))))
+
 ;;; KILL CURRENT BUFFER
 (defun ido-kill-buffer-at-head ()
   "Kill the buffer at the head of `ido-matches'.
@@ -3827,7 +3944,7 @@ If cursor is not at the end of the user input, delete to end of input."
     (let ((enable-recursive-minibuffers t)
          (buf (ido-name (car ido-matches))))
       (when buf
-       (kill-buffer buf)
+       (ido-kill-buffer-internal buf)
        ;; Check if buffer still exists.
        (if (get-buffer buf)
            ;; buffer couldn't be killed.
@@ -3871,7 +3988,7 @@ Record command in `command-history' if optional RECORD is non-nil."
      ((eq method 'kill)
       (if record
          (ido-record-command 'kill-buffer buffer))
-      (kill-buffer buffer))
+      (ido-kill-buffer-internal buffer))
 
      ((eq method 'other-window)
       (if record
@@ -4170,8 +4287,7 @@ For details of keybindings, see `ido-find-file'."
            ido-text-init contents
            ido-rotate-temp t
            ido-exit 'refresh)
-      (save-excursion
-       (set-buffer buffer)
+      (with-current-buffer buffer
        (ido-tidy))
       (throw 'ido contents))))
 
@@ -4390,6 +4506,7 @@ For details of keybindings, see `ido-find-file'."
                    minibuffer-completion-table
                    minibuffer-completion-predicate
                    (not minibuffer-completion-confirm))))
+         (setq ido-show-confirm-message nil)
          (ido-trace "inf" inf)
          (insert inf))
        ))))
@@ -4422,6 +4539,8 @@ For details of keybindings, see `ido-find-file'."
 
     (cond ((null comps)
           (cond
+           (ido-show-confirm-message
+            (or (nth 10 ido-decorations) " [Confirm]"))
            (ido-directory-nonreadable
             (or (nth 8 ido-decorations) " [Not readable]"))
            (ido-directory-too-big
@@ -4488,7 +4607,6 @@ For details of keybindings, see `ido-find-file'."
   (when (ido-active)
     (add-hook 'pre-command-hook 'ido-tidy nil t)
     (add-hook 'post-command-hook 'ido-exhibit nil t)
-    (setq cua-inhibit-cua-keys t)
     (when (featurep 'xemacs)
       (ido-exhibit)
       (goto-char (point-min)))
@@ -4654,6 +4772,14 @@ DEF, if non-nil, is the default value."
        (ido-choice-list choices))
     (ido-read-internal 'list prompt hist def require-match initial-input)))
 
+(defun ido-unload-function ()
+  "Unload the Ido library."
+  (ido-mode -1)
+  (setq minor-mode-map-alist (assq-delete-all 'ido-mode minor-mode-map-alist))
+  ;; continue standard unloading
+  nil)
+
+(provide 'ido)
 
 ;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
 ;;; ido.el ends here