Fix minor mode docstrings for the new meaning of a nil ARG.
[bpt/emacs.git] / lisp / ido.el
index 2df9b86..8859901 100644 (file)
@@ -1,7 +1,6 @@
-;;; ido.el --- interactively do things with buffers and files.
+;;; ido.el --- interactively do things with buffers and files
 
-;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
@@ -351,7 +350,7 @@ should be enabled.  The following values are possible:
 
 Setting this variable directly does not take effect;
 use either \\[customize] or the function `ido-mode'."
-  :set #'(lambda (symbol value)
+  :set #'(lambda (_symbol value)
           (ido-mode value))
   :initialize 'custom-initialize-default
   :require 'ido
@@ -462,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
@@ -1135,6 +1128,9 @@ Only used if `ido-use-virtual-buffers' is non-nil.")
 ;; Set to 'ignore to inhibit switching between find-file/switch-buffer.
 (defvar ido-context-switch-command)
 
+;; Dynamically bound in ido-read-internal.
+(defvar ido-completing-read)
+
 ;;; FUNCTIONS
 
 (defun ido-active (&optional merge)
@@ -1289,8 +1285,6 @@ Only used if `ido-use-virtual-buffers' is non-nil.")
 (defun ido-may-cache-directory (&optional dir)
   (setq dir (or dir ido-current-directory))
   (cond
-   ((ido-directory-too-big-p dir)
-    nil)
    ((and (ido-is-root-directory dir)
         (or ido-enable-tramp-completion
             (memq system-type '(windows-nt ms-dos))))
@@ -1299,6 +1293,8 @@ Only used if `ido-use-virtual-buffers' is non-nil.")
     (ido-cache-unc-valid))
    ((ido-is-ftp-directory dir)
     (ido-cache-ftp-valid))
+   ((ido-directory-too-big-p dir)
+    nil)
    (t t)))
 
 (defun ido-pp (list &optional sep)
@@ -1467,9 +1463,16 @@ Removes badly formatted data and ignored directories."
   ;; ido kill emacs hook
   (ido-save-history))
 
+(defun ido-common-initialization ()
+  (ido-init-completion-maps)
+  (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup)
+  (add-hook 'choose-completion-string-functions 'ido-choose-completion-string))
+
 (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."
+  "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)
@@ -1490,8 +1493,8 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise."
 
 ;;;###autoload
 (defun ido-mode (&optional arg)
-  "Toggle ido speed-ups on or off.
-With ARG, turn ido speed-up on if arg is positive, off otherwise.
+  "Toggle ido mode on or off.
+With ARG, turn ido-mode on if arg is positive, off otherwise.
 Turning on ido-mode will remap (via a minor-mode keymap) the default
 keybindings for the `find-file' and `switch-to-buffer' families of
 commands to the ido versions of these functions.
@@ -1510,12 +1513,9 @@ This function also adds a hook to the minibuffer."
         (t nil)))
 
   (ido-everywhere (if ido-everywhere 1 -1))
-  (when ido-mode
-    (ido-init-completion-maps))
 
   (when ido-mode
-    (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup)
-    (add-hook 'choose-completion-string-functions 'ido-choose-completion-string)
+    (ido-common-initialization)
     (ido-load-history)
 
     (add-hook 'kill-emacs-hook 'ido-kill-emacs-hook)
@@ -1553,7 +1553,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
@@ -1821,7 +1822,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.
@@ -1963,31 +1964,24 @@ If INITIAL is non-nil, it specifies the initial input string."
       (ido-set-matches)
       (if (and ido-matches (eq ido-try-merged-list 'auto))
          (setq ido-try-merged-list t))
-      (let
-         ((minibuffer-local-completion-map
-           (if (memq ido-cur-item '(file dir))
-               minibuffer-local-completion-map
-             ido-completion-map))
-          (minibuffer-local-filename-completion-map
-           (if (memq ido-cur-item '(file dir))
-               ido-completion-map
-             minibuffer-local-filename-completion-map))
-          (max-mini-window-height (or ido-max-window-height
-                                      (and (boundp 'max-mini-window-height) max-mini-window-height)))
+      (let ((max-mini-window-height (or ido-max-window-height
+                                       (and (boundp 'max-mini-window-height)
+                                            max-mini-window-height)))
           (ido-completing-read t)
           (ido-require-match require-match)
           (ido-use-mycompletion-depth (1+ (minibuffer-depth)))
-          (show-paren-mode nil))
+          (show-paren-mode nil)
+          ;; Postpone history adding till later
+          (history-add-new-input nil))
        ;; prompt the user for the file name
        (setq ido-exit nil)
        (setq ido-final-text
              (catch 'ido
-               (completing-read
-                (ido-make-prompt item prompt)
-                '(("dummy" . 1)) nil nil ; table predicate require-match
-                (prog1 ido-text-init (setq ido-text-init nil)) ;initial-contents
-                history))))
-      (ido-trace "completing-read" ido-final-text)
+               (read-from-minibuffer (ido-make-prompt item prompt)
+                                     (prog1 ido-text-init
+                                       (setq ido-text-init nil))
+                                     ido-completion-map nil hist))))
+      (ido-trace "read-from-minibuffer" ido-final-text)
       (if (get-buffer ido-completion-buffer)
          (kill-buffer ido-completion-buffer))
 
@@ -2157,6 +2151,12 @@ If INITIAL is non-nil, it specifies the initial input string."
 
         (t
          (setq done t))))))
+    (add-to-history (cond
+                    ((consp hist)
+                     (or (car hist) 'minibuffer-history))
+                    (hist hist)
+                    (t 'minibuffer-history))
+                   ido-selected)
     ido-selected))
 
 (defun ido-edit-input ()
@@ -2181,9 +2181,7 @@ 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)
-          (ido-use-virtual-buffers (if (eq method 'kill)
-                                       nil    ;; Don't consider virtual buffers for killing
-                                     ido-use-virtual-buffers))
+          (ido-use-virtual-buffers 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))
@@ -2428,7 +2426,7 @@ If cursor is not at the end of the user input, move to end of input."
        (ido-record-command 'write-file filename)
        (add-to-history 'file-name-history filename)
        (ido-record-work-directory)
-       (write-file filename))
+       (write-file filename t))
 
        ((eq method 'read-only)
        (ido-record-work-file filename)
@@ -2919,7 +2917,7 @@ If no buffer or file exactly matching the prompt exists, maybe create a new one.
     (setq ido-rotate-temp t)
     (exit-minibuffer)))
 
-(defun ido-wide-find-dir-or-delete-dir (&optional dir)
+(defun ido-wide-find-dir-or-delete-dir (&optional _dir)
   "Prompt for DIR to search for using find, starting from current directory.
 If input stack is non-empty, delete current directory component."
   (interactive)
@@ -3028,11 +3026,11 @@ If repeated, insert text from buffer instead."
            ido-try-merged-list nil)
       (exit-minibuffer))))
 
-(defun ido-copy-current-word (all)
+(defun ido-copy-current-word (_all)
   "Insert current word (file or directory name) from current buffer."
   (interactive "P")
   (let ((word (with-current-buffer ido-entry-buffer
-               (let ((p (point)) start-line end-line start-name name)
+               (let ((p (point)) start-line end-line start-name)
                  (if (and mark-active (/= p (mark)))
                      (setq start-name (mark))
                    (beginning-of-line)
@@ -3070,8 +3068,8 @@ If repeated, insert text from buffer instead."
   (if ido-matches
       (let ((next (cadr ido-matches)))
        (setq ido-cur-list (ido-chop ido-cur-list next))
-       (setq ido-rescan t)
-       (setq ido-rotate t))))
+       (setq ido-matches (ido-chop ido-matches next))
+       (setq ido-rescan nil))))
 
 (defun ido-prev-match ()
   "Put last element of `ido-matches' at the front of the list."
@@ -3079,8 +3077,8 @@ If repeated, insert text from buffer instead."
   (if ido-matches
       (let ((prev (car (last ido-matches))))
        (setq ido-cur-list (ido-chop ido-cur-list prev))
-       (setq ido-rescan t)
-       (setq ido-rotate t))))
+       (setq ido-matches (ido-chop ido-matches prev))
+       (setq ido-rescan nil))))
 
 (defun ido-next-match-dir ()
   "Find next directory in match list.
@@ -3239,7 +3237,7 @@ for first matching file."
   ;; Input is list of ("file" . "dir") cons cells.
   ;; Output is sorted list of ("file "dir" ...) lists
   (let ((l (sort items (lambda (a b) (string-lessp (car b) (car a)))))
-       res a cur dirs)
+       res a cur)
     (while l
       (setq a (car l)
            l (cdr l))
@@ -3907,7 +3905,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)))))))
@@ -3922,10 +3920,10 @@ 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)))
          (nextbuf (cadr ido-matches)))
-      (when (get-buffer buf)
+      (cond
+       ((get-buffer buf)
        ;; If next match names a buffer use the buffer object; buffer
-       ;; name may be changed by packages such as uniquify; mindful
-       ;; of virtual buffers.
+       ;; name may be changed by packages such as uniquify.
        (when (and nextbuf (get-buffer nextbuf))
          (setq nextbuf (get-buffer nextbuf)))
        (if (null (kill-buffer buf))
@@ -3939,7 +3937,13 @@ If cursor is not at the end of the user input, delete to end of input."
          (setq ido-default-item nextbuf
                ido-text-init ido-text
                ido-exit 'refresh)
-         (exit-minibuffer))))))
+         (exit-minibuffer)))
+       ;; Handle virtual buffers
+       ((assoc buf ido-virtual-buffers)
+       (setq recentf-list
+             (delete (cdr (assoc buf ido-virtual-buffers)) recentf-list))
+       (setq ido-cur-list (delete buf ido-cur-list))
+       (setq ido-rescan t))))))
 
 ;;; DELETE CURRENT FILE
 (defun ido-delete-file-at-head ()
@@ -4490,17 +4494,13 @@ For details of keybindings, see `ido-find-file'."
 
        ;; Insert the match-status information:
        (ido-set-common-completion)
-       (let ((inf (ido-completions
-                   contents
-                   minibuffer-completion-table
-                   minibuffer-completion-predicate
-                   (not minibuffer-completion-confirm))))
+       (let ((inf (ido-completions contents)))
          (setq ido-show-confirm-message nil)
          (ido-trace "inf" inf)
          (insert inf))
        ))))
 
-(defun ido-completions (name candidates predicate require-match)
+(defun ido-completions (name)
   ;; Return the string that is displayed after the user's text.
   ;; Modified from `icomplete-completions'.
 
@@ -4739,13 +4739,14 @@ See `read-directory-name' for additional parameters."
          (concat ido-current-directory filename)))))
 
 ;;;###autoload
-(defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def)
+(defun ido-completing-read (prompt choices &optional _predicate require-match
+                            initial-input hist def _inherit-input-method)
   "Ido replacement for the built-in `completing-read'.
 Read a string in the minibuffer with ido-style completion.
 PROMPT is a string to prompt with; normally it ends in a colon and a space.
 CHOICES is a list of strings which are the possible completions.
-PREDICATE is currently ignored; it is included to be compatible
- with `completing-read'.
+PREDICATE and INHERIT-INPUT-METHOD is currently ignored; it is included
to be compatible with `completing-read'.
 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
  the input is (or completes to) an element of CHOICES or is null.
  If the input is null, `ido-completing-read' returns DEF, or an empty
@@ -4759,6 +4760,8 @@ DEF, if non-nil, is the default value."
        (ido-directory-too-big nil)
        (ido-context-switch-command 'ignore)
        (ido-choice-list choices))
+    ;; Initialize ido before invoking ido-read-internal
+    (ido-common-initialization)
     (ido-read-internal 'list prompt hist def require-match initial-input)))
 
 (defun ido-unload-function ()
@@ -4770,5 +4773,4 @@ DEF, if non-nil, is the default value."
 
 (provide 'ido)
 
-;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
 ;;; ido.el ends here