-;;; 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>
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
;; 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)
(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))))
(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)
;; 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 using ido-mode everywhere file and directory names are read.
+With ARG, turn ido-mode on if arg is positive, off otherwise."
:global t
:group 'ido
(when (get 'ido-everywhere 'file)
;;;###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.
(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)
(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
(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 history))))
+ (ido-trace "read-from-minibuffer" ido-final-text)
(if (get-buffer ido-completion-buffer)
(kill-buffer ido-completion-buffer))
(t
(setq done t))))))
+ (add-to-history (or history 'minibuffer-history) ido-selected)
ido-selected))
(defun ido-edit-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))
(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)
(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)
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)
(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."
(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.
;; 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))
(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)))))))
(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))
(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 ()
;; 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'.
(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
(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 ()
(provide 'ido)
-;; arch-tag: b63a3500-1735-41bd-8a01-05373f0864da
;;; ido.el ends here