[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 1c2705bb2c 164/288: Merge pull request #38 from syohe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 1c2705bb2c 164/288: Merge pull request #38 from syohex/improve-replacement |
Date: |
Thu, 6 Jan 2022 03:58:49 -0500 (EST) |
branch: elpa/anzu
commit 1c2705bb2c75ddd04a004554b0370d8d6007f2bd
Merge: ee53798dc2 3adcdab743
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Merge pull request #38 from syohex/improve-replacement
Improve replacement command
---
anzu.el | 65 ++++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 36 insertions(+), 29 deletions(-)
diff --git a/anzu.el b/anzu.el
index 53a0278239..a33b960f13 100644
--- a/anzu.el
+++ b/anzu.el
@@ -298,8 +298,8 @@
(let ((prompt (anzu--query-prompt-base use-region use-regexp)))
(if (and query-replace-defaults (not at-cursor))
(format "%s (default %s -> %s) " prompt
- (query-replace-descr (car query-replace-defaults))
- (query-replace-descr (cdr query-replace-defaults)))
+ (query-replace-descr (caar query-replace-defaults))
+ (query-replace-descr (cdar query-replace-defaults)))
prompt)))
(defvar anzu--replaced-markers nil)
@@ -308,9 +308,8 @@
(set-marker m beg buf)
(push m anzu--replaced-markers)))
-(defun anzu--add-overlay (regexp beg end)
+(defun anzu--add-overlay (beg end)
(let ((ov (make-overlay beg end)))
- (overlay-put ov 'from-regexp regexp)
(overlay-put ov 'from-string (buffer-substring-no-properties beg end))
(overlay-put ov 'face 'anzu-replace-highlight)
(overlay-put ov 'anzu-replace t)))
@@ -349,19 +348,20 @@
(when (and (>= beg overlay-beg) (<= end overlay-end) (not
finish))
(cl-incf overlayed)
(anzu--set-marker beg buf)
- (anzu--add-overlay str beg end))))
+ (anzu--add-overlay beg end))))
(setq anzu--cached-count count)
overlayed))))))
(defun anzu--search-outside-visible (buf input beg end use-regexp)
(let ((searchfn (if use-regexp 're-search-forward 'search-forward)))
- (with-selected-window (get-buffer-window buf)
- (goto-char beg)
- (when (funcall searchfn input end t)
- (setq anzu--outside-point (match-beginning 0))
- (let ((overlay-limit (anzu--overlay-limit)))
- (anzu--count-and-highlight-matched buf input beg end use-regexp
- overlay-limit nil))))))
+ (when (or (not use-regexp) (anzu--validate-regexp input))
+ (with-selected-window (get-buffer-window buf)
+ (goto-char beg)
+ (when (funcall searchfn input end t)
+ (setq anzu--outside-point (match-beginning 0))
+ (let ((overlay-limit (anzu--overlay-limit)))
+ (anzu--count-and-highlight-matched buf input beg end use-regexp
+ overlay-limit nil)))))))
(defun anzu--check-minibuffer-input (buf beg end use-regexp overlay-limit)
(let* ((content (minibuffer-contents))
@@ -426,9 +426,9 @@
(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)
+ (cons (caar query-replace-defaults)
(query-replace-compile-replacement
- (cdr query-replace-defaults) use-regexp))
+ (cdar query-replace-defaults) use-regexp))
(add-to-history query-replace-from-history-variable from nil t)
(when use-regexp
(anzu--query-validate-from-regexp from))
@@ -442,9 +442,8 @@
((and (consp compiled) (stringp (car compiled)))
(car compiled)))))
-(defun anzu--evaluate-occurrence (ov to-regexp replacements)
- (let ((from-regexp (overlay-get ov 'from-regexp))
- (from-string (overlay-get ov 'from-string))
+(defun anzu--evaluate-occurrence (ov to-regexp replacements fixed-case
from-regexp)
+ (let ((from-string (overlay-get ov 'from-string))
(compiled (anzu--compile-replace-text to-regexp)))
(with-temp-buffer
(insert from-string)
@@ -453,8 +452,8 @@
(or (ignore-errors
(if (consp compiled)
(replace-match (funcall (car compiled) (cdr compiled)
- replacements) t)
- (replace-match compiled t))
+ replacements) fixed-case)
+ (replace-match compiled fixed-case))
(buffer-substring (point-min) (point-max)))
"")))))
@@ -471,19 +470,27 @@
(let ((separator (or anzu-replace-to-string-separator "")))
(propertize (concat separator str) 'face 'anzu-replace-to)))
-(defun anzu--append-replaced-string (buf beg end use-regexp overlay-limit)
+(defsubst anzu--replaced-literal-string (ov replaced from)
+ (let ((str (buffer-substring-no-properties
+ (overlay-start ov) (overlay-end ov))))
+ (when (string-match str from)
+ (replace-match replaced (not case-fold-search) nil str))))
+
+(defun anzu--append-replaced-string (buf beg end use-regexp overlay-limit from)
(let ((content (minibuffer-contents))
(replacements 0))
(unless (string= content anzu--last-replace-input)
(setq anzu--last-replace-input content)
(with-current-buffer buf
- (dolist (ov (anzu--overlays-in-range beg (min end overlay-limit)))
- (let ((replace-evaled (and use-regexp (anzu--evaluate-occurrence
- ov content replacements))))
- (if replace-evaled
- (cl-incf replacements)
- (setq replace-evaled content))
- (overlay-put ov 'after-string (anzu--propertize-to-string
replace-evaled))))))))
+ (let ((case-fold-search (anzu--case-fold-search from)))
+ (dolist (ov (anzu--overlays-in-range beg (min end overlay-limit)))
+ (let ((replace-evaled
+ (if (not use-regexp)
+ (anzu--replaced-literal-string ov content from)
+ (prog1 (anzu--evaluate-occurrence ov content replacements
+ (not case-fold-search)
from)
+ (cl-incf replacements)))))
+ (overlay-put ov 'after-string (anzu--propertize-to-string
replace-evaled)))))))))
(defsubst anzu--outside-overlay-limit (orig-beg orig-limit)
(save-excursion
@@ -511,7 +518,7 @@
(with-selected-window (or
(active-minibuffer-window)
(minibuffer-window))
(anzu--append-replaced-string
- curbuf beg end use-regexp overlay-limit))))))
+ curbuf beg end use-regexp overlay-limit
from))))))
(prog1 (read-from-minibuffer to-prompt
nil nil nil
query-replace-from-history-variable nil
t)
@@ -526,7 +533,7 @@
(query-replace-compile-replacement
(let ((to (anzu--read-to-string from prompt beg end use-regexp
overlay-limit)))
(add-to-history query-replace-to-history-variable to nil t)
- (setq query-replace-defaults (cons from to))
+ (add-to-history 'query-replace-defaults (cons from to) nil t)
to)
use-regexp))
- [nongnu] elpa/anzu 413bd09ebc 079/288: Fix different behavior from query-replace-regexp, (continued)
- [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
- [nongnu] elpa/anzu 630d663238 087/288: Fix invalid return type, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9b772435ea 090/288: Support backward replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 81b4eb6e29 093/288: Fix increasing anzu information in mode-line issue(#13), ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1ea6980019 106/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu caf83591e4 134/288: Merge pull request #28 from syohex/improve-replace-mode-line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5d209726cd 156/288: Merge pull request #36 from syohex/case-sensitive-for-at-cursor-command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ee53798dc2 160/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1c2705bb2c 164/288: Merge pull request #38 from syohex/improve-replacement,
ELPA Syncer <=
- [nongnu] elpa/anzu d4dcd76f47 190/288: Merge pull request #48 from syohex/improve-history, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 370b9f162f 181/288: Merge pull request #45 from syohex/fix-zero-width-replacement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 8a1eb22317 174/288: Merge pull request #42 from syohex/fix-replace-command-bug, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a1f56b6dad 193/288: Merge pull request #50 from syohex/fix-default-input-49, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 6dd966b4e2 186/288: Implement separator feature of Emacs 25, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5e87e8c07a 187/288: Use own history variable for maintenance, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 10a05eb50c 166/288: Disable blink-matching-paren for improvement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5abdc5b889 038/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 0418c2b6d4 041/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 218a63ce47 015/288: Highlight code and add screenshot explanation, ELPA Syncer, 2022/01/06