[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 88a7059601 236/288: Implement isearch-query-replace-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 88a7059601 236/288: Implement isearch-query-replace- like commands |
Date: |
Thu, 6 Jan 2022 03:58:56 -0500 (EST) |
branch: elpa/anzu
commit 88a70596017279bca39e8c28f6f51890b2ba92f1
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Implement isearch-query-replace- like commands
---
anzu.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 46 insertions(+), 9 deletions(-)
diff --git a/anzu.el b/anzu.el
index 942a4aa0a0..73a2e388b0 100644
--- a/anzu.el
+++ b/anzu.el
@@ -315,9 +315,9 @@
(if use-regexp " regexp" "")
(if use-region " in region" "")) )
-(defun anzu--query-prompt (use-region use-regexp at-cursor)
+(defun anzu--query-prompt (use-region use-regexp at-cursor isearch-p)
(let ((prompt (anzu--query-prompt-base use-region use-regexp)))
- (if (and anzu--query-defaults (not at-cursor))
+ (if (and anzu--query-defaults (not at-cursor) (not isearch-p))
(format "%s (default %s -> %s) "
prompt
(query-replace-descr (caar anzu--query-defaults))
@@ -634,6 +634,13 @@
(force-mode-line-update)
symbol-regexp)))
+(defun anzu--query-from-isearch-string (buf beg end use-regexp overlay-limit)
+ (anzu--count-and-highlight-matched buf isearch-string beg end use-regexp
overlay-limit t)
+ (setq anzu--total-matched anzu--cached-count)
+ (force-mode-line-update)
+ (add-to-history query-replace-from-history-variable isearch-string nil t)
+ isearch-string)
+
(defun anzu--thing-begin (thing)
(let ((bound (bounds-of-thing-at-point thing)))
(if bound
@@ -717,7 +724,8 @@
(cl-return nil)
(forward-char 1)))))))
-(cl-defun anzu--query-replace-common (use-regexp &key at-cursor thing
prefix-arg (query t))
+(cl-defun anzu--query-replace-common (use-regexp
+ &key at-cursor thing prefix-arg (query
t) isearch-p)
(anzu--cons-mode-line 'replace-query)
(let* ((use-region (use-region-p))
(orig-point (point))
@@ -725,18 +733,21 @@
(overlay-limit (anzu--overlay-limit))
(beg (anzu--region-begin use-region (anzu--begin-thing at-cursor
thing) backward))
(end (anzu--region-end use-region thing))
- (prompt (anzu--query-prompt use-region use-regexp at-cursor))
+ (prompt (anzu--query-prompt use-region use-regexp at-cursor
isearch-p))
(delimited (and current-prefix-arg (not (eq current-prefix-arg '-))))
(curbuf (current-buffer))
(clear-overlay nil))
(when (and anzu-deactivate-region use-region)
(deactivate-mark t))
(unwind-protect
- (let* ((from (if (and at-cursor beg)
- (progn
- (setq delimited nil)
- (anzu--query-from-at-cursor curbuf beg end
overlay-limit))
- (anzu--query-from-string prompt beg end use-regexp
overlay-limit)))
+ (let* ((from (cond ((and at-cursor beg)
+ (setq delimited nil)
+ (anzu--query-from-at-cursor curbuf beg end
overlay-limit))
+ (isearch-p
+ (anzu--query-from-isearch-string
+ curbuf beg end use-regexp overlay-limit))
+ (t (anzu--query-from-string
+ prompt beg end use-regexp overlay-limit))))
(to (cond ((consp from)
(prog1 (cdr from)
(setq from (car from)
@@ -798,5 +809,31 @@
(goto-char (marker-position orig))
(set-marker orig nil)))
+(defun anzu--isearch-query-replace-common (use-regexp arg)
+ (isearch-done nil t)
+ (isearch-clean-overlays)
+ (let ((isearch-recursive-edit nil)
+ (backward (< (prefix-numeric-value arg) 0)))
+ (when (and isearch-other-end
+ (if backward
+ (> isearch-other-end (point))
+ (< isearch-other-end (point)))
+ (not (and transient-mark-mode mark-active
+ (if backward
+ (> (mark) (point))
+ (< (mark) (point))))))
+ (goto-char isearch-other-end))
+ (anzu--query-replace-common use-regexp :prefix-arg arg :isearch-p t)))
+
+;;;###autoload
+(defun anzu-isearch-query-replace (arg)
+ (interactive "p")
+ (anzu--isearch-query-replace-common nil arg))
+
+;;;###autoload
+(defun anzu-isearch-query-replace-regexp (arg)
+ (interactive "p")
+ (anzu--isearch-query-replace-common t arg))
+
(provide 'anzu)
;;; anzu.el ends here
- [nongnu] elpa/anzu e782725f80 162/288: Support case sensitive highlighting, (continued)
- [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
- [nongnu] elpa/anzu db819bfb06 184/288: Merge pull request #47 from syohex/fix-46, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4d81f2f0cd 192/288: Fix order of conditions in cond, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f41db6225d 194/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 07b7802d9d 212/288: Fix literal replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b11642d49c 207/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 88a7059601 236/288: Implement isearch-query-replace- like commands,
ELPA Syncer <=
- [nongnu] elpa/anzu 1eceed7498 196/288: Merge pull request #51 from syohex/highlight-matching-groups, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu dde4d83cfa 235/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1ce32470dd 200/288: Merge pull request #54 from syohex/check-from-regexp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu faae95ccd9 237/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 008c2659b1 208/288: Use https, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu c05a8ac594 206/288: Merge pull request #57 from syohex/fix-typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu de3d805c9a 211/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9c821d182c 217/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ed5e91b0c4 259/288: Add face at no-match case, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9574e8140f 247/288: Merge pull request #76 from Fuco1/bugfix/fix-customize-type, ELPA Syncer, 2022/01/06