/[emacs]/emacs/lisp/ido.el
ViewVC logotype

Diff of /emacs/lisp/ido.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.41 by kfstorm, Sat Sep 11 21:43:42 2004 UTC revision 1.42 by kfstorm, Wed Sep 22 22:49:07 2004 UTC
# Line 933  it doesn't interfere with other minibuff Line 933  it doesn't interfere with other minibuff
933  ;;; Variables with dynamic bindings.  ;;; Variables with dynamic bindings.
934  ;;; Declared here to keep the byte compiler quiet.  ;;; Declared here to keep the byte compiler quiet.
935    
936  ;; Stores the current ido item type ('file, 'dir or 'buffer).  ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list).
937  (defvar ido-cur-item)  (defvar ido-cur-item)
938    
939  ;; Stores the current list of items that will be searched through.  ;; Stores the current list of items that will be searched through.
# Line 942  it doesn't interfere with other minibuff Line 942  it doesn't interfere with other minibuff
942  ;; at the end of the list.  Created by `ido-make-item-list'.  ;; at the end of the list.  Created by `ido-make-item-list'.
943  (defvar ido-cur-list)  (defvar ido-cur-list)
944    
945    ;; Stores the choice list for ido-completing-read
946    (defvar ido-choice-list)
947    
948  ;; Stores the list of items which are ignored when building  ;; Stores the list of items which are ignored when building
949  ;; `ido-cur-list'.  It is in no specific order.  ;; `ido-cur-list'.  It is in no specific order.
950  (defvar ido-ignored-list)  (defvar ido-ignored-list)
# Line 992  it doesn't interfere with other minibuff Line 995  it doesn't interfere with other minibuff
995  ;; Stores temporary state of literal find file.  ;; Stores temporary state of literal find file.
996  (defvar ido-find-literal)  (defvar ido-find-literal)
997    
998    ;; Set to 'ignore to inhibit switching between find-file/switch-buffer.
999    (defvar ido-context-switch-command)
1000    
1001  ;;; FUNCTIONS  ;;; FUNCTIONS
1002    
# Line 1346  This function also adds a hook to the mi Line 1351  This function also adds a hook to the mi
1351      (define-key map "?" 'ido-completion-help)      (define-key map "?" 'ido-completion-help)
1352    
1353      (when (memq ido-cur-item '(file dir))      (when (memq ido-cur-item '(file dir))
1354        (define-key map "\C-b" 'ido-enter-switch-buffer)        (define-key map "\C-b" (or ido-context-switch-command 'ido-enter-switch-buffer))
1355        (define-key map "\C-d" 'ido-enter-dired)        (define-key map "\C-d" (or (and ido-context-switch-command 'ignore) 'ido-enter-dired))
1356        (define-key map "\C-f" 'ido-fallback-command)        (define-key map "\C-f" 'ido-fallback-command)
1357        (define-key map [down] 'ido-next-match-dir)        (define-key map [down] 'ido-next-match-dir)
1358        (define-key map [up]   'ido-prev-match-dir)        (define-key map [up]   'ido-prev-match-dir)
# Line 1378  This function also adds a hook to the mi Line 1383  This function also adds a hook to the mi
1383        )        )
1384    
1385      (when (eq ido-cur-item 'buffer)      (when (eq ido-cur-item 'buffer)
1386          (define-key map "\C-f" (or ido-context-switch-command 'ido-enter-find-file))
1387        (define-key map "\C-b" 'ido-fallback-command)        (define-key map "\C-b" 'ido-fallback-command)
       (define-key map "\C-f" 'ido-enter-find-file)  
1388        (define-key map "\C-k" 'ido-kill-buffer-at-head)        (define-key map "\C-k" 'ido-kill-buffer-at-head)
1389        )        )
1390    
# Line 1625  If INITIAL is non-nil, it specifies the Line 1630  If INITIAL is non-nil, it specifies the
1630         ((eq ido-cur-item 'buffer)         ((eq ido-cur-item 'buffer)
1631          (setq ido-ignored-list nil          (setq ido-ignored-list nil
1632                ido-cur-list (ido-make-buffer-list ido-default-item)))                ido-cur-list (ido-make-buffer-list ido-default-item)))
1633           ((eq ido-cur-item 'list)
1634            (setq ido-ignored-list nil
1635                  ido-cur-list (ido-make-choice-list ido-default-item)))
1636         (t nil))         (t nil))
1637        (setq ido-rotate-temp nil)        (setq ido-rotate-temp nil)
1638    
# Line 1709  If INITIAL is non-nil, it specifies the Line 1717  If INITIAL is non-nil, it specifies the
1717         ((eq ido-exit 'keep)         ((eq ido-exit 'keep)
1718          (setq ido-keep-item-list t))          (setq ido-keep-item-list t))
1719    
1720         ((memq ido-exit '(dired fallback findfile findbuffer))         ((memq ido-exit '(dired fallback find-file switch-to-buffer insert-buffer insert-file))
1721          (setq done t))          (setq done t))
1722    
1723         ((eq ido-exit 'updir)         ((eq ido-exit 'updir)
# Line 1789  If INITIAL is non-nil, it specifies the Line 1797  If INITIAL is non-nil, it specifies the
1797    (exit-minibuffer))    (exit-minibuffer))
1798    
1799  ;;; MAIN FUNCTIONS  ;;; MAIN FUNCTIONS
1800  (defun ido-buffer-internal (method &optional fallback prompt default initial)  (defun ido-buffer-internal (method &optional fallback prompt default initial switch-cmd)
1801    ;; Internal function for ido-switch-buffer and friends    ;; Internal function for ido-switch-buffer and friends
1802    (if (not ido-mode)    (if (not ido-mode)
1803        (call-interactively (or fallback 'switch-to-buffer))        (call-interactively (or fallback 'switch-to-buffer))
1804      (let ((buf (ido-read-buffer (or prompt "Buffer: ") default nil initial)))      (let* ((ido-context-switch-command switch-cmd)
1805               (buf (ido-read-buffer (or prompt "Buffer: ") default nil initial)))
1806    
1807        ;; Choose the buffer name: either the text typed in, or the head        ;; Choose the buffer name: either the text typed in, or the head
1808        ;; of the list of matches        ;; of the list of matches
1809    
1810        (cond        (cond
1811         ((eq ido-exit 'findfile)         ((eq ido-exit 'find-file)
1812          (ido-file-internal ido-default-file-method nil nil nil nil ido-text))          (ido-file-internal ido-default-file-method nil nil nil nil ido-text))
1813    
1814           ((eq ido-exit 'insert-file)
1815            (ido-file-internal 'insert 'insert-file nil "Insert file: " nil ido-text 'ido-enter-insert-buffer))
1816    
1817         ((eq ido-exit 'fallback)         ((eq ido-exit 'fallback)
1818          (let ((read-buffer-function nil))          (let ((read-buffer-function nil))
1819            (call-interactively (or fallback 'switch-to-buffer))))            (call-interactively (or fallback 'switch-to-buffer))))
# Line 1842  buffer to be selected, which will go to Line 1854  buffer to be selected, which will go to
1854  If REQUIRE-MATCH is non-nil, an existing-buffer must be selected.  If REQUIRE-MATCH is non-nil, an existing-buffer must be selected.
1855  If INITIAL is non-nil, it specifies the initial input string."  If INITIAL is non-nil, it specifies the initial input string."
1856    (let ((ido-current-directory nil)    (let ((ido-current-directory nil)
1857          (ido-directory-nonreadable nil))          (ido-directory-nonreadable nil)
1858            (ido-context-switch-command (if (boundp 'ido-context-switch-command) ido-context-switch-command 'ignore)))
1859      (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match initial)))      (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match initial)))
1860    
1861  (defun ido-record-work-directory (&optional dir)  (defun ido-record-work-directory (&optional dir)
# Line 1886  If INITIAL is non-nil, it specifies the Line 1899  If INITIAL is non-nil, it specifies the
1899    ;; Add final slash to result in case it was missing from DEFAULT-DIRECTORY.    ;; Add final slash to result in case it was missing from DEFAULT-DIRECTORY.
1900    (ido-final-slash (expand-file-name (or dir default-directory)) t))    (ido-final-slash (expand-file-name (or dir default-directory)) t))
1901    
1902  (defun ido-file-internal (method &optional fallback default prompt item initial)  (defun ido-file-internal (method &optional fallback default prompt item initial switch-cmd)
1903    ;; Internal function for ido-find-file and friends    ;; Internal function for ido-find-file and friends
1904    (unless item    (unless item
1905      (setq item 'file))      (setq item 'file))
1906    (let* ((ido-current-directory (ido-expand-directory default))    (let* ((ido-current-directory (ido-expand-directory default))
1907           (ido-directory-nonreadable (ido-nonreadable-directory-p ido-current-directory))           (ido-directory-nonreadable (ido-nonreadable-directory-p ido-current-directory))
1908             (ido-context-switch-command switch-cmd)
1909           filename)           filename)
1910    
1911      (cond      (cond
# Line 1943  If INITIAL is non-nil, it specifies the Line 1957  If INITIAL is non-nil, it specifies the
1957                (read-file-name-function nil))                (read-file-name-function nil))
1958            (call-interactively (or fallback 'find-file))))            (call-interactively (or fallback 'find-file))))
1959    
1960         ((eq ido-exit 'findbuffer)         ((eq ido-exit 'switch-to-buffer)
1961          (ido-buffer-internal ido-default-buffer-method nil nil nil ido-text))          (ido-buffer-internal ido-default-buffer-method nil nil nil ido-text))
1962    
1963           ((eq ido-exit 'insert-buffer)
1964            (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil ido-text 'ido-enter-insert-file))
1965    
1966         ((eq ido-exit 'dired)         ((eq ido-exit 'dired)
1967          (dired (concat ido-current-directory (or ido-text ""))))          (dired (concat ido-current-directory (or ido-text ""))))
1968    
# Line 2227  If no buffer or file exactly matching th Line 2244  If no buffer or file exactly matching th
2244  (defun ido-enter-find-file ()  (defun ido-enter-find-file ()
2245    "Drop into find-file from buffer switching."    "Drop into find-file from buffer switching."
2246    (interactive)    (interactive)
2247    (setq ido-exit 'findfile)    (setq ido-exit 'find-file)
2248    (exit-minibuffer))    (exit-minibuffer))
2249    
2250  (defun ido-enter-switch-buffer ()  (defun ido-enter-switch-buffer ()
2251    "Drop into ido-switch-buffer from file switching."    "Drop into ido-switch-buffer from file switching."
2252    (interactive)    (interactive)
2253    (setq ido-exit 'findbuffer)    (setq ido-exit 'switch-to-buffer)
2254    (exit-minibuffer))    (exit-minibuffer))
2255    
2256  (defun ido-enter-dired ()  (defun ido-enter-dired ()
# Line 2242  If no buffer or file exactly matching th Line 2259  If no buffer or file exactly matching th
2259    (setq ido-exit 'dired)    (setq ido-exit 'dired)
2260    (exit-minibuffer))    (exit-minibuffer))
2261    
2262    (defun ido-enter-insert-buffer ()
2263      "Drop into insert buffer from insert file."
2264      (interactive)
2265      (setq ido-exit 'insert-buffer)
2266      (exit-minibuffer))
2267    
2268    (defun ido-enter-insert-file ()
2269      "Drop into insert file from insert buffer."
2270      (interactive)
2271      (setq ido-exit 'insert-file)
2272      (exit-minibuffer))
2273    
2274    
2275  (defun ido-up-directory (&optional clear)  (defun ido-up-directory (&optional clear)
2276    "Go up one directory level."    "Go up one directory level."
# Line 2560  for first matching file." Line 2589  for first matching file."
2589        (ido-make-dir-list1 ido-current-directory))        (ido-make-dir-list1 ido-current-directory))
2590       ((eq ido-cur-item 'buffer)       ((eq ido-cur-item 'buffer)
2591        (ido-make-buffer-list1))        (ido-make-buffer-list1))
2592         ((eq ido-cur-item 'list)
2593          ido-choice-list)
2594       (t nil))))       (t nil))))
2595    
2596    
# Line 2722  for first matching file." Line 2753  for first matching file."
2753      (run-hooks 'ido-make-buffer-list-hook)      (run-hooks 'ido-make-buffer-list-hook)
2754      ido-temp-list))      ido-temp-list))
2755    
2756    (defun ido-make-choice-list (default)
2757      ;; Return the current list of choices.
2758      ;; If DEFAULT is non-nil, and corresponds to an element of choices,
2759      ;; it is put to the start of the list.
2760      (let ((ido-temp-list ido-choice-list))
2761        (if default
2762            (progn
2763              (setq ido-temp-list
2764                    (delete default ido-temp-list))
2765              (setq ido-temp-list
2766                    (cons default ido-temp-list))))
2767        ; (run-hooks 'ido-make-choice-list-hook)
2768        ido-temp-list))
2769    
2770  (defun ido-to-end (items)  (defun ido-to-end (items)
2771    ;; Move the elements from ITEMS to the end of `ido-temp-list'    ;; Move the elements from ITEMS to the end of `ido-temp-list'
2772    (mapcar    (mapcar
# Line 3277  For details of keybindings, do `\\[descr Line 3322  For details of keybindings, do `\\[descr
3322  The buffer name is selected interactively by typing a substring.  The buffer name is selected interactively by typing a substring.
3323  For details of keybindings, do `\\[describe-function] ido'."  For details of keybindings, do `\\[describe-function] ido'."
3324    (interactive)    (interactive)
3325    (ido-buffer-internal 'display 'display-buffer))    (ido-buffer-internal 'display 'display-buffer nil nil nil 'ignore))
3326    
3327  ;;;###autoload  ;;;###autoload
3328  (defun ido-kill-buffer ()  (defun ido-kill-buffer ()
# Line 3285  For details of keybindings, do `\\[descr Line 3330  For details of keybindings, do `\\[descr
3330  The buffer name is selected interactively by typing a substring.  The buffer name is selected interactively by typing a substring.
3331  For details of keybindings, do `\\[describe-function] ido'."  For details of keybindings, do `\\[describe-function] ido'."
3332    (interactive)    (interactive)
3333    (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " (buffer-name (current-buffer))))    (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " (buffer-name (current-buffer)) nil 'ignore))
3334    
3335  ;;;###autoload  ;;;###autoload
3336  (defun ido-insert-buffer ()  (defun ido-insert-buffer ()
# Line 3293  For details of keybindings, do `\\[descr Line 3338  For details of keybindings, do `\\[descr
3338  The buffer name is selected interactively by typing a substring.  The buffer name is selected interactively by typing a substring.
3339  For details of keybindings, do `\\[describe-function] ido'."  For details of keybindings, do `\\[describe-function] ido'."
3340    (interactive)    (interactive)
3341    (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: "))    (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil nil 'ido-enter-insert-file))
3342    
3343  ;;;###autoload  ;;;###autoload
3344  (defun ido-switch-buffer-other-frame ()  (defun ido-switch-buffer-other-frame ()
# Line 3311  For details of keybindings, do `\\[descr Line 3356  For details of keybindings, do `\\[descr
3356    (interactive "DDir: ")    (interactive "DDir: ")
3357    (if (not (equal (substring dir -1) "/"))    (if (not (equal (substring dir -1) "/"))
3358        (setq dir (concat dir "/")))        (setq dir (concat dir "/")))
3359    (ido-file-internal ido-default-file-method nil dir))    (ido-file-internal ido-default-file-method nil dir nil nil nil 'ignore))
3360    
3361  ;;;###autoload  ;;;###autoload
3362  (defun ido-find-file ()  (defun ido-find-file ()
# Line 3404  For details of keybindings, do `\\[descr Line 3449  For details of keybindings, do `\\[descr
3449  The file name is selected interactively by typing a substring.  The file name is selected interactively by typing a substring.
3450  For details of keybindings, do `\\[describe-function] ido-find-file'."  For details of keybindings, do `\\[describe-function] ido-find-file'."
3451    (interactive)    (interactive)
3452    (ido-file-internal 'display))    (ido-file-internal 'display nil nil nil nil nil 'ignore))
3453    
3454  ;;;###autoload  ;;;###autoload
3455  (defun ido-find-file-other-frame ()  (defun ido-find-file-other-frame ()
# Line 3426  For details of keybindings, do `\\[descr Line 3471  For details of keybindings, do `\\[descr
3471          (ido-report-no-match nil)          (ido-report-no-match nil)
3472          (ido-confirm-unique-completion t)          (ido-confirm-unique-completion t)
3473          (ido-auto-merge-work-directories-length -1))          (ido-auto-merge-work-directories-length -1))
3474      (ido-file-internal 'write 'write-file nil "Write file: ")))      (ido-file-internal 'write 'write-file nil "Write file: " nil nil 'ignore)))
3475    
3476  ;;;###autoload  ;;;###autoload
3477  (defun ido-insert-file ()  (defun ido-insert-file ()
# Line 3434  For details of keybindings, do `\\[descr Line 3479  For details of keybindings, do `\\[descr
3479  The file name is selected interactively by typing a substring.  The file name is selected interactively by typing a substring.
3480  For details of keybindings, do `\\[describe-function] ido-find-file'."  For details of keybindings, do `\\[describe-function] ido-find-file'."
3481    (interactive)    (interactive)
3482    (ido-file-internal 'insert 'insert-file nil "Insert file: "))    (ido-file-internal 'insert 'insert-file nil "Insert file: " nil nil 'ido-enter-insert-buffer))
3483    
3484  ;;;###autoload  ;;;###autoload
3485  (defun ido-dired ()  (defun ido-dired ()
# Line 3515  For details of keybindings, do `\\[descr Line 3560  For details of keybindings, do `\\[descr
3560    
3561          ;; Handle explicit directory changes          ;; Handle explicit directory changes
3562          (cond          (cond
3563           ((eq ido-cur-item 'buffer)           ((memq ido-cur-item '(buffer list))
3564            )            )
3565    
3566           ((= (length contents) 0)           ((= (length contents) 0)
# Line 3830  For details of keybindings, do `\\[descr Line 3875  For details of keybindings, do `\\[descr
3875  (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate)  (defun ido-read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
3876    "Read file name, prompting with PROMPT and completing in directory DIR.    "Read file name, prompting with PROMPT and completing in directory DIR.
3877  See `read-file-name' for additional parameters."  See `read-file-name' for additional parameters."
3878    (cond    (let (filename)
3879    ((or (eq predicate 'file-directory-p)      (cond
3880         (eq (get this-command 'ido) 'dir)       ((or (eq predicate 'file-directory-p)
3881         (memq this-command ido-read-file-name-as-directory-commands))            (eq (get this-command 'ido) 'dir)
3882     (ido-read-directory-name prompt dir default-filename mustmatch initial))            (memq this-command ido-read-file-name-as-directory-commands))
3883    ((and (not (eq (get this-command 'ido) 'ignore))        (setq filename
3884          (not (memq this-command ido-read-file-name-non-ido))              (ido-read-directory-name prompt dir default-filename mustmatch initial)))
3885          (or (null predicate) (eq predicate 'file-exists-p)))       ((and (not (eq (get this-command 'ido) 'ignore))
3886     (let* (filename             (not (memq this-command ido-read-file-name-non-ido))
3887            ido-saved-vc-hb             (or (null predicate) (eq predicate 'file-exists-p)))
3888            (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))        (let* (ido-saved-vc-hb
3889            (ido-current-directory (ido-expand-directory dir))               (ido-context-switch-command 'ignore)
3890            (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))               (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
3891            (ido-work-directory-index -1)               (ido-current-directory (ido-expand-directory dir))
3892            (ido-work-file-index -1)               (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
3893            (ido-find-literal nil))               (ido-work-directory-index -1)
3894       (setq filename               (ido-work-file-index -1)
3895             (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial))               (ido-find-literal nil))
3896       (if filename          (setq ido-exit nil)
3897           (concat ido-current-directory filename))))          (setq filename
3898    (t                (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial))
3899     (let ((read-file-name-function nil))          (cond
3900       (read-file-name prompt dir default-filename mustmatch initial predicate)))))           ((eq ido-exit 'fallback)
3901              (setq filename 'fallback))
3902             (filename
3903              (setq filename
3904                    (concat ido-current-directory filename))))))
3905         (t
3906          (setq filename 'fallback)))
3907        (if (eq filename 'fallback)
3908            (let ((read-file-name-function nil))
3909              (read-file-name prompt dir default-filename mustmatch initial predicate))
3910          filename)))
3911    
3912  ;;;###autoload  ;;;###autoload
3913  (defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial)  (defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial)
3914    "Read directory name, prompting with PROMPT and completing in directory DIR.    "Read directory name, prompting with PROMPT and completing in directory DIR.
3915  See `read-file-name' for additional parameters."  See `read-file-name' for additional parameters."
3916    (let* (filename    (let* (filename
3917             (ido-context-switch-command 'ignore)
3918           ido-saved-vc-hb           ido-saved-vc-hb
3919           (ido-current-directory (ido-expand-directory dir))           (ido-current-directory (ido-expand-directory dir))
3920           (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))           (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
# Line 3871  See `read-file-name' for additional para Line 3927  See `read-file-name' for additional para
3927              ido-current-directory              ido-current-directory
3928            (concat ido-current-directory filename)))))            (concat ido-current-directory filename)))))
3929    
3930    ;;;###autoload
3931    (defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def)
3932      "Read a string in the minibuffer with ido-style completion.
3933    PROMPT is a string to prompt with; normally it ends in a colon and a space.
3934    CHOICES is a list of strings which are the possible completions.
3935    PREDICATE is currently ignored; it is included to be compatible
3936     with `completing-read'.
3937    If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
3938     the input is (or completes to) an element of CHOICES or is null.
3939     If the input is null, `ido-completing-read' returns DEF, or an empty
3940     string if DEF is nil, regardless of the value of REQUIRE-MATCH.
3941    If INITIAL-INPUT is non-nil, insert it in the minibuffer initially,
3942     with point positioned at the end.
3943    HIST, if non-nil, specifies a history list.
3944    DEF, if non-nil, is the default value."
3945      (let ((ido-current-directory nil)
3946            (ido-directory-nonreadable nil)
3947            (ido-context-switch-command 'ignore)
3948            (ido-choice-list choices))
3949        (ido-read-internal 'list prompt hist def require-match initial-input)))
3950    
3951    
3952  ;;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da  ;;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
3953  ;;; ido.el ends here  ;;; ido.el ends here

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26