help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replace-regexp from A to B?


From: Emanuel Berg
Subject: Re: replace-regexp from A to B?
Date: Sun, 26 Aug 2018 18:02:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Rodolfo Medina wrote:

> Is it possible, and how?, to perform
> a replace-regexp from a certain point, e.g.
> the current one, or from a certain
> word/expression, up to the next occurrence of
> a certain other word/expression...? In my
> case, with MusiXTeX documents, the starting
> point should be the TeX command `\startpiece'
> and the final one `\Endpiece'. So I could
> replace strings/expressions within a single
> musical piece without going out of it.

You can set the region manually and then use
a function with

    (goto-char START)
    (while (re-search-forward REGEXP STOP t)
      (replace-match TO-STRING nil nil))

where START is (region-beginning) and STOP is
(region-end). First check if there is a region
with (use-region-p) !

Or if you want it fully automated make a search
for "\startpiece" and set START, then make
a search for "\Endpiece" and set STOP. Do this
in Elisp as well.

But then you'd have to supply them (the
delimitators) as arguments so it won't
necessarily be faster because you'd have to
type them each time rather than to set
the region.

If they (the delimitators) are always the same
you could hard-code them, of course. Then it'll
be very fast to invoke :)

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]