[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))))
- [nongnu] elpa/annotate 32d82c4557 018/372: no more nil annotations, (continued)
- [nongnu] elpa/annotate 32d82c4557 018/372: no more nil annotations, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate aa075cfe04 002/372: change annotation display from overlay to property, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 94c2a9455f 019/372: increment version number, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 530b4aa78a 022/372: increment version number, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f2bcc95e8b 024/372: add melpa links, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a6f7279a4c 016/372: fixed typos and version error, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 0bd3bdce01 017/372: improved README, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate ffac176c22 021/372: fix upside-down annotation construction, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 936f081575 005/372: doesn't create empty annotations any more, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate fc2c0395d7 007/372: add missing require, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 6372f8e340 009/372: implement save and load,
ELPA Syncer <=
- [nongnu] elpa/annotate 856ebe246b 020/372: properly ignore non-annotation overlays, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 8f252d2892 025/372: clear-annotations does not clear all overlays, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 2084f831bc 026/372: added export functionality as sort-of-diffscuss, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 52f0d97e51 030/372: new version and documentation, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate b0266c6350 047/372: version 0.4.1, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 4647264264 049/372: auto-reflow annotations when frame size changes, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 785b5aea7f 042/372: rework annotation display logic, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate d6a4fcc18e 035/372: add next-annotation and previous-annotation keys, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f5711b4f27 067/372: - prevent crash and error when a frame's width is less than value of, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 1a43bfbb1e 061/372: fixes bug with annotations ending on beginning-of-line, ELPA Syncer, 2022/02/04