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.
Update
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)
original:
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.disney.com%2F&\;data=02%7C01%7CDonald.Duck%40disney.com%7Cfd8a40dd8138470286be08d8020da460%7C07ef1208413c4b5e9cdd64ef305754f0%7C0%7C0%7C637261604914185764&\;sdata=UdFaQR32cGXKu7ZrBU%2BGg8TJ%2BOeTZUMBV9N%2BE8Vi22s%3D&\;reserved=0
bounded:
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.disney.com%2F&