From: Tim Vaughan Date: Fri, 26 Apr 2019 16:00:38 +0000 (+0200) Subject: Added buttons for urls in text files. X-Git-Tag: v1.0.0~44 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=41d6c3b6d5234db34f5184755cd903116a5c7abe;p=elpher.git Added buttons for urls in text files. --- diff --git a/elopher.el b/elopher.el index 767f556..f058179 100644 --- a/elopher.el +++ b/elopher.el @@ -328,8 +328,25 @@ The result is stored as a string in the variable elopher-selector-string." ;; Text retrieval (defun elopher-process-text (string) - (let ((chopped-str (replace-regexp-in-string "\r\n\.\r\n$" "\r\n" string))) - (replace-regexp-in-string "\r" "" chopped-str))) + (let* ((chopped-str (replace-regexp-in-string "\r\n\.\r\n$" "\r\n" string)) + (cleaned-str (replace-regexp-in-string "\r" "" chopped-str))) + (elopher-buttonify-urls cleaned-str))) + +(defvar elopher-url-regex "\\https?://\\([a-z.\-]+\\)\\([^ \r\n\t(),]*\\)") + +(defun elopher-buttonify-urls (string) + (with-temp-buffer + (insert string) + (goto-char (point-min)) + (while (re-search-forward elopher-url-regex nil t) + (let ((url (match-string 0))) + (make-text-button (match-beginning 0) + (match-end 0) + 'elopher-url url + 'action #'elopher-click-url + 'follow-link t + 'help-echo (format "mouse-1, RET: open url %s" url)))) + (buffer-string))) (defun elopher-get-text-node () (let ((content (elopher-node-content elopher-current-node))