]> code.delx.au - gnu-emacs/blobdiff - lisp/ido.el
Merge from emacs-24; up to 2012-05-07T14:57:18Z!michael.albinus@gmx.de
[gnu-emacs] / lisp / ido.el
index d1b5fd07938c70f3804e4e1e057facd8b56e7f15..d48e7ba858ba6209192b45fbb5b358ec637bac66 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ido.el --- interactively do things with buffers and files
 
-;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
 ;; The highlighting of matching items is controlled via ido-use-faces.
 ;; The faces used are ido-first-match, ido-only-match and
 ;; ido-subdir.
-;; Colouring of the matching item was suggested by
+;; Coloring of the matching item was suggested by
 ;; Carsten Dominik (dominik@strw.leidenuniv.nl).
 
 ;; Replacement for read-buffer and read-file-name
 ;; can be used by other packages to read a buffer name, a file name,
 ;; or a directory name in the `ido' way.
 
-;;; Acknowledgements
+;;; Acknowledgments
 
 ;; Infinite amounts of gratitude goes to Stephen Eglen <stephen@cns.ed.ac.uk>
 ;; who wrote iswitch-buffer mode - from which I ripped off 99% of the code
 ;; ifindf package back into iswitchb.
 ;;
 ;; This is basically what ido (interactively do) is all about; but I
-;; found it ackward to merge my changes into the "iswitchb-" namespace,
+;; found it awkward to merge my changes into the "iswitchb-" namespace,
 ;; so I invented a common "ido-" namespace for the merged packages.
 ;;
 ;; This version is based on ido.el version 1.57 released on
@@ -461,12 +461,6 @@ See `ido-default-file-method' for details."
                   (const :tag "Show in other frame" other-frame)
                   (const :tag "Ask to show in other frame" maybe-frame)
                   (const :tag "Raise frame if already shown" raise-frame))
-    :type '(choice (const selected-window)
-                  (const other-window)
-                  (const display)
-                  (const other-frame)
-                  (const maybe-frame)
-                  (const raise-frame))
     :group 'ido)
 
 (defcustom ido-enable-flex-matching nil
@@ -499,6 +493,18 @@ as first char even if `ido-enable-prefix' is nil."
   :type 'boolean
   :group 'ido)
 
+;; See http://debbugs.gnu.org/2042 for more info.
+(defcustom ido-buffer-disable-smart-matches t
+  "Non-nil means not to re-order matches for buffer switching.
+By default, ido aranges matches in the following order:
+
+  full-matches > suffix matches > prefix matches > remaining matches
+
+which can get in the way for buffer switching."
+  :version "24.3"
+  :type 'boolean
+  :group 'ido)
+
 (defcustom ido-confirm-unique-completion nil
   "Non-nil means that even a unique completion must be confirmed.
 This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer]
@@ -776,7 +782,7 @@ can be completed using TAB,
 (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
+the buffer gets cleaned up by midnight.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
@@ -797,44 +803,39 @@ subdirs in the alternatives."
   :type 'boolean
   :group 'ido)
 
-(defface ido-first-match  '((t (:bold t)))
+(defface ido-first-match  '((t :weight bold))
   "Face used by ido for highlighting first match."
   :group 'ido)
 
 (defface ido-only-match  '((((class color))
-                                 (:foreground "ForestGreen"))
-                                (t (:italic t)))
+                           :foreground "ForestGreen")
+                          (t :slant italic))
   "Face used by ido for highlighting only match."
   :group 'ido)
 
 (defface ido-subdir  '((((min-colors 88) (class color))
-                             (:foreground "red1"))
-                           (((class color))
-                             (:foreground "red"))
-                            (t (:underline t)))
+                       :foreground "red1")
+                      (((class color))
+                       :foreground "red")
+                      (t :underline t))
   "Face used by ido for highlighting subdirs in the alternatives."
   :group 'ido)
 
-(defface ido-virtual '((t (:inherit font-lock-builtin-face)))
+(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))
-                               (:foreground "yellow1"
-                                :background "red1"
-                                :width condensed))
-                              (((class color))
-                               (:foreground "yellow"
-                                :background "red"
-                                :width condensed))
-                              (t (:inverse-video t)))
+(defface ido-indicator '((((min-colors 88) (class color))
+                         :foreground "yellow1" :background "red1" :width condensed)
+                        (((class color))
+                         :foreground "yellow" :background "red" :width condensed)
+                        (t :inverse-video t))
   "Face used by ido for highlighting its indicators."
   :group 'ido)
 
 (defface ido-incomplete-regexp
-  '((t
-     (:inherit font-lock-warning-face)))
+  '((t :inherit font-lock-warning-face))
   "Ido face for indicating incomplete regexps."
   :group 'ido)
 
@@ -878,7 +879,7 @@ The following variables are available, but should not be changed:
   :group 'ido)
 
 (defvar ido-rewrite-file-prompt-rules nil
-  "*Alist of rewriting rules for directory names in ido prompts.
+  "Alist of rewriting rules for directory names in ido prompts.
 A list of elements of the form (FROM . TO) or (FROM . FUNC), each
 meaning to rewrite the directory name if matched by FROM by either
 substituting the matched string by TO or calling the function FUNC
@@ -899,9 +900,14 @@ Otherwise, only the current list of matches is shown."
   :type 'boolean
   :group 'ido)
 
-(defvar ido-all-frames 'visible
-  "*Argument to pass to `walk-windows' when finding visible files.
-See documentation of `walk-windows' for useful values.")
+(defcustom ido-all-frames 'visible
+  "Argument to pass to `walk-windows' when Ido is finding buffers.
+See documentation of `walk-windows' for useful values."
+  :type '(choice (const :tag "Selected frame only" nil)
+                (const :tag "All existing frames" t)
+                (const :tag "All visible frames" visible)
+                (const :tag "All frames on this terminal" 0))
+  :group 'ido)
 
 (defcustom ido-minibuffer-setup-hook nil
   "Ido-specific customization of minibuffer setup.
@@ -1475,8 +1481,10 @@ Removes badly formatted data and ignored directories."
   (add-hook 'choose-completion-string-functions 'ido-choose-completion-string))
 
 (define-minor-mode ido-everywhere
-  "Toggle using ido-mode everywhere file and directory names are read.
-With ARG, turn ido-mode on if arg is positive, off otherwise."
+  "Toggle use of Ido for all buffer/file reading.
+With a prefix argument ARG, enable this feature if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil."
   :global t
   :group 'ido
   (when (get 'ido-everywhere 'file)
@@ -1557,7 +1565,8 @@ This function also adds a hook to the minibuffer."
        (setq ido-minor-mode-map-entry (cons 'ido-mode map))
        (add-to-list 'minor-mode-map-alist ido-minor-mode-map-entry))))
 
-  (message "Ido mode %s" (if ido-mode "enabled" "disabled")))
+  (when (called-interactively-p 'any)
+    (message "Ido mode %s" (if ido-mode "enabled" "disabled"))))
 
 
 ;;; IDO KEYMAP
@@ -1695,7 +1704,7 @@ This function also adds a hook to the minibuffer."
 (defun ido-nonreadable-directory-p (dir)
   ;; Return t if dir is a directory, but not readable
   ;; Do not check for non-readable directories via tramp, as this causes a premature
-  ;; connect on incomplete tramp paths (after entring just method:).
+  ;; connect on incomplete tramp paths (after entering just method:).
   (let ((ido-enable-tramp-completion nil))
     (and (ido-final-slash dir)
         (not (ido-is-unc-host dir))
@@ -1705,7 +1714,7 @@ This function also adds a hook to the minibuffer."
 (defun ido-directory-too-big-p (dir)
   ;; Return t if dir is a directory, but too big to show
   ;; Do not check for non-readable directories via tramp, as this causes a premature
-  ;; connect on incomplete tramp paths (after entring just method:).
+  ;; connect on incomplete tramp paths (after entering just method:).
   (let ((ido-enable-tramp-completion nil))
     (and (numberp ido-max-directory-size)
         (ido-final-slash dir)
@@ -1725,8 +1734,9 @@ This function also adds a hook to the minibuffer."
     (unless (and ido-enable-tramp-completion
                 (string-match "\\`/[^/]*@\\'" dir))
       (setq dir (ido-final-slash dir t))))
-  (if (get-buffer ido-completion-buffer)
-      (kill-buffer ido-completion-buffer))
+  (and ido-completion-buffer
+       (get-buffer ido-completion-buffer)
+       (kill-buffer ido-completion-buffer))
   (cond
    ((equal dir ido-current-directory)
     nil)
@@ -1739,8 +1749,9 @@ This function also adds a hook to the minibuffer."
    (t
     (ido-trace "cd" dir)
     (setq ido-current-directory dir)
-    (if (get-buffer ido-completion-buffer)
-       (kill-buffer ido-completion-buffer))
+    (and ido-completion-buffer
+        (get-buffer ido-completion-buffer)
+        (kill-buffer ido-completion-buffer))
     (setq ido-directory-nonreadable (ido-nonreadable-directory-p dir))
     (setq ido-directory-too-big (and (not ido-directory-nonreadable)
                                     (ido-directory-too-big-p dir)))
@@ -1825,7 +1836,7 @@ This function also adds a hook to the minibuffer."
 ;;       e.g. the file name may be ignored or joined with ido-current-directory, and
 ;;       the relevant function is called (find-file, write-file, etc).
 
-(defun ido-read-internal (item prompt history &optional default require-match initial)
+(defun ido-read-internal (item prompt hist &optional default require-match initial)
   "Perform the `ido-read-buffer' and `ido-read-file-name' functions.
 Return the name of a buffer or file selected.
 PROMPT is the prompt to give to the user.
@@ -1983,10 +1994,11 @@ If INITIAL is non-nil, it specifies the initial input string."
                (read-from-minibuffer (ido-make-prompt item prompt)
                                      (prog1 ido-text-init
                                        (setq ido-text-init nil))
-                                     ido-completion-map nil history))))
+                                     ido-completion-map nil hist))))
       (ido-trace "read-from-minibuffer" ido-final-text)
-      (if (get-buffer ido-completion-buffer)
-         (kill-buffer ido-completion-buffer))
+      (and ido-completion-buffer
+          (get-buffer ido-completion-buffer)
+          (kill-buffer ido-completion-buffer))
 
       (ido-trace "\n_EXIT_" ido-exit)
 
@@ -2154,7 +2166,12 @@ If INITIAL is non-nil, it specifies the initial input string."
 
         (t
          (setq done t))))))
-    (add-to-history (or history 'minibuffer-history) ido-selected)
+    (add-to-history (cond
+                    ((consp hist)
+                     (or (car hist) 'minibuffer-history))
+                    (hist hist)
+                    (t 'minibuffer-history))
+                   ido-selected)
     ido-selected))
 
 (defun ido-edit-input ()
@@ -3150,7 +3167,7 @@ for first matching file."
 ;;; CREATE LIST OF ALL CURRENT FILES
 
 (defun ido-all-completions ()
-  ;; Return unsorted list of all competions.
+  ;; Return unsorted list of all completions.
   (let ((ido-process-ignore-lists nil)
        (ido-directory-too-big nil))
     (cond
@@ -3264,7 +3281,7 @@ for first matching file."
     (while filenames
       (setq filename (car filenames)
            filenames (cdr filenames))
-      (if (and (string-match "^/" filename)
+      (if (and (file-name-absolute-p filename)
               (file-exists-p filename))
          (setq d (file-name-directory filename)
                f (file-name-nondirectory filename)
@@ -3455,8 +3472,6 @@ This is to make them appear as if they were \"virtual buffers\"."
       (nconc ido-temp-list items)
     (setq ido-temp-list items)))
 
-(declare-function tramp-tramp-file-p "tramp" (name))
-
 (defun ido-file-name-all-completions-1 (dir)
   (cond
    ((ido-nonreadable-directory-p dir) '())
@@ -3464,8 +3479,6 @@ This is to make them appear as if they were \"virtual buffers\"."
    ;; Caller must have done that if necessary.
 
    ((and ido-enable-tramp-completion
-        (or (fboundp 'tramp-completion-mode-p)
-            (require 'tramp nil t))
         (string-match "\\`/[^/]+[:@]\\'" dir))
     ;; Strip method:user@host: part of tramp completions.
     ;; Tramp completions do not include leading slash.
@@ -3478,7 +3491,9 @@ This is to make them appear as if they were \"virtual buffers\"."
                ;; /ftp:user@host:./ => ok
                (and
                 (not (string= "/ftp:" dir))
-                (tramp-tramp-file-p dir)
+                (file-remote-p dir)
+                ;; tramp-ftp-file-name-p is available only when tramp
+                ;; has been loaded.
                 (fboundp 'tramp-ftp-file-name-p)
                 (funcall 'tramp-ftp-file-name-p dir)
                 (string-match ":\\'" dir)
@@ -3685,10 +3700,17 @@ This is to make them appear as if they were \"virtual buffers\"."
         (rex0 (if ido-enable-regexp text (regexp-quote text)))
         (rexq (concat rex0 (if slash ".*/" "")))
         (re (if ido-enable-prefix (concat "\\`" rexq) rexq))
-        (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
+        (full-re (and do-full
+                      (and (eq ido-cur-item 'buffer)
+                           (not ido-buffer-disable-smart-matches))
+                      (not ido-enable-regexp)
+                      (not (string-match "\$\\'" rex0))
                       (concat "\\`" rex0 (if slash "/" "") "\\'")))
         (suffix-re (and do-full slash
-                        (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
+                        (and (eq ido-cur-item 'buffer)
+                             (not ido-buffer-disable-smart-matches))
+                        (not ido-enable-regexp)
+                        (not (string-match "\$\\'" rex0))
                         (concat rex0 "/\\'")))
         (prefix-re (and full-re (not ido-enable-prefix)
                         (concat "\\`" rexq)))
@@ -3837,8 +3859,9 @@ This is to make them appear as if they were \"virtual buffers\"."
 (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)
-       (kill-buffer ido-completion-buffer))
+    (and ido-completion-buffer
+        (get-buffer ido-completion-buffer)
+        (kill-buffer ido-completion-buffer))
     (cond
      ((ido-active t) ;; ido-use-merged-list
       (setq ido-current-directory ""
@@ -3857,7 +3880,8 @@ This is to make them appear as if they were \"virtual buffers\"."
   "Show possible completions in a *File Completions* buffer."
   (interactive)
   (setq ido-rescan nil)
-  (let ((temp-buf (get-buffer ido-completion-buffer))
+  (let ((temp-buf (and ido-completion-buffer
+                      (get-buffer ido-completion-buffer)))
        display-it full-list)
     (if (and (eq last-command this-command) temp-buf)
        ;; scroll buffer
@@ -3876,7 +3900,7 @@ This is to make them appear as if they were \"virtual buffers\"."
            (scroll-other-window))
          (set-buffer buf))
       (setq display-it t))
-    (if display-it
+    (if (and ido-completion-buffer display-it)
        (with-output-to-temp-buffer ido-completion-buffer
          (let ((completion-list (sort
                                  (cond
@@ -3903,7 +3927,7 @@ This is to make them appear as if they were \"virtual buffers\"."
                  (funcall f completion-list
                           :help-string "ido "
                           :activate-callback
-                          '(lambda (x y z) (message "Doesn't work yet, sorry!"))))
+                          (lambda (x y z) (message "Doesn't work yet, sorry!"))))
              ;; else running Emacs
              ;;(add-hook 'completion-setup-hook 'completion-setup-function)
              (display-completion-list completion-list)))))))
@@ -4041,8 +4065,7 @@ their normal keybindings, except for the following: \\<ido-buffer-completion-map
 RET Select the buffer at the front of the list of matches.  If the
 list is empty, possibly prompt to create new buffer.
 
-\\[ido-select-text] Select the current prompt as the buffer.
-If no buffer is found, prompt for a new one.
+\\[ido-select-text] Use the current input string verbatim.
 
 \\[ido-next-match] Put the first element at the end of the list.
 \\[ido-prev-match] Put the last element at the start of the list.
@@ -4128,8 +4151,7 @@ except for the following: \\<ido-file-completion-map>
 RET Select the file at the front of the list of matches.  If the
 list is empty, possibly prompt to create new file.
 
-\\[ido-select-text] Select the current prompt as the buffer or file.
-If no buffer or file is found, prompt for a new one.
+\\[ido-select-text] Use the current input string verbatim.
 
 \\[ido-next-match] Put the first element at the end of the list.
 \\[ido-prev-match] Put the last element at the start of the list.
@@ -4137,6 +4159,7 @@ If no buffer or file is found, prompt for a new one.
 matches all files.  If there is only one match, select that file.
 If there is no common suffix, show a list of all matching files
 in a separate window.
+\\[ido-magic-delete-char] Open the specified directory in Dired mode.
 \\[ido-edit-input] Edit input string (including directory).
 \\[ido-prev-work-directory] or \\[ido-next-work-directory] go to previous/next directory in work directory history.
 \\[ido-merge-work-directories] search for file in the work directory history.
@@ -4148,7 +4171,6 @@ in a separate window.
 \\[ido-toggle-regexp] Toggle regexp searching.
 \\[ido-toggle-prefix] Toggle between substring and prefix matching.
 \\[ido-toggle-case] Toggle case-sensitive searching of file names.
-\\[ido-toggle-vc] Toggle version control for this file.
 \\[ido-toggle-literal] Toggle literal reading of this file.
 \\[ido-completion-help] Show list of matching files in separate window.
 \\[ido-toggle-ignore] Toggle ignoring files listed in `ido-ignore-files'."