;; Author: Tim Vaughan <timv@ughan.xyz>
;; Created: 11 April 2019
-;; Version: 2.6.0
+;; Version: 2.6.1
;; Keywords: comm gopher
;; Homepage: http://thelambdalab.xyz/elpher
;; Package-Requires: ((emacs "26"))
;;; Global constants
;;
-(defconst elpher-version "2.6.0"
+(defconst elpher-version "2.6.1"
"Current version of elpher.")
(defconst elpher-margin-width 6
(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)
(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
"\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))))))
(let* ((kill-buffer-query-functions nil)
(port (elpher-address-port address))
(host (elpher-address-host address))
- (response-string "")
+ (response-string-parts nil)
(proc (open-network-stream "elpher-process"
nil
(if force-ipv4 (dns-query host) host)
(when timer
(cancel-timer timer)
(setq timer nil))
- (setq response-string
- (concat response-string string))))
+ (setq response-string-parts
+ (cons string response-string-parts))))
(set-process-sentinel proc
(lambda (proc event)
(condition-case the-error
(concat (elpher-address-to-url address)
"\r\n"))))
((string-prefix-p "deleted" event)) ; do nothing
- ((and (string-empty-p response-string)
+ ((and (not response-string-parts)
(not force-ipv4))
; Try again with IPv4
(message "Connection failed. Retrying with IPv4.")
(elpher-get-gemini-response address renderer t))
(t
(funcall #'elpher-process-gemini-response
- response-string
+ (apply #'concat (reverse response-string-parts))
renderer)
(elpher-restore-pos)))
(error
(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))))
(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)
(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
(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))))))