[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 67b98d6103 146/288: Improve calculation of current re
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 67b98d6103 146/288: Improve calculation of current replacement position |
Date: |
Thu, 6 Jan 2022 03:58:48 -0500 (EST) |
branch: elpa/anzu
commit 67b98d61034161b071482ff72a7be9315a151646
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Improve calculation of current replacement position
'^' or 'no' are supported by this change
---
anzu.el | 42 ++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/anzu.el b/anzu.el
index 2cc7de8768..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)
@@ -208,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)))))
@@ -229,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
@@ -258,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
@@ -299,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)
@@ -306,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))
@@ -332,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))))))
@@ -582,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)
@@ -614,7 +635,8 @@
(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
@@ -624,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 e817db8532 115/288: Fix byte compile warning for Emacs 24.3, (continued)
- [nongnu] elpa/anzu e817db8532 115/288: Fix byte compile warning for Emacs 24.3, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f3c83f3109 116/288: Merge pull request #21 from syohex/fix-byte-compile-warning, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b7185acafc 122/288: Use original function name instead of alias, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a77aa41dbc 121/288: Update Git animation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 59fec57b13 124/288: Add Cask file for testing, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 43cb178b16 133/288: Update mode line like searching in replacing command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e53fe6d0fc 135/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 48eb310d24 139/288: Improve restoring point when canceling, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 2a3d8d76d2 141/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e567375313 142/288: Improve case when bounds-og-thing-at-point returns nil, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 67b98d6103 146/288: Improve calculation of current replacement position,
ELPA Syncer <=
- [nongnu] elpa/anzu c8f3e7b651 150/288: Merge pull request #35 from syohex/better-migemo-checking, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 962c425d39 149/288: Better checking whether using migemo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ffaf6b3c10 153/288: Add MELPA badges, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5b2ce629b7 154/288: Update MELPA links, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu d3650160d7 161/288: Don't search if input regexp is not valid yet., ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu dcae136088 173/288: Fix displaying current replaced point, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e3aab048b4 168/288: Disable blink-matching-paren in read 'to' string, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b9bac0e2f8 178/288: Merge pull request #43 from syohex/fix-compile-regexp-error-case, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1f7ac26191 189/288: Just call isearch-symbol-regexp instead of constructing own regexp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 10bc7c5fbd 171/288: Merge pull request #41 from syohex/refactoring, ELPA Syncer, 2022/01/06