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

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

[nongnu] elpa/annotate 6372f8e340 009/372: implement save and load


From: ELPA Syncer
Subject: [nongnu] elpa/annotate 6372f8e340 009/372: implement save and load
Date: Fri, 4 Feb 2022 16:58:14 -0500 (EST)

branch: elpa/annotate
commit 6372f8e340556910f156c13708f8196bb86d67af
Author: Bastian <basti@bastibe.de>
Commit: Bastian Bechtold <bb@Mr-Bigglesworth.local>

    implement save and load
---
 annotate.el | 70 +++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 54 insertions(+), 16 deletions(-)

diff --git a/annotate.el b/annotate.el
index 653d28043e..4a8eefaaca 100644
--- a/annotate.el
+++ b/annotate.el
@@ -99,21 +99,59 @@
 (defun annotate-save-annotations ()
   "Save all annotations to disk."
   (interactive)
-  (let ((annotations
-         (mapcar 'annotate-describe-annotation (overlays-in 0 (buffer-size)))))
-    (append-to-file (concat (format "\n:%s\n" (buffer-file-name))
-                            (apply 'concat annotations))
-                    nil annotate-file)))
+  (let ((file-annotations
+         (mapcar 'annotate-describe-annotation (overlays-in 0 (buffer-size))))
+        (all-annotations (annotate-load-annotation-data)))
+    (if (assoc-string (buffer-file-name) all-annotations)
+        (setcdr (assoc-string (buffer-file-name) all-annotations)
+                file-annotations)
+      (setq all-annotations
+            (push (cons (buffer-file-name) file-annotations)
+                  all-annotations)))
+    (annotate-dump-annotation-data all-annotations)))
+
+(defun annotate-load-annotations ()
+  "Load all annotations from disk."
+  (interactive)
+  (let ((annotations (cdr (assoc-string (buffer-file-name)
+                                        (annotate-load-annotation-data)))))
+    (message "%s" annotations)
+    (when (not (eq nil annotations))
+      (save-excursion
+        (dolist (annotation annotations)
+          (message "%s" annotation)
+          (let* ((start (nth 0 annotation))
+                 (end (nth 1 annotation))
+                 (text (nth 2 annotation))
+                 (highlight (make-overlay start end)))
+            (message "%s" annotation)
+            (overlay-put highlight 'face annotate-highlight-face)
+            (overlay-put highlight 'annotation text)
+            (setq text (propertize text 'face annotate-annotation-face))
+            (goto-char end)
+            (move-end-of-line nil)
+            (let ((prefix (make-string (- annotate-annotation-column
+                                          (annotate-line-length)) ? )))
+              (put-text-property (point)
+                                 (1+ (point))
+                                 'display
+                                 (concat prefix text "\n")))))))))
 
 (defun annotate-describe-annotation (highlight)
-  (save-excursion
-    (goto-char (overlay-start highlight))
-    (format "%s (line %s, %s-%s): %s\n"
-            (prin1-to-string (buffer-substring-no-properties
-                              (overlay-start highlight)
-                              (overlay-end highlight)))
-            (line-number-at-pos)
-            (current-column)
-            (+ (current-column) (- (overlay-end highlight)
-                                   (overlay-start highlight)))
-            (prin1-to-string (overlay-get highlight 'annotation)))))
+  (list
+   (overlay-start highlight)
+   (overlay-end highlight)
+   (overlay-get highlight 'annotation)))
+
+(defun annotate-load-annotation-data ()
+  (with-temp-buffer
+    (when (file-exists-p annotate-file)
+      (insert-file-contents annotate-file))
+    (end-of-buffer)
+    (cond ((= (point) 1) nil)
+          (t (beginning-of-buffer)
+             (read (current-buffer))))))
+
+(defun annotate-dump-annotation-data (data)
+  (with-temp-file annotate-file
+    (prin1 data (current-buffer))))



reply via email to

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