[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu cc427254a0 040/288: Introduce search threshold
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu cc427254a0 040/288: Introduce search threshold |
Date: |
Thu, 6 Jan 2022 03:58:38 -0500 (EST) |
branch: elpa/anzu
commit cc427254a0affcae31bbcb28bb59abd51cb63f1d
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Introduce search threshold
---
anzu.el | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/anzu.el b/anzu.el
index 7c1877eeec..aacaf6f88b 100644
--- a/anzu.el
+++ b/anzu.el
@@ -58,6 +58,12 @@
:type 'integer
:group 'anzu)
+(defcustom anzu-search-threshold nil
+ "Limit of search number"
+ :type '(choice (integer :tag "Threshold of search")
+ (boolean :tag "No threshold" nil))
+ :group 'anzu)
+
(defcustom anzu-use-migemo nil
"Flag of using migemo"
:type 'boolean
@@ -81,6 +87,7 @@
(defvar anzu--total-matched 0)
(defvar anzu--current-posion 0)
+(defvar anzu--overflow-p nil)
(defvar anzu--last-isearch-string nil)
(defvar anzu--cached-positions nil)
(defvar anzu--last-command nil)
@@ -92,6 +99,9 @@
t)
(invalid-regexp nil)))
+(defsubst anzu--construct-position-info (count overflow positions)
+ (list :count count :overflow overflow :positions positions))
+
(defun anzu--search-all-position (str)
(unless anzu--last-command
(setq anzu--last-command last-command))
@@ -103,6 +113,7 @@
(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
@@ -113,8 +124,10 @@
(when (= (match-beginning 0) (match-end 0)) ;; Case of anchor such
as "^"
(if (eobp)
(setq finish t)
- (forward-char 1))))
- (let ((result (cons count (reverse positions))))
+ (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)))))
@@ -130,10 +143,10 @@
(let ((result (if (string= isearch-string anzu--last-isearch-string)
anzu--cached-positions
(anzu--search-all-position isearch-string))))
- (let ((total (car result))
- (positions (cdr result)))
- (setq anzu--total-matched total
- anzu--current-posion (anzu--where-is-here positions (point))
+ (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-isearch-string isearch-string)
(force-mode-line-update)))))
@@ -149,20 +162,29 @@
(defsubst anzu--reset-status ()
(setq anzu--total-matched 0
anzu--current-posion 0
- anzu--last-command nil))
+ anzu--last-command nil
+ anzu--overflow-p nil))
(defun anzu--reset-mode-line ()
(anzu--reset-status)
(when (and anzu-cons-mode-line-p (anzu--mode-line-not-set-p))
(setq mode-line-format (cdr mode-line-format))))
+(defsubst anzu--format-here-position (here total)
+ (if (and anzu--overflow-p (zerop here))
+ (format "%d+" total)
+ here))
+
(defun anzu--update-mode-line-default (here total)
- (propertize (format "(%d/%d)" here total) 'face 'anzu-mode-line))
+ (propertize (format "(%s/%d%s)"
+ (anzu--format-here-position here total)
+ total (if anzu--overflow-p "+" ""))
+ 'face 'anzu-mode-line))
(defun anzu--update-mode-line ()
(let ((update-func (or anzu-mode-line-update-function
'anzu--update-mode-line-default)))
- (funcall update-func anzu--current-posion anzu--total-matched)))
+ (funcall update-func anzu--current-posion anzu--total-matched)))
;;;###autoload
(define-minor-mode anzu-mode
- [nongnu] elpa/anzu 12612a2b4f 202/288: Update document of custom function, (continued)
- [nongnu] elpa/anzu 12612a2b4f 202/288: Update document of custom function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 27e3a89622 203/288: Correct misspellings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b80dc0ca92 210/288: Merge pull request #59 from syohex/buffer-local-status, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a08ff2f7db 215/288: Wrap migemo-forward with ignore-errors, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f2aad769c1 227/288: Update copyright year, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ff54963946 232/288: Merge pull request #67 from syohex/refactoring, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 116501bf9e 216/288: Merge pull request #62 from syohex/fix-migemo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a35649e401 017/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 84183d2a79 022/288: update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f4618cd335 023/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cc427254a0 040/288: Introduce search threshold,
ELPA Syncer <=
- [nongnu] elpa/anzu 591b27621c 047/288: Merge pull request #11 from syohex/support-query-replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1fc36f460c 046/288: Implement anzu-query-regexp and anzu-query-regexp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cdee5811bb 048/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 28953f86f9 051/288: bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 2bcd549c5a 054/288: Re-factoring: reduce global variables, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9a055d9b0b 056/288: Add replacement feature like evil replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ce021b7234 057/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 602aa46fe7 070/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4d50eb8274 072/288: Implement anzu-query-replace-at-cursor-thing, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ad0d7bce91 073/288: Update document, ELPA Syncer, 2022/01/06