-;;; URL buttons
-
-(defconst lurk-url-regex
- (rx (:
- (group (+ alpha))
- "://"
- (group (or (+ (any alnum "." "-"))
- (+ (any alnum ":"))))
- (opt (group (: ":" (+ digit))))
- (opt (group (: "/"
- (opt
- (* (any alnum ",.-~/@|:%#=&_"))
- (+ (any alnum "-~/@|:%#=&")))))))))
-
-(defun lurk-click-url (button)
- (browse-url (button-get button 'url)))
-
-(defun lurk-buttonify-urls (string)
- "Turn substrings which look like urls in STRING into clickable buttons."
- (with-temp-buffer
- (insert string)
- (goto-char (point-min))
- (while (re-search-forward lurk-url-regex nil t)
- (let ((url (match-string 0)))
- (make-text-button (match-beginning 0)
- (match-end 0)
- 'action #'lurk-click-url
- 'url url
- 'follow-link t
- 'face 'button
- 'help-echo "Open URL in browser.")))
- (buffer-string)))
-