;;; Code:
-(defvar cua-inhibit-cua-keys)
+(defvar recentf-list)
;;; User Variables
;;
:type '(repeat string)
:group 'ido)
+(defcustom ido-use-virtual-buffers nil
+ "If non-nil, refer to past buffers as well as existing ones.
+Essentially it works as follows: Say you are visiting a file and
+the buffer gets cleaned up by mignight.el. Later, you want to
+switch to that buffer, but find it's no longer open. With
+virtual buffers enabled, the buffer name stays in the buffer
+list (using the `ido-virtual' face, and always at the end), and if
+you select it, it opens the file back up again. This allows you
+to think less about whether recently opened files are still open
+or not. Most of the time you can quit Emacs, restart, and then
+switch to a file buffer that was previously open as if it still
+were.
+ This feature relies upon the `recentf' package, which will be
+enabled if this variable is configured to a non-nil value."
+ :version "24.1"
+ :type 'boolean
+ :group 'ido)
+
(defcustom ido-use-faces t
"Non-nil means use ido faces to highlighting first match, only match and
subdirs in the alternatives."
"Face used by ido for highlighting subdirs in the alternatives."
:group 'ido)
+(defface ido-virtual '((t (:inherit font-lock-builtin-face)))
+ "Face used by ido for matching virtual buffer names."
+ :version "24.1"
+ :group 'ido)
+
(defface ido-indicator '((((min-colors 88) (class color))
(:foreground "yellow1"
:background "red1"
"Non-nil means to explicitly cursor on entry to minibuffer.
Value is an integer which is number of chars to right of prompt.")
+(defvar ido-virtual-buffers nil
+ "List of virtual buffers, that is, past visited files.
+This is a copy of `recentf-list', pared down and with faces applied.
+Only used if `ido-use-virtual-buffers' is non-nil.")
+
;;; Variables with dynamic bindings.
;;; Declared here to keep the byte compiler quiet.
(define-key map "\C-o" 'ido-copy-current-word)
(define-key map "\C-w" 'ido-copy-current-file-name)
(define-key map [(meta ?l)] 'ido-toggle-literal)
- (define-key map "\C-v" 'ido-toggle-vc)
(set-keymap-parent map ido-file-dir-completion-map)
(setq ido-file-completion-map map))
(define-key map "\C-x\C-f" 'ido-enter-find-file)
(define-key map "\C-x\C-b" 'ido-fallback-command)
(define-key map "\C-k" 'ido-kill-buffer-at-head)
+ (define-key map "\C-o" 'ido-toggle-virtual-buffers)
(set-keymap-parent map ido-common-completion-map)
(setq ido-buffer-completion-map map)))
(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))
(require-match (confirm-nonexistent-file-or-buffer))
(buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default
- require-match initial)))
+ require-match initial))
+ filename)
;; Choose the buffer name: either the text typed in, or the head
;; of the list of matches
(point))))
(ido-visit-buffer buf method t)))
+ ;; check for a virtual buffer reference
+ ((and ido-use-virtual-buffers ido-virtual-buffers
+ (setq filename (assoc buf ido-virtual-buffers)))
+ (ido-visit-buffer (find-file-noselect (cdr filename)) method t))
+
+ ((and (eq ido-create-new-buffer 'prompt)
+ (null require-match)
+ (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
+ nil)
+
;; buffer doesn't exist
((and (eq ido-create-new-buffer 'never)
(null require-match))
(setq ido-exit 'keep)
(exit-minibuffer))))
+(defun ido-toggle-virtual-buffers ()
+ "Toggle the use of virtual buffers.
+See `ido-use-virtual-buffers' for explanation of virtual buffer."
+ (interactive)
+ (when (and ido-mode (eq ido-cur-item 'buffer))
+ (setq ido-use-virtual-buffers (not ido-use-virtual-buffers))
+ (setq ido-text-init ido-text)
+ (setq ido-exit 'refresh)
+ (exit-minibuffer)))
+
(defun ido-reread-directory ()
"Read current directory again.
May be useful if cached version is no longer valid, but directory
((eq this-original-command 'viper-del-backward-char-in-insert)
(funcall this-original-command))
(t
- (delete-backward-char (prefix-numeric-value count)))))
+ (delete-char (- (prefix-numeric-value count))))))
(defun ido-delete-backward-word-updir (count)
"Delete all chars backwards, or at beginning of buffer, go up one level."
(if default
(setq ido-temp-list
(cons default (delete default ido-temp-list))))
+ (if ido-use-virtual-buffers
+ (ido-add-virtual-buffers-to-list))
(run-hooks 'ido-make-buffer-list-hook)
ido-temp-list))
+(defun ido-add-virtual-buffers-to-list ()
+ "Add recently visited files, and bookmark files, to the buffer list.
+This is to make them appear as if they were \"virtual buffers\"."
+ ;; If no buffers matched, and virtual buffers are being used, then
+ ;; consult the list of past visited files, to see if we can find
+ ;; the file which the user might thought was still open.
+ (unless recentf-mode (recentf-mode 1))
+ (setq ido-virtual-buffers nil)
+ (let (name)
+ (dolist (head recentf-list)
+ (and (setq name (file-name-nondirectory head))
+ (null (get-file-buffer head))
+ (not (assoc name ido-virtual-buffers))
+ (not (member name ido-temp-list))
+ (not (ido-ignore-item-p name ido-ignore-buffers))
+ ;;(file-exists-p head)
+ (push (cons name head) ido-virtual-buffers))))
+ (when ido-virtual-buffers
+ (if ido-use-faces
+ (dolist (comp ido-virtual-buffers)
+ (put-text-property 0 (length (car comp))
+ 'face 'ido-virtual
+ (car comp))))
+ (setq ido-temp-list
+ (nconc ido-temp-list
+ (nreverse (mapcar #'car ido-virtual-buffers))))))
+
(defun ido-make-choice-list (default)
;; Return the current list of choices.
;; If DEFAULT is non-nil, and corresponds to an element of choices,
;; Strip method:user@host: part of tramp completions.
;; Tramp completions do not include leading slash.
(let* ((len (1- (length dir)))
- (tramp-completion-mode t)
+ (non-essential t)
(compl
(or (file-name-all-completions "" dir)
;; work around bug in ange-ftp.
(when (ido-active)
(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 (featurep 'xemacs)
(ido-exhibit)
(goto-char (point-min)))