all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Wiegley <johnw@gnu.org>
Subject: Re: Patch for "virtual buffers" in iswitchb
Date: Tue, 20 Apr 2004 14:32:25 -0700	[thread overview]
Message-ID: <m2brlmibdi.fsf@Majnun.local> (raw)
In-Reply-To: <m2y8otbkta.fsf@Majnun.local> (John Wiegley's message of "Sun, 18 Apr 2004 04:13:37 -0700")

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))

  reply	other threads:[~2004-04-20 21:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-18 11:13 Patch for "virtual buffers" in iswitchb John Wiegley
2004-04-20 21:32 ` John Wiegley [this message]
2004-04-30 11:41   ` John Wiegley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2brlmibdi.fsf@Majnun.local \
    --to=johnw@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.