From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "B. T. Raven" Newsgroups: gmane.emacs.help Subject: Re: AW: replace a textblock in multiple files Date: Thu, 28 Sep 2006 19:51:13 -0500 Organization: UseNetServer.com Message-ID: <217bb$451c6c6f$49f2044$25034@DIALUPUSA.NET> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1159494043 5743 80.91.229.2 (29 Sep 2006 01:40:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 29 Sep 2006 01:40:43 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 29 03:40:42 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GT7MX-0002Wa-5k for geh-help-gnu-emacs@m.gmane.org; Fri, 29 Sep 2006 03:40:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GT7MW-0007Zr-Fd for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Sep 2006 21:40:24 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!uns-out.usenetserver.com!news.usenetserver.com!pc03.usenetserver.com!DIALUPUSA.NET!not-for-mail Original-Newsgroups: gnu.emacs.help X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Original-X-Complaints-To: abuse@usenetserver.com Original-Lines: 41 Original-X-Trace: 217bb451c6c6fa13a85e125034 Original-Xref: shelby.stanford.edu gnu.emacs.help:142088 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:37708 Archived-At: "Mathias Dahl" wrote in message news:u8xk6iqel.fsf@gmail.com... > writes: > > > 1) i want to work on several subdirectories, not only in one directory > > 2) i want to replace blocks consisting of more than one line. > > In dired, navigate one folder "higher" than where you want to start > your replacement. Then insert the directory you want to work with > using C-u i and add an R to the arguments at the prompt. This will add > all files recursively into the dired buffer and you can work with the > files from there. > > The Q command should accept multi line blocks as long as you can find > a regexp to do it. If not, maybe you want to write a small helper > elisp function. Beautiful! Emacs can do it out of the box without loading any further resources. Here is what I did combining this problem with the one in the other thread about replacing text in the html block: C-u [actual numeric argument not needed] C-x d [here modify the ls switches to make them read -IR as per Mathias] [specify parent of all sub-directories of interest; files in this parent directory containing matches to regexp will be processed too.] %g someregexp* Q sameregexp [a buffer is opened for each file in parent and in all subdirectories containing match(es) to regexp and the process works exactly as in C-M-%. * In the block search-replace example you could use: (not tested but I think the middle pair of escaped parentheses will be interpreted as grouping rather than as matched substring for later reference by \1 \2) \(\)\(.\|^J\)*?\(\) RET \1\2 RET ;; search-replace arbitary text bracketed by start- and endpattern. ^J is input with C-qC-j [Thanks to Florian Kaufman for this. Now I understand non-greedy operators better.] Ed