Function: bounds-of-thing-at-point
bounds-of-thing-at-point is an autoloaded and byte-compiled function
defined in thingatpt.el.gz.
Signature
(bounds-of-thing-at-point THING)
Documentation
Determine the start and end buffer locations for the THING at point.
THING should be a symbol specifying a type of syntactic entity.
Possibilities include symbol, list, sexp, defun,
filename, url, email, uuid, word, sentence, whitespace,
line, and page.
See the file thingatpt.el for documentation on how to define a
valid THING.
Return a cons cell (START . END) giving the start and end positions of the thing found.
Source Code
;; Defined in /usr/src/emacs/lisp/thingatpt.el.gz
;; General routines
;;;###autoload
(defun bounds-of-thing-at-point (thing)
"Determine the start and end buffer locations for the THING at point.
THING should be a symbol specifying a type of syntactic entity.
Possibilities include `symbol', `list', `sexp', `defun',
`filename', `url', `email', `uuid', `word', `sentence', `whitespace',
`line', and `page'.
See the file `thingatpt.el' for documentation on how to define a
valid THING.
Return a cons cell (START . END) giving the start and end
positions of the thing found."
(if (get thing 'bounds-of-thing-at-point)
(funcall (get thing 'bounds-of-thing-at-point))
(let ((orig (point)))
(ignore-errors
(save-excursion
;; Try moving forward, then back.
(funcall ;; First move to end.
(or (get thing 'end-op)
(lambda () (forward-thing thing 1))))
(funcall ;; Then move to beg.
(or (get thing 'beginning-op)
(lambda () (forward-thing thing -1))))
(let ((beg (point)))
(if (<= beg orig)
;; If that brings us all the way back to ORIG,
;; it worked. But END may not be the real end.
;; So find the real end that corresponds to BEG.
;; FIXME: in which cases can `real-end' differ from `end'?
(let ((real-end
(progn
(funcall
(or (get thing 'end-op)
(lambda () (forward-thing thing 1))))
(point))))
(when (and (<= orig real-end) (< beg real-end))
(cons beg real-end)))
(goto-char orig)
;; Try a second time, moving backward first and then forward,
;; so that we can find a thing that ends at ORIG.
(funcall ;; First, move to beg.
(or (get thing 'beginning-op)
(lambda () (forward-thing thing -1))))
(funcall ;; Then move to end.
(or (get thing 'end-op)
(lambda () (forward-thing thing 1))))
(let ((end (point))
(real-beg
(progn
(funcall
(or (get thing 'beginning-op)
(lambda () (forward-thing thing -1))))
(point))))
(if (and (<= real-beg orig) (<= orig end) (< real-beg end))
(cons real-beg end))))))))))