[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/annotate 2084f831bc 026/372: added export functionality as
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/annotate 2084f831bc 026/372: added export functionality as sort-of-diffscuss |
Date: |
Fri, 4 Feb 2022 16:58:16 -0500 (EST) |
branch: elpa/annotate
commit 2084f831bcf175525130113d19fc62d029267897
Author: Bastian <basti@bastibe.de>
Commit: Bastian <basti@bastibe.de>
added export functionality as sort-of-diffscuss
---
annotate.el | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/annotate.el b/annotate.el
index 2f3eafac17..d7704819b6 100644
--- a/annotate.el
+++ b/annotate.el
@@ -86,6 +86,12 @@
:type 'number
:group 'annotate)
+;;;###autoload
+(defcustom annotate-diff-export-context 2
+ "How many lines of context to include in diff export."
+ :type 'number
+ :group 'annotate)
+
(defun annotate-initialize ()
"Load annotations and set up save hook."
(annotate-load-annotations)
@@ -122,6 +128,83 @@
(annotate-dump-annotation-data all-annotations)
(message "Annotations saved.")))
+;;;###autoload
+(defun annotate-export-annotations ()
+ "Export all annotations as a diff-like file."
+ (interactive)
+ (let ((export-buffer (generate-new-buffer "*annotations*"))
+ (annotations (annotate-describe-annotations))
+ (filename (buffer-file-name)))
+ (with-current-buffer export-buffer
+ (insert "--- " filename "\n")
+ (insert "+++ " filename "\n"))
+ (save-excursion
+ (dolist (ann annotations)
+ (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))
+ (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))
+ (with-current-buffer export-buffer
+ (insert (annotate-diff-line-range start end) "\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 " "))))))
+ (switch-to-buffer export-buffer)
+ (diff-mode)
+ (view-mode)))
+
+(defun annotate-prefix-lines (text prefix)
+ "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"))))
+ (apply 'concat (map 'list (lambda (l) (concat prefix l "\n")) lines))))
+
+(defun annotate-diff-line-range (start end)
+ "Calculate diff-like line range for annotation."
+ (format "@@ -%i,%i +%i,%i @@"
+ (line-number-at-pos start) (line-number-at-pos start)
+ (line-number-at-pos end) (line-number-at-pos end)))
+
;;;###autoload
(defun annotate-load-annotations ()
"Load all annotations from disk."
- [nongnu] elpa/annotate 530b4aa78a 022/372: increment version number, (continued)
- [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, 2022/02/04
- [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 <=
- [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
- [nongnu] elpa/annotate 9ffdc1f762 060/372: fix for annotations with wide characters, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 19acc501d8 086/372: - added/fixed more docstrings., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 774e643af4 081/372: - fixed retrocompatibility with old annotation file format., ELPA Syncer, 2022/02/04