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: Pascal J. Bourguignon
Subject: Re: A variant of match-end, but after replacement?
Date: Mon, 20 Jul 2015 00:45:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Barry Margolin <address@hidden> writes:

> In article <address@hidden>,
>  Marcin Borkowski <address@hidden> wrote:
>
>> On 2015-07-19, at 15:41, Pascal J. Bourguignon <address@hidden> wrote:
>> 
>> > Marcin Borkowski <address@hidden> 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.

Not very much:

    (let ((end        (match-end 1))
          (new-string (replace-match new-text t t string 1)))
      (do-something-from new-string
                         (+ end (- (length string) (legnth new-string)))))


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

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