[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/annotate 526ced3131 013/372: create minor mode
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/annotate 526ced3131 013/372: create minor mode |
Date: |
Fri, 4 Feb 2022 16:58:15 -0500 (EST) |
branch: elpa/annotate
commit 526ced31313f5d49d358cf6358804c3063e4b3ee
Author: Bastian Bechtold <bb@Mr-Bigglesworth.local>
Commit: Bastian Bechtold <bb@Mr-Bigglesworth.local>
create minor mode
---
annotate.el | 136 ++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 81 insertions(+), 55 deletions(-)
diff --git a/annotate.el b/annotate.el
index 1e2a0d23ec..d1e0cfcc0b 100644
--- a/annotate.el
+++ b/annotate.el
@@ -5,6 +5,18 @@
:version 0.1
:group 'text)
+(define-minor-mode annotate-mode
+ "Toggle Annotate mode."
+ :init-value nil
+ :lighter " Ann"
+ :keymap (make-sparse-keymap)
+ :group 'annotate
+ :after-hook (if annotate-mode
+ (annotate-initialize)
+ (annotate-shutdown)))
+
+(define-key annotate-mode-map (kbd "C-c C-a") 'annotate-annotate)
+
(defcustom annotate-file "~/.file-annotations"
"File where annotations are stored."
:type 'file
@@ -15,46 +27,99 @@
"Face for annotation highlights."
:group 'annotate)
-(defcustom annotate-highlight-face 'annotate-highlight
- "Face for annotations."
- :type 'face
- :group 'annotate)
-
(defface annotate-annotation
'((t (:background "coral" :foreground "black")))
"Face for annotations."
:group 'annotate)
-(defcustom annotate-annotation-face 'annotate-annotation
- "Face for annotations."
- :type 'face
- :group 'annotate)
-
(defcustom annotate-annotation-column 85
"Where annotations appear."
:type 'number
:group 'annotate)
+(defun annotate-initialize ()
+ "Load annotations and set up save hook."
+ (annotate-load-annotations)
+ (add-hook 'after-save-hook 'annotate-save-annotations t t))
+
+(defun annotate-shutdown ()
+ "Clear annotations and remove save hook."
+ (annotate-clear-annotations)
+ (remove-hook 'after-save-hook 'annotate-save-annotations t))
+
(defun annotate-annotate ()
"Create, modify, or delete annotation."
(interactive)
(let ((overlay (car (overlays-at (point)))))
- (message "%s" (overlayp overlay))
(cond ((and (overlayp overlay) (overlay-get overlay 'annotation))
(annotate-change-annotation (point)))
(t
(destructuring-bind (start end) (annotate-bounds)
(annotate-create-annotation start end))))))
+(defun annotate-save-annotations ()
+ "Save all annotations to disk."
+ (interactive)
+ (let ((file-annotations
+ (mapcar 'annotate-describe-annotation (overlays-in 0 (buffer-size))))
+ (all-annotations (annotate-load-annotation-data)))
+ (if (assoc-string (buffer-file-name) all-annotations)
+ (setcdr (assoc-string (buffer-file-name) all-annotations)
+ file-annotations)
+ (setq all-annotations
+ (push (cons (buffer-file-name) file-annotations)
+ all-annotations)))
+ (annotate-dump-annotation-data all-annotations)
+ (message "Annotations saved.")))
+
+(defun annotate-load-annotations ()
+ "Load all annotations from disk."
+ (interactive)
+ (let ((annotations (cdr (assoc-string (buffer-file-name)
+ (annotate-load-annotation-data)))))
+ (when (eq nil annotations)
+ (message "No annotations found."))
+ (when (not (eq nil annotations))
+ (save-excursion
+ (dolist (annotation annotations)
+ (let* ((start (nth 0 annotation))
+ (end (nth 1 annotation))
+ (text (nth 2 annotation))
+ (highlight (make-overlay start end)))
+ (overlay-put highlight 'face 'annotate-highlight)
+ (overlay-put highlight 'annotation text)
+ (setq text (propertize text 'face 'annotate-annotation))
+ (goto-char end)
+ (move-end-of-line nil)
+ (let ((prefix (make-string (- annotate-annotation-column
+ (annotate-line-length)) ? )))
+ (put-text-property (point)
+ (1+ (point))
+ 'display
+ (concat prefix text "\n"))))))
+ (message "Annotations loaded."))))
+
+(defun annotate-clear-annotations ()
+ "Clear all current annotations."
+ (interactive)
+ (let ((highlights
+ (overlays-in 0 (buffer-size))))
+ (save-excursion
+ (dolist (highlight highlights)
+ (goto-char (overlay-end highlight))
+ (move-end-of-line nil)
+ (delete-overlay highlight)
+ (remove-text-properties (point) (1+ (point)) '(display nil))))))
+
(defun annotate-create-annotation (start end)
"Create a new annotation for selected region."
(let ((highlight (make-overlay start end))
(annotation (read-from-minibuffer "Annotation: "))
(prefix (make-string (- annotate-annotation-column
(annotate-line-length)) ? )))
(when (not (string= "" annotation))
- (overlay-put highlight 'face annotate-highlight-face)
+ (overlay-put highlight 'face 'annotate-highlight)
(overlay-put highlight 'annotation annotation)
- (setq annotation (propertize annotation 'face annotate-annotation-face))
+ (setq annotation (propertize annotation 'face 'annotate-annotation))
(save-excursion
(move-end-of-line nil)
(put-text-property (point) (1+ (point)) 'display (concat prefix
annotation "\n"))))))
@@ -73,7 +138,7 @@
(remove-text-properties (point) (1+ (point)) '(display nil)))
(t
(overlay-put highlight 'annotation annotation)
- (setq annotation (propertize annotation 'face
annotate-annotation-face))
+ (setq annotation (propertize annotation 'face 'annotate-annotation))
(put-text-property (point) (1+ (point)) 'display (concat prefix
annotation "\n")))))))
(defun annotate-line-length ()
@@ -95,47 +160,6 @@
((thing-at-point 'symbol) (cdr (bounds-of-thing-at-point 'symbol)))
(t (1+ (point))))))
-(defun annotate-save-annotations ()
- "Save all annotations to disk."
- (interactive)
- (let ((file-annotations
- (mapcar 'annotate-describe-annotation (overlays-in 0 (buffer-size))))
- (all-annotations (annotate-load-annotation-data)))
- (if (assoc-string (buffer-file-name) all-annotations)
- (setcdr (assoc-string (buffer-file-name) all-annotations)
- file-annotations)
- (setq all-annotations
- (push (cons (buffer-file-name) file-annotations)
- all-annotations)))
- (annotate-dump-annotation-data all-annotations)))
-
-(defun annotate-load-annotations ()
- "Load all annotations from disk."
- (interactive)
- (let ((annotations (cdr (assoc-string (buffer-file-name)
- (annotate-load-annotation-data)))))
- (message "%s" annotations)
- (when (not (eq nil annotations))
- (save-excursion
- (dolist (annotation annotations)
- (message "%s" annotation)
- (let* ((start (nth 0 annotation))
- (end (nth 1 annotation))
- (text (nth 2 annotation))
- (highlight (make-overlay start end)))
- (message "%s" annotation)
- (overlay-put highlight 'face annotate-highlight-face)
- (overlay-put highlight 'annotation text)
- (setq text (propertize text 'face annotate-annotation-face))
- (goto-char end)
- (move-end-of-line nil)
- (let ((prefix (make-string (- annotate-annotation-column
- (annotate-line-length)) ? )))
- (put-text-property (point)
- (1+ (point))
- 'display
- (concat prefix text "\n")))))))))
-
(defun annotate-describe-annotation (highlight)
(list
(overlay-start highlight)
@@ -154,3 +178,5 @@
(defun annotate-dump-annotation-data (data)
(with-temp-file annotate-file
(prin1 data (current-buffer))))
+
+(provide 'annotate)
- [nongnu] branch elpa/annotate created (now 0cfad246ee), ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate cecb77fecc 004/372: can now edit and delete annotations, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate d7246d5220 006/372: implemented annotation saving, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a648cd44df 010/372: make auxiliary functions non-interactive, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f6780672bc 011/372: fix change annotation function, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f6203f0d40 012/372: improved default column, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 526ced3131 013/372: create minor mode,
ELPA Syncer <=
- [nongnu] elpa/annotate 7531343d7b 001/372: initial prototype, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 6c33ac48d0 003/372: annotate without region, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 32d82c4557 018/372: no more nil annotations, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate aa075cfe04 002/372: change annotation display from overlay to property, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 94c2a9455f 019/372: increment version number, ELPA Syncer, 2022/02/04
- [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