;;; ido.el --- interactively do things with buffers and files
-;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
;; Author: Kim F. Storm <storm@cua.dk>
;; Based on: iswitchb by Stephen Eglen <stephen@cns.ed.ac.uk>
;;; Code:
(defvar recentf-list)
+(require 'seq)
;;;; Options
'("\\` ")
"List of regexps or functions matching buffer names to ignore.
For example, traditional behavior is not to list buffers whose names begin
-with a space, for which the regexp is `\\` '. See the source file for
+with a space, for which the regexp is `\\\\=` '. See the source file for
example functions that filter buffer names."
:type '(repeat (choice regexp function))
:group 'ido)
'("\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./")
"List of regexps or functions matching file names to ignore.
For example, traditional behavior is not to list files whose names begin
-with a #, for which the regexp is `\\`#'. See the source file for
+with a #, for which the regexp is `\\\\=`#'. See the source file for
example functions that filter filenames."
:type '(repeat (choice regexp function))
:group 'ido)
(defcustom ido-enter-matching-directory 'only
"Additional methods to enter sub-directory of first/only matching item.
-If value is 'first, enter first matching sub-directory when typing a slash.
-If value is 'only, typing a slash only enters the sub-directory if it is
+If value is `first', enter first matching sub-directory when typing a slash.
+If value is `only', typing a slash only enters the sub-directory if it is
the only matching item.
If value is t, automatically enter a sub-directory when it is the only
matching item, even without typing a slash."
(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
-ask user whether to create buffer, or 'never to never create new buffer."
+Choices are `always' to create new buffers unconditionally, `prompt' to
+ask user whether to create buffer, or `never' to never create new buffer."
:type '(choice (const always)
(const prompt)
(const never))
It is intended for use in customizing Ido for interoperation
with other packages. For instance:
- (add-hook 'ido-minibuffer-setup-hook
+ (add-hook \\='ido-minibuffer-setup-hook
(lambda () (setq-local max-mini-window-height 3)))
will constrain Emacs to a maximum minibuffer height of 3 lines when
(when ido-everywhere
(when (memq ido-mode '(both file))
(put 'ido-everywhere 'file (cons read-file-name-function nil))
- (setq read-file-name-function 'ido-read-file-name))
+ (setq read-file-name-function #'ido-read-file-name))
(when (memq ido-mode '(both buffer))
(put 'ido-everywhere 'buffer (cons read-buffer-function nil))
- (setq read-buffer-function 'ido-read-buffer))))
+ (setq read-buffer-function #'ido-read-buffer))))
(defvar ido-minor-mode-map-entry nil)
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.
-However, if ARG arg equals 'files, remap only commands for files, or
-if it equals 'buffers, remap only commands for buffer switching.
+However, if ARG arg equals `files', remap only commands for files, or
+if it equals `buffers', remap only commands for buffer switching.
This function also adds a hook to the minibuffer."
(interactive "P")
(setq ido-mode
((and (eq ido-create-new-buffer 'prompt)
(null require-match)
- (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
+ (not (y-or-n-p (format-message
+ "No buffer matching `%s', create one? " buf))))
nil)
;; buffer doesn't exist
((and (eq ido-create-new-buffer 'prompt)
(null require-match)
- (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
+ (not (y-or-n-p (format-message
+ "No buffer matching `%s', create one? " buf))))
nil)
;; create a new buffer
(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)
+(defun ido-restrict-to-matches (&optional removep)
+ "Set current item list to the currently matched items.
+
+When argument REMOVEP is non-nil, the currently matched items are
+instead removed from the current item list."
+ (interactive "P")
(when ido-matches
- (setq ido-cur-list ido-matches
+ (setq ido-cur-list (if removep
+ ;; An important feature is to preserve the
+ ;; order of the elements.
+ (seq-difference ido-cur-list ido-matches)
+ ido-matches)
+ ido-matches ido-cur-list
ido-text-init ""
ido-rescan nil
ido-exit 'keep)
(unless recentf-mode (recentf-mode 1))
(setq ido-virtual-buffers nil)
(let (name)
- (dolist (head recentf-list)
+ (dolist (head (append
+ recentf-list
+ (and (fboundp 'bookmark-get-filename)
+ (delq nil (mapcar #'bookmark-get-filename
+ (bound-and-true-p bookmark-alist))))))
(setq name (file-name-nondirectory head))
;; In case HEAD is a directory with trailing /. See bug#14552.
(when (equal name "")
(let* ((len (1- (length dir)))
(non-essential t)
(compl
- (or (file-name-all-completions "" dir)
+ (or ;; We do not want to be disturbed by "File does not
+ ;; exist" errors.
+ (ignore-errors (file-name-all-completions "" dir))
;; work around bug in ange-ftp.
;; /ftp:user@host: => nil
;; /ftp:user@host:./ => ok
(not (and (eq ido-cur-item 'buffer)
ido-buffer-disable-smart-matches))
(not ido-enable-regexp)
- (not (string-match "\$\\'" rex0))
+ (not (string-match "$\\'" rex0))
(concat "\\`" rex0 (if slash "/" "") "\\'")))
(suffix-re (and do-full slash
(not (and (eq ido-cur-item 'buffer)
ido-buffer-disable-smart-matches))
(not ido-enable-regexp)
- (not (string-match "\$\\'" rex0))
+ (not (string-match "$\\'" rex0))
(concat rex0 "/\\'")))
(prefix-re (and full-re (not ido-enable-prefix)
(concat "\\`" rexq)))
(put 'dired-do-rename 'ido 'ignore)
;;;###autoload
-(defun ido-read-buffer (prompt &optional default require-match)
+(defun ido-read-buffer (prompt &optional default require-match predicate)
"Ido replacement for the built-in `read-buffer'.
Return the name of a buffer selected.
PROMPT is the prompt to give to the user. DEFAULT if given is the default
(if (eq ido-exit 'fallback)
(let ((read-buffer-function nil))
(run-hook-with-args 'ido-before-fallback-functions 'read-buffer)
- (read-buffer prompt default require-match))
+ (read-buffer prompt default require-match predicate))
buf)))
;;;###autoload