🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #3721

Re: Searching through multiple buffers in Emacs

#3721
From: Brandon S. Allbery
Date: Sat, 23 Dec 1989 15:41
33 lines
1883 bytes
As quoted from <3787@jhunix.HCF.JHU.EDU> by msc_wdqn@jhunix.HCF.JHU.EDU (Daniel Q Naiman):
+---------------
| Is there a way to search through multiple buffers in emacs
| for a regular expression? 
+---------------

Not as such, no.  But you can do it in Lisp:

	(defun re-search-all-buffers (regexp)
	  "Search all buffers for REGEXP, returning the first buffer with a match."
	  (interactive "sEnter regexp: ")
	  (save-excursion
	    (catch 'buffer-search-loop
	      (mapcar (function (lambda (buf)
				  (set-buffer buf)
				  (and (re-search regexp nil t)
				       (progn
					 (message "\"%s\" found in buffer %s."
						  regexp (buffer-name buf))
					 (throw 'buffer-search-loop buf))))))
	      (message "\"%s\" not found in any buffer." regexp)
	      nil)))

This general scheme can be used to do anything else you might like with each
match as well; for example, recursive edit each match.

++Brandon
-- 
Brandon S. Allbery    allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)
uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu bsa@telotech.uucp
*(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)*
*Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*
expnet.all: Experiments in *net management and organization.  Mail me for info.
Technical Details
Message-ID: <1989Dec23.154118.6775@NCoast.ORG>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!cwjcc!ncoast!allbery
References: <3787@jhunix.HCF.JHU.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!cwjcc!ncoast!allbery
From: allbery@NCoast.ORG (Brandon S. Allbery)
Newsgroups: comp.editors
Subject: Re: Searching through multiple buffers in Emacs
Message-ID: <1989Dec23.154118.6775@NCoast.ORG>
Date: 23 Dec 89 15:41:18 GMT
References: <3787@jhunix.HCF.JHU.EDU>
Reply-To: allbery@ncoast.ORG (Brandon S. Allbery)
Followup-To: comp.editors
Organization: North Coast Public Access UN*X, Cleveland, OH
Lines: 33