aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Fogel <[email protected]>2007-06-16 01:03:35 +0000
committerKarl Fogel <[email protected]>2007-06-16 01:03:35 +0000
commitbaef4cbec38e736b3dfd05aec00b783112103c5f (patch)
treef655412aa79bea305b5d69ab3fb1222da3e189bc
parentb32ce4c33acdac8d1fef85f9cd5ec4de3aa4e0fe (diff)
* 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.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/thingatpt.el31
2 files changed, 37 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c93f195d08..ec8ca907ee 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2007-06-15 Karl Fogel <[email protected]>
+
+ * 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.
+
2007-06-15 Masatake YAMATO <[email protected]>
* vc-bzr.el (vc-bzr-root): Cache the output of shell command
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index fd387a22c0..0d57091fb0 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -67,7 +67,7 @@
"Determine the start and end buffer locations for the THING at point.
THING is a symbol which specifies the kind of syntactic entity you want.
Possibilities include `symbol', `list', `sexp', `defun', `filename', `url',
-`word', `sentence', `whitespace', `line', `page' and others.
+`email', `word', `sentence', `whitespace', `line', `page' and others.
See the file `thingatpt.el' for documentation on how to define
a symbol as a valid THING.
@@ -124,7 +124,7 @@ of the textual entity that was found."
"Return the THING at point.
THING is a symbol which specifies the kind of syntactic entity you want.
Possibilities include `symbol', `list', `sexp', `defun', `filename', `url',
-`word', `sentence', `whitespace', `line', `page' and others.
+`email', `word', `sentence', `whitespace', `line', `page' and others.
See the file `thingatpt.el' for documentation on how to define
a symbol as a valid THING."
@@ -340,6 +340,33 @@ point."
(goto-char (car bounds))
(error "No URL here")))))
+;; Email addresses
+(defvar thing-at-point-email-regexp
+ "<?[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]+@[-.a-zA-Z0-9]+>?"
+ "A regular expression probably matching an email address.
+This does not match the real name portion, only the address, optionally
+with angle brackets.")
+
+;; Haven't set 'forward-op on 'email nor defined 'forward-email' because
+;; not sure they're actually needed, and URL seems to skip them too.
+;; Note that (end-of-thing 'email) and (beginning-of-thing 'email)
+;; work automagically, though.
+
+(put 'email 'bounds-of-thing-at-point
+ (lambda ()
+ (let ((thing (thing-at-point-looking-at thing-at-point-email-regexp)))
+ (if thing
+ (let ((beginning (match-beginning 0))
+ (end (match-end 0)))
+ (cons beginning end))))))
+
+(put 'email 'thing-at-point
+ (lambda ()
+ (let ((boundary-pair (bounds-of-thing-at-point 'email)))
+ (if boundary-pair
+ (buffer-substring-no-properties
+ (car boundary-pair) (cdr boundary-pair))))))
+
;; Whitespace
(defun forward-whitespace (arg)