[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 9fc916b6de 131/288: Fix for symbol search and toggle
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 9fc916b6de 131/288: Fix for symbol search and toggle in isearch-mode |
Date: |
Thu, 6 Jan 2022 03:58:46 -0500 (EST) |
branch: elpa/anzu
commit 9fc916b6de70360a10bf8e3a94b2305cdd0c4a12
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
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 31f1f8b817 089/288: Bump up version and update Changes, (continued)
- [nongnu] elpa/anzu 31f1f8b817 089/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 138ebcb0e0 098/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f73bab2744 100/288: Merge pull request #16 from syohex/fix-case-sensitive, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 906287cb5e 104/288: Switch cl-lib.el from cl.el, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a0a16ab869 108/288: Merge pull request #19 from syohex/improve-prompt, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu c26de0ecef 112/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4b9c6479d8 117/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 24a2589f10 119/288: Merge pull request #23 from syohex/fix-replacement-issue, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 6cad7a027f 123/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu fb003540df 129/288: fix typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9fc916b6de 131/288: Fix for symbol search and toggle in isearch-mode,
ELPA Syncer <=
- [nongnu] elpa/anzu 0bdbfcb209 138/288: Improve case when input does not match anything in visiable range(#30), ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu af40f91a98 140/288: Merge pull request #31 from syohex/no-match-case, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 04ac39641e 143/288: Merge pull request #32 from syohex/fix-at-cursor-beginning-point, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu c61f6734b1 152/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 3adcdab743 163/288: Correct saving replacement history, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9064fc7892 169/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 75bd476be1 045/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 8622c1fa93 049/288: Fix typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b8d328805a 053/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu bb3f7b63ef 059/288: Implement anzu-query-replace-at-cursor, ELPA Syncer, 2022/01/06