Commit 5d5c701e authored by Leo Liu's avatar Leo Liu
Browse files

* thingatpt.el (thing-at-point-looking-at): Add optional arg

DISTANCE to bound the search. All uses changed.

Fixes: debbugs:15808
parent 65de43ad
2013-11-06 Leo Liu <sdl.web@gmail.com>
* thingatpt.el (thing-at-point-looking-at): Add optional arg
DISTANCE to bound the search. All uses changed. (Bug#15808)
2013-11-06 Glenn Morris <rgm@gnu.org> 2013-11-06 Glenn Morris <rgm@gnu.org>
* Makefile.in (setwins, setwins_almost, setwins_for_subdirs): Simplify. * Makefile.in (setwins, setwins_almost, setwins_for_subdirs): Simplify.
......
...@@ -476,19 +476,22 @@ looks like an email address, \"ftp://\" if it starts with ...@@ -476,19 +476,22 @@ looks like an email address, \"ftp://\" if it starts with
;; matches that straddle the start position so we search forwards once ;; matches that straddle the start position so we search forwards once
;; and then back repeatedly and then back up a char at a time. ;; and then back repeatedly and then back up a char at a time.
(defun thing-at-point-looking-at (regexp) (defun thing-at-point-looking-at (regexp &optional distance)
"Return non-nil if point is in or just after a match for REGEXP. "Return non-nil if point is in or just after a match for REGEXP.
Set the match data from the earliest such match ending at or after Set the match data from the earliest such match ending at or after
point." point."
(save-excursion (save-excursion
(let ((old-point (point)) match) (let ((old-point (point))
(forward-bound (and distance (+ (point) distance)))
(backward-bound (and distance (- (point) distance)))
match)
(and (looking-at regexp) (and (looking-at regexp)
(>= (match-end 0) old-point) (>= (match-end 0) old-point)
(setq match (point))) (setq match (point)))
;; Search back repeatedly from end of next match. ;; Search back repeatedly from end of next match.
;; This may fail if next match ends before this match does. ;; This may fail if next match ends before this match does.
(re-search-forward regexp nil 'limit) (re-search-forward regexp forward-bound 'limit)
(while (and (re-search-backward regexp nil t) (while (and (re-search-backward regexp backward-bound t)
(or (> (match-beginning 0) old-point) (or (> (match-beginning 0) old-point)
(and (looking-at regexp) ; Extend match-end past search start (and (looking-at regexp) ; Extend match-end past search start
(>= (match-end 0) old-point) (>= (match-end 0) old-point)
...@@ -518,7 +521,8 @@ with angle brackets.") ...@@ -518,7 +521,8 @@ with angle brackets.")
(put 'email 'bounds-of-thing-at-point (put 'email 'bounds-of-thing-at-point
(lambda () (lambda ()
(let ((thing (thing-at-point-looking-at thing-at-point-email-regexp))) (let ((thing (thing-at-point-looking-at
thing-at-point-email-regexp 500)))
(if thing (if thing
(let ((beginning (match-beginning 0)) (let ((beginning (match-beginning 0))
(end (match-end 0))) (end (match-end 0)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment