[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/annotate f5436b2bff 366/372: - added helper functions to m
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/annotate f5436b2bff 366/372: - added helper functions to manage annotation's interval and 'annotate-db-merge-annotations'. |
Date: |
Fri, 4 Feb 2022 16:59:23 -0500 (EST) |
branch: elpa/annotate
commit f5436b2bffce6d923ce9010d0ce89e73219eebfa
Author: cage <cage@invalid>
Commit: cage <cage@invalid>
- added helper functions to manage annotation's interval and
'annotate-db-merge-annotations'.
---
annotate.el | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 73 insertions(+), 16 deletions(-)
diff --git a/annotate.el b/annotate.el
index 4494530686..dcc48567b0 100644
--- a/annotate.el
+++ b/annotate.el
@@ -1384,6 +1384,29 @@ essentially what you get from:
\(annotate-annotations-from-dump (nth index (annotate-load-annotations))))."
(cl-second annotation))
+(defun annotate--interval-left-limit (a)
+ (cl-first a))
+
+(defun annotate--interval-right-limit (a)
+ (cl-second a))
+
+(defun annotate--make-interval (left-limit right-limit)
+ (list left-limit right-limit))
+
+(defun annotate-annotation-interval (annotation)
+ "Returns a list of two numbers representing the left and right
+limit respectively of the portion of the buffer where this
+annotation is applied.
+Note that this function returns the character interval
+yyyyyyyy ggg
+ ^^^^^^^ ← Annotation interval i the database (extends for one more than the
last character)
+ |----| ← The interval that this function returns.
+
+In other terms the interval i the database is a closed interval while the
interval that
+this function return is closed on the left and open on the right side."
+ (annotate--make-interval (annotate-beginning-of-annotation annotation)
+ (1- (annotate-ending-of-annotation annotation))))
+
(defun annotate-annotation-string (annotation)
"Get the text of an annotation. The arg 'annotation' must be a single
annotation field got from a file dump of all annotated buffers,
@@ -1562,25 +1585,25 @@ annotation."
annotations
file-checksum)))
+(defun annotate--deserialize-database-file (file)
+ (with-temp-buffer
+ (let* ((annotations-file file)
+ (attributes (file-attributes annotations-file)))
+ (cond
+ ((not (file-exists-p annotations-file))
+ (signal 'annotate-db-file-not-found (list annotations-file)))
+ ((= (file-attribute-size attributes)
+ 0)
+ nil)
+ (t
+ (insert-file-contents annotations-file)
+ (mapcar 'annotate--expand-record-path (read (current-buffer))))))))
+
(defun annotate-load-annotation-data (&optional ignore-errors)
"Read and returns saved annotations."
- (cl-labels ((%load-annotation-data ()
- (let ((annotations-file annotate-file))
- (with-temp-buffer
- (let* ((annotate-file annotations-file)
- (attributes (file-attributes annotate-file)))
- (cond
- ((not (file-exists-p annotate-file))
- (signal 'annotate-db-file-not-found (list
annotate-file)))
- ((= (file-attribute-size attributes)
- 0)
- nil)
- (t
- (insert-file-contents annotate-file)
- (mapcar 'annotate--expand-record-path (read
(current-buffer))))))))))
(if ignore-errors
- (ignore-errors (%load-annotation-data))
- (%load-annotation-data))))
+ (ignore-errors (annotate-deserialize-database-file annotate-file))
+ (annotate--deserialize-database-file annotate-file)))
(defun annotate-dump-annotation-data (data &optional save-empty-db)
"Save `data' into annotation file."
@@ -3176,5 +3199,39 @@ code, always use load files from trusted sources!"
;; end of switching database
+;;; merging database
+
+(defun annotate--merge-interval (a b)
+ (let ((new-left-limit (min (annotate--interval-left-limit a)
+ (annotate--interval-left-limit b)))
+ (new-right-limit (max (annotate--interval-right-limit a)
+ (annotate--interval-right-limit b))))
+ (annotate--make-interval new-left-limit
+ new-right-limit)))
+
+(defun annotate--db-annotations-overlaps-p (annotation-a annotation-b)
+ (let ((interval-a (annotate-annotation-interval annotation-a))
+ (interval-b (annotate-annotation-interval annotation-b)))
+ (not (or (< (annotate--interval-right-limit interval-b)
+ (annotate--interval-left-limit interval-a))
+ (> (annotate--interval-left-limit interval-b)
+ (annotate--interval-right-limit interval-a))))))
+
+(defun annotate-db-merge-annotations (host guest)
+ (when (annotate--db-annotations-overlaps-p host guest)
+ (let* ((interval-host (annotate-annotation-interval host))
+ (interval-guest (annotate-annotation-interval guest))
+ (text-host (annotate-annotation-string host))
+ (text-guest (annotate-annotation-string guest))
+ (new-interval (annotate--merge-interval interval-host
interval-guest))
+ (new-annotation-text (concat text-host " " text-guest))
+ (left (annotate--interval-left-limit new-interval))
+ (right (1+ (annotate--interval-right-limit
new-interval)))
+ (new-annotated-text (with-current-buffer (current-buffer)
+ (buffer-substring-no-properties left
right))))
+ (annotate-make-annotation left right new-annotation-text
new-annotated-text))))
+
+;;; end of merging datatase
+
(provide 'annotate)
;;; annotate.el ends here
- [nongnu] elpa/annotate f33eecba7b 362/372: - prevented asking to delete a database that does not actually exists, (continued)
- [nongnu] elpa/annotate f33eecba7b 362/372: - prevented asking to delete a database that does not actually exists, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 1350e1d073 338/372: - fixed annotated text shown in the summary window, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 3e3c1b1066 368/372: - fixed function name;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a484ffa0b6 319/372: - allowed removing (or cutting) annotations when buffer is in read-only mode., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 936389e36a 316/372: - prevented asking for annotation when trying to annotate a newline character., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 36d3729c27 339/372: - updated version number and docs., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a8762cd08a 344/372: - removed garbage at the end of an error message., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 9aba6305fe 342/372: Merge pull request #109 from cage2/fix-replace-button, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate bd12129213 333/372: Merge pull request #106 from cage2/fixed-call-comment-region, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 83e81e0979 369/372: - added missing docstrings and improved a bit the old ones., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f5436b2bff 366/372: - added helper functions to manage annotation's interval and 'annotate-db-merge-annotations'.,
ELPA Syncer <=
- [nongnu] elpa/annotate 59c52e7318 162/372: - updated documentation to reflects changes in the code, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate fd9c403ecc 164/372: - changed quotation mark sentence., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a28e7b4fd2 028/372: refactored and documented export function, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate b2cd959cfa 053/372: Annotations of long lines start at the next line, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate e98c93a12b 072/372: - added 'annotate-' prefix to public symbols;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 6289c87bf8 029/372: annotation buffer now has proper file name, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate e1daa61b99 065/372: use `locate-user-emacs-file` to specify default save file, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 392197f943 155/372: Merge branch 'master' into annotations-on-their-own-line, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 3bb486d0cf 158/372: - changed `let*' with `let'., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate c007611614 159/372: - removed useless rebinding of 'annotate-annotation-position-policy'., ELPA Syncer, 2022/02/04