[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 6b01763088 077/288: Improve replace regular expressio
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 6b01763088 077/288: Improve replace regular expression |
Date: |
Thu, 6 Jan 2022 03:58:41 -0500 (EST) |
branch: elpa/anzu
commit 6b017630888d5dceb7c857c54371698526aaeeb6
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Improve replace regular expression
Such as \,(...), \# etc
---
anzu.el | 51 +++++++++++++++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/anzu.el b/anzu.el
index 06e9d8b585..1f3a2eda03 100644
--- a/anzu.el
+++ b/anzu.el
@@ -361,40 +361,51 @@
(anzu--query-validate-from-regexp from))
from)))
-(defun anzu--calculate-replace-text (str use-regexp)
- (let ((compiled (query-replace-compile-replacement str use-regexp)))
+(defun anzu--compile-replace-text (str)
+ (let ((compiled (query-replace-compile-replacement str t)))
(cond ((stringp compiled) compiled)
((and (consp compiled) (functionp (car compiled)))
- (funcall (car compiled) (cdr compiled) 0))
+ compiled)
((and (consp compiled) (stringp (car compiled)))
(car compiled)))))
-(defun anzu--evaluate-occurrence (ov to-regexp)
+(defun anzu--evaluate-occurrence (ov to-regexp replace-count)
(let ((from-regexp (overlay-get ov 'from-regexp))
- (from-string (overlay-get ov 'from-string)))
+ (from-string (overlay-get ov 'from-string))
+ (compiled (anzu--compile-replace-text to-regexp)))
(with-temp-buffer
(insert from-string)
(goto-char (point-min))
- (if (re-search-forward from-regexp nil t)
- (progn
- (replace-match to-regexp)
- (buffer-substring-no-properties (point-min) (point-max)))
- to-regexp))))
+ (when (re-search-forward from-regexp nil t)
+ (if (consp compiled)
+ (replace-match (funcall (car compiled) (cdr compiled)
+ replace-count))
+ (replace-match compiled))
+ (buffer-substring (point-min) (point-max))))))
+
+(defun anzu--overlay-sort (a b)
+ (< (overlay-start a) (overlay-start b)))
+
+(defsubst anzu--overlays-in-range (beg end)
+ (loop for ov in (overlays-in beg end)
+ when (overlay-get ov 'anzu-replace)
+ collect ov into anzu-overlays
+ finally return (sort anzu-overlays 'anzu--overlay-sort)))
(defun anzu--append-replaced-string (buf beg end use-regexp overlay-limit)
- (let ((content (minibuffer-contents)))
+ (let ((content (minibuffer-contents))
+ (replace-count 0))
(unless (string= content anzu--last-replace-input)
(setq anzu--last-replace-input content)
(with-current-buffer buf
- (let ((overlay-end (min end overlay-limit))
- (replace (anzu--calculate-replace-text content use-regexp)))
- (dolist (ov (overlays-in beg overlay-end))
- (when (overlay-get ov 'anzu-replace)
- (let ((replace-evaled (if use-regexp
- (anzu--evaluate-occurrence ov replace)
- replace)))
- (overlay-put ov 'after-string
- (propertize replace-evaled 'face
'anzu-replace-to))))))))))
+ (dolist (ov (anzu--overlays-in-range beg (min end overlay-limit)))
+ (let ((replace-evaled (and use-regexp (anzu--evaluate-occurrence
+ ov content replace-count))))
+ (if replace-evaled
+ (incf replace-count)
+ (setq replace-evaled content))
+ (overlay-put ov 'after-string
+ (propertize replace-evaled 'face
'anzu-replace-to))))))))
(defun anzu--read-to-string (from prompt beg end use-regexp overlay-limit)
(let ((curbuf (current-buffer))
- [nongnu] elpa/anzu 9ec5a834cf 025/288: Bump up version and update Changes, (continued)
- [nongnu] elpa/anzu 9ec5a834cf 025/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 8f91b00c91 028/288: Improve the documentation a bit, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b644e9d067 034/288: Better one-line description, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 06ae1b1f7e 035/288: Merge pull request #9 from purcell/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 06f4cf2fe7 037/288: Introduce anzu-minimum-input-length, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e82b3d4236 069/288: Use delimiter regexp at anzu-query-replace-at-cursor, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b211f9a50f 067/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4f024cd623 081/288: Clear last input cache after isearch command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 3a7fcf2096 094/288: Merge pull request #14 from syohex/fix-increasing-anzuinfo-issue, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 537b8bfd36 071/288: Add autoload cookie, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 6b01763088 077/288: Improve replace regular expression,
ELPA Syncer <=
- [nongnu] elpa/anzu abd5953eac 018/288: Add Installation section, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4cfbddbc07 020/288: Reset match count variables in isearch-mode-end-hook, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu de70e2fa4a 031/288: Enable mode unconditionally in examples, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 2b88e1fcbc 021/288: Improve for not regexp search commands, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5e6bad85d4 036/288: bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 169cf55674 044/288: Use previous result if regexp validation is failed, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu d256c967f3 052/288: Fix message in mode-line at replace command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 413bd09ebc 079/288: Fix different behavior from query-replace-regexp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b310647932 085/288: Add separator parameter of 'to' string, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 047c5eee99 083/288: add anzu replace command screencast, ELPA Syncer, 2022/01/06