[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark e78f549267 069/173: intrnl: housekeep to sav
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark e78f549267 069/173: intrnl: housekeep to save; refactor remove |
Date: |
Fri, 28 Jan 2022 16:58:02 -0500 (EST) |
branch: externals/org-remark
commit e78f54926745a90aa42212235d323f34f8ff1fa6
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
intrnl: housekeep to save; refactor remove
Housekeep the internal variable `org-marginalia-highlights'.
Case 1. Both start and end of an overlay are 1
This should not happen when you manually mark a text
region. A typical cause of this case is when you delete a
region that contains a highlight overlay.
Case 2. The overlay points to no buffer
This case happens when overlay is deleted by
`overlay-delete' but the variable not cleared.
---
org-marginalia.el | 67 +++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 53 insertions(+), 14 deletions(-)
diff --git a/org-marginalia.el b/org-marginalia.el
index 5929188793..a90769dcdc 100644
--- a/org-marginalia.el
+++ b/org-marginalia.el
@@ -298,6 +298,7 @@ and `org-marginalia-prev'."
;; You cannot use `undo' to undo highlighter.
(deactivate-mark)
(unless (buffer-modified-p) (set-buffer-modified-p t))))
+ (org-marginalia-housekeep)
(org-marginalia-sort-highlights-list))
;;;###autoload
@@ -371,6 +372,8 @@ in the current buffer. Each highlight is represented by
this data structure:
(source-path (abbreviate-file-name filename))
(title (or (car (cdr (assoc "TITLE" (org-collect-keywords
'("TITLE")))))
(file-name-sans-extension (file-name-nondirectory
(buffer-file-name))))))
+ (org-marginalia-housekeep)
+ (org-marginalia-sort-highlights-list)
(dolist (highlight org-marginalia-highlights)
(org-marginalia-save-single-highlight highlight title source-path))
;; Tracking
@@ -413,25 +416,13 @@ notes you have written, for the highlight."
(when-let* ((id (get-char-property point 'org-marginalia-id)))
;; Remove the highlight overlay and id
(dolist (ov (overlays-at (point)))
+ ;; Remove the element in the variable org-marginalia-highlights
(when (overlay-get ov 'org-marginalia-id)
(delete ov org-marginalia-highlights)
(delete-overlay ov)))
- ;; Remove the element in the variable org-marginalia-highlights
- ;; TODO need to go through this org-marginalia-hightlights stuff
(org-marginalia-sort-highlights-list)
;; Update the marginalia note file accordingly
- (with-current-buffer (find-file-noselect org-marginalia-notes-file-path)
- (org-with-wide-buffer
- (when-let ((id-headline (org-find-property org-marginalia-prop-id id)))
- (goto-char id-headline)
- (org-narrow-to-subtree)
- (org-delete-property org-marginalia-prop-id)
- (org-delete-property org-marginalia-prop-source-beg)
- (org-delete-property org-marginalia-prop-source-end)
- (when arg
- ;; TODO I would love to add the y-n prompt if there is any notes
written
- (delete-region (point-min)(point-max))
- (message "Deleted the marginal notes.")))))
+ (org-marginalia-remove-marginalia id arg)
t))
(defun org-marginalia-next ()
@@ -647,6 +638,54 @@ state."
(overlay-put highlight 'face 'org-marginalia-highlighter))
t))
+(defun org-marginalia-remove-marginalia (id &optional delete-notes)
+ "Remove marginalia entry for the ID for the current buffer.
+By default, it deletes only the properties of the entry keeping
+the headline intact. You can pass DELETE-NOTES and delete the all
+notes of the entry."
+ (with-current-buffer (find-file-noselect org-marginalia-notes-file-path)
+ (org-with-wide-buffer
+ (when-let ((id-headline (org-find-property org-marginalia-prop-id id)))
+ (goto-char id-headline)
+ (org-narrow-to-subtree)
+ (org-delete-property org-marginalia-prop-id)
+ (org-delete-property org-marginalia-prop-source-beg)
+ (org-delete-property org-marginalia-prop-source-end)
+ (when delete-notes
+ ;; TODO I would love to add the y-n prompt if there is any notes
written
+ (delete-region (point-min)(point-max))
+ (message "Deleted the marginal notes."))
+ (when (buffer-modified-p) (save-buffer))))
+ t))
+
+(defun org-marginalia-housekeep ()
+ "Housekeep the internal variable `org-marginalia-highlights'.
+
+Case 1. Both start and end of an overlay are 1
+
+ This should not happen when you manually mark a text
+ region. A typical cause of this case is when you delete a
+ region that contains a highlight overlay.
+
+Case 2. The overlay points to no buffer
+
+ This case happens when overlay is deleted by
+ `overlay-delete' but the variable not cleared."
+
+ (interactive)
+ (dolist (ov org-marginalia-highlights)
+ ;; Both start and end of an overlay is 1 should not happen when you
manually
+ ;; mark a text region. A typical cause of this case is when you delete a
+ ;; region that contains a highlight overlay.
+ (when (and (overlay-buffer ov)
+ (= 1 (overlay-start ov))
+ (= 1 (overlay-end ov)))
+ (org-marginalia-remove-marginalia (overlay-get ov 'org-marginalia-id))
+ (delete-overlay ov))
+ (unless (overlay-buffer ov)
+ (setq org-marginalia-highlights (delete ov org-marginalia-highlights))))
+ t)
+
;;;; Footer
(provide 'org-marginalia)
- [elpa] externals/org-remark 73e332b1d5 113/173: add: convert-legacy-data + refactor, (continued)
- [elpa] externals/org-remark 73e332b1d5 113/173: add: convert-legacy-data + refactor, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 2954965bb3 127/173: add: define org-remark-mark explicitly for autoload cookie, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark e27e0d6dad 023/173: feat: Add om/toggle for show/hide highlighters, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark bfeffae259 027/173: doc: Minor update, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 6be3fc988b 039/173: doc: Minor update, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 3c270b4e28 025/173: doc: Update readme with a title screen, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 3af3a47e1b 047/173: feat: Add transient navigation to next/prev, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark d8908d6aba 054/173: doc: fix code example in README, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark f9c313342c 067/173: chg: separate global-tracking.el, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark a42ca0f756 066/173: readme for marginalia, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark e78f549267 069/173: intrnl: housekeep to save; refactor remove,
ELPA Syncer <=
- [elpa] externals/org-remark 7176e9d460 073/173: add: ID inherits. fix: housekeep, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 9bb66a742e 074/173: fix: overlay front-advance, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 2ed345c66c 071/173: rm: create-id option, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark b6e6a55f63 075/173: chg: customization notes-file-path type to file, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark ca0c0ac674 080/173: doc: global-tracking docstring, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 12e0b631eb 076/173: lint: shorten longer than 80 char, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 9d63088869 086/173: docs: README, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark ad93331bf7 089/173: doc: update README with comment on autoload, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 75698160aa 098/173: fix: for name change, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark c946340b50 096/173: intrnl: refactor & docstrings, ELPA Syncer, 2022/01/28