Improve zero-width match handling in tp-match and tp-regexp

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-12 03:39:26 +00:00
parent a34c1ee625
commit 519a5ec42f

8
tp.el
View File

@ -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