[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: query-replace-regexp: Can't use \0 in TO-STRING
From: |
Juri Linkov |
Subject: |
Re: query-replace-regexp: Can't use \0 in TO-STRING |
Date: |
Wed, 10 May 2017 01:02:04 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu) |
>> >> Why not \0? I think \0 is more intuitive and also used in vim.
>> > I agree is more intuitive, and it works in `replace-match', or instance:
>> > (mapcar
>> > (lambda (group)
>> > (let ((str "foo123"))
>> > (when (string-match "[a-z]+\\([1-9]+\\)" str)
>> > (replace-match "bar" nil nil str group))))
>> > (list 0 1))
>> > => ("bar" "foobar")
>> >
>> > Are you willing to write a patch to implement it?
>>
>> The following patch works on my machine for regexp replacing. But I
>> don't known if \0 should be supported in other places such as
>> sort-regexp-fields, occur.
>
> If this is accepted (and I'm not sure we should), then the user manual
> should also be updated, and NEWS should have an entry about the
> change.
Some other regexp engines support the \0 format as well:
http://www.regular-expressions.info/refreplacebackref.html
What is important is to clearly differentiate the whole match from
back references in the documentation (i.e. unlike back references
\0 works only in replacements, not matches).