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

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

[elpa] externals/crdt 93af8b0 68/80: PoC visualize author


From: ELPA Syncer
Subject: [elpa] externals/crdt 93af8b0 68/80: PoC visualize author
Date: Sat, 28 Aug 2021 10:57:44 -0400 (EDT)

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

    PoC visualize author
---
 crdt.el | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/crdt.el b/crdt.el
index 99349b3..b3b0863 100644
--- a/crdt.el
+++ b/crdt.el
@@ -394,6 +394,29 @@ Also set CRDT--PSEUDO-CURSOR-TABLE to NIL."
       (crdt--clear-pseudo-cursor-table)
       (setq crdt--overlay-table nil)))
 
+;;; Author visualization
+
+(defsubst crdt--visualize-author-1 (beg end site)
+  (put-text-property beg end
+                     'font-lock-face `(:underline ,(crdt--get-cursor-color 
site))))
+(defun crdt--visualize-author ()
+  (save-restriction
+    (widen)
+    (let ((pos (point-max)))
+     (while (> pos (point-min))
+       (let* ((prev-pos (previous-single-property-change pos 'crdt-id nil 
(point-min)))
+              (crdt-id (car-safe (crdt--get-crdt-id-pair prev-pos))))
+         (when crdt-id (crdt--visualize-author-1 prev-pos pos (crdt--id-site 
crdt-id)))
+         (setq pos prev-pos))))))
+
+(define-minor-mode crdt-visualize-author-mode
+    "" nil " CRDT-VAuthor" nil
+    (if crdt-visualize-author-mode
+        (crdt--visualize-author)
+      (save-restriction
+        (widen)
+        (remove-list-of-text-properties (point-min) (point-max) 
'(font-lock-face)))))
+
 ;;; Shared buffer utils
 
 (defsubst crdt--server-p (&optional session)
@@ -722,6 +745,8 @@ It informs other peers that the buffer is killed."
 (defun crdt--local-insert (beg end)
   "To be called after a local insert happened in current buffer from BEG to 
END.
 Returns a list of (insert type) messages to be sent."
+  (when crdt-visualize-author-mode
+    (crdt--visualize-author-1 beg end (crdt--session-local-id crdt--session)))
   (let (resulting-commands)
     (crdt--with-insertion-information
      (beg end)
@@ -815,6 +840,8 @@ Start the search around POSITION-HINT."
       (goto-char beg)
       (insert content)
       (setq end (point))
+      (when crdt-visualize-author-mode
+        (crdt--visualize-author-1 beg end (crdt--id-site id)))
       ;; work around for input method overlays
       (cl-loop for ov in (overlays-at beg)
             do (unless (overlay-get ov 'crdt-meta)



reply via email to

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