]> rhodes.io Git - squeeze-el.git/commitdiff
Christophe Weblog Wiki Code Publications Music
manage messages split into multiple chunks
authorChristophe Rhodes <csr21@cantab.net>
Tue, 21 Oct 2014 16:40:32 +0000 (17:40 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Tue, 21 Oct 2014 16:40:32 +0000 (17:40 +0100)
buffer content until we find at least one newline character.
Technically this doesn't handle multiple messages ending in an
incomplete one; as proof of concept it'll do.

squeeze.el

index 1e34449f76861986fee4ab9ca0ca31686188cb59..18586145f8a92d4f5fdc5246275c2a866ac90e57 100644 (file)
 
 (defvar squeeze-control-inhibit-display nil)
 
-(defun squeeze-update-state (string)
-  (let (done-something)
-    (dolist (line (split-string string "\n"))
-      (when (squeeze-update-state-from-line line)
-        (setq done-something t)))
-    (when done-something
-      (unless squeeze-control-inhibit-display
-        (squeeze-control-display-players))))
-  string)
+(lexical-let ((buffer ""))
+  (defun squeeze-update-state (string)
+    (if (cl-position ?\n string)
+        (let (done-something)
+          (setq string (concat buffer string))
+          (dolist (line (split-string string "\n"))
+            (when (squeeze-update-state-from-line line)
+              (setq done-something t)))
+          (when done-something
+            (unless squeeze-control-inhibit-display
+              (squeeze-control-display-players)))
+          (setq buffer ""))
+      (setq buffer (concat buffer string)))
+    string))
 
 (defconst squeeze-player-line-regexp
   "^\\(\\(?:[0-9a-f]\\{2\\}%3A\\)\\{5\\}[0-9a-f]\\{2\\}\\) ")