aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Wiegley2010-04-04 02:55:19 -0400
committerJohn Wiegley2010-04-04 02:55:19 -0400
commit0523d11710e8be81083af7f756dcc5f937ce1047 (patch)
treea0ca33c8eb60720bededb5152d8c82b9accbbbc4
parent202ff0d6ee56d743219c01870be24ccc0d14b429 (diff)
downloademacs-0523d11710e8be81083af7f756dcc5f937ce1047.tar.gz
emacs-0523d11710e8be81083af7f756dcc5f937ce1047.zip
2010-04-04 John Wiegley <jwiegley@gmail.com>
* ido.el (ido-use-virtual-buffers): New variable to indicate whether "virtual buffer" support is enabled for IDO. 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. NOTE: This feature has been present in iswitchb for several years now, and I'm porting the same logic to IDO. (ido-virtual): Face used to indicate virtual buffers in the list. (ido-buffer-internal): If a buffer is chosen, and no such buffer exists, but a virtual buffer of that name does (which would be why it was in the list), recreate the buffer by reopening the file. (ido-make-buffer-list): If virtual buffers are being used, call `ido-add-virtual-buffers-to-list' before the make list hook. (ido-virtual-buffers): New variable which contains a copy of the current contents of the `recentf-list', albeit pared down for the sake of speed, and with proper faces applied. (ido-add-virtual-buffers-to-list): Using the `recentf-list', create a list of "virtual buffers" to present to the user in addition to the currently open set. Note that this logic could get rather slow if that list is too large. With the default `recentf-max-saved-items' of 200, there is little speed penalty.
-rw-r--r--lisp/ChangeLog30
-rw-r--r--lisp/ido.el56
2 files changed, 85 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 48aed300527..6b4bc0f3785 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,33 @@
12010-04-04 John Wiegley <jwiegley@gmail.com>
2
3 * ido.el (ido-use-virtual-buffers): New variable to indicate
4 whether "virtual buffer" support is enabled for IDO. Essentially
5 it works as follows: Say you are visiting a file and the buffer
6 gets cleaned up by mignight.el. Later, you want to switch to that
7 buffer, but find it's no longer open. With virtual buffers
8 enabled, the buffer name stays in the buffer list (using the
9 ido-virtual face, and always at the end), and if you select it, it
10 opens the file back up again. This allows you to think less about
11 whether recently opened files are still open or not. Most of the
12 time you can quit Emacs, restart, and then switch to a file buffer
13 that was previously open as if it still were. NOTE: This feature
14 has been present in iswitchb for several years now, and I'm
15 porting the same logic to IDO.
16 (ido-virtual): Face used to indicate virtual buffers in the list.
17 (ido-buffer-internal): If a buffer is chosen, and no such buffer
18 exists, but a virtual buffer of that name does (which would be why
19 it was in the list), recreate the buffer by reopening the file.
20 (ido-make-buffer-list): If virtual buffers are being used, call
21 `ido-add-virtual-buffers-to-list' before the make list hook.
22 (ido-virtual-buffers): New variable which contains a copy of the
23 current contents of the `recentf-list', albeit pared down for the
24 sake of speed, and with proper faces applied.
25 (ido-add-virtual-buffers-to-list): Using the `recentf-list',
26 create a list of "virtual buffers" to present to the user in
27 addition to the currently open set. Note that this logic could
28 get rather slow if that list is too large. With the default
29 `recentf-max-saved-items' of 200, there is little speed penalty.
30
12010-04-03 Stefan Monnier <monnier@iro.umontreal.ca> 312010-04-03 Stefan Monnier <monnier@iro.umontreal.ca>
2 32
3 * font-lock.el: Require CL when compiling. 33 * font-lock.el: Require CL when compiling.
diff --git a/lisp/ido.el b/lisp/ido.el
index 48acc50581d..fdfd27ca7d3 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -774,6 +774,13 @@ can be completed using TAB,
774 :type '(repeat string) 774 :type '(repeat string)
775 :group 'ido) 775 :group 'ido)
776 776
777(defcustom ido-use-virtual-buffers nil
778 "If non-nil, refer to past buffers as well as existing ones.
779This feature relies upon the `recentf' package, which will be
780enabled if this variable is configured to a non-nil value."
781 :type 'boolean
782 :group 'ido)
783
777(defcustom ido-use-faces t 784(defcustom ido-use-faces t
778 "Non-nil means use ido faces to highlighting first match, only match and 785 "Non-nil means use ido faces to highlighting first match, only match and
779subdirs in the alternatives." 786subdirs in the alternatives."
@@ -798,6 +805,10 @@ subdirs in the alternatives."
798 "Face used by ido for highlighting subdirs in the alternatives." 805 "Face used by ido for highlighting subdirs in the alternatives."
799 :group 'ido) 806 :group 'ido)
800 807
808(defface ido-virtual '((t (:inherit font-lock-builtin-face)))
809 "Face used by ido for matching virtual buffer names."
810 :group 'ido)
811
801(defface ido-indicator '((((min-colors 88) (class color)) 812(defface ido-indicator '((((min-colors 88) (class color))
802 (:foreground "yellow1" 813 (:foreground "yellow1"
803 :background "red1" 814 :background "red1"
@@ -2155,7 +2166,8 @@ If cursor is not at the end of the user input, move to end of input."
2155 (ido-directory-too-big nil) 2166 (ido-directory-too-big nil)
2156 (require-match (confirm-nonexistent-file-or-buffer)) 2167 (require-match (confirm-nonexistent-file-or-buffer))
2157 (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default 2168 (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default
2158 require-match initial))) 2169 require-match initial))
2170 filename)
2159 2171
2160 ;; Choose the buffer name: either the text typed in, or the head 2172 ;; Choose the buffer name: either the text typed in, or the head
2161 ;; of the list of matches 2173 ;; of the list of matches
@@ -2191,6 +2203,16 @@ If cursor is not at the end of the user input, move to end of input."
2191 (point)))) 2203 (point))))
2192 (ido-visit-buffer buf method t))) 2204 (ido-visit-buffer buf method t)))
2193 2205
2206 ;; check for a virtual buffer reference
2207 ((and ido-use-virtual-buffers ido-virtual-buffers
2208 (setq filename (assoc buf ido-virtual-buffers)))
2209 (ido-visit-buffer (find-file-noselect (cdr filename)) method t))
2210
2211 ((and (eq ido-create-new-buffer 'prompt)
2212 (null require-match)
2213 (not (y-or-n-p (format "No buffer matching `%s', create one? " buf))))
2214 nil)
2215
2194 ;; buffer doesn't exist 2216 ;; buffer doesn't exist
2195 ((and (eq ido-create-new-buffer 'never) 2217 ((and (eq ido-create-new-buffer 'never)
2196 (null require-match)) 2218 (null require-match))
@@ -3350,9 +3372,41 @@ for first matching file."
3350 (delete default ido-temp-list)) 3372 (delete default ido-temp-list))
3351 (setq ido-temp-list 3373 (setq ido-temp-list
3352 (cons default ido-temp-list)))) 3374 (cons default ido-temp-list))))
3375 (if ido-use-virtual-buffers
3376 (ido-add-virtual-buffers-to-list))
3353 (run-hooks 'ido-make-buffer-list-hook) 3377 (run-hooks 'ido-make-buffer-list-hook)
3354 ido-temp-list)) 3378 ido-temp-list))
3355 3379
3380(defvar ido-virtual-buffers nil)
3381
3382(defun ido-add-virtual-buffers-to-list ()
3383 "Add recently visited files, and bookmark files, to the buffer list.
3384This is to make them appear as if they were \"virtual buffers\"."
3385 ;; If no buffers matched, and virtual buffers are being used, then
3386 ;; consult the list of past visited files, to see if we can find
3387 ;; the file which the user might thought was still open.
3388 (setq ido-virtual-buffers nil)
3389 (let ((head recentf-list) name)
3390 (while head
3391 (if (and (setq name (file-name-nondirectory (car head)))
3392 (null (get-file-buffer (car head)))
3393 (not (assoc name ido-virtual-buffers))
3394 (not (ido-ignore-item-p name ido-ignore-buffers))
3395 ;;(file-exists-p (car head))
3396 )
3397 (setq ido-virtual-buffers
3398 (cons (cons name (car head)) ido-virtual-buffers)))
3399 (setq head (cdr head))))
3400 (when ido-virtual-buffers
3401 (if ido-use-faces
3402 (dolist (comp ido-virtual-buffers)
3403 (put-text-property 0 (length (car comp))
3404 'face 'ido-virtual
3405 (car comp))))
3406 (setq ido-temp-list
3407 (nconc ido-temp-list
3408 (nreverse (mapcar #'car ido-virtual-buffers))))))
3409
3356(defun ido-make-choice-list (default) 3410(defun ido-make-choice-list (default)
3357 ;; Return the current list of choices. 3411 ;; Return the current list of choices.
3358 ;; If DEFAULT is non-nil, and corresponds to an element of choices, 3412 ;; If DEFAULT is non-nil, and corresponds to an element of choices,