emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/crdt 1a08765 51/80: slightly cleanup protocol and doc


From: ELPA Syncer
Subject: [elpa] externals/crdt 1a08765 51/80: slightly cleanup protocol and doc
Date: Sat, 28 Aug 2021 10:57:40 -0400 (EDT)

branch: externals/crdt
commit 1a087659999296751ddb6338e1102ff8d2f24ecb
Author: Qiantan Hong <qhong@mit.edu>
Commit: Qiantan Hong <qhong@mit.edu>

    slightly cleanup protocol and doc
---
 HACKING.org | 12 +++++++++---
 crdt.el     | 28 ++++++++++++++++++----------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/HACKING.org b/HACKING.org
index 7e3d315..44a8245 100644
--- a/HACKING.org
+++ b/HACKING.org
@@ -70,11 +70,17 @@ and second last two bytes represent site ID.
     Might be used for error recovery or other optimization in the future.
     One optimization I have in mind is let server try to merge all CRDT item 
into a single
     one and try to synchronize this state to clients at best effort.
-    body takes the form =(buffer-name major-mode . crdt-id-list)=
-    - =major-mode= is the major mode used at the server site
-    - =content= is the string in the buffer
+    body takes the form =(buffer-name . crdt-id-list)=
     - =crdt-id-list= is generated from =CRDT--DUMP-IDS=
 
+  - ready ::
+    body takes the form =(buffer-name major-mode-symbol)=
+    Indicates the end of a batch of synchronization messages
+    (which usually contains some =cursor= messages, a =sync= message,
+    and some =overlay-*= messages).
+    The client should now try to enable =major-mode-symbol= in the
+    synchronized buffer.
+
   - add ::
     Indicates that the server has started sharing some buffers.
     body takes the form =buffer-name-list=
diff --git a/crdt.el b/crdt.el
index 144777a..50fde7f 100644
--- a/crdt.el
+++ b/crdt.el
@@ -1071,7 +1071,6 @@ The network process for the client connection is PROCESS."
   (with-current-buffer buffer
     (process-send-string process (crdt--format-message `(sync
                                                          
,crdt--buffer-network-name
-                                                         ,major-mode
                                                          ,@ (crdt--dump-ids 
(point-min) (point-max) nil nil t))))
     ;; synchronize cursor
     (maphash (lambda (site-id ov-pair)
@@ -1110,7 +1109,7 @@ The network process for the client connection is PROCESS."
                                                                ,(car k) ,(cdr 
k) ,prop ,value))))))
              crdt--overlay-table)
 
-    (process-send-string process (crdt--format-message `(ready 
,crdt--buffer-network-name)))))
+    (process-send-string process (crdt--format-message `(ready 
,crdt--buffer-network-name ,major-mode)))))
 
 (defun crdt--greet-client (process)
   "Send initial information when a client connects.
@@ -1193,24 +1192,33 @@ The network process for the client connection is 
PROCESS."
 
 (cl-defmethod crdt-process-message ((message (head sync)) _process)
   (unless (crdt--server-p)             ; server shouldn't receive this
-    (cl-destructuring-bind (buffer-name mode . ids) (cdr message)
+    (cl-destructuring-bind (buffer-name . ids) (cdr message)
       (crdt--with-buffer-name
        buffer-name
        (let ((crdt--inhibit-update t))
+         (unless crdt--buffer-sync-callback
+           ;; try to get to the same position after sync,
+           ;; if crdt--buffer-sync-callback is not set yet
+           (let ((pos (point)))
+             (setq crdt--buffer-sync-callback
+                   (lambda ()
+                     (goto-char
+                      (max (min pos (point-max))
+                           (point-max)))))))
          (erase-buffer)
-         (crdt--load-ids ids)
-         (if (fboundp mode)
-             (unless (eq major-mode mode)
-               (funcall mode)            ; trust your server...
-               (crdt-mode))
-           (message "Server uses %s, but not available locally." mode)))))
+         (crdt--load-ids ids))))
     (crdt--refresh-buffers-maybe)))
 
 (cl-defmethod crdt-process-message ((message (head ready)) _process)
   (unless (crdt--server-p)             ; server shouldn't receive this
-    (cl-destructuring-bind (buffer-name) (cdr message)
+    (cl-destructuring-bind (buffer-name mode) (cdr message)
       (crdt--with-buffer-name
        buffer-name
+       (if (fboundp mode)
+           (unless (eq major-mode mode)
+             (funcall mode)            ; trust your server...
+             (crdt-mode))
+         (message "Server uses %s, but not available locally." mode))
        (when crdt--buffer-sync-callback
          (funcall crdt--buffer-sync-callback)
          (setq crdt--buffer-sync-callback nil))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]