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

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

Signature

(thing-at-point--bounds-of-well-formed-url BEG END PT)

Source Code

;; Defined in /usr/src/emacs/lisp/thingatpt.el.gz
(defun thing-at-point--bounds-of-well-formed-url (beg end pt)
  (save-excursion
    (goto-char beg)
    (let (url-beg paren-end regexp)
      (save-restriction
	(narrow-to-region beg end)
	;; The scheme component must either match at BEG, or have no
	;; other alphanumerical ASCII characters before it.
	(setq regexp (concat "\\(?:\\`\\|[^a-zA-Z0-9]\\)\\("
			     (or thing-at-point-beginning-of-url-regexp
				 (regexp-opt thing-at-point-uri-schemes))
			     "\\)"))
	(and (re-search-forward regexp end t)
	     ;; URI must have non-empty contents.
	     (< (point) end)
	     (setq url-beg (match-beginning 1))))
      (when url-beg
	;; If there is an open paren before the URI, truncate to the
	;; matching close paren.
	(and (> url-beg (point-min))
	     (eq (car-safe (syntax-after (1- url-beg))) 4)
	     (save-restriction
	       (narrow-to-region (1- url-beg) (min end (point-max)))
	       (setq paren-end (ignore-errors
                                 ;; Make the scan work inside comments.
                                 (let ((parse-sexp-ignore-comments nil))
                                   (scan-lists (1- url-beg) 1 0)))))
	     (not (blink-matching-check-mismatch (1- url-beg) paren-end))
	     (setq end (1- paren-end)))
	;; Ensure PT is actually within BOUNDARY. Check the following
	;; example with point on the beginning of the line:
	;;
	;; 3,1406710489,https://gnu.org,0,"0"
	(and (<= url-beg pt end) (cons url-beg end))))))