X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=blobdiff_plain;f=elpher.el;h=dec79ae52c2c3f535a714871c95f019e1c154cff;hp=be78a0aeb8caad731a48f5dcc5f5d50f271a89f6;hb=04594c95ceb8c6818a3f901c636be4dc17a1aff1;hpb=00aa89d8ad9f321e4eb288499a404897eb9188c4 diff --git a/elpher.el b/elpher.el index be78a0a..dec79ae 100644 --- a/elpher.el +++ b/elpher.el @@ -506,7 +506,7 @@ to ADDRESS." (let* ((kill-buffer-query-functions nil) (port (elpher-address-port address)) (host (elpher-address-host address)) - (selector-string "") + (selector-string-parts nil) (proc (open-network-stream "elpher-process" nil (if force-ipv4 (dns-query host) host) @@ -538,8 +538,8 @@ to ADDRESS." (set-process-filter proc (lambda (_proc string) (cancel-timer timer) - (setq selector-string - (concat selector-string string)))) + (setq selector-string-parts + (cons string selector-string-parts)))) (set-process-sentinel proc (lambda (_proc event) (condition-case the-error @@ -553,7 +553,8 @@ to ADDRESS." "\r\n")))) (t (cancel-timer timer) - (funcall renderer selector-string) + (funcall renderer (apply #'concat + (reverse selector-string-parts))) (elpher-restore-pos))) (error (elpher-network-error address the-error)))))) @@ -1014,18 +1015,45 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d" (elpher-collapse-dot-sequences (url-filename address))))) address)) +(defun elpher-gemini-insert-link (link-line) + (let* ((url (elpher-gemini-get-link-url link-line)) + (display-string (let ((s (elpher-gemini-get-link-display-string link-line))) + (if (string-empty-p s) url s))) + (address (elpher-address-from-gemini-url url)) + (type (if address (elpher-address-type address) nil)) + (type-map-entry (cdr (assoc type elpher-type-map)))) + (insert "→ ") + (if type-map-entry + (let* ((face (elt type-map-entry 3)) + (filtered-display-string (ansi-color-filter-apply display-string)) + (page (elpher-make-page filtered-display-string address))) + (insert-text-button filtered-display-string + 'face face + 'elpher-page page + 'action #'elpher-click-link + 'follow-link t + 'help-echo (elpher-page-button-help page))) + (insert (propertize display-string 'face 'elpher-unknown))) + (insert "\n"))) + +(defun elpher-gemini-insert-header (header-line) + (insert header-line "\n")) + +(defun elpher--trim-prefix-p (prefix string) + (string-prefix-p prefix (string-trim-left string))) + (defun elpher-render-gemini-map (data _parameters) "Render DATA as a gemini map file, PARAMETERS is currently unused." (elpher-with-clean-buffer - (dolist (line (split-string data "\n")) - (if (string-prefix-p "=>" line) - (let* ((url (elpher-gemini-get-link-url line)) - (display-string (elpher-gemini-get-link-display-string line)) - (address (elpher-address-from-gemini-url url))) - (if (> (length display-string) 0) - (elpher-insert-index-record display-string address) - (elpher-insert-index-record url address))) - (elpher-insert-index-record line))) + (let ((preformatted nil)) + (auto-fill-mode 1) + (dolist (line (split-string data "\n")) + (cond + ((elpher--trim-prefix-p "```" line) (setq preformatted (not preformatted))) + (preformatted (insert (elpher-process-text-for-display line) "\n")) + ((elpher--trim-prefix-p "=>" line) (elpher-gemini-insert-link line)) + ((elpher--trim-prefix-p "#" line) (elpher-gemini-insert-header line)) + (t (insert (elpher-process-text-for-display line)) (newline))))) (elpher-cache-content (elpher-page-address elpher-current-page) (buffer-string)))) @@ -1059,7 +1087,7 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d" (port (let ((given-port (elpher-address-port address))) (if (> given-port 0) given-port 79))) (host (elpher-address-host address)) - (selector-string "") + (selector-string-parts nil) (proc (open-network-stream "elpher-process" nil (if force-ipv4 (dns-query host) host) @@ -1080,8 +1108,8 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d" (set-process-filter proc (lambda (_proc string) (cancel-timer timer) - (setq selector-string - (concat selector-string string)))) + (setq selector-string-parts + (cons string selector-string-parts)))) (set-process-sentinel proc (lambda (_proc event) (condition-case the-error @@ -1094,7 +1122,8 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d" (concat user "\r\n")))) (t (cancel-timer timer) - (funcall renderer selector-string) + (funcall renderer (apply #'concat + (reverse selector-string-parts))) (elpher-restore-pos))))))) (error (elpher-network-error address the-error))))))