diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index f651dc9..5686cc9 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -552,6 +552,7 @@ xref--buf-pairs-iterator (end (move-marker (make-marker) (+ beg (xref-match-length item)) (marker-buffer beg)))) + (set-marker-insertion-type end t) (let ((pair (cons beg end))) (push pair all-pairs) ;; Perform sanity check first. @@ -593,7 +594,7 @@ xref--outdated-p (defun xref--query-replace-1 (from to iter) (let* ((query-replace-lazy-highlight nil) (continue t) - did-it-once buf-pairs pairs + did-it-once buf-pairs current-beg current-end ;; Counteract the "do the next match now" hack in ;; `perform-replace'. And still, it'll report that those @@ -605,23 +606,24 @@ xref--query-replace-1 (<= 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)))) + (let ((tmp-pairs (cdr buf-pairs)) pair) + (while (and (not pair) tmp-pairs) + (setq current-beg (caar tmp-pairs) + current-end (cdar tmp-pairs)) + (unless (< current-beg (point)) + (goto-char current-beg) + (when (re-search-forward from current-end noerror) + (setq pair (car tmp-pairs)))) + (setq tmp-pairs (cdr tmp-pairs))) + pair)))) (while (and continue (setq buf-pairs (funcall iter :next))) (if did-it-once ;; Reuse the same window for subsequent buffers. (switch-to-buffer (car buf-pairs)) (xref--with-dedicated-window - (pop-to-buffer (car buf-pairs))) + (pop-to-buffer (car buf-pairs)) + (goto-char (point-min))) (setq did-it-once t)) - (setq pairs (cdr buf-pairs)) (setq continue (perform-replace from to t t nil nil multi-query-replace-map))) (unless did-it-once (user-error "No suitable matches here"))))