diff --git a/thingatpt.el b/thingatpt.el index 1686c02..1040f15 100644 --- a/thingatpt.el +++ b/thingatpt.el @@ -501,11 +501,14 @@ point." ;; Search back repeatedly from end of next match. ;; This may fail if next match ends before this match does. (re-search-forward regexp forward-bound 'limit) - (while (and (re-search-backward regexp backward-bound t) - (or (> (match-beginning 0) old-point) - (and (looking-at regexp) ; Extend match-end past search start - (>= (match-end 0) old-point) - (setq match (point)))))) + (let (old-match) + (while (and (re-search-backward regexp backward-bound t) + (setq old-match (point)) + (not (equal old-match match)) + (or (> (match-beginning 0) old-point) + (and (looking-at regexp) ; Extend match-end past search start + (>= (match-end 0) old-point) + (setq old-match match match (point))))))) (if (not match) nil (goto-char match) ;; Back up a char at a time in case search skipped