[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 5cf1c7c16e 238/288: Merge pull request #72 from syohe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 5cf1c7c16e 238/288: Merge pull request #72 from syohex/isearch-query-replace-api |
Date: |
Thu, 6 Jan 2022 03:58:56 -0500 (EST) |
branch: elpa/anzu
commit 5cf1c7c16e97536d6bdbaf5a78ab211ec66efdc8
Merge: dde4d83cfa faae95ccd9
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Merge pull request #72 from syohex/isearch-query-replace-api
Implement isearch-query-replace- like commands
---
README.md | 11 +++++++++++
anzu.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 57 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index d35b23f095..f2fe3ff13e 100644
--- a/README.md
+++ b/README.md
@@ -82,6 +82,14 @@ in the function.
![anzu-replace-demo](image/anzu-replace-demo-noquery.gif)
+#### `anzu-isearch-query-replace`
+
+Anzu version of `isearch-query-replace`
+
+#### `anzu-isearch-query-replace-regexp`
+
+Anzu version of `isearch-query-replace-regexp`
+
## Customization
#### `anzu-mode-line`
@@ -202,6 +210,9 @@ Separator of `to` string.
'(anzu-search-threshold 1000)
'(anzu-replace-threshold 50)
'(anzu-replace-to-string-separator " => "))
+
+(define-key isearch-mode-map (kbd "M-%") #'anzu-isearch-query-replace)
+(define-key isearch-mode-map (kbd "C-M-%") #'anzu-isearch-query-replace-regexp)
```
[melpa-link]: https://melpa.org/#/anzu
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 c0d58a61c2 136/288: A couple of grammar and typo fixes, (continued)
- [nongnu] elpa/anzu c0d58a61c2 136/288: A couple of grammar and typo fixes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 41f19cd2c2 214/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4426cff3bf 205/288: Correct removed hook function name, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu df60e608f1 233/288: Update document about update function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu e46563628d 234/288: Use "#'" instead of "'" for detecting typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 11544ea75c 242/288: Consider user's case-fold-search, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 42996934e2 239/288: Change syntax for bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu dad14fa96c 244/288: Use h5 header for interfaces, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 324c3e2db4 245/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [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 <=
- [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, 2022/01/06
- [nongnu] elpa/anzu ab561fe896 151/288: Use symbol-value instead of eval-when-compile + defvar, ELPA Syncer, 2022/01/06