I am trying to filter URLs and elisp
thing-at-point 'url doesn't bounds a url properly because it has backslashes
\in it. I believe that backslashes are unsafe in urls, but that's a separate topic. The fact is that I am receiving emails with URLs that have them.
So my question is if there is any way to ensure that thing-at-point allows backslashes, so that urls can be properly bounded? The relevant functions should be available at thingatpt.el Thank you in advance.
This is phils' solution
(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))))))
and this is the original and url bounded by
thing-at-point-bounds-of-url-at-point (both edited)