* 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.
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)))))
(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")