;;; 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
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)
;; the file which the user might thought was still open.
(unless recentf-mode (recentf-mode 1))
(setq ido-virtual-buffers nil)
- (let ((bookmarks (and (boundp 'bookmark-alist)
- bookmark-alist))
- name)
+ (let (name)
(dolist (head (append
recentf-list
- (delq nil (mapcar (lambda (bookmark)
- (cdr (assoc 'filename bookmark)))
- bookmarks))))
+ (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)))