Hi Dmitry, > Thanks for working on this. > >> + (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. Stefan confirmed that "\\=" is reliable. Thanks for the suggestion. Now everything is ready. Please try the latest patch in bug#14013 together with the patch for xref.el below. I've tested with your test cases from bug#53758, and everything works well. >> - ;; 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. I guess this might need more conditionals like (>= emacs-major-version 29).