X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/c0466914ba3ad88c402b0301646b4b5db8aeb913..2988341a84f6e5faef7e5f5ce2c55142935d0fee:/lisp/thingatpt.el?ds=sidebyside diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index fd387a22c0..96a7924779 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, -;; 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +;; 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." @@ -165,7 +169,7 @@ a symbol as a valid THING." (nth 3 (parse-partial-sexp (point) orig))))) (defun end-of-sexp () - (let ((char-syntax (char-syntax (char-after (point))))) + (let ((char-syntax (char-syntax (char-after)))) (if (or (eq char-syntax ?\)) (and (eq char-syntax ?\") (in-string-p))) (forward-char 1) @@ -174,7 +178,7 @@ a symbol as a valid THING." (put 'sexp 'end-op 'end-of-sexp) (defun beginning-of-sexp () - (let ((char-syntax (char-syntax (char-before (point))))) + (let ((char-syntax (char-syntax (char-before)))) (if (or (eq char-syntax ?\() (and (eq char-syntax ?\") (in-string-p))) (forward-char -1) @@ -204,7 +208,7 @@ a symbol as a valid THING." (goto-char (point-min))))) (defvar thing-at-point-url-path-regexp - "[^]\t\n \"'()<>[^`{}]*[^]\t\n \"'()<>[^`{}.,;]+" + "[^]\t\n \"'<>[^`{}]*[^]\t\n \"'<>[^`{}.,;]+" "A regular expression probably matching the host and filename or e-mail part of a URL.") (defvar thing-at-point-short-url-regexp @@ -340,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) @@ -374,10 +405,10 @@ point." (interactive "p") (while (< arg 0) (skip-syntax-backward - (char-to-string (char-syntax (char-after (1- (point)))))) + (char-to-string (char-syntax (char-before)))) (setq arg (1+ arg))) (while (> arg 0) - (skip-syntax-forward (char-to-string (char-syntax (char-after (point))))) + (skip-syntax-forward (char-to-string (char-syntax (char-after)))) (setq arg (1- arg)))) ;; Aliases @@ -406,15 +437,22 @@ Signal an error if the entire string was not used." (if (or (not pred) (funcall pred sexp)) sexp))) ;;;###autoload -(defun sexp-at-point () (form-at-point 'sexp)) +(defun sexp-at-point () + "Return the sexp at point, or nil if none is found." + (form-at-point 'sexp)) ;;;###autoload (defun symbol-at-point () + "Return the symbol at point, or nil if none is found." (let ((thing (thing-at-point 'symbol))) (if thing (intern thing)))) ;;;###autoload -(defun number-at-point () (form-at-point 'sexp 'numberp)) +(defun number-at-point () + "Return the number at point, or nil if none is found." + (form-at-point 'sexp 'numberp)) ;;;###autoload -(defun list-at-point () (form-at-point 'list 'listp)) +(defun list-at-point () + "Return the Lisp list at point, or nil if none is found." + (form-at-point 'list 'listp)) ;; arch-tag: bb65a163-dae2-4055-aedc-fe11f497f698 ;;; thingatpt.el ends here