diff options
Diffstat (limited to 'net/signel.org')
-rw-r--r-- | net/signel.org | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/net/signel.org b/net/signel.org index 799a975..9d70d65 100644 --- a/net/signel.org +++ b/net/signel.org @@ -234,17 +234,27 @@ We're almost ready to write our filter. It will: Or, in elisp: #+begin_src emacs-lisp +(defvar signel--line-buffer "") + (defun signel--filter (proc str) (signel--ordinary-insertion-filter proc str) - (when-let ((msg (signel--msg-contents str))) - (let ((source (signel--msg-source msg)) - (stamp (signel--msg-timestamp msg)) - (data (signel--msg-data msg)) - (rec-stamp (signel--msg-receipt-timestamp msg))) - (when source - (signel--update-chat-buffer source data stamp rec-stamp msg))))) + (let ((str (concat signel--line-buffer str))) + (if-let ((msg (signel--msg-contents str))) + (let ((source (signel--msg-source msg)) + (stamp (signel--msg-timestamp msg)) + (data (signel--msg-data msg)) + (rec-stamp (signel--msg-receipt-timestamp msg))) + (setq signel--line-buffer "") + (when source + (signel--update-chat-buffer source data stamp rec-stamp msg))) + (setq signel--line-buffer + (if (string-match-p ".*\n$" str) "" str))))) #+end_src +We've had to take care of the case when the filter receives input that +is not a complete JSON expression: in the case of signal-cli, that +only happens when we haven't seen yet an end of line. + The function to insert the raw contents in the process buffer is surprisingly hard to get right, but the emacs manual spells out a reasonable implementation, which i just copied: |