Function: thing-at-point-bounds-of-url-at-point

thing-at-point-bounds-of-url-at-point is a byte-compiled function defined in thingatpt.el.gz.

Signature

(thing-at-point-bounds-of-url-at-point &optional LAX)

Documentation

Return a cons cell containing the start and end of the URI at point.

Try to find a URI using thing-at-point-markedup-url-regexp. If that fails, try with thing-at-point-beginning-of-url-regexp. If that also fails, and optional argument LAX is non-nil, return the bounds of a possible ill-formed URI (one lacking a scheme).

Source Code

;; Defined in /usr/src/emacs/lisp/thingatpt.el.gz
(defun thing-at-point-bounds-of-url-at-point (&optional lax)
  "Return a cons cell containing the start and end of the URI at point.
Try to find a URI using `thing-at-point-markedup-url-regexp'.
If that fails, try with `thing-at-point-beginning-of-url-regexp'.
If that also fails, and optional argument LAX is non-nil, return
the bounds of a possible ill-formed URI (one lacking a scheme)."
  ;; Look for the old <URL:foo> markup.  If found, use it.
  (or (thing-at-point--bounds-of-markedup-url)
      ;; Otherwise, find the bounds within which a URI may exist.  The
      ;; method is similar to `ffap-string-at-point'.  Note that URIs
      ;; may contain parentheses but may not contain spaces (RFC3986).
      (let* ((allowed-chars "--:=&?$+@-Z_[:alpha:]~#,%;*()!'")
	     (skip-before "^[0-9a-zA-Z]")
	     (skip-after  ":;.,!?'")
	     (pt (point))
	     (beg (save-excursion
		    (skip-chars-backward allowed-chars)
		    (skip-chars-forward skip-before pt)
		    (point)))
	     (end (save-excursion
		    (skip-chars-forward allowed-chars)
		    (skip-chars-backward skip-after pt)
		    (point))))
	(or (thing-at-point--bounds-of-well-formed-url beg end pt)
	    (if lax (cons beg end))))))