Fixed issue to do with current buffer changing during download.
authorplugd <plugd@thelambdalab.xyz>
Tue, 9 Aug 2022 00:38:42 +0000 (10:38 +1000)
committerplugd <plugd@thelambdalab.xyz>
Tue, 9 Aug 2022 00:39:22 +0000 (10:39 +1000)
Thanks to Troels Henriksen for reporting this issue.

ISSUES.org
elpher.el

index 1cf6229..60c6a99 100644 (file)
@@ -23,13 +23,16 @@ timer fire up early means that it interferes with requests for
 user interaction that may appear during the initial connection setup.
 E.g., asking for approval of uknown TLS certificates.
 
-** OPEN Downloads failing
+* Closed Bugs
+
+** CLOSED Downloads failing
+:LOGBOOK:
+- State "CLOSED"     from "OPEN"       [2022-08-09 Tue 10:38]
+:END:
 
 Downloads fail when focus is shifted away from
 the elpher buffer before the download has completed.
 
-* Closed Bugs
-
 ** CLOSED Relative Gemini links processed improperly
 :LOGBOOK:
 - State "CLOSED"     from "OPEN"       [2021-08-04 Wed 15:54]
index 2a30f99..882ed2a 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -570,7 +570,7 @@ This variable is used by `elpher-show-visited-pages'.")
 (defun elpher-visit-page (page &optional renderer no-history)
   "Visit PAGE using its own renderer or RENDERER, if non-nil.
 Additionally, push PAGE onto the history stack and the list of
-previously-visited pages,unless NO-HISTORY is non-nil."
+previously-visited pages, unless NO-HISTORY is non-nil."
   (elpher-save-pos)
   (elpher-process-cleanup)
   (unless no-history
@@ -869,7 +869,8 @@ the host operating system and the local network capabilities.)"
                                                                  nil force-ipv4))
                                       (t
                                        (elpher-network-error address "Connection time-out."))))))
-               (proc (if socks (socks-open-network-stream "elpher-process" nil host service)
+               (proc (if socks
+                         (socks-open-network-stream "elpher-process" nil host service)
                        (make-network-process :name "elpher-process"
                                              :host host
                                              :family (and (or force-ipv4
@@ -883,6 +884,7 @@ the host operating system and the local network capabilities.)"
                                                   (cons 'gnutls-x509pki
                                                         (apply #'gnutls-boot-parameters
                                                                gnutls-params)))))))
+          (process-put proc 'elpher-buffer (current-buffer))
           (setq elpher-network-timer timer)
           (set-process-coding-system proc 'binary 'binary)
           (set-process-query-on-exit-flag proc nil)
@@ -926,17 +928,19 @@ the host operating system and the local network capabilities.)"
                                                                   response-processor
                                                                   use-tls t))
                                        (response-string-parts
-                                        (elpher-with-clean-buffer
-                                         (insert "Data received.  Rendering..."))
-                                        (funcall response-processor
-                                                 (apply #'concat (reverse response-string-parts)))
-                                        (elpher-restore-pos))
+                                        (with-current-buffer (process-get proc 'elpher-buffer)
+                                          (elpher-with-clean-buffer
+                                           (insert "Data received.  Rendering..."))
+                                          (funcall response-processor
+                                                   (apply #'concat (reverse response-string-parts)))
+                                          (elpher-restore-pos)))
                                        (t
                                         (error "No response from server")))
                                     (error
                                      (elpher-network-error address the-error)))))
           (when socks
-            (if use-tls (apply #'gnutls-negotiate :process proc gnutls-params))
+            (if use-tls
+                (apply #'gnutls-negotiate :process proc gnutls-params))
             (funcall (process-sentinel proc) proc "open\n")))
       (error
        (elpher-process-cleanup)