diff options
| author | Leo Liu | 2013-11-06 17:06:05 +0800 |
|---|---|---|
| committer | Leo Liu | 2013-11-06 17:06:05 +0800 |
| commit | 5d5c701ef9c651af49a1c4cf365eb5f3754efe0b (patch) | |
| tree | cc5cd4abadd31264b9ffffc8b7564bc78ae57d1a | |
| parent | 65de43ada9373d0139a4dd583933d988a0f9b9a9 (diff) | |
| download | emacs-5d5c701ef9c651af49a1c4cf365eb5f3754efe0b.tar.gz emacs-5d5c701ef9c651af49a1c4cf365eb5f3754efe0b.zip | |
* thingatpt.el (thing-at-point-looking-at): Add optional arg
DISTANCE to bound the search. All uses changed.
Fixes: debbugs:15808
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/thingatpt.el | 14 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 90f71bb01a1..d775afd9c5b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-11-06 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | * thingatpt.el (thing-at-point-looking-at): Add optional arg | ||
| 4 | DISTANCE to bound the search. All uses changed. (Bug#15808) | ||
| 5 | |||
| 1 | 2013-11-06 Glenn Morris <rgm@gnu.org> | 6 | 2013-11-06 Glenn Morris <rgm@gnu.org> |
| 2 | 7 | ||
| 3 | * Makefile.in (setwins, setwins_almost, setwins_for_subdirs): Simplify. | 8 | * Makefile.in (setwins, setwins_almost, setwins_for_subdirs): Simplify. |
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index b67a32a24f7..0887c7f1fe4 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el | |||
| @@ -476,19 +476,22 @@ looks like an email address, \"ftp://\" if it starts with | |||
| 476 | ;; matches that straddle the start position so we search forwards once | 476 | ;; matches that straddle the start position so we search forwards once |
| 477 | ;; and then back repeatedly and then back up a char at a time. | 477 | ;; and then back repeatedly and then back up a char at a time. |
| 478 | 478 | ||
| 479 | (defun thing-at-point-looking-at (regexp) | 479 | (defun thing-at-point-looking-at (regexp &optional distance) |
| 480 | "Return non-nil if point is in or just after a match for REGEXP. | 480 | "Return non-nil if point is in or just after a match for REGEXP. |
| 481 | Set the match data from the earliest such match ending at or after | 481 | Set the match data from the earliest such match ending at or after |
| 482 | point." | 482 | point." |
| 483 | (save-excursion | 483 | (save-excursion |
| 484 | (let ((old-point (point)) match) | 484 | (let ((old-point (point)) |
| 485 | (forward-bound (and distance (+ (point) distance))) | ||
| 486 | (backward-bound (and distance (- (point) distance))) | ||
| 487 | match) | ||
| 485 | (and (looking-at regexp) | 488 | (and (looking-at regexp) |
| 486 | (>= (match-end 0) old-point) | 489 | (>= (match-end 0) old-point) |
| 487 | (setq match (point))) | 490 | (setq match (point))) |
| 488 | ;; Search back repeatedly from end of next match. | 491 | ;; Search back repeatedly from end of next match. |
| 489 | ;; This may fail if next match ends before this match does. | 492 | ;; This may fail if next match ends before this match does. |
| 490 | (re-search-forward regexp nil 'limit) | 493 | (re-search-forward regexp forward-bound 'limit) |
| 491 | (while (and (re-search-backward regexp nil t) | 494 | (while (and (re-search-backward regexp backward-bound t) |
| 492 | (or (> (match-beginning 0) old-point) | 495 | (or (> (match-beginning 0) old-point) |
| 493 | (and (looking-at regexp) ; Extend match-end past search start | 496 | (and (looking-at regexp) ; Extend match-end past search start |
| 494 | (>= (match-end 0) old-point) | 497 | (>= (match-end 0) old-point) |
| @@ -518,7 +521,8 @@ with angle brackets.") | |||
| 518 | 521 | ||
| 519 | (put 'email 'bounds-of-thing-at-point | 522 | (put 'email 'bounds-of-thing-at-point |
| 520 | (lambda () | 523 | (lambda () |
| 521 | (let ((thing (thing-at-point-looking-at thing-at-point-email-regexp))) | 524 | (let ((thing (thing-at-point-looking-at |
| 525 | thing-at-point-email-regexp 500))) | ||
| 522 | (if thing | 526 | (if thing |
| 523 | (let ((beginning (match-beginning 0)) | 527 | (let ((beginning (match-beginning 0)) |
| 524 | (end (match-end 0))) | 528 | (end (match-end 0))) |