X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/2a59b30d1674b21e3fdfd62e9d25799fdd110f24..2b96868715a33d5c1bfbd03e961a222076398722:/lisp/thingatpt.el diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index c0aa80ef1a..095ad0fbe1 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -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 ;; Maintainer: FSF @@ -10,16 +11,19 @@ ;; 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 . + ;;; 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 @@ -240,7 +247,7 @@ This may contain whitespace (including newlines) .") (let ((strip (thing-at-point-looking-at thing-at-point-markedup-url-regexp))) ;; (url "") short (if (or strip -` (thing-at-point-looking-at thing-at-point-url-regexp) + (thing-at-point-looking-at thing-at-point-url-regexp) ;; Access scheme omitted? ;; (setq short (thing-at-point-looking-at ;; thing-at-point-short-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 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)