=== modified file 'lisp/ido.el' --- lisp/ido.el 2010-05-25 02:11:08 +0000 +++ lisp/ido.el 2010-05-28 12:26:03 +0000 @@ -774,8 +774,10 @@ :type '(repeat string) :group 'ido) -(defcustom ido-use-virtual-buffers nil - "If non-nil, refer to past buffers as well as existing ones. +(defcustom ido-use-virtual-buffers 'never + "If `always', refer to past buffers as well as existing ones. +If `auto', refer to past buffers only when the current input +doesn't match an existing buffer. 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 @@ -785,11 +787,12 @@ 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." +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 + :type '(choice (const always) + (const auto) + (const never)) :group 'ido) (defcustom ido-use-faces t @@ -1056,7 +1059,7 @@ (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.") +Only used if `ido-use-virtual-buffers' is not `never'.") ;;; Variables with dynamic bindings. ;;; Declared here to keep the byte compiler quiet. @@ -1095,6 +1098,15 @@ ;; Don't process ido-ignore- lists once. (defvar ido-process-ignore-lists-inhibit) +;; existing buffers including ignored ones when switching buffers in ido +(defvar ido-existing-buffers) + +;; ido virtual buffers are currently enabled +(defvar ido-virtual-buffers-enabled) + +;; stop ido virtual buffers from being added +(defvar ido-virtual-buffers-inhibit) + ;; Buffer from which ido was entered. (defvar ido-entry-buffer) @@ -1841,6 +1853,7 @@ (icomplete-mode nil) ;; prevent icomplete starting up ;; Exported dynamic variables: ido-cur-list + ido-existing-buffers ido-ignored-list (ido-rotate-temp nil) (ido-keep-item-list nil) @@ -1859,6 +1872,12 @@ (run-hooks 'ido-setup-hook) + (when (eq ido-cur-item 'buffer) + (setq ido-existing-buffers + ;; ido-process-ignore-lists nil means not to ignore + (let (ido-process-ignore-lists ido-virtual-buffers-enabled) + (ido-make-buffer-list nil)))) + (while (not done) (ido-trace "\n_LOOP_" ido-text-init) (setq ido-exit nil) @@ -2181,9 +2200,11 @@ (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)) + ;; when method is 'kill don't enable virtual buffers; this + ;; is the case when calling `idl-kill-buffer'. + (ido-virtual-buffers-enabled (and (eq ido-use-virtual-buffers 'always) + (not (eq method 'kill)))) + (ido-virtual-buffers-inhibit (not ido-virtual-buffers-enabled)) (require-match (confirm-nonexistent-file-or-buffer)) (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default require-match initial)) @@ -2224,7 +2245,8 @@ (ido-visit-buffer buf method t))) ;; check for a virtual buffer reference - ((and ido-use-virtual-buffers ido-virtual-buffers + ((and ido-virtual-buffers-enabled + ido-virtual-buffers (setq filename (assoc buf ido-virtual-buffers))) (ido-visit-buffer (find-file-noselect (cdr filename)) method t)) @@ -2712,7 +2734,8 @@ 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-virtual-buffers-enabled + (not ido-virtual-buffers-enabled)) (setq ido-text-init ido-text) (setq ido-exit 'refresh) (exit-minibuffer))) @@ -3403,7 +3426,7 @@ (when (and default (buffer-live-p (get-buffer default))) (setq ido-temp-list (cons default (delete default ido-temp-list)))) - (if ido-use-virtual-buffers + (if (and (boundp ido-virtual-buffers-enabled) ido-virtual-buffers-enabled) (ido-add-virtual-buffers-to-list)) (run-hooks 'ido-make-buffer-list-hook) ido-temp-list)) @@ -4465,6 +4488,33 @@ (setq ido-exit 'refresh) (exit-minibuffer))) + (when (and (eq ido-use-virtual-buffers 'auto) + (eq ido-cur-item 'buffer) + (not ido-matches) + ido-virtual-buffers-inhibit) + (setq ido-text-init ido-text) + (setq ido-virtual-buffers-enabled t) + (setq ido-virtual-buffers-inhibit nil) + (setq ido-exit 'refresh) + (exit-minibuffer)) + + (when (and (eq ido-use-virtual-buffers 'auto) + (eq ido-cur-item 'buffer) + ido-matches + ido-virtual-buffers-enabled + (not ido-virtual-buffers-inhibit)) + ;; protect ido-matches from being modified by ido-set-matches + (let ((ido-matches ido-matches)) + (let ((ido-cur-list ido-existing-buffers) + (ido-rotate ido-rotate)) + (ido-set-matches)) + (when ido-matches + (setq ido-virtual-buffers-enabled nil) + (setq ido-virtual-buffers-inhibit t) + (setq ido-text-init ido-text) + (setq ido-exit 'refresh) + (exit-minibuffer)))) + (when (and ido-rescan (not ido-matches)