]> code.delx.au - gnu-emacs/blobdiff - lisp/ido.el
(ido-save-history): Set the `coding' local
[gnu-emacs] / lisp / ido.el
index 10418d209aa41d0b6f48d9cd1e96cea337b7638f..2a32743907853cd871917daf8c733f665ed88b77 100644 (file)
@@ -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,
@@ -449,7 +449,7 @@ in merged file and directory lists."
 ;(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 +469,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 +898,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 +1309,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)
@@ -1575,6 +1577,7 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise."
     (define-key map [(meta down)] 'ido-next-work-directory)
     (define-key map [backspace] 'ido-delete-backward-updir)
     (define-key map "\d"        'ido-delete-backward-updir)
+    (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS
     (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir)  ; M-DEL
 
     (define-key map [(control backspace)] 'ido-up-directory)
@@ -1939,8 +1942,14 @@ If INITIAL is non-nil, it specifies the initial input string."
       (if (and ido-matches (eq ido-try-merged-list 'auto))
          (setq ido-try-merged-list t))
       (let
-         ((minibuffer-local-completion-map ido-completion-map)
-          (minibuffer-local-filename-completion-map ido-completion-map)
+         ((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)))
           (ido-completing-read t)
@@ -2163,9 +2172,9 @@ If cursor is not at the end of the user input, move to end of input."
 
        ((eq ido-exit 'fallback)
        (let ((read-buffer-function nil))
-         (run-hook-with-args 'ido-before-fallback-functions
-                             (or fallback 'switch-to-buffer))
-         (call-interactively (or fallback 'switch-to-buffer))))
+         (setq this-command (or fallback 'switch-to-buffer))
+         (run-hook-with-args 'ido-before-fallback-functions this-command)
+         (call-interactively this-command)))
 
        ;; Check buf is non-nil.
        ((not buf) nil)
@@ -2173,6 +2182,7 @@ If cursor is not at the end of the user input, move to end of input."
 
        ;; View buffer if it exists
        ((get-buffer buf)
+       (add-to-history 'buffer-name-history buf)
        (if (eq method 'insert)
            (progn
              (ido-record-command 'insert-buffer buf)
@@ -2192,6 +2202,7 @@ If cursor is not at the end of the user input, move to end of input."
 
        ;; create a new buffer
        (t
+       (add-to-history 'buffer-name-history buf)
        (setq buf (get-buffer-create buf))
        (if (fboundp 'set-buffer-major-mode)
            (set-buffer-major-mode buf))
@@ -2271,9 +2282,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))
@@ -2304,9 +2316,9 @@ If cursor is not at the end of the user input, move to end of input."
        ;; we don't want to change directory of current buffer.
        (let ((default-directory ido-current-directory)
              (read-file-name-function nil))
-         (run-hook-with-args 'ido-before-fallback-functions
-                             (or fallback 'find-file))
-         (call-interactively (or fallback 'find-file))))
+         (setq this-command (or fallback 'find-file))
+         (run-hook-with-args 'ido-before-fallback-functions this-command)
+         (call-interactively this-command)))
 
        ((eq ido-exit 'switch-to-buffer)
        (ido-buffer-internal ido-default-buffer-method nil nil nil ido-text))
@@ -2363,9 +2375,11 @@ If cursor is not at the end of the user input, move to end of input."
        ((eq method 'write)
        (ido-record-work-file filename)
        (setq default-directory ido-current-directory)
-       (ido-record-command 'write-file (concat ido-current-directory filename))
+       (setq filename (concat ido-current-directory filename))
+       (ido-record-command 'write-file filename)
+       (add-to-history 'file-name-history filename)
        (ido-record-work-directory)
-       (write-file (concat ido-current-directory filename)))
+       (write-file filename))
 
        ((eq method 'read-only)
        (ido-record-work-file filename)
@@ -2381,6 +2395,7 @@ If cursor is not at the end of the user input, move to end of input."
        (ido-record-command
         (if ido-find-literal 'insert-file-literally 'insert-file)
         filename)
+       (add-to-history 'file-name-history filename)
        (ido-record-work-directory)
        (insert-file-1 filename
                       (if ido-find-literal
@@ -2391,6 +2406,7 @@ If cursor is not at the end of the user input, move to end of input."
        (ido-record-work-file filename)
        (setq filename (concat ido-current-directory filename))
        (ido-record-command 'find-file filename)
+       (add-to-history 'file-name-history filename)
        (ido-record-work-directory)
        (ido-visit-buffer (find-file-noselect filename nil ido-find-literal) method))))))
 
@@ -2403,8 +2419,8 @@ If cursor is not at the end of the user input, move to end of input."
 (defun ido-set-common-completion  ()
   ;; Find common completion of `ido-text' in `ido-matches'
   ;; The result is stored in `ido-common-match-string'
-  (let* (val)
-    (setq  ido-common-match-string nil)
+  (let (val)
+    (setq ido-common-match-string nil)
     (if (and ido-matches
             (not ido-enable-regexp) ;; testing
              (stringp ido-text)
@@ -3341,7 +3357,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)
@@ -3349,6 +3365,8 @@ for first matching file."
       (nconc ido-temp-list items)
     (setq ido-temp-list items)))
 
+(declare-function tramp-tramp-file-p "net/tramp" (name))
+
 (defun ido-file-name-all-completions-1 (dir)
   (cond
    ((ido-nonreadable-directory-p dir) '())
@@ -3356,24 +3374,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)))
@@ -3590,7 +3609,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
@@ -3635,7 +3654,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)
@@ -3804,7 +3823,7 @@ for first matching file."
 If cursor is not at the end of the user input, delete to end of input."
   (interactive)
   (if (not (eobp))
-      (kill-line)
+      (delete-region (point) (line-end-position))
     (let ((enable-recursive-minibuffers t)
          (buf (ido-name (car ido-matches))))
       (when buf
@@ -3822,7 +3841,7 @@ If cursor is not at the end of the user input, delete to end of input."
 If cursor is not at the end of the user input, delete to end of input."
   (interactive)
   (if (not (eobp))
-      (kill-line)
+      (delete-region (point) (line-end-position))
     (let ((enable-recursive-minibuffers t)
          (file (ido-name (car ido-matches))))
       (if file
@@ -3939,7 +3958,7 @@ in a separate window.
 (defun ido-switch-buffer-other-window ()
   "Switch to another buffer and show it in another window.
 The buffer name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido'."
+For details of keybindings, see `ido-switch-buffer'."
   (interactive)
   (ido-buffer-internal 'other-window 'switch-to-buffer-other-window))
 
@@ -3947,7 +3966,7 @@ For details of keybindings, do `\\[describe-function] ido'."
 (defun ido-display-buffer ()
   "Display a buffer in another window but don't select it.
 The buffer name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido'."
+For details of keybindings, see `ido-switch-buffer'."
   (interactive)
   (ido-buffer-internal 'display 'display-buffer nil nil nil 'ignore))
 
@@ -3955,7 +3974,7 @@ For details of keybindings, do `\\[describe-function] ido'."
 (defun ido-kill-buffer ()
   "Kill a buffer.
 The buffer name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido'."
+For details of keybindings, see `ido-switch-buffer'."
   (interactive)
   (ido-buffer-internal 'kill 'kill-buffer "Kill buffer: " (buffer-name (current-buffer)) nil 'ignore))
 
@@ -3963,7 +3982,7 @@ For details of keybindings, do `\\[describe-function] ido'."
 (defun ido-insert-buffer ()
   "Insert contents of a buffer in current buffer after point.
 The buffer name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido'."
+For details of keybindings, see `ido-switch-buffer'."
   (interactive)
   (ido-buffer-internal 'insert 'insert-buffer "Insert buffer: " nil nil 'ido-enter-insert-file))
 
@@ -3971,7 +3990,7 @@ For details of keybindings, do `\\[describe-function] ido'."
 (defun ido-switch-buffer-other-frame ()
   "Switch to another buffer and show it in another frame.
 The buffer name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido'."
+For details of keybindings, see `ido-switch-buffer'."
   (interactive)
   (if ido-mode
       (ido-buffer-internal 'other-frame)
@@ -3981,8 +4000,7 @@ For details of keybindings, do `\\[describe-function] ido'."
 (defun ido-find-file-in-dir (dir)
   "Switch to another file starting from DIR."
   (interactive "DDir: ")
-  (if (not (equal (substring dir -1) "/"))
-      (setq dir (concat dir "/")))
+  (setq dir (file-name-as-directory dir))
   (ido-file-internal ido-default-file-method nil dir nil nil nil 'ignore))
 
 ;;;###autoload
@@ -4034,7 +4052,7 @@ in a separate window.
 (defun ido-find-file-other-window ()
   "Switch to another file and show it in another window.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'other-window 'find-file-other-window))
 
@@ -4042,7 +4060,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-find-alternate-file ()
   "Switch to another file and show it in another window.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'alt-file 'find-alternate-file nil "Find alternate file: "))
 
@@ -4050,7 +4068,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-find-file-read-only ()
   "Edit file read-only with name obtained via minibuffer.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'read-only 'find-file-read-only nil "Find file read-only: "))
 
@@ -4058,7 +4076,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-find-file-read-only-other-window ()
   "Edit file read-only in other window with name obtained via minibuffer.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'read-only 'find-file-read-only-other-window nil "Find file read-only other window: "))
 
@@ -4066,7 +4084,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-find-file-read-only-other-frame ()
   "Edit file read-only in other frame with name obtained via minibuffer.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'read-only 'find-file-read-only-other-frame nil "Find file read-only other frame: "))
 
@@ -4074,7 +4092,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-display-file ()
   "Display a file in another window but don't select it.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'display nil nil nil nil nil 'ignore))
 
@@ -4082,7 +4100,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-find-file-other-frame ()
   "Switch to another file and show it in another frame.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'other-frame 'find-file-other-frame))
 
@@ -4090,7 +4108,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-write-file ()
   "Write current buffer to a file.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (let ((ido-process-ignore-lists t)
        (ido-work-directory-match-only nil)
@@ -4104,7 +4122,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-insert-file ()
   "Insert contents of file in current buffer.
 The file name is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (ido-file-internal 'insert 'insert-file nil "Insert file: " nil nil 'ido-enter-insert-buffer))
 
@@ -4112,7 +4130,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-dired ()
   "Call `dired' the ido way.
 The directory is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (let ((ido-report-no-match nil)
        (ido-auto-merge-work-directories-length -1))
@@ -4121,7 +4139,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
 (defun ido-list-directory ()
   "Call `list-directory' the ido way.
 The directory is selected interactively by typing a substring.
-For details of keybindings, do `\\[describe-function] ido-find-file'."
+For details of keybindings, see `ido-find-file'."
   (interactive)
   (let ((ido-report-no-match nil)
        (ido-auto-merge-work-directories-length -1))