From: Christophe Rhodes Date: Tue, 21 Oct 2014 16:40:32 +0000 (+0100) Subject: manage messages split into multiple chunks X-Git-Url: http://christophe.rhodes.io/gitweb/?a=commitdiff_plain;h=66deea724bf232b683d6371a6c9fd102a6369a29;p=squeeze-el.git manage messages split into multiple chunks 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. --- diff --git a/squeeze.el b/squeeze.el index 1e34449..1858614 100644 --- a/squeeze.el +++ b/squeeze.el @@ -39,15 +39,20 @@ (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\\}\\) ")