all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Karl Fogel <kfogel@red-bean.com>
To: Andreas Roehler <andreas.roehler@easy-emacs.de>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Adding email address support to thingatpt.el.
Date: Tue, 27 Feb 2007 04:08:50 -0800	[thread overview]
Message-ID: <87abyz7qgd.fsf@floss.red-bean.com> (raw)
In-Reply-To: <45E32048.8050309@easy-emacs.de> (Andreas Roehler's message of "Mon\, 26 Feb 2007 19\:00\:40 +0100")

Andreas Roehler <andreas.roehler@easy-emacs.de> writes:
> Just for consideration:
>
> Email at point might be used to pick emails from a
> csv-database. Than `;' and `,' as delimiters should be
> possible together with or instead of angles.

It's okay, they're already treated as boundaries, because they're not
legal in the email address.  (I tested just now to make sure.)

Unless you mean they should be returned *as part of* the email
address, like ",andreas.roehler@easy-emacs.ed,"?  But that wouldn't be
good -- commas and semicolons are not the same as angle brackets in
that respect.

> AFAIU rfc2822, several more chars are allowed to be
> part of an email-adress than regexp honours now:

It's tough to know what to include.  Many characters that technically
could be part of an email address are rarely used in practice, and
instead appear much more often as delimiters (in certain contexts).
So if thingatpt.el is to Do The Right Thing most often for the user,
it probably can't comply precisely with the RFC.

I'm including the latest patch below, for reference, but I won't do
anything with it until after the release.

-Karl

2007-02-25  Karl Fogel  <kfogel@red-bean.com>

   * 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: thingatpt.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/thingatpt.el,v
retrieving revision 1.40
diff -u -r1.40 thingatpt.el
--- thingatpt.el	21 Jan 2007 03:53:10 -0000	1.40
+++ thingatpt.el	27 Feb 2007 03:07:51 -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
+  "<?[-+_.~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)

  reply	other threads:[~2007-02-27 12:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-25 19:25 Adding email address support to thingatpt.el Karl Fogel
2007-02-25 10:50 ` Andreas Schwab
2007-02-26  3:27 ` Richard Stallman
2007-02-26 13:31   ` Karl Fogel
2007-02-26 18:00     ` Andreas Roehler
2007-02-27 12:08       ` Karl Fogel [this message]
2007-02-27  7:37         ` Andreas Roehler
2007-02-27 14:49           ` Drew Adams
2007-02-27 20:49             ` Karl Fogel
2007-02-27 17:19           ` Karl Fogel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87abyz7qgd.fsf@floss.red-bean.com \
    --to=kfogel@red-bean.com \
    --cc=andreas.roehler@easy-emacs.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.