emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/anzu 349e772b84 019/288: Fix #5 issue


From: ELPA Syncer
Subject: [nongnu] elpa/anzu 349e772b84 019/288: Fix #5 issue
Date: Thu, 6 Jan 2022 03:58:35 -0500 (EST)

branch: elpa/anzu
commit 349e772b84033969f82431b0eb560980dec5cb6e
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>

    Fix #5 issue
    
    If input is anchor such as '^', '$', matched count loop makes infinite loop.
---
 anzu.el | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/anzu.el b/anzu.el
index f38762c70b..0e332dc5dd 100644
--- a/anzu.el
+++ b/anzu.el
@@ -71,20 +71,33 @@
 (defvar anzu--last-isearch-string nil)
 (defvar anzu--cached-positions nil)
 
+(defun anzu--validate-regexp (regexp)
+  (condition-case err
+      (progn
+        (string-match-p regexp "")
+        t)
+    (invalid-regexp nil)))
+
 (defun anzu--search-all-position (str)
-  (save-excursion
-    (goto-char (point-min))
-    (let ((positions '())
-          (count 0)
-          (search-func (if (and anzu-use-migemo migemo-isearch-enable-p)
-                           'migemo-forward
-                         're-search-forward)))
-      (while (funcall search-func str nil t)
-        (push (cons (match-beginning 0) (match-end 0)) positions)
-        (incf count))
-      (let ((result (cons count (reverse positions))))
-        (setq anzu--cached-positions (copy-sequence result))
-        result))))
+  (when (anzu--validate-regexp str)
+    (save-excursion
+      (goto-char (point-min))
+      (let ((positions '())
+            (count 0)
+            (finish nil)
+            (search-func (if (and anzu-use-migemo migemo-isearch-enable-p)
+                             'migemo-forward
+                           're-search-forward)))
+        (while (and (not finish) (funcall search-func str nil t))
+          (push (cons (match-beginning 0) (match-end 0)) positions)
+          (incf count)
+          (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))))
+          (setq anzu--cached-positions (copy-sequence result))
+          result)))))
 
 (defun anzu--where-is-here (positions here)
   (loop for (start . end) in positions



reply via email to

[Prev in Thread] Current Thread [Next in Thread]