]> code.delx.au - gnu-emacs/blobdiff - lisp/ido.el
*** empty log message ***
[gnu-emacs] / lisp / ido.el
index d4c5d4fbeeca166788e78a5af2100a374c92d12b..56cf8be3ece9c60b710118e1d18957c409d527ec 100644 (file)
@@ -489,6 +489,15 @@ Value can be toggled within `ido' using `ido-toggle-prefix'."
   :type 'boolean
   :group 'ido)
 
+(defcustom ido-cannot-complete-command 'ido-completion-help
+  "*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."
+  :type 'function
+  :group 'ido)
+
+
 (defcustom ido-record-commands t
   "*Non-nil means that `ido' will record commands in command history.
 Note that the non-ido equivalent command is recorded."
@@ -635,7 +644,6 @@ If value is 'slash, only enter if typing final slash, else do it always."
                 (other :tag "Always" t))
   :group 'ido)
 
-Non-nil means if typing / results in only one matching directory, enter it 
 (defcustom ido-create-new-buffer 'prompt
   "*Specify whether a new buffer is created if no buffer matches substring.
 Choices are 'always to create new buffers unconditionally, 'prompt to
@@ -653,7 +661,7 @@ ask user whether to create buffer, or 'never to never create new buffer."
 (defcustom ido-separator nil
   "*String used by ido to separate the alternatives in the minibuffer.
 Obsolete.  Set 3rd element of `ido-decorations' instead."
-  :type 'string
+  :type '(choice string (const nil))
   :group 'ido)
 
 (defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]")
@@ -815,9 +823,6 @@ the file name using normal read-file-name style."
 (defvar  ido-buffer-history nil
   "History of buffers selected using `ido-switch-buffer'.")
 
-(defvar ido-xemacs  (string-match "XEmacs" (emacs-version))
-  "Non-nil if we are running XEmacs.  Otherwise, assume we are running Emacs.")
-
 (defvar ido-last-directory-list nil
   "List of last selected directory paths.
 See `ido-enable-last-directory-history' for details.")
@@ -836,6 +841,11 @@ whenever a file is opened with ido-find-file and family.")
   "List of file-name-all-completions results.
 Each element in the list is of the form (dir (mtime) file...).")
 
+(defvar ido-ignore-item-temp-list nil
+  "List of items to ignore in current ido invocation.
+Intended to be let-bound by functions which calls ido repeatedly.
+Should never be set permanently.")
+
 ;; Temporary storage
 
 (defvar ido-eoinput 1
@@ -1264,6 +1274,8 @@ This function also adds a hook to the minibuffer."
     (define-key map "\C-s" 'ido-next-match)
     (define-key map "\C-t" 'ido-toggle-regexp)
     (define-key map "\C-z" 'ido-undo-merge-work-directory)
+    (define-key map [(control ? )] 'ido-restrict-to-matches)
+    (define-key map [(control ?@)] 'ido-restrict-to-matches)
     (define-key map [right] 'ido-next-match)
     (define-key map [left] 'ido-prev-match)
     (define-key map "?" 'ido-completion-help)
@@ -1452,17 +1464,19 @@ If INITIAL is non-nil, it specifies the initial input string."
       (setq ido-rescan t)
       (setq ido-rotate nil)
       (setq ido-text "")
-      (if ido-set-default-item
-       (setq ido-default-item
-            (cond
-             ((eq item 'buffer)
-              (if (bufferp default) (buffer-name default) default))
-             ((stringp default) default)
-             ((eq item 'file)
-              (and ido-enable-last-directory-history 
-                   (let ((d (assoc ido-current-directory ido-last-directory-list)))
-                     (and d (cdr d))))))
-            ido-set-default-item nil))
+      (when ido-set-default-item
+       (setq ido-default-item
+             (cond
+              ((eq item 'buffer)
+               (if (bufferp default) (buffer-name default) default))
+              ((stringp default) default)
+              ((eq item 'file)
+               (and ido-enable-last-directory-history 
+                    (let ((d (assoc ido-current-directory ido-last-directory-list)))
+                      (and d (cdr d)))))))
+       (if (member ido-default-item ido-ignore-item-temp-list)
+           (setq ido-default-item nil))
+       (setq ido-set-default-item nil))
 
       (if ido-process-ignore-lists-inhibit
          (setq ido-process-ignore-lists nil))
@@ -1621,13 +1635,11 @@ If INITIAL is non-nil, it specifies the initial input string."
 
        (t
        (setq ido-selected
-             (if (and ido-matches (equal ido-final-text ""))
-                 (ido-name (car ido-matches))  ;; possibly choose the default file
-               (if (or (eq ido-exit 'takeprompt)
-                       (null ido-matches))
-                   ido-final-text
-                 ;; else take head of list
-                 (ido-name (car ido-matches)))))
+             (if (or (eq ido-exit 'takeprompt)
+                     (null ido-matches))
+                 ido-final-text
+               ;; else take head of list
+               (ido-name (car ido-matches))))
 
        (cond
         ((eq item 'buffer)
@@ -1642,7 +1654,6 @@ If INITIAL is non-nil, it specifies the initial input string."
          (or (ido-is-root-directory)
              (ido-set-current-directory (file-name-directory (substring ido-current-directory 0 -1))))
          (setq ido-set-default-item t))
-
         ((and (string-equal ido-current-directory "/")
               (string-match "..:\\'" ido-selected)) ;; Ange-ftp 
          (ido-set-current-directory "/" ido-selected)
@@ -1701,6 +1712,7 @@ If INITIAL is non-nil, it specifies the initial input string."
 
        ;; Check buf is non-nil.
        ((not buf) nil)
+       ((= (length buf) 0) nil)
 
        ;; View buffer if it exists
        ((get-buffer buf)
@@ -1922,8 +1934,7 @@ If INITIAL is non-nil, it specifies the initial input string."
 
      ((not ido-matches)
       (when ido-completion-buffer
-       (setq this-command 'ido-completion-help)
-       (ido-completion-help)))
+       (call-interactively (setq this-command ido-cannot-complete-command))))
          
      ((= 1 (length ido-matches))
       ;; only one choice, so select it.
@@ -1940,7 +1951,7 @@ If INITIAL is non-nil, it specifies the initial input string."
            (delete-region (minibuffer-prompt-end) (point))
            (insert res))
        ;; else nothing to complete
-       (ido-completion-help)
+       (call-interactively (setq this-command ido-cannot-complete-command))
        )))))
 
 (defun ido-complete-space ()
@@ -2357,6 +2368,16 @@ for first matching file."
       (if (> i 0)
          (setq ido-cur-list (ido-chop ido-cur-list (nth i ido-matches)))))))
 
+(defun ido-restrict-to-matches () 
+  "Set current item list to the currently matched items."
+  (interactive)
+  (when ido-matches
+    (setq ido-cur-list ido-matches
+         ido-text-init ""
+         ido-rescan nil
+         ido-exit 'keep)
+    (exit-minibuffer)))
+
 (defun ido-chop (items elem)
   "Remove all elements before ELEM and put them at the end of ITEMS."
   (let ((ret nil)
@@ -2424,7 +2445,6 @@ for first matching file."
        res)
     (while paths
       (setq path (car paths)
-           paths (cdr paths)
            paths (cdr paths))
       (if (and (string-match "^/" path)
               (file-exists-p path))
@@ -2512,6 +2532,7 @@ for first matching file."
     (if (and res (not (eq res t)))
        (setq res (ido-sort-merged-list res auto)))
     (when (and (or ido-rotate-temp ido-rotate-file-list-default)
+              (listp res)
               (> (length text) 0))
       (let ((elt (assoc text res)))
        (when (and elt (not (eq elt (car res))))
@@ -2526,7 +2547,7 @@ for first matching file."
        (mapcar
         (lambda (x)
           (let ((name (buffer-name x)))
-            (if (not (or (ido-ignore-item-p name ido-ignore-buffers) (memq name visible)))
+            (if (not (or (ido-ignore-item-p name ido-ignore-buffers) (member name visible)))
                 name)))
         (buffer-list frame))))
 
@@ -2716,12 +2737,13 @@ for first matching file."
 (defun ido-get-bufname (win)
   ;; Used by `ido-get-buffers-in-frames' to walk through all windows
   (let ((buf (buffer-name (window-buffer win))))
-       (if (not (member buf ido-bufs-in-frame))
-           ;; Only add buf if it is not already in list.
-           ;; This prevents same buf in two different windows being
-           ;; put into the list twice.
-           (setq ido-bufs-in-frame
-                 (cons buf ido-bufs-in-frame)))))
+       (unless (or (member buf ido-bufs-in-frame)
+                   (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
+         ;; put into the list twice.
+         (setq ido-bufs-in-frame
+               (cons buf ido-bufs-in-frame)))))
 
 ;;; FIND MATCHING ITEMS
 
@@ -2777,7 +2799,9 @@ for first matching file."
         
 (defun ido-ignore-item-p (name re-list &optional ignore-ext)
   ;; Return t if the buffer or file NAME should be ignored.
-  (and ido-process-ignore-lists re-list
+  (or (member name ido-ignore-item-temp-list)
+      (and
+       ido-process-ignore-lists re-list
        (let ((data       (match-data))
             (ext-list   (and ignore-ext ido-ignore-extensions
                              completion-ignored-extensions))
@@ -2808,7 +2832,7 @@ for first matching file."
         (if ignorep
             (setq ido-ignored-list (cons name ido-ignored-list)))
         (set-match-data data)
-        ignorep)))
+        ignorep))))
 
 
 ;; Private variable used by `ido-word-matching-substring'.
@@ -2898,10 +2922,10 @@ for first matching file."
                                    (ido-all-completions))
                                   (t
                                    (copy-sequence (or ido-matches ido-cur-list)))))))
-           (if ido-xemacs 
+           (if (featurep 'xemacs)
                ;; XEmacs extents are put on by default, doesn't seem to be
                ;; any way of switching them off.
-               ;; This obscure code avoids a byte compiler warning in GNU emacs.
+               ;; This obscure code avoids a byte compiler warning in Emacs.
                (let ((f 'display-completion-list))
                  (funcall f completion-list
                           :help-string "ido "
@@ -2976,7 +3000,7 @@ Record command in command-history if optional RECORD is non-nil."
            (select-frame-set-input-focus newframe)
          (raise-frame newframe)
          (select-frame newframe)
-         (if (not ido-xemacs)
+         (unless (featurep 'xemacs)
            (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
        (select-window win))
        (t
@@ -2995,13 +3019,10 @@ Record command in command-history if optional RECORD is non-nil."
       (display-buffer buffer))
 
      ((eq method 'otherframe)
-      (progn
-       (switch-to-buffer-other-frame buffer)
-       (if (not ido-xemacs)
-           (if (fboundp 'select-frame-set-input-focus)
-               (select-frame-set-input-focus (selected-frame))
-             (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
-       )))))
+      (switch-to-buffer-other-frame buffer)
+      (unless (featurep 'xemacs)
+       (select-frame-set-input-focus (selected-frame)))
+      ))))
 
 
 (defun ido-window-buffer-p  (buffer)
@@ -3009,7 +3030,7 @@ Record command in command-history if optional RECORD is non-nil."
   ;; If BUFFER is visible in the current frame, return nil.
   (let ((blist (ido-get-buffers-in-frames 'current)))
     ;;If the buffer is visible in current frame, return nil
-    (if (memq buffer blist)
+    (if (member buffer blist)
        nil
       ;;  maybe in other frame or icon
       (get-buffer-window buffer 0) ; better than 'visible
@@ -3543,11 +3564,12 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
   "Minibuffer setup hook for `ido'."
   ;; Copied from `icomplete-minibuffer-setup-hook'.
   (when (and (boundp 'ido-completing-read) 
-            (or ido-xemacs (= ido-use-mycompletion-depth (minibuffer-depth))))
+            (or (featurep 'xemacs)
+                (= ido-use-mycompletion-depth (minibuffer-depth))))
     (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 ido-xemacs
+    (when (featurep 'xemacs)
       (ido-exhibit)
       (goto-char (point-min)))
     (run-hooks 'ido-minibuffer-setup-hook)))
@@ -3597,15 +3619,12 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
   "Read file name, prompting with PROMPT and completing in directory DIR.
 See `read-file-name' for additional parameters."
-  (message "%S %S %S %S" this-command ido-read-file-name-non-ido 
-          predicate (memq this-command ido-read-file-name-non-ido))
   (cond
   ((or (eq predicate 'file-directory-p)
        (memq this-command ido-read-file-name-as-directory-commands))
    (ido-read-directory-name prompt dir default-filename mustmatch initial))
   ((and (not (memq this-command ido-read-file-name-non-ido))
        (or (null predicate) (eq predicate 'file-exists-p)))
-   (message "gotit")
    (let (filename
         ido-saved-vc-mt
         (vc-master-templates (and (boundp 'vc-master-templates) vc-master-templates))