[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A variant of match-end, but after replacement?
From: |
Marcin Borkowski |
Subject: |
Re: A variant of match-end, but after replacement? |
Date: |
Mon, 20 Jul 2015 02:06:09 +0200 |
On 2015-07-20, at 00:45, Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> Barry Margolin <barmar@alum.mit.edu> writes:
>
>> 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.
>
> 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)))))
I give up. It seems that a PhD in math is not enough to deal with
string-length arithmetic;-). Shame on me! (OTOH, mails from you often
teach me that when I have the impression that I'm smart, it's usually
only an impression.)
Thanks a lot!
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
- Re: A variant of match-end, but after replacement?, (continued)
- Re: A variant of match-end, but after replacement?, Marcin Borkowski, 2015/07/19
- Re: A variant of match-end, but after replacement?, Nicolas Richard, 2015/07/20
- Message not available
- Re: A variant of match-end, but after replacement?, Pascal J. Bourguignon, 2015/07/19
- Re: A variant of match-end, but after replacement?, Marcin Borkowski, 2015/07/19
- Re: A variant of match-end, but after replacement?, Dmitry Gutov, 2015/07/19
- Re: A variant of match-end, but after replacement?, Marcin Borkowski, 2015/07/19
- Message not available
- Re: A variant of match-end, but after replacement?, Pascal J. Bourguignon, 2015/07/19
- Re: A variant of match-end, but after replacement?, Marcin Borkowski, 2015/07/19
- Message not available
- Re: A variant of match-end, but after replacement?, Barry Margolin, 2015/07/19
- Re: A variant of match-end, but after replacement?, Pascal J. Bourguignon, 2015/07/19
- Re: A variant of match-end, but after replacement?,
Marcin Borkowski <=
- Message not available
- Re: A variant of match-end, but after replacement?, Pascal J. Bourguignon, 2015/07/19