branch: elpa/anzu
commit dcae1360887947b36eb513bf7768037768acb4ed
Author: Syohei YOSHIDA <[email protected]>
Commit: Syohei YOSHIDA <[email protected]>
Fix displaying current replaced point
It does not work if replaced words are out of sight.
---
anzu.el | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/anzu.el b/anzu.el
index 3c9c2498fe..a92067557b 100644
--- a/anzu.el
+++ b/anzu.el
@@ -350,7 +350,6 @@
(forward-char 1)))
(when (and (>= beg overlay-beg) (<= end overlay-end) (not
finish))
(cl-incf overlayed)
- (anzu--set-marker beg buf)
(anzu--add-overlay beg end))))
(setq anzu--cached-count count)
overlayed))))))
@@ -615,7 +614,7 @@
(defsubst anzu--current-replaced-index (curpoint)
(cl-loop for m in anzu--replaced-markers
- for i = 1 then (+ i 1)
+ for i = 1 then (1+ i)
for pos = (marker-position m)
when (= pos curpoint)
return i))
@@ -627,6 +626,14 @@
(force-mode-line-update)
(setq anzu--current-position (or index 1))))))
+(defun anzu--set-replaced-markers (from beg end use-regexp)
+ (save-excursion
+ (goto-char beg)
+ (cl-loop with curbuf = (current-buffer)
+ with search-func = (if use-regexp 're-search-forward
'search-forward)
+ while (funcall search-func from end t)
+ do (anzu--set-marker (match-beginning 0) curbuf))))
+
(cl-defun anzu--query-replace-common (use-regexp &key at-cursor thing
prefix-arg (query t))
(anzu--cons-mode-line 'replace-query)
(let* ((use-region (use-region-p))
@@ -654,6 +661,7 @@
(anzu--query-replace-read-to
from prompt beg end use-regexp overlay-limit))))
(anzu--clear-overlays curbuf beg end)
+ (anzu--set-replaced-markers from beg end use-regexp)
(setq anzu--state 'replace anzu--current-position 0
anzu--replaced-markers (reverse anzu--replaced-markers)
clear-overlay t)
@@ -668,6 +676,7 @@
(anzu--clear-overlays curbuf beg end))
(when (zerop anzu--current-position)
(goto-char orig-point))
+ (anzu--cleanup-markers)
(anzu--reset-mode-line)
(force-mode-line-update)))))