diff options
author | jao <jao@gnu.org> | 2020-02-27 01:32:24 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-02-27 01:32:24 +0000 |
commit | 63eab2a162b19d40cdd6ebe0529e0aadfb54bd3f (patch) | |
tree | 83df5b21704a4fa582b92f1c1ac0773f1c813bcf /net | |
parent | eeb709a2c0a40366f0f03f332f799f0f252d0cf3 (diff) | |
download | elibs-63eab2a162b19d40cdd6ebe0529e0aadfb54bd3f.tar.gz elibs-63eab2a162b19d40cdd6ebe0529e0aadfb54bd3f.tar.bz2 |
signel improvements
Diffstat (limited to 'net')
-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: |