From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Karl Fogel Newsgroups: gmane.emacs.devel Subject: Adding email address support to thingatpt.el. Date: Sun, 25 Feb 2007 11:25:01 -0800 Message-ID: <87vehqox9u.fsf@floss.red-bean.com> Reply-To: Karl Fogel NNTP-Posting-Host: lo.gmane.org X-Trace: sea.gmane.org 1172399130 22396 80.91.229.12 (25 Feb 2007 10:25:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 25 Feb 2007 10:25:30 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 25 11:25:24 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HLGZG-0004uT-7y for ged-emacs-devel@m.gmane.org; Sun, 25 Feb 2007 11:25:22 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HLGZF-00046g-TO for ged-emacs-devel@m.gmane.org; Sun, 25 Feb 2007 05:25:21 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HLGZ2-000469-4D for emacs-devel@gnu.org; Sun, 25 Feb 2007 05:25:08 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HLGZ0-00042t-7Y for emacs-devel@gnu.org; Sun, 25 Feb 2007 05:25:07 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HLGZ0-00042p-0C for emacs-devel@gnu.org; Sun, 25 Feb 2007 05:25:06 -0500 Original-Received: from sanpietro.red-bean.com ([66.146.193.61]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HLGYz-0001RB-Is for emacs-devel@gnu.org; Sun, 25 Feb 2007 05:25:05 -0500 Original-Received: from localhost ([127.0.0.1]:38434 helo=floss.red-bean.com ident=kfogel) by sanpietro.red-bean.com with esmtp (Exim 4.63) (envelope-from ) id 1HLGYw-0001dD-6o for emacs-devel@gnu.org; Sun, 25 Feb 2007 04:25:02 -0600 X-detected-kernel: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:66787 Archived-At: I was surprised to find that thingatpt.el doesn't support email addresses, so made the patch below. I'd like comments before committing, though, as I've never modified thingatpt.el before. If we're in a freeze, this can wait. (I can't tell if we're in a freeze or not, from looking at the Savannah pages for Emacs.) -Karl 2007-02-25 Karl Fogel * 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. Index: lisp/thingatpt.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/thingatpt.el,v retrieving revision 1.40 diff -u -r1.40 thingatpt.el --- lisp/thingatpt.el 21 Jan 2007 03:53:10 -0000 1.40 +++ lisp/thingatpt.el 25 Feb 2007 10:13:49 -0000 @@ -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 @@ "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 @@ (goto-char (car bounds)) (error "No URL here"))))) +;; Email addresses +(defvar thing-at-point-email-regexp + "<\\{0,1\\}[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]+@[-.a-zA-Z0-9]+>\\{0,1\\}" + "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 (thing-at-point-bounds-of-email-at-point))) + (if boundary-pair + (buffer-substring-no-properties + (car boundary-pair) (cdr boundary-pair)))))) + ;; Whitespace (defun forward-whitespace (arg)