[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch for "virtual buffers" in iswitchb
From: |
John Wiegley |
Subject: |
Re: Patch for "virtual buffers" in iswitchb |
Date: |
Tue, 20 Apr 2004 14:32:25 -0700 |
User-agent: |
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (darwin) |
After receiving an e-mail from the author of recentf -- which is
already part of the Emacs distribution and handles maintenance of a
list of "recently opened files" -- I've altered the virtual buffers
patch to iswitchb.el to use that package instead of doing the work
itself:
--- iswitchb.el 18 Apr 2004 03:28:12 -0700 1.48
+++ iswitchb.el 20 Apr 2004 14:30:00 -0700
@@ -305,6 +305,20 @@
:type 'integer
:group 'iswitchb)
+(defcustom iswitchb-use-virtual-buffers nil
+ "*If non-nil, refer to past buffers when none match.
+This feature relies upon the `recentf' package, which will be
+enabled if this variable is configured to a non-nil value."
+ :type 'boolean
+ :require 'recentf
+ :set (function
+ (lambda (sym value)
+ (recentf-mode value)
+ (set sym value)))
+ :group 'iswitchb)
+
+(defvar iswitchb-virtual-buffers nil)
+
(defcustom iswitchb-cannot-complete-hook 'iswitchb-completion-help
"*Hook run when `iswitchb-complete' can't complete any more.
The most useful values are `iswitchb-completion-help', which pops up a
@@ -613,7 +627,16 @@
(if (and (not (eq iswitchb-exit 'usefirst))
(get-buffer iswitchb-final-text))
;; This happens for example if the buffer was chosen with the mouse.
- (setq iswitchb-matches (list iswitchb-final-text)))
+ (setq iswitchb-matches (list iswitchb-final-text)
+ iswitchb-virtual-buffers nil))
+
+ (if (and iswitchb-use-virtual-buffers
+ iswitchb-virtual-buffers
+ (not (iswitchb-existing-buffer-p)))
+ (let ((virt (car iswitchb-virtual-buffers)))
+ (find-file-noselect virt)
+ (setq iswitchb-matches (list (file-name-nondirectory virt))
+ iswitchb-virtual-buffers nil)))
;; Handling the require-match must be done in a better way.
(if (and require-match (not (iswitchb-existing-buffer-p)))
@@ -833,7 +856,8 @@
(setq iswitchb-matches
(let* ((buflist iswitchb-buflist))
(iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp
- buflist)))))
+ buflist))
+ iswitchb-virtual-buffers nil)))
(defun iswitchb-get-matched-buffers (regexp
&optional string-format buffer-list)
@@ -1225,6 +1253,33 @@
first)
(setq comps (cons first (cdr comps)))))
+ ;; 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.
+ (when (and iswitchb-use-virtual-buffers (null comps)
+ recentf-list)
+ (setq iswitchb-virtual-buffers nil)
+ (let ((head recentf-list) name)
+ (while head
+ (if (and (null (find-buffer-visiting (car head)))
+ (setq name (file-name-nondirectory (car head)))
+ (or (if iswitchb-regexp
+ (string-match iswitchb-text name))
+ (string-match (regexp-quote iswitchb-text) name))
+ (not (iswitchb-ignore-buffername-p name))
+ (file-exists-p (car head)))
+ (setq iswitchb-virtual-buffers
+ (cons (car head) iswitchb-virtual-buffers)))
+ (setq head (cdr head)))
+ (setq comps (mapcar 'file-name-nondirectory
+ (nreverse iswitchb-virtual-buffers)))
+ (let ((comp comps))
+ (while comp
+ (put-text-property 0 (length (car comp))
+ 'face 'font-lock-builtin-face
+ (car comp))
+ (setq comp (cdr comp))))))
+
(cond ((null comps) (format " %sNo match%s"
open-bracket-determined
close-bracket-determined))