diff options
| author | Karl Fogel | 2007-06-16 01:03:35 +0000 |
|---|---|---|
| committer | Karl Fogel | 2007-06-16 01:03:35 +0000 |
| commit | baef4cbec38e736b3dfd05aec00b783112103c5f (patch) | |
| tree | f655412aa79bea305b5d69ab3fb1222da3e189bc /lisp/thingatpt.el | |
| parent | b32ce4c33acdac8d1fef85f9cd5ec4de3aa4e0fe (diff) | |
| download | emacs-baef4cbec38e736b3dfd05aec00b783112103c5f.tar.gz emacs-baef4cbec38e736b3dfd05aec00b783112103c5f.zip | |
* thingatpt.el: Add support for email addresses (`email').
(thing-at-point, bounds-of-thing-at-point): Document `email' support.
(thing-at-point-email-regexp): New variable.
(`email'): Put `bounds-of-thing-at-point' and `thing-at-point'
properties on this symbol, with lambda forms for values.
Diffstat (limited to 'lisp/thingatpt.el')
| -rw-r--r-- | lisp/thingatpt.el | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index fd387a22c0f..0d57091fb09 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el | |||
| @@ -67,7 +67,7 @@ | |||
| 67 | "Determine the start and end buffer locations for the THING at point. | 67 | "Determine the start and end buffer locations for the THING at point. |
| 68 | THING is a symbol which specifies the kind of syntactic entity you want. | 68 | THING is a symbol which specifies the kind of syntactic entity you want. |
| 69 | Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', | 69 | Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', |
| 70 | `word', `sentence', `whitespace', `line', `page' and others. | 70 | `email', `word', `sentence', `whitespace', `line', `page' and others. |
| 71 | 71 | ||
| 72 | See the file `thingatpt.el' for documentation on how to define | 72 | See the file `thingatpt.el' for documentation on how to define |
| 73 | a symbol as a valid THING. | 73 | a symbol as a valid THING. |
| @@ -124,7 +124,7 @@ of the textual entity that was found." | |||
| 124 | "Return the THING at point. | 124 | "Return the THING at point. |
| 125 | THING is a symbol which specifies the kind of syntactic entity you want. | 125 | THING is a symbol which specifies the kind of syntactic entity you want. |
| 126 | Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', | 126 | Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', |
| 127 | `word', `sentence', `whitespace', `line', `page' and others. | 127 | `email', `word', `sentence', `whitespace', `line', `page' and others. |
| 128 | 128 | ||
| 129 | See the file `thingatpt.el' for documentation on how to define | 129 | See the file `thingatpt.el' for documentation on how to define |
| 130 | a symbol as a valid THING." | 130 | a symbol as a valid THING." |
| @@ -340,6 +340,33 @@ point." | |||
| 340 | (goto-char (car bounds)) | 340 | (goto-char (car bounds)) |
| 341 | (error "No URL here"))))) | 341 | (error "No URL here"))))) |
| 342 | 342 | ||
| 343 | ;; Email addresses | ||
| 344 | (defvar thing-at-point-email-regexp | ||
| 345 | "<?[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]+@[-.a-zA-Z0-9]+>?" | ||
| 346 | "A regular expression probably matching an email address. | ||
| 347 | This does not match the real name portion, only the address, optionally | ||
| 348 | with angle brackets.") | ||
| 349 | |||
| 350 | ;; Haven't set 'forward-op on 'email nor defined 'forward-email' because | ||
| 351 | ;; not sure they're actually needed, and URL seems to skip them too. | ||
| 352 | ;; Note that (end-of-thing 'email) and (beginning-of-thing 'email) | ||
| 353 | ;; work automagically, though. | ||
| 354 | |||
| 355 | (put 'email 'bounds-of-thing-at-point | ||
| 356 | (lambda () | ||
| 357 | (let ((thing (thing-at-point-looking-at thing-at-point-email-regexp))) | ||
| 358 | (if thing | ||
| 359 | (let ((beginning (match-beginning 0)) | ||
| 360 | (end (match-end 0))) | ||
| 361 | (cons beginning end)))))) | ||
| 362 | |||
| 363 | (put 'email 'thing-at-point | ||
| 364 | (lambda () | ||
| 365 | (let ((boundary-pair (bounds-of-thing-at-point 'email))) | ||
| 366 | (if boundary-pair | ||
| 367 | (buffer-substring-no-properties | ||
| 368 | (car boundary-pair) (cdr boundary-pair)))))) | ||
| 369 | |||
| 343 | ;; Whitespace | 370 | ;; Whitespace |
| 344 | 371 | ||
| 345 | (defun forward-whitespace (arg) | 372 | (defun forward-whitespace (arg) |