unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "B. T. Raven" <ecinmn@alcisp.com>
Subject: Re: AW: replace a textblock in multiple files
Date: Thu, 28 Sep 2006 19:51:13 -0500	[thread overview]
Message-ID: <217bb$451c6c6f$49f2044$25034@DIALUPUSA.NET> (raw)
In-Reply-To: u8xk6iqel.fsf@gmail.com


"Mathias Dahl" <brakjoller@gmail.com> wrote in message
news:u8xk6iqel.fsf@gmail.com...
> <C.Strobl@dlr.de> 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 <column_right> 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)

 \(<starttextpattern>\)\(.\|^J\)*?\(<endtextpattern>\) RET
\1<replacementtext>\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

  reply	other threads:[~2006-09-29  0:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7420.1159269539.9609.help-gnu-emacs@gnu.org>
2006-09-26 15:44 ` AW: replace a textblock in multiple files Mathias Dahl
2006-09-29  0:51   ` B. T. Raven [this message]
2006-09-27  3:36 ` Benjamin Rutt
2006-09-26  0:52 Benjamin Rutt
2006-09-26 11:18 ` AW: " C.Strobl

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='217bb$451c6c6f$49f2044$25034@DIALUPUSA.NET' \
    --to=ecinmn@alcisp.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).