X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=elopher.el;h=3e35921992d2d2ae7bd8fb4a5d9935374a1dc277;hb=c95abb707d90ad6829b426fdbd4f9e0f0a69568a;hp=dfb5c776b6f0f556d1ff4962f9ab936e5d10db03;hpb=20fb5d3a386e6546ed881d5005a6acb77521388d;p=elpher.git diff --git a/elopher.el b/elopher.el index dfb5c77..3e35921 100644 --- a/elopher.el +++ b/elopher.el @@ -248,7 +248,7 @@ Otherwise, use the system browser via the BROWSE-URL function." 'action #'elopher-click-link 'follow-link t 'help-echo help-string)) - (?7 (elopher-insert-margin "S") + (?7 (elopher-insert-margin "S") ; Query (insert-text-button display-string 'face elopher-search-face 'elopher-node (elopher-make-node elopher-current-node @@ -257,7 +257,7 @@ Otherwise, use the system browser via the BROWSE-URL function." 'action #'elopher-click-link 'follow-link t 'help-echo help-string)) - (?h (elopher-insert-margin "W") + (?h (elopher-insert-margin "W") ; Web link (let ((url (elt (split-string selector "URL:") 1))) (insert-text-button display-string 'face elopher-http-face @@ -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)) @@ -433,24 +450,23 @@ The result is stored as a string in the variable elopher-selector-string." (defun elopher-get-node-download () (let* ((address (elopher-node-address elopher-current-node)) (selector (elopher-address-selector address))) - (unwind-protect - (let* ((filename-proposal (file-name-nondirectory selector)) - (filename (read-file-name "Save file as: " - nil nil nil - (if (> (length filename-proposal) 0) - filename-proposal - "gopher.file")))) - (message "Downloading...") - (setq elopher-download-filename filename) - (elopher-get-selector address - (lambda (proc event) - (let ((coding-system-for-write 'binary)) - (with-temp-file elopher-download-filename - (insert elopher-selector-string))) + (elopher-visit-parent-node) ; Do first in case of non-local exits. + (let* ((filename-proposal (file-name-nondirectory selector)) + (filename (read-file-name "Save file as: " + nil nil nil + (if (> (length filename-proposal) 0) + filename-proposal + "gopher.file")))) + (message "Downloading...") + (setq elopher-download-filename filename) + (elopher-get-selector address + (lambda (proc event) + (let ((coding-system-for-write 'binary)) + (with-temp-file elopher-download-filename + (insert elopher-selector-string) (message (format "Download complate, saved to file %s." - elopher-download-filename))))) - (elopher-visit-parent-node)))) - + elopher-download-filename))))))))) + ;;; Navigation procedures ;;