Subject: bug#54733: Match again in perform-replace

From: Juri Linkov <[email-masked]>
Date: Tue, 21 Jun 2022 20:55:19 +0300

>> +				(replace-search search-string limit
>> +						regexp-flag delimited-flag
>> +						case-fold-search backward))
>
> I don't know this code too well, but perhaps SEARCH_STRING here should be
> anchored with something like "\\=" at the beginning?
>
> Otherwise the search can succeed here even if the next match is not
> here. Not sure how important that is, though.

I'm afraid that prepending "\\=" might break a complex regexp somehow.
So maybe using replace-search is not the best thing to do.  I'm inclined
to leave looking-at, but only when the default search function is used.
Currently I'm writing a new function to search in rectangular regions
in bug#14013, but there are many corner cases, so it will take more time.
Then this new function could be used in xref as well since the rectangular
region uses the same pairs of points as xref--query-replace-1 does.
Then perform-replace could detect if this search function is used,
and not to do "the next match now" hack.

>> -         ;; Counteract the "do the next match now" hack in
>> -         ;; `perform-replace'.  And still, it'll report that those
>> -         ;; matches were "filtered out" at the end.
>> -         (isearch-filter-predicate
>> -          (lambda (beg end)
>> -            (and current-beg
>> -                 (>= beg current-beg)
>> -                 (<= end current-end))))
>
> Please note that we'll likely have to keep this code here for a number of
> Emacs releases. So the patch should be tested with both versions: with this
> code present and with it removed, to ensure present and future
> compatibility.

Keeping compatibility should be concerned here definitely.
I hope to post the complete patch in a few days.