emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/annotate a169038431 050/372: new export option


From: ELPA Syncer
Subject: [nongnu] elpa/annotate a169038431 050/372: new export option
Date: Fri, 4 Feb 2022 16:58:18 -0500 (EST)

branch: elpa/annotate
commit a1690384317ce366e5a33aec916949e3328a0117
Author: Bastian Bechtold <bb@Mr-Bigglesworth.local>
Commit: Bastian Bechtold <bb@Mr-Bigglesworth.local>

    new export option
---
 README.md   |  3 +++
 annotate.el | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 1527b8d8c7..c0f5e140f7 100644
--- a/README.md
+++ b/README.md
@@ -74,3 +74,6 @@ This package is released under the MIT license.
 
 - **2015-10-06 V0.4.3 Bastian Bechtold**  
   Bugfixes. No more hidden newlines, no more annotations in undo-list, no more 
error messages with annotations at bol, mark deactivated after creating 
annotation, annotations auto-reflow on frame size change.
+
+- **2015-10-06 V0.4.4 Bastian Bechtold**  
+  Added a new export system. Let's see if it turns out to be more useful than 
the previous one.
diff --git a/annotate.el b/annotate.el
index 192fa02c87..8f45823aab 100644
--- a/annotate.el
+++ b/annotate.el
@@ -5,7 +5,7 @@
 ;; Maintainer: Bastian Bechtold
 ;; URL: https://github.com/bastibe/annotate.el
 ;; Created: 2015-06-10
-;; Version: 0.4.3
+;; Version: 0.4.4
 
 ;; This file is NOT part of GNU Emacs.
 
@@ -50,7 +50,7 @@
 ;;;###autoload
 (defgroup annotate nil
   "Annotate files without changing them."
-  :version "0.4.3"
+  :version "0.4.4"
   :group 'text)
 
 ;;;###autoload
@@ -104,6 +104,12 @@
   :type 'boolean
   :group 'annotate)
 
+;;;###autoload
+(defcustom annotate-integrate-marker " ANNOTATION: "
+  "Marker that is written before every integrated annotation."
+  :type 'string
+  :group 'annotate)
+
 (defun annotate-initialize ()
   "Load annotations and set up save and display hooks."
   (annotate-load-annotations)
@@ -202,6 +208,66 @@
     (if annotate-use-messages
         (message "Annotations saved."))))
 
+;;;###autoload
+(defun annotate-integrate-annotations ()
+  "Write all annotations into the file as comments below the annotated line.
+An example might look like this:"
+  (interactive)
+  (save-excursion
+    (dolist (ov (sort (overlays-in 0 (buffer-size))
+                      (lambda (o1 o2)
+                        (< (overlay-start o1) (overlay-start o2)))))
+      (goto-char (overlay-start ov))
+      (cond
+       ;; overlay spans more than one line
+       ((string-match "\n" (buffer-substring (overlay-start ov)
+                                             (overlay-end ov)))
+        ;; partially underline first line
+        (let ((ov-start (point))
+              (bol (progn (beginning-of-line)
+                          (point)))
+              (eol (progn (end-of-line)
+                          (point))))
+          (end-of-line)
+          (insert "\n" comment-start
+                  (make-string (max 0 (- ov-start bol (string-width 
comment-start))) ? )
+                  (make-string (max 0 (- eol ov-start)) ?~)))
+        ;; fully underline second to second-to-last line
+        (while (< (progn (next-line)
+                         (end-of-line)
+                         (point)) (overlay-end ov))
+          (let ((bol (progn (beginning-of-line)
+                            (point)))
+                (eol (progn (end-of-line)
+                            (point))))
+            (end-of-line)
+            (insert "\n" comment-start
+                    (make-string (max 0 (- eol bol (string-width 
comment-start))) ?~))))
+        ;; partially underline last line
+        (let ((bol (progn (beginning-of-line)
+                          (point)))
+              (ov-end (overlay-end ov)))
+          (end-of-line)
+          (insert "\n" comment-start
+                  (make-string (max 0 (- ov-end bol (string-width 
comment-start))) ?~)))
+        ;; insert actual annotation text
+        (insert "\n" comment-start annotate-integrate-marker (overlay-get ov 
'annotation)))
+       ;; overlay is within one line
+       (t
+        (let ((ov-start (overlay-start ov))
+              (ov-end (overlay-end ov))
+              (bol (progn (beginning-of-line)
+                          (point))))
+          (end-of-line)
+          (insert "\n" comment-start
+                  (make-string (max 0 (- ov-start bol (string-width 
comment-start))) ? )
+                  (if (= bol ov-start)
+                      (make-string (max 0 (- ov-end ov-start 1)) ?~)
+                    (make-string (max 0 (- ov-end ov-start)) ?~))
+                    "\n" comment-start annotate-integrate-marker (overlay-get 
ov 'annotation)))))
+      (remove-text-properties
+         (point) (1+ (point)) '(display nil)))))
+
 ;;;###autoload
 (defun annotate-export-annotations ()
   "Export all annotations as a unified diff file.
@@ -335,7 +401,7 @@ annotation plus the newline."
             (goto-char (overlay-end (car overlays)))))
       ;; capture the area from the overlay to EOL for the modification guard
       ;; and the newline itself for the annotation.
-      (re-search-forward "\\(.*\\)\\(\n\\)")
+      (re-search-forward "\\(.*\\(\n\\)\\)")
       t)))
 
 (defun annotate-lineate (text)
@@ -411,7 +477,7 @@ that strips dangling `display` properties of text 
insertions if
 text is inserted. This cleans up after newline insertions between
 an overlay and it's annotation."
   (list 'face nil
-        'insert-behind-hooks '(annotate--remove-annotation-property)))
+        'insert-in-front-hooks '(annotate--remove-annotation-property)))
 
 (defun annotate-context-before (pos)
   "Context lines before POS."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]