Fixed reflow behaviour around bullets.
[elpher.git] / elpher.el
index 2f39db6..b169f76 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -4,7 +4,7 @@
 
 ;; Author: Tim Vaughan <plugd@thelambdalab.xyz>
 ;; Created: 11 April 2019
-;; Version: 2.7.4
+;; Version: 2.7.6
 ;; Keywords: comm gopher
 ;; Homepage: http://thelambdalab.xyz/elpher
 ;; Package-Requires: ((emacs "26"))
@@ -70,7 +70,7 @@
 ;;; Global constants
 ;;
 
-(defconst elpher-version "2.7.4"
+(defconst elpher-version "2.7.6"
   "Current version of elpher.")
 
 (defconst elpher-margin-width 6
@@ -222,6 +222,10 @@ the time when the text is rendered."
   '((t :inherit bold :height 1.2))
   "Face used for gemini heading level 3.")
 
+(defface elpher-gemini-preformatted
+  '((t :inherit fixed-pitch))
+  "Face used for pre-formatted gemini text blocks.")
+
 ;;; Model
 ;;
 
@@ -547,6 +551,7 @@ to ADDRESS."
     (error "Cannot retrieve gopher selector: port number > 65536"))
   (condition-case nil
       (let* ((kill-buffer-query-functions nil)
+             (gnutls-verify-error nil) ; We use the NSM for verification
              (port (elpher-address-port address))
              (host (elpher-address-host address))
              (selector-string-parts nil)
@@ -875,6 +880,7 @@ to ADDRESS."
       (error "Cannot establish gemini connection: port number > 65536"))
     (condition-case nil
         (let* ((kill-buffer-query-functions nil)
+               (gnutls-verify-error nil) ; We use the NSM for verification
                (port (elpher-address-port address))
                (host (elpher-address-host address))
                (response-string-parts nil)
@@ -954,7 +960,7 @@ that the response was malformed."
                     (meta (string-trim (substring header 2))))
                 (list code meta body))
             (error "Malformed response: No response status found in header %s" header)))
-      (error "Malformed response: No CRLF-delimited header found"))))
+      (error "Malformed response: No CRLF-delimited header found in response %s" response))))
 
 (defun elpher-process-gemini-response (response-string renderer)
   "Process the gemini response RESPONSE-STRING and pass the result to RENDERER."
@@ -1140,6 +1146,18 @@ by HEADER-LINE."
                             (_ 'default)))
               "\n"))))
 
+(defun elpher-gemini-insert-text (text-line)
+  "Insert a plain non-preformatted TEXT-LINE into a text/gemini document.
+This function uses Emacs' auto-fill to wrap text sensibly to a maximum
+width defined by elpher-gemini-max-fill-width."
+  (insert (elpher-process-text-for-display text-line))
+  (let* ((prefix-end-idx (string-match "[^ \t*]" text-line))
+         (fill-prefix (if prefix-end-idx
+                          (let ((raw-prefix (substring text-line 0 prefix-end-idx)))
+                            (replace-regexp-in-string "\*" " " raw-prefix))
+                        nil)))
+    (newline)))
+
 (defun elpher-render-gemini-map (data _parameters)
   "Render DATA as a gemini map file, PARAMETERS is currently unused."
   (elpher-with-clean-buffer
@@ -1149,10 +1167,12 @@ by HEADER-LINE."
      (dolist (line (split-string data "\n"))
        (cond
         ((string-prefix-p "```" line) (setq preformatted (not preformatted)))
-        (preformatted (insert (elpher-process-text-for-display line) "\n"))
+        (preformatted (insert (elpher-process-text-for-display
+                               (propertize line 'face 'elpher-gemini-preformatted))
+                              "\n"))
         ((string-prefix-p "=>" line) (elpher-gemini-insert-link line))
         ((string-prefix-p "#" line) (elpher-gemini-insert-header line))
-        (t (insert (elpher-process-text-for-display line)) (newline)))))
+        (t (elpher-gemini-insert-text line)))))
    (elpher-cache-content
     (elpher-page-address elpher-current-page)
     (buffer-string))))