[comp.editors] Searching through multiple buffers in Emacs

msc_wdqn@jhunix.HCF.JHU.EDU (Daniel Q Naiman) (12/23/89)

Is there a way to search through multiple buffers in emacs
for a regular expression? 

Dan Naiman
Department of Mathematical Sciences 
Johns Hopkins University

allbery@NCoast.ORG (Brandon S. Allbery) (12/23/89)

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.