about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--thogai.el21
1 files changed, 12 insertions, 9 deletions
diff --git a/thogai.el b/thogai.el
index 2a4fa57..65d3407 100644
--- a/thogai.el
+++ b/thogai.el
@@ -566,15 +566,18 @@ BYTES is a list of 6 bytes in the Gemini protocol."
         ;; The Gemini protocol represents each stroke by 6
         ;; bytes. Decode stroke once 6 bytes are received.
         (when (= (length bytes) bytes-per-stroke)
-          (let ((stroke (thogai-gemini-decode-stroke (reverse bytes))))
-            ;; Log to paper tape.
-            (with-current-buffer (process-buffer process)
-              (insert stroke)
-              (insert "\n"))
-            ;; Insert into stroke ring, and process translation.
-            (ring-insert thogai-stroke-ring stroke)
-            (thogai-process-stroke thogai-stroke-ring))
-          (setq bytes nil))))))
+          ;; Stroke processing could result in errors, typically from
+          ;; user commands bound to strokes. Hence, unwind-protect.
+          (unwind-protect
+              (let ((stroke (thogai-gemini-decode-stroke (reverse bytes))))
+                ;; Log to paper tape.
+                (with-current-buffer (process-buffer process)
+                  (insert stroke)
+                  (insert "\n"))
+                ;; Insert into stroke ring, and process translation.
+                (ring-insert thogai-stroke-ring stroke)
+                (thogai-process-stroke thogai-stroke-ring))
+            (setq bytes nil)))))))
 
 (defun thogai-gemini-connect (port speed)
   "Connect to steno machine via the Gemini protocol.