From 519a5ec42ff6fb2dd74df1c9e1ed78d1a251b44c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 03:39:26 +0000 Subject: [PATCH] Improve zero-width match handling in tp-match and tp-regexp Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com> --- tp.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tp.el b/tp.el index 501148b..7d2402e 100644 --- a/tp.el +++ b/tp.el @@ -614,8 +614,8 @@ Returns: (end (match-end 0))) (when properties (tp-put object beg end properties)) - ;; Advance by at least 1 to avoid infinite loop on empty match - (setq pos (max (1+ beg) end)))) + ;; Advance position: for zero-width match, advance by 1 to avoid infinite loop + (setq pos (if (= beg end) (1+ beg) end)))) object)) ;; Buffer or nil (current buffer) (t @@ -678,8 +678,8 @@ Returns: (end (match-end 0))) (when properties (tp-put object beg end properties)) - ;; Advance by at least 1 to avoid infinite loop on zero-width match - (setq pos (max (1+ beg) end)))) + ;; Advance position: for zero-width match, advance by 1 to avoid infinite loop + (setq pos (if (= beg end) (1+ beg) end)))) object)) ;; Buffer or nil (current buffer) (t