[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 1ae7297bc7 132/288: Merge pull request #27 from syohe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 1ae7297bc7 132/288: Merge pull request #27 from syohex/fix-for-toggle-search |
Date: |
Thu, 6 Jan 2022 03:58:46 -0500 (EST) |
branch: elpa/anzu
commit 1ae7297bc743e8779d636ddeb705723ea1c64782
Merge: ffcffffc1a 9fc916b6de
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Merge pull request #27 from syohex/fix-for-toggle-search
Fix for symbol search and toggle in isearch-mode
---
anzu.el | 72 ++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 44 insertions(+), 28 deletions(-)
diff --git a/anzu.el b/anzu.el
index a42951ec83..a4a2e1fb9c 100644
--- a/anzu.el
+++ b/anzu.el
@@ -130,6 +130,7 @@
(defvar anzu--state nil)
(defvar anzu--cached-count 0)
(defvar anzu--last-replace-input "")
+(defvar anzu--last-search-state nil)
(defun anzu--validate-regexp (regexp)
(condition-case nil
@@ -145,36 +146,45 @@
(let ((case-fold-search nil))
(not (string-match-p "[A-Z]" input))))
+(defsubst anzu--word-search-p ()
+ (and (not (memq anzu--last-command anzu-regexp-search-commands))
+ (not isearch-regexp)))
+
+(defun anzu--transform-input (str)
+ (cond ((eq isearch-word 'isearch-symbol-regexp)
+ (setq str (concat "\\_<" str "\\_>")))
+ ((anzu--word-search-p)
+ (setq str (regexp-quote str)))
+ (t str)))
+
(defun anzu--search-all-position (str)
(unless anzu--last-command
(setq anzu--last-command last-command))
- (when (and (not (memq anzu--last-command anzu-regexp-search-commands))
- (not isearch-regexp))
- (setq str (regexp-quote str)))
- (if (not (anzu--validate-regexp str))
- anzu--cached-positions
- (save-excursion
- (goto-char (point-min))
- (let ((positions '())
- (count 0)
- (overflow nil)
- (finish nil)
- (search-func (if (and anzu-use-migemo migemo-isearch-enable-p)
- 'migemo-forward
- 're-search-forward))
- (case-fold-search (anzu--case-fold-search str)))
- (while (and (not finish) (funcall search-func str nil t))
- (push (cons (match-beginning 0) (match-end 0)) positions)
- (cl-incf count)
- (when (= (match-beginning 0) (match-end 0)) ;; Case of anchor such
as "^"
- (if (eobp)
- (setq finish t)
- (forward-char 1)))
- (when (and anzu-search-threshold (>= count anzu-search-threshold))
- (setq overflow t finish t)))
- (let ((result (anzu--construct-position-info count overflow (reverse
positions))))
- (setq anzu--cached-positions (copy-sequence result))
- result)))))
+ (let ((input (anzu--transform-input str)))
+ (if (not (anzu--validate-regexp input))
+ anzu--cached-positions
+ (save-excursion
+ (goto-char (point-min))
+ (let ((positions '())
+ (count 0)
+ (overflow nil)
+ (finish nil)
+ (search-func (if (and anzu-use-migemo migemo-isearch-enable-p)
+ 'migemo-forward
+ 're-search-forward))
+ (case-fold-search (anzu--case-fold-search input)))
+ (while (and (not finish) (funcall search-func input nil t))
+ (push (cons (match-beginning 0) (match-end 0)) positions)
+ (cl-incf count)
+ (when (= (match-beginning 0) (match-end 0)) ;; Case of anchor such
as "^"
+ (if (eobp)
+ (setq finish t)
+ (forward-char 1)))
+ (when (and anzu-search-threshold (>= count anzu-search-threshold))
+ (setq overflow t finish t)))
+ (let ((result (anzu--construct-position-info count overflow (reverse
positions))))
+ (setq anzu--cached-positions (copy-sequence result))
+ result))))))
(defun anzu--where-is-here (positions here)
(cl-loop for (start . end) in positions
@@ -183,15 +193,21 @@
return i
finally return 0))
+(defun anzu--use-result-cache-p (input)
+ (and (eq isearch-word (car anzu--last-search-state))
+ (eq isearch-regexp (cdr anzu--last-search-state))
+ (string= input anzu--last-isearch-string)))
+
(defun anzu--update ()
(when (>= (length isearch-string) anzu-minimum-input-length)
- (let ((result (if (string= isearch-string anzu--last-isearch-string)
+ (let ((result (if (anzu--use-result-cache-p isearch-string)
anzu--cached-positions
(anzu--search-all-position isearch-string))))
(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--last-search-state (cons isearch-word isearch-regexp)
anzu--last-isearch-string isearch-string)
(force-mode-line-update)))))
- [nongnu] elpa/anzu 91f3478003 097/288: Merge pull request #15 from syohex/fix-nonprefix-case, (continued)
- [nongnu] elpa/anzu 91f3478003 097/288: Merge pull request #15 from syohex/fix-nonprefix-case, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 189c0eaf9f 101/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 0b3cf4b0a6 103/288: Merge pull request #17 from syohex/add-nonquery-replace-command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 2a9785459b 111/288: Merge pull request #20 from syohex/enable-lexical-binding, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 8e92765ab7 113/288: Specify Emacs version, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 8fe3d080ff 114/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 11dcdf722f 128/288: Use package-file instead of package, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 718d5845d1 126/288: Merge pull request #25 from syohex/add-lines-region, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 485f463a40 127/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ffcffffc1a 130/288: Merge pull request #26 from cedricporter/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1ae7297bc7 132/288: Merge pull request #27 from syohex/fix-for-toggle-search,
ELPA Syncer <=
- [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