[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu ec0d1f5485 147/288: Merge pull request #33 from syohe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu ec0d1f5485 147/288: Merge pull request #33 from syohex/fix-replace-command-bugs |
Date: |
Thu, 6 Jan 2022 03:58:48 -0500 (EST) |
branch: elpa/anzu
commit ec0d1f548592c8185d127ae30663317e48aa9e42
Merge: b600df38cb 67b98d6103
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Merge pull request #33 from syohex/fix-replace-command-bugs
Fix replace command bugs
---
anzu.el | 54 +++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 41 insertions(+), 13 deletions(-)
diff --git a/anzu.el b/anzu.el
index e36a089654..e09a466748 100644
--- a/anzu.el
+++ b/anzu.el
@@ -122,7 +122,7 @@
:group 'anzu)
(defvar anzu--total-matched 0)
-(defvar anzu--current-posion 0)
+(defvar anzu--current-position 0)
(defvar anzu--overflow-p nil)
(defvar anzu--last-isearch-string nil)
(defvar anzu--cached-positions nil)
@@ -131,6 +131,7 @@
(defvar anzu--cached-count 0)
(defvar anzu--last-replace-input "")
(defvar anzu--last-search-state nil)
+(defvar anzu--last-replaced-count nil)
(defvar anzu--outside-point nil)
(defun anzu--validate-regexp (regexp)
@@ -207,7 +208,7 @@
(let ((curpos (anzu--where-is-here (plist-get result :positions)
(point))))
(setq anzu--total-matched (plist-get result :count)
anzu--overflow-p (plist-get result :overflow)
- anzu--current-posion curpos
+ anzu--current-position curpos
anzu--last-search-state (cons isearch-word isearch-regexp)
anzu--last-isearch-string isearch-string)
(force-mode-line-update)))))
@@ -228,7 +229,7 @@
(defsubst anzu--reset-status ()
(setq anzu--total-matched 0
- anzu--current-posion 0
+ anzu--current-position 0
anzu--state nil
anzu--last-command nil
anzu--last-isearch-string nil
@@ -257,7 +258,7 @@
(defun anzu--update-mode-line ()
(let ((update-func (or anzu-mode-line-update-function
'anzu--update-mode-line-default)))
- (funcall update-func anzu--current-posion anzu--total-matched)))
+ (funcall update-func anzu--current-position anzu--total-matched)))
;;;###autoload
(define-minor-mode anzu-mode
@@ -298,6 +299,12 @@
(query-replace-descr (cdr query-replace-defaults)))
prompt)))
+(defvar anzu--replaced-markers nil)
+(defsubst anzu--set-marker (beg buf)
+ (let ((m (make-marker)))
+ (set-marker m beg buf)
+ (push m anzu--replaced-markers)))
+
(defun anzu--add-overlay (regexp beg end)
(let ((ov (make-overlay beg end)))
(overlay-put ov 'from-regexp regexp)
@@ -305,9 +312,14 @@
(overlay-put ov 'face 'anzu-replace-highlight)
(overlay-put ov 'anzu-replace t)))
+(defsubst anzu--cleanup-markers ()
+ (mapc (lambda (m) (set-marker m nil)) anzu--replaced-markers)
+ (setq anzu--replaced-markers nil))
+
;; Return highlighted count
(defun anzu--count-and-highlight-matched (buf str replace-beg replace-end
use-regexp overlay-limit)
+ (anzu--cleanup-markers)
(when (not use-regexp)
(setq str (regexp-quote str)))
(if (not (anzu--validate-regexp str))
@@ -331,6 +343,7 @@
(forward-char 1)))
(when (and (>= beg overlay-beg) (<= end overlay-end) (not
finish))
(cl-incf overlayed)
+ (anzu--set-marker beg buf)
(anzu--add-overlay str beg end))))
(setq anzu--cached-count count)
overlayed))))))
@@ -401,8 +414,11 @@
(sit-for 2))))
(defun anzu--query-from-string (prompt beg end use-regexp overlay-limit)
- (let ((from (anzu--read-from-string prompt beg end use-regexp
overlay-limit)))
- (if (and (string= from "") query-replace-defaults)
+ (let* ((from (anzu--read-from-string prompt beg end use-regexp
overlay-limit))
+ (is-empty (string= from "")))
+ (when (and (not is-empty) (not query-replace-defaults))
+ (setq anzu--last-replaced-count anzu--total-matched))
+ (if (and is-empty query-replace-defaults)
(cons (car query-replace-defaults)
(query-replace-compile-replacement
(cdr query-replace-defaults) use-regexp))
@@ -578,10 +594,19 @@
(list from to delimited beg end backward)
(list from to delimited beg end)))
-(defadvice replace-match-maybe-edit (before anzu-replace-match activate)
- (when (eq anzu--state 'replace)
- (force-mode-line-update)
- (cl-incf anzu--current-posion)))
+(defsubst anzu--current-replaced-index (curpoint)
+ (cl-loop for m in anzu--replaced-markers
+ for i = 1 then (+ i 1)
+ for pos = (marker-position m)
+ when (= pos curpoint)
+ return i))
+
+(defadvice replace-highlight (before anzu-replace-highlight activate)
+ (when (and (eq anzu--state 'replace) anzu--replaced-markers)
+ (let ((index (anzu--current-replaced-index (ad-get-arg 0))))
+ (when (or (not index) (/= index anzu--current-position))
+ (force-mode-line-update)
+ (setq anzu--current-position (or index 1))))))
(cl-defun anzu--query-replace-common (use-regexp &key at-cursor thing
prefix-arg (query t))
(anzu--cons-mode-line 'replace-query)
@@ -604,11 +629,14 @@
(anzu--query-from-at-cursor curbuf beg end
overlay-limit))
(anzu--query-from-string prompt beg end use-regexp
overlay-limit)))
(to (if (consp from)
- (prog1 (cdr from) (setq from (car from)))
+ (prog1 (cdr from)
+ (setq from (car from)
+ anzu--total-matched anzu--last-replaced-count))
(anzu--query-replace-read-to
from prompt beg end use-regexp overlay-limit))))
(anzu--clear-overlays curbuf beg end)
- (setq anzu--state 'replace anzu--current-posion 1
+ (setq anzu--state 'replace anzu--current-position 0
+ anzu--replaced-markers (reverse anzu--replaced-markers)
clear-overlay t)
(if use-regexp
(apply 'perform-replace
(anzu--construct-perform-replace-arguments
@@ -618,7 +646,7 @@
(progn
(unless clear-overlay
(anzu--clear-overlays curbuf beg end))
- (when (zerop anzu--current-posion)
+ (when (zerop anzu--current-position)
(goto-char orig-point))
(anzu--reset-mode-line)
(force-mode-line-update)))))
- [nongnu] elpa/anzu 3328619fec 251/288: Update Changes and bump up version, (continued)
- [nongnu] elpa/anzu 3328619fec 251/288: Update Changes and bump up version, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5cf1c7c16e 238/288: Merge pull request #72 from syohex/isearch-query-replace-api, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a1860f4c53 267/288: update url, copyright, and maintainer name, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 896b2be2eb 281/288: Wordsmith the documentation re *-thing functions (#111), ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 33e4f13429 287/288: migrate tests from circleci to github actions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 13dadaed10 284/288: update circleci to new docker images, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 14e4483a5e 286/288: Add ability to use lax whitespace (#119), ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 420f0c6894 137/288: Merge pull request #29 from bbatsov/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cb70e6c611 145/288: Fix wrong counting total matched number when used default input, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b600df38cb 144/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ec0d1f5485 147/288: Merge pull request #33 from syohex/fix-replace-command-bugs,
ELPA Syncer <=
- [nongnu] elpa/anzu ab561fe896 151/288: Use symbol-value instead of eval-when-compile + defvar, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 439e904931 155/288: Enable case-sensitive replacement for at cursor commands, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 686b264468 158/288: Refactoring: better getting migemo variable, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e664721a7f 157/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 137fc52ca2 159/288: Merge pull request #37 from syohex/improve-for-migemo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e782725f80 162/288: Support case sensitive highlighting, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cf3370967b 170/288: Refactoring for evil-anzu, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 53db7f64b7 177/288: Reduce condition check, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cb20bdcbfe 167/288: Merge pull request #40 from syohex/improve-replace-command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b723c16507 172/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06