[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/annotate 463e215bec 284/372: - fixed export for annotated
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/annotate 463e215bec 284/372: - fixed export for annotated text made from a single line. |
Date: |
Fri, 4 Feb 2022 16:59:08 -0500 (EST) |
branch: elpa/annotate
commit 463e215bec0082be0151a314b70e162a2986c22b
Author: cage <cage-invalid@invalid>
Commit: cage <cage-invalid@invalid>
- fixed export for annotated text made from a single line.
---
annotate.el | 174 ++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 99 insertions(+), 75 deletions(-)
diff --git a/annotate.el b/annotate.el
index 923e67ace2..16c9eb0b9a 100644
--- a/annotate.el
+++ b/annotate.el
@@ -753,60 +753,78 @@ An example might look like this:
This diff does not contain any changes, but highlights the
annotation, and can be conveniently viewed in diff-mode."
(interactive)
- (let* ((filename (annotate-actual-file-name))
- (export-buffer (generate-new-buffer (concat filename
- ".annotations.diff")))
- (annotations (sort (annotate-all-annotations)
- (lambda (a b)
- (< (overlay-start a)
- (overlay-start b)))))
- (parent-buffer-mode major-mode))
- ;; write the diff file description
- (with-current-buffer export-buffer
- (funcall parent-buffer-mode)
- (let ((time-string
- (format-time-string "%F %H:%M:%S.%N %z"
- (nth 5 (file-attributes filename 'integer)))))
- (insert "--- " filename "\t" time-string "\n")
- (insert "+++ " filename "\t" time-string "\n")))
- ;; write diff, highlight, and comment for each annotation
- (save-excursion
- ;; sort annotations by location in the file
- (dolist (ann annotations)
- (let* ((start (overlay-start ann))
- (end (overlay-end ann))
- (text (overlay-get ann 'annotation))
- ;; beginning of first annotated line
- (bol (progn (goto-char start)
- (beginning-of-line)
- (point)))
- ;; end of last annotated line
- (eol (progn (goto-char end)
- (end-of-line)
- (point)))
- ;; all lines that contain annotations
- (annotated-lines (buffer-substring bol eol))
- ;; context lines before the annotation
- (previous-lines (annotate-context-before start))
- ;; context lines after the annotation
- (following-lines (annotate-context-after end))
- (chain-last-p (annotate-chain-last-p ann))
- ;; line header for diff chunk
- (diff-range (annotate-diff-line-range start end
chain-last-p)))
- (with-current-buffer export-buffer
- (insert "@@ " diff-range " @@\n")
- (when previous-lines
- (insert (annotate-prefix-lines " " previous-lines)))
- (insert (annotate-prefix-lines "-" annotated-lines))
- ;; loop over annotation lines and insert with highlight
- ;; and annotation text
- (let ((annotation-line-list (butlast (split-string
+ (cl-labels ((build-annotation-text-lines (text)
+ (let* ((lines (annotate--split-lines text))
+ (commented-lines (mapcar (lambda (a) (concat "+"
+
(annotate-wrap-in-comment a)))
+ lines)))
+ (annotate--join-with-string commented-lines "\n"))))
+
+ (let* ((filename (annotate-actual-file-name))
+ (export-buffer (generate-new-buffer (concat filename
+ ".annotations.diff")))
+ (annotations (sort (annotate-all-annotations)
+ (lambda (a b)
+ (< (overlay-start a)
+ (overlay-start b)))))
+ (parent-buffer-mode major-mode))
+ ;; write the diff file description
+ (with-current-buffer export-buffer
+ (funcall parent-buffer-mode)
+ (let ((time-string
+ (format-time-string "%F %H:%M:%S.%N %z"
+ (nth 5 (file-attributes filename
'integer)))))
+ (insert "--- " filename "\t" time-string "\n")
+ (insert "+++ " filename "\t" time-string "\n")))
+ ;; write diff, highlight, and comment for each annotation
+ (save-excursion
+ ;; sorted annotations by location in the file
+ (dolist (ann annotations)
+ (let* ((start (overlay-start ann))
+ (end (overlay-end ann))
+ (text (overlay-get ann 'annotation))
+ ;; beginning of first annotated line
+ (bol (progn (goto-char start)
+ (beginning-of-line)
+ (point)))
+ ;; end of last annotated line
+ (eol (progn (goto-char end)
+ (end-of-line)
+ (point)))
+ ;; all lines that contain annotations
+ (annotated-lines (buffer-substring bol eol))
+ ;; context lines before the annotation
+ (previous-lines (annotate-context-before start))
+ ;; context lines after the annotation
+ (following-lines (annotate-context-after end))
+ (chain-last-p (annotate-chain-last-p ann))
+ (annotation-line-list (butlast (split-string
(annotate-prefix-lines "+"
annotated-lines)
"\n")))
- (integration-padding (if (and (> (1- start) 0)
- (> (1- start) bol))
- (make-string (- (1- start) bol) ?
)
- "")))
+ (integration-padding (if (and (> (1- start) 0)
+ (> (1- start) bol))
+ (make-string (- (1- start) bol) ? )
+ ""))
+ (added-lines-text (build-annotation-text-lines (concat
integration-padding
+
text)))
+ ;; line header for diff chunk
+ (diff-range (annotate-diff-line-range start end
+
added-lines-text
+
chain-last-p)))
+ (with-current-buffer export-buffer
+ (insert "@@ " diff-range " @@\n")
+ (when previous-lines
+ (insert (annotate-prefix-lines " " previous-lines)))
+ (insert (annotate-prefix-lines "-" annotated-lines))
+ ;; loop over annotation lines and insert with highlight
+ ;; and annotation text
+ (let ((annotation-line-list (butlast (split-string
+ (annotate-prefix-lines "+"
annotated-lines)
+ "\n")))
+ (integration-padding (if (and (> (1- start) 0)
+ (> (1- start) bol))
+ (make-string (- (1- start) bol)
? )
+ "")))
(insert (car annotation-line-list) "\n")
(unless (string= (car annotation-line-list) "+")
(insert "+"
@@ -815,13 +833,12 @@ annotation, and can be conveniently viewed in diff-mode."
annotate-integrate-higlight))
"\n"))
(when (annotate-chain-last-p ann)
- (insert "+"
- (annotate-wrap-in-comment integration-padding text)
+ (insert (build-annotation-text-lines (concat
integration-padding text))
"\n")))
- (insert (annotate-prefix-lines " " following-lines))))))
- (switch-to-buffer export-buffer)
- (diff-mode)
- (view-mode)))
+ (insert (annotate-prefix-lines " " following-lines t))))))
+ (switch-to-buffer export-buffer)
+ (diff-mode)
+ (view-mode))))
(defun annotate--font-lock-matcher (limit)
"Finds the next annotation. Matches two areas:
@@ -985,7 +1002,7 @@ to 'maximum-width'."
(cl-defun annotate--split-lines (text &optional (separator "\n"))
"Returns text splitted by `separator' (default: \"\n\")"
(save-match-data
- (split-string text "\n")))
+ (split-string text separator)))
(defun annotate--join-with-string (strings junction)
(cl-reduce (lambda (a b) (concat a junction b))
@@ -1209,32 +1226,39 @@ first line of the buffer"
(end-of-line (1+ annotate-diff-export-context))
(buffer-substring-no-properties (1+ eol) (point)))))
-(defun annotate-prefix-lines (prefix text)
+(defun annotate-prefix-lines (prefix text &optional omit-trailing-null)
"Prepend PREFIX to each line in TEXT."
- (let ((lines (split-string text "\n")))
+ (let ((lines (annotate--split-lines text "\n")))
+ (when omit-trailing-null
+ (let ((last-not-empty (cl-position-if-not 'annotate-string-empty-p
+ lines
+ :from-end t)))
+ (setf lines (subseq lines 0 (1+ last-not-empty)))))
(apply 'concat (mapcar (lambda (l) (concat prefix l "\n")) lines))))
-(defun annotate-diff-line-range (start end chain-last-p)
+(defun annotate-diff-line-range (start end lines-annotation-text chain-last-p)
"Calculate diff-like line range for annotation."
(save-excursion
- (let* ((lines-before (- (- annotate-diff-export-context)
- (forward-line (-
annotate-diff-export-context)))) ; this move point, too!
+ (let* ((lines-count (count-lines (point-min) (point-max)))
+ ;; forward-line move the point, too!
+ (lines-before (- (- annotate-diff-export-context)
+ (forward-line (-
annotate-diff-export-context))))
+ ;; because of forward-line above point has been moved
+ ;; 'annotate-diff-export-context' lines or at the first
+ ;; line of the buffer
(start-line (line-number-at-pos (point)))
- (diff-offset-start (+ 1
- (- lines-before)
- annotate-diff-export-context))
+ (diff-offset-start (- (line-number-at-pos start)
+ start-line))
+ (diff-offset-end (min annotate-diff-export-context
+ (- lines-count (line-number-at-pos start))))
(end-increment (if chain-last-p
- 2
- 1))
- (diff-offset-end (+ diff-offset-start
- end-increment
- (- (line-number-at-pos end)
- (line-number-at-pos start)))))
+ (+ 2 (length (annotate--split-lines
lines-annotation-text)))
+ 2)))
(format "-%i,%i +%i,%i"
start-line
- diff-offset-start
+ (+ diff-offset-start diff-offset-end 1)
start-line
- diff-offset-end))))
+ (+ diff-offset-start diff-offset-end end-increment)))))
;;; database related procedures
- [nongnu] elpa/annotate 30ee7a0b87 198/372: - fixed 'annotate-previous-annotation-ends' and 'annotate-next-annotation-ends', (continued)
- [nongnu] elpa/annotate 30ee7a0b87 198/372: - fixed 'annotate-previous-annotation-ends' and 'annotate-next-annotation-ends', ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 1143087515 213/372: - updated documentation., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate b8fd76f712 216/372: Merge pull request #60 from cage2/rethink-multiline-annotations, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a37ec08035 249/372: - added signalling of error to 'annotate-switch-db';, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 34f0df8d5b 251/372: - updated documentation., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate bc89867f65 289/372: Merge pull request #92 from cage2/expand-db-path, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate be998ca006 263/372: Merge pull request #81 from cage2/popup-annotation, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 804c7b9421 257/372: - Removed internal link because of issue #79., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a9f061cecd 268/372: - added more docstrings., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 88ed6f22cb 285/372: - rewritten export and integrate of annotations, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 463e215bec 284/372: - fixed export for annotated text made from a single line.,
ELPA Syncer <=
- [nongnu] elpa/annotate e53c0f5adf 296/372: - added checking encrypted (GPG) file format, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate be48989c98 299/372: - fixed 'annotate-previous-annotation-ends', ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 59ca58c06b 308/372: changed function from 'font-lock-ensure' to 'font-lock-flush'., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f823c3cf09 354/372: - changed default for asking confirm before deleting an annotation: the value is now 'nil' (do not prompt for confirmation)., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 3bb813cd62 360/372: - updated NEWS.org and Changelog., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 140eb6b6cb 363/372: - updated NEWS.org;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate b22f594f3b 336/372: Merge pull request #107 from cage2/prevent-saving-empty-db, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate de86b9b22e 341/372: - removed uses of regular expressions from 'annotate-unwrap-text'., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate e083073ead 371/372: - updated Changelog;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 0901aa52bc 367/372: - added the others procedures to import an annotation database., ELPA Syncer, 2022/02/04