]> code.delx.au - gnu-emacs/blobdiff - lisp/thingatpt.el
Merge from gnus--devo--0
[gnu-emacs] / lisp / thingatpt.el
index e2618bca8fd919709b9ba6bc8aefcea76173075d..095ad0fbe1659ccc3082126e3cc98f94ebf43a26 100644 (file)
@@ -1,7 +1,8 @@
 ;;; thingatpt.el --- get the `thing' at point
 
-;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000
-;;   2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
+;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+;;   Free Software Foundation, Inc.
 
 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz>
 ;; Maintainer: FSF
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
 
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
 ;;; Commentary:
 
 ;; This file provides routines for getting the "thing" at the location of
@@ -67,7 +71,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 +128,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."
@@ -214,15 +218,18 @@ Hostname matching is stricter in this case than for
 ``thing-at-point-url-regexp''.")
 
 (defvar thing-at-point-uri-schemes
-  ;; Officials from http://www.iana.org/assignments/uri-schemes
+  ;; Officials from http://www.iana.org/assignments/uri-schemes.html
   '("ftp://" "http://" "gopher://" "mailto:" "news:" "nntp:"
     "telnet://" "wais://" "file:/" "prospero:" "z39.50s:" "z39.50r:"
     "cid:" "mid:" "vemmi:" "service:" "imap:" "nfs:" "acap:" "rtsp:"
     "tip:" "pop:" "data:" "dav:" "opaquelocktoken:" "sip:" "tel:" "fax:"
     "modem:" "ldap:" "https://" "soap.beep:" "soap.beeps:" "urn:" "go:"
     "afs:" "tn3270:" "mailserver:"
+    "crid:" "dict:" "dns:" "dtn:" "h323:" "im:" "info:" "ipp:"
+    "iris.beep:" "mtqp:" "mupdate:" "pres:" "sips:" "snmp:" "tag:"
+    "tftp:" "xmlrpc.beep:" "xmlrpc.beeps:" "xmpp:"
   ;; Compatibility
-    "snews:")
+    "snews:" "irc:" "mms://" "mmsh://")
   "Uniform Resource Identifier (URI) Schemes.")
 
 (defvar thing-at-point-url-regexp
@@ -275,7 +282,10 @@ starts with \"ftp\" and not \"ftp:/\", or \"http://\" by default."
          ;; strip whitespace
          (while (string-match "[ \t\n\r]+" url)
            (setq url (replace-match "" t t url)))
-         (and short (setq url (concat (cond ((string-match "@" url)
+         (and short (setq url (concat (cond ((string-match "^[a-zA-Z]+:" url)
+                                              ;; already has a URL scheme.
+                                              "")
+                                            ((string-match "@" url)
                                               "mailto:")
                                             ;; e.g. ftp.swiss... or ftp-swiss...
                                              ((string-match "^ftp" url)
@@ -334,6 +344,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)