[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 939187fd7a0: ; Fix 'thing-at-point' edge case involving overlappi
From: |
Eshel Yaron |
Subject: |
master 939187fd7a0: ; Fix 'thing-at-point' edge case involving overlapping matches |
Date: |
Sat, 10 Feb 2024 11:40:59 -0500 (EST) |
branch: master
commit 939187fd7a07249a1a76d98e8d91051fa76b8727
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
; Fix 'thing-at-point' edge case involving overlapping matches
* lisp/thingatpt.el (thing-at-point-looking-at): When finding a match
that ends before point, continue searching from the beginning of that
match, not its end, in case the match we're looking is overlapping with
this one.
* test/lisp/thingatpt-tests.el
(thing-at-point-looking-at-overlapping-matches): New test.
---
lisp/thingatpt.el | 3 ++-
test/lisp/thingatpt-tests.el | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index b532bafff82..83ddc640d35 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -621,13 +621,14 @@ Optional argument DISTANCE limits search for REGEXP
forward and
back from point."
(let* ((old (point))
(beg (if distance (max (point-min) (- old distance)) (point-min)))
- (end (and distance (min (point-max) (+ old distance))))
+ (end (if distance (min (point-max) (+ old distance))))
prev match)
(save-excursion
(goto-char beg)
(while (and (setq prev (point)
match (re-search-forward regexp end t))
(< (match-end 0) old))
+ (goto-char (match-beginning 0))
;; Avoid inflooping when `regexp' matches the empty string.
(unless (< prev (point)) (forward-char))))
(and match (<= (match-beginning 0) old (match-end 0)))))
diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el
index 56bc4fdc9dc..e50738f1122 100644
--- a/test/lisp/thingatpt-tests.el
+++ b/test/lisp/thingatpt-tests.el
@@ -182,6 +182,13 @@ position to retrieve THING.")
(should (thing-at-point-looking-at "2abcd"))
(should (equal (match-data) m2)))))
+(ert-deftest thing-at-point-looking-at-overlapping-matches ()
+ (with-temp-buffer
+ (insert "foo.bar.baz")
+ (goto-char (point-max))
+ (should (thing-at-point-looking-at "[a-z]+\\.[a-z]+"))
+ (should (string= "bar.baz" (match-string 0)))))
+
(ert-deftest test-symbol-thing-1 ()
(with-temp-buffer
(insert "foo bar zot")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 939187fd7a0: ; Fix 'thing-at-point' edge case involving overlapping matches,
Eshel Yaron <=