[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: replace matches in any string
From: |
Lars Magne Ingebrigtsen |
Subject: |
Re: replace matches in any string |
Date: |
Fri, 03 Sep 2010 00:18:56 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
>> For one thing I guess it is too late to change the API. For another,
>> that prevents strings from being garbage-collected as long as they are
>> present in some match-data. While the same is true of buffers, a dead
>> buffer does not take significant space.
>
> We already save the matched object if it's a buffer, and no, the
> potential "space leak" is not a significant problem.
It's one string per match data, so it's not significant.
>> What's wrong with match-substitute-replacement ?
>
> Indeed, I had forgotten about it.
Oh, that exists? Never mind, then. :-) So you already save all the
matched substrings in case somebody calls a the function
`match-substitute-replacement', which nobody has heard of (there's one
(1) use of the function in question in the Emacs sources...
Hang on. This is the definition:
(defun match-substitute-replacement (replacement
&optional fixedcase literal string subexp)
"Return REPLACEMENT as it will be inserted by `replace-match'.
In other words, all back-references in the form `\\&' and `\\N'
are substituted with actual strings matched by the last search.
Optional FIXEDCASE, LITERAL, STRING and SUBEXP have the same
meaning as for `replace-match'."
(let ((match (match-string 0 string)))
(save-match-data
(set-match-data (mapcar (lambda (x)
(if (numberp x)
(- x (match-beginning 0))
x))
(match-data t)))
(replace-match replacement fixedcase literal match subexp))))
This doesn't help at all.
The use case is that you had some string do a match, but you don't have
access to the string variable. You just want the matches that you know
were made, aka perlish $1, $2, $3. I reiterate my first posting on this
issue as a feature request.
--
(domestic pets only, the antidote for overdose, milk.)
address@hidden * Lars Magne Ingebrigtsen
- Re: replace matches in any string, (continued)
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Re: replace matches in any string, David Kastrup, 2010/09/02
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Re: replace matches in any string, David Kastrup, 2010/09/02
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Recommended gnus spam filter system?, Camm Maguire, 2010/09/02
- Re: Recommended gnus spam filter system?, Frank Schmitt, 2010/09/02
- Re: Recommended gnus spam filter system?, Karl Fogel, 2010/09/02
- Re: Recommended gnus spam filter system?, Thorsten Bonow, 2010/09/03
- Re: replace matches in any string, Stefan Monnier, 2010/09/02
- Re: replace matches in any string,
Lars Magne Ingebrigtsen <=
- Re: replace matches in any string, Davis Herring, 2010/09/02
- Re: replace matches in any string, David Kastrup, 2010/09/03
- Re: replace matches in any string, Lars Magne Ingebrigtsen, 2010/09/03