From: Juri Linkov <juri@jurta.org>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 54733@debbugs.gnu.org
Subject: bug#54733: Match again in perform-replace
Date: Thu, 30 Jun 2022 20:52:10 +0300 [thread overview]
Message-ID: <86mtdut4xh.fsf@mail.linkov.net> (raw)
In-Reply-To: <9d54db84-77ba-6453-dcfa-864a7c05e692@yandex.ru> (Dmitry Gutov's message of "Tue, 21 Jun 2022 02:59:06 +0300")
[-- Attachment #1: Type: text/plain, Size: 1371 bytes --]
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).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xref--query-replace-1.patch --]
[-- Type: text/x-diff, Size: 2018 bytes --]
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 0213ab3cc5..9b4adffa41 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -858,29 +858,9 @@ xref--outdated-p
;; FIXME: Write a nicer UI.
(defun xref--query-replace-1 (from to iter)
- (let* ((query-replace-lazy-highlight nil)
- (continue t)
+ (let* ((continue t)
did-it-once buf-pairs pairs
- current-beg current-end
- ;; 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))))
- (replace-re-search-function
- (lambda (from &optional _bound noerror)
- (let (found pair)
- (while (and (not found) pairs)
- (setq pair (pop pairs)
- current-beg (car pair)
- current-end (cdr pair))
- (goto-char current-beg)
- (when (re-search-forward from current-end noerror)
- (setq found t)))
- found))))
+ (region-extract-function (lambda (_) pairs)))
(while (and continue (setq buf-pairs (funcall iter :next)))
(if did-it-once
;; Reuse the same window for subsequent buffers.
@@ -889,8 +869,10 @@ xref--query-replace-1
(pop-to-buffer (car buf-pairs)))
(setq did-it-once t))
(setq pairs (cdr buf-pairs))
+ (goto-char (point-min))
(setq continue
- (perform-replace from to t t nil nil multi-query-replace-map)))
+ (perform-replace from to t t nil nil multi-query-replace-map
+ nil nil nil t)))
(unless did-it-once (user-error "No suitable matches here"))
(when (and continue (not buf-pairs))
(message "All results processed"))))
prev parent reply other threads:[~2022-06-30 17:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-05 17:16 bug#54733: Match again in perform-replace Juri Linkov
2022-04-05 17:53 ` Juri Linkov
2022-04-29 17:41 ` Juri Linkov
2022-05-03 7:10 ` Juri Linkov
2022-06-20 23:59 ` Dmitry Gutov
2022-06-21 17:55 ` Juri Linkov
2022-06-22 7:36 ` Juri Linkov
2022-06-24 17:25 ` Juri Linkov
2022-06-30 17:52 ` Juri Linkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86mtdut4xh.fsf@mail.linkov.net \
--to=juri@jurta.org \
--cc=54733@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.