: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."
(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
(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]")
(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.")
"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
(define-key map "\C-c" 'ido-toggle-case)
(define-key map "\C-e" 'ido-edit-input)
(define-key map "\t" 'ido-complete)
+ (define-key map " " 'ido-complete-space)
(define-key map "\C-j" 'ido-select-text)
(define-key map "\C-m" 'ido-exit-minibuffer)
(define-key map "\C-p" 'ido-toggle-prefix)
(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)
(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))
(catch 'ido
(completing-read
(ido-make-prompt item prompt)
- '(("dummy".1)) nil nil ; table predicate require-match
+ '(("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)
(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)
(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)
;; Check buf is non-nil.
((not buf) nil)
+ ((= (length buf) 0) nil)
;; View buffer if it exists
((get-buffer buf)
((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.
(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 ()
+ "Try completion unless inserting the space makes sense."
+ (interactive)
+ (if (and (stringp ido-common-match-string)
+ (stringp ido-text)
+ (cond
+ ((> (length ido-common-match-string) (length ido-text))
+ (= (aref ido-common-match-string (length ido-text)) ? ))
+ (ido-matches
+ (let (insert-space
+ (re (concat (regexp-quote ido-text) " "))
+ (comp ido-matches))
+ (while comp
+ (if (string-match re (ido-name (car comp)))
+ (setq comp nil insert-space t)
+ (setq comp (cdr comp))))
+ insert-space))
+ (t nil)))
+ (insert " ")
+ (ido-complete)))
+
(defun ido-undo-merge-work-directory (&optional text try refresh)
"Undo or redo last ido directory merge operation.
If no merge has yet taken place, toggle automatic merging option."
(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)
res)
(while paths
(setq path (car paths)
- paths (cdr paths)
paths (cdr paths))
(if (and (string-match "^/" path)
(file-exists-p path))
res t))))))
(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))))
+ (setq res (delq elt res))
+ (setq res (cons elt res)))))
(message nil)
res))
(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))))
(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
ido-enable-flex-matching
(> (length ido-text) 1)
(not ido-enable-regexp))
- (setq re (mapconcat 'identity (split-string ido-text "") ".*"))
+ (setq re (mapconcat #'regexp-quote (split-string ido-text "") ".*"))
(if ido-enable-prefix
(setq re (concat "\\`" re)))
(mapcar
(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))
(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'.
(if ido-enable-regexp
subs
(regexp-quote subs)))
- (setq res (mapcar 'ido-word-matching-substring items))
+ (setq res (mapcar #'ido-word-matching-substring items))
(setq res (delq nil res)) ;; remove any nil elements (shouldn't happen)
- (setq alist (mapcar 'ido-makealist res)) ;; could use an OBARRAY
+ (setq alist (mapcar #'ido-makealist res)) ;; could use an OBARRAY
;; try-completion returns t if there is an exact match.
- (let ((completion-ignore-case ido-case-fold))
-
- (try-completion subs alist))))
+ (let* ((completion-ignore-case ido-case-fold)
+ (comp (try-completion subs alist)))
+ (if (eq comp t)
+ subs
+ comp))))
(defun ido-word-matching-substring (word)
;; Return part of WORD before 1st match to `ido-change-word-sub'.
(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 "
(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
(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)
;; 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
(let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999))
(alternatives
(apply
- (function concat)
+ #'concat
(cdr (apply
- (function nconc)
- (mapcar '(lambda (com)
- (setq com (ido-name com))
- (setq items (1- items))
- (cond
- ((< items 0) ())
- ((= items 0) (list (nth 3 ido-decorations))) ; " | ..."
- (t
- (list (or ido-separator (nth 2 ido-decorations)) ; " | "
- (let ((str (substring com 0)))
- (if (and ido-use-faces
- (not (string= str first))
- (ido-final-slash str))
- (put-text-property 0 (length str) 'face 'ido-subdir-face str))
- str)))))
- comps))))))
+ #'nconc
+ (mapcar
+ (lambda (com)
+ (setq com (ido-name com))
+ (setq items (1- items))
+ (cond
+ ((< items 0) ())
+ ((= items 0) (list (nth 3 ido-decorations))) ; " | ..."
+ (t
+ (list (or ido-separator (nth 2 ido-decorations)) ; " | "
+ (let ((str (substring com 0)))
+ (if (and ido-use-faces
+ (not (string= str first))
+ (ido-final-slash str))
+ (put-text-property 0 (length str) 'face 'ido-subdir-face str))
+ str)))))
+ comps))))))
(concat
;; put in common completion item -- what you get by pressing tab
- (if (> (length ido-common-match-string) (length name))
+ (if (and (stringp ido-common-match-string)
+ (> (length ido-common-match-string) (length name)))
(concat (nth 4 ido-decorations) ;; [ ... ]
(substring ido-common-match-string (length name))
(nth 5 ido-decorations)))
"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)))
(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))