From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: John Wiegley Newsgroups: gmane.emacs.devel Subject: Re: Patch for "virtual buffers" in iswitchb Date: Tue, 20 Apr 2004 14:32:25 -0700 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1082500748 25614 80.91.224.253 (20 Apr 2004 22:39:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 20 Apr 2004 22:39:08 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Apr 21 00:38:59 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BG3tJ-000593-00 for ; Wed, 21 Apr 2004 00:38:57 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BG3tJ-0007br-00 for ; Wed, 21 Apr 2004 00:38:57 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BG3qo-0002fP-Rc for emacs-devel@quimby.gnus.org; Tue, 20 Apr 2004 18:36:22 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BG3mc-0001dL-FO for emacs-devel@gnu.org; Tue, 20 Apr 2004 18:32:02 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BG3kE-00012R-CD for emacs-devel@gnu.org; Tue, 20 Apr 2004 18:30:07 -0400 Original-Received: from [204.251.10.90] (helo=pop.directnic.com) by monty-python.gnu.org with smtp (Exim 4.30) id 1BG2r7-0006uO-2M for emacs-devel@gnu.org; Tue, 20 Apr 2004 17:32:37 -0400 Original-Received: by pop.directnic.com (iris/0.153:492879); 20 Apr 2004 21:32:31 +0000 X-Iris-Host: 3521758782/[209.233.198.62] Original-Received: from [209.233.198.62] (EHLO Majnun.local) (209.233.198.62) by pop.directnic.com (iris/0.153:492879/relay) with ESMTP for ; 20 Apr 2004 21:32:24 +0000 Original-Received: by Majnun.local (Postfix, from userid 501) id B7B25229295; Tue, 20 Apr 2004 14:32:25 -0700 (PDT) Original-To: emacs-devel@gnu.org In-Reply-To: (John Wiegley's message of "Sun, 18 Apr 2004 04:13:37 -0700") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (darwin) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:21963 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:21963 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))