[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/annotate a28e7b4fd2 028/372: refactored and documented exp
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/annotate a28e7b4fd2 028/372: refactored and documented export function |
Date: |
Fri, 4 Feb 2022 16:58:16 -0500 (EST) |
branch: elpa/annotate
commit a28e7b4fd280beb5bfac469eb807dab1384cc714
Author: Bastian <basti@bastibe.de>
Commit: Bastian <basti@bastibe.de>
refactored and documented export function
---
annotate.el | 158 ++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 105 insertions(+), 53 deletions(-)
diff --git a/annotate.el b/annotate.el
index f9c0f5c112..c3651653ec 100644
--- a/annotate.el
+++ b/annotate.el
@@ -130,79 +130,131 @@
;;;###autoload
(defun annotate-export-annotations ()
- "Export all annotations as a diff-like file."
+ "Export all annotations as a unified diff file.
+An example might look like this:
+
+--- /home/bastibe/Projects/annotate.el/annotate.el 2015-06-19
15:13:36.718796738 +0200
++++ /home/bastibe/Projects/annotate.el/annotate.el 2015-06-19
15:13:36.718796738 +0200
+@@ -73,5 +73,5 @@
+ ;;;###autoload
+ (defface annotate-highlight
+- '((t (:underline \"coral\")))
++ '((t (:underline \"coral\")))
+# ~~~~~~~~~~~~~~~~~~
+# this doesn't work in cli
+ \"Face for annotation highlights.\"
+ :group 'annotate)
+
+This diff does not contain any changes, but highlights the
+annotation, and can be conveniently viewed in diff-mode."
(interactive)
(let ((export-buffer (generate-new-buffer "*annotations*"))
(annotations (annotate-describe-annotations))
(filename (buffer-file-name)))
+ ;; write the diff file description
(with-current-buffer export-buffer
(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 (sort annotations (lambda (a1 a2)
(< (car a1) (car a2)))))
- (let ((start (nth 0 ann))
- (end (nth 1 ann))
- (text (nth 2 ann))
- (bol nil)
- (eol nil)
- (line nil)
- (previous-lines nil)
- (following-lines nil)
- (diff-range nil))
- (goto-char start)
- (beginning-of-line)
- (setq bol (point))
- (beginning-of-line (- (1- annotate-diff-export-context)))
- (setq previous-lines (buffer-substring-no-properties (point) (1-
bol)))
- (goto-char end)
- (end-of-line)
- (setq eol (point))
- (end-of-line (1+ annotate-diff-export-context))
- (setq following-lines (buffer-substring-no-properties (1+ eol)
(point)))
- (setq line (buffer-substring bol eol))
- (setq diff-range (annotate-diff-line-range start end))
+ (let* ((start (nth 0 ann))
+ (end (nth 1 ann))
+ (text (nth 2 ann))
+ ;; 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))
+ ;; line header for diff chunk
+ (diff-range (annotate-diff-line-range start end)))
(with-current-buffer export-buffer
(insert "@@ " diff-range " @@\n")
- (insert (annotate-prefix-lines previous-lines " "))
- (insert (annotate-prefix-lines line "-"))
- (let ((selection (butlast (split-string (annotate-prefix-lines
line "+") "\n"))))
- (cond ((= (length selection) 1)
- (insert (first selection) "\n")
- (unless (string= (first selection) "+")
- (insert "#"
- (make-string (- start bol) ? )
- (make-string (- end start) ?~)
- "\n"))
- (insert "#" (make-string (- start bol) ? ) text "\n"))
- (t
- (insert (first selection) "\n")
- (insert "#"
- (make-string (- start bol) ? )
- (make-string (- (length (first selection)) (-
start bol)) ?~)
- "\n")
- (dolist (line (cdr (butlast selection)))
- (insert line "\n"
- "#" (make-string (length line) ?~) "\n"))
- (insert (car (last selection)) "\n")
- (insert "#"
- (make-string (- (length (car (last selection)))
(- eol end) 1) ?~)
- "\n")
- (insert "#" text "\n"))))
- (insert (annotate-prefix-lines following-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"))))
+ (cond
+ ;; annotation has only one line
+ ((= (length annotation-line-list) 1)
+ (insert (first annotation-line-list) "\n")
+ (unless (string= (first annotation-line-list) "+")
+ (insert "#"
+ (make-string (- start bol) ? )
+ (make-string (- end start) ?~)
+ "\n"))
+ (insert "#" (make-string (- start bol) ? ) text "\n"))
+ ;; annotation has more than one line
+ (t
+ (let ((line (first annotation-line-list))) ; first line
+ ;; first diff line
+ (insert line "\n")
+ ;; underline highlight (from start to eol)
+ (unless (string= line "+") ; empty line
+ (insert "#"
+ (make-string (- start bol) ? )
+ (make-string (- (length line) (- start bol)) ?~)
+ "\n")))
+ (dolist (line (cdr (butlast annotation-line-list))) ; nth line
+ ;; nth diff line
+ (insert line "\n")
+ ;; nth underline highlight (from bol to eol)
+ (unless (string= line "+")
+ (insert "#" (make-string (length line) ?~) "\n")))
+ (let ((line (car (last annotation-line-list))))
+ ;; last diff line
+ (insert line "\n")
+ ;; last underline highlight (from bol to end)
+ (unless (string= line "+")
+ (insert "#"
+ (make-string (- (length line) (- eol end) 1) ?~)
+ "\n")))
+ ;; annotation text
+ (insert "#" text "\n"))))
+ (insert (annotate-prefix-lines " " following-lines))))))
(switch-to-buffer export-buffer)
(diff-mode)
(view-mode)))
-(defun annotate-prefix-lines (text prefix)
+(defun annotate-context-before (pos)
+ "Context lines before POS."
+ (save-excursion
+ (goto-char pos)
+ (beginning-of-line)
+ (let ((bol (point)))
+ (beginning-of-line (- (1- annotate-diff-export-context)))
+ (buffer-substring-no-properties (point) (1- bol)))))
+
+(defun annotate-context-after (pos)
+ "Context lines after POS."
+ (save-excursion
+ (goto-char pos)
+ (end-of-line)
+ (let ((eol (point)))
+ (end-of-line (1+ annotate-diff-export-context))
+ (buffer-substring-no-properties (1+ eol) (point)))))
+
+(defun annotate-prefix-lines (prefix text)
"Prepend PREFIX to each line in TEXT."
- ;; don't split a single new line into two lines
- (let ((lines (if (string= text "\n")
- '("")
- (split-string text "\n"))))
+ (let ((lines (split-string text "\n")))
(apply 'concat (map 'list (lambda (l) (concat prefix l "\n")) lines))))
(defun annotate-diff-line-range (start end)
- [nongnu] elpa/annotate a484ffa0b6 319/372: - allowed removing (or cutting) annotations when buffer is in read-only mode., (continued)
- [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, 2022/02/04
- [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 <=
- [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
- [nongnu] elpa/annotate c7891d8d24 163/372: - tried to make the file more "site friendly"., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate ec0ed147a2 170/372: - fixed error for regexp search in 'annotate--font-lock-matcher', ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 1525550f85 182/372: - changed test for annotation rejection and removed (maybe) useless check., ELPA Syncer, 2022/02/04