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

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

Re: A variant of match-end, but after replacement?


From: Barry Margolin
Subject: Re: A variant of match-end, but after replacement?
Date: Sun, 19 Jul 2015 16:18:08 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <mailman.7160.1437335923.904.help-gnu-emacs@gnu.org>,
 Marcin Borkowski <mbork@mbork.pl> wrote:

> On 2015-07-19, at 15:41, Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> 
> > Marcin Borkowski <mbork@mbork.pl> writes:
> >
> >>>     (let ((old-end (prog1 (match-end 1)
> >>>                      (replace-match "newtext" t t string 1)))) 
> >>>        (do-something old-end))
> >>
> >> Still not there - I can't assume that "newtext" will have the same
> >> length as the thing it replaced...
> >
> > Sorry, I misread what you wanted. 
> >
> >     (let ((new-end (+ (prog1 (match-beginning 1)
> >                          (replace-match new-text t t string 1)))
> >                       (length new-text)))
> >        (do-somthing-from new-end))
> 
> Thanks!  That's easy, and indeed it will work, since the length of the
> replacement is fixed in my use-case.

Yeah, this would be trickier if new-text contained back-references.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

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