*** empty log message ***
[bpt/emacs.git] / lisp / ido.el
index 0808075..314f495 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 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
@@ -11,7 +11,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -436,20 +436,19 @@ in merged file and directory lists."
   :type '(repeat (choice regexp function))
   :group 'ido)
 
-;;; Examples for setting the value of ido-ignore-buffers
-;(defun ido-ignore-c-mode (name)
-;  "Ignore all c mode buffers -- example function for ido."
-;  (save-excursion
-;    (set-buffer name)
-;    (string-match "^C$" mode-name)))
-;
-;(setq ido-ignore-buffers '("^ " ido-ignore-c-mode))
+;; Examples for setting the value of ido-ignore-buffers
+;;(defun ido-ignore-c-mode (name)
+;;  "Ignore all c mode buffers -- example function for ido."
+;;  (with-current-buffer name
+;;    (derived-mode-p 'c-mode)))
+;;
+;;(setq ido-ignore-buffers '("^ " ido-ignore-c-mode))
 
-;;; Examples for setting the value of ido-ignore-files
-;(setq ido-ignore-files '("^ " "\\.c$" "\\.h$"))
+;; Examples for setting the value of ido-ignore-files
+;;(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)
@@ -469,7 +468,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)
@@ -898,7 +897,7 @@ See documentation of `walk-windows' for useful values.")
 (defcustom ido-minibuffer-setup-hook nil
   "*Ido-specific customization of minibuffer setup.
 
-This hook is run during minibuffer setup iff `ido' will be active.
+This hook is run during minibuffer setup if `ido' is active.
 It is intended for use in customizing ido for interoperation
 with other packages.  For instance:
 
@@ -1309,6 +1308,8 @@ Value is an integer which is number of chars to right of prompt.")
       (unwind-protect
          (with-current-buffer buf
            (erase-buffer)
+           (insert ";;; -*- coding: utf-8 -*-\n")
+           (setq buffer-file-coding-system 'utf-8)
            (ido-pp 'ido-last-directory-list)
            (ido-pp 'ido-work-directory-list)
            (ido-pp 'ido-work-file-list)
@@ -2280,9 +2281,10 @@ If cursor is not at the end of the user input, move to end of input."
                filename t))
 
         ((and ido-use-filename-at-point
-              (setq fn (if (eq ido-use-filename-at-point 'guess)
-                           (with-no-warnings (ffap-guesser))
-                         (ffap-string-at-point)))
+              (setq fn (with-no-warnings
+                         (if (eq ido-use-filename-at-point 'guess)
+                             (ffap-guesser)
+                           (ffap-string-at-point))))
               (not (string-match "^http:/" fn))
               (setq d (file-name-directory fn))
               (file-directory-p d))
@@ -2535,17 +2537,18 @@ If no merge has yet taken place, toggle automatic merging option."
 
 ;;; Magic C-f
 
-(defun ido-magic-forward-char ()
+(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."
-  (interactive)
+  (interactive "P")
   (cond
-   ((not (eobp))
-    (forward-char 1))
+   ((or arg (not (eobp)))
+    (forward-char (min (prefix-numeric-value arg)
+                      (- (point-max) (point)))))
    ((memq ido-cur-item '(file dir))
     (ido-fallback-command))
    (ido-context-switch-command
@@ -2555,17 +2558,19 @@ C-x d ... C-f    fallback to non-ido dired."
 
 ;;; Magic C-b
 
-(defun ido-magic-backward-char ()
+(defun ido-magic-backward-char (arg)
   "Move backward in user input or perform magic action.
 If no user input is present, or at start of input, perform magic actions:
 C-x C-f C-b  switch to `ido-switch-buffer'.
 C-x C-d C-b  switch to `ido-switch-buffer'.
 C-x d C-b    switch to `ido-switch-buffer'.
 C-x C-b C-b  fallback to non-ido `switch-to-buffer'."
-  (interactive)
+  (interactive "P")
   (cond
-   ((> (point) (minibuffer-prompt-end))
-    (forward-char -1))
+   ((or arg (> (point) (minibuffer-prompt-end)))
+    (forward-char
+     (- (min (prefix-numeric-value arg)
+            (- (point) (minibuffer-prompt-end))))))
    ((eq last-command this-command)
     (when (and (memq ido-cur-item '(file dir))
               (not (bobp)))
@@ -2579,14 +2584,15 @@ C-x C-b C-b  fallback to non-ido `switch-to-buffer'."
 
 ;;; Magic C-d
 
-(defun ido-magic-delete-char ()
+(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."
-  (interactive)
+  (interactive "P")
   (cond
-   ((not (eobp))
-    (delete-char 1))
+   ((or arg (not (eobp)))
+    (delete-char (min (prefix-numeric-value arg)
+                      (- (point-max) (point)))))
    (ido-context-switch-command
     nil)
    ((memq ido-cur-item '(file dir))
@@ -3354,7 +3360,7 @@ for first matching file."
 
 (defun ido-to-end (items)
   ;; Move the elements from ITEMS to the end of `ido-temp-list'
-  (mapcar
+  (mapc
    (lambda (elem)
      (setq ido-temp-list (delq elem ido-temp-list)))
    items)
@@ -3362,6 +3368,8 @@ for first matching file."
       (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) '())
@@ -3369,24 +3377,25 @@ for first matching file."
    ;; Caller must have done that if necessary.
 
    ((and ido-enable-tramp-completion
-        (or (fboundp 'tramp-completion-mode)
+        (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.
-    (let ((len (1- (length dir)))
-         (compl
-          (or (file-name-all-completions "" dir)
-              ;; work around bug in ange-ftp.
-              ;; /ftp:user@host: => nil
-              ;; /ftp:user@host:./ => ok
-              (and
-               (not (string= "/ftp:" dir))
-               (tramp-tramp-file-p dir)
-               (fboundp 'tramp-ftp-file-name-p)
-               (funcall 'tramp-ftp-file-name-p dir)
-               (string-match ":\\'" dir)
-               (file-name-all-completions "" (concat dir "./"))))))
+    (let* ((len (1- (length dir)))
+          (tramp-completion-mode t)
+          (compl
+           (or (file-name-all-completions "" dir)
+               ;; work around bug in ange-ftp.
+               ;; /ftp:user@host: => nil
+               ;; /ftp:user@host:./ => ok
+               (and
+                (not (string= "/ftp:" dir))
+                (tramp-tramp-file-p dir)
+                (fboundp 'tramp-ftp-file-name-p)
+                (funcall 'tramp-ftp-file-name-p dir)
+                (string-match ":\\'" dir)
+                (file-name-all-completions "" (concat dir "./"))))))
       (if (and compl
               (> (length (car compl)) len)
               (string= (substring (car compl) 0 len) (substring dir 1)))
@@ -3603,7 +3612,7 @@ for first matching file."
         full-matches suffix-matches prefix-matches matches)
     (setq ido-incomplete-regexp nil)
     (condition-case error
-        (mapcar
+        (mapc
          (lambda (item)
            (let ((name (ido-name item)))
             (if (and (or non-prefix-dot
@@ -3648,7 +3657,7 @@ for first matching file."
       (setq re (mapconcat #'regexp-quote (split-string ido-text "") ".*"))
       (if ido-enable-prefix
          (setq re (concat "\\`" re)))
-      (mapcar
+      (mapc
        (lambda (item)
         (let ((name (ido-name item)))
           (if (string-match re name)
@@ -4649,5 +4658,5 @@ DEF, if non-nil, is the default value."
     (ido-read-internal 'list prompt hist def require-match initial-input)))
 
 
-;;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
+;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
 ;;; ido.el ends here