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

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

[elpa] externals/org-remark 6ef0b47bd2 12/16: fix: revert-buffer duplica


From: ELPA Syncer
Subject: [elpa] externals/org-remark 6ef0b47bd2 12/16: fix: revert-buffer duplicates highlights
Date: Sat, 29 Jul 2023 18:58:48 -0400 (EDT)

branch: externals/org-remark
commit 6ef0b47bd2ac7426fdf89d55b3e6680ffccf5bf7
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>

    fix: revert-buffer duplicates highlights
    
    Before this change, `revert-buffer` would duplicate the highlights in
    the buffer -- visibly duplicating the icons. Now this is fixed.
---
 org-remark.el | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/org-remark.el b/org-remark.el
index 78404fc880..67529efa9c 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -6,7 +6,7 @@
 ;; URL: https://github.com/nobiot/org-remark
 ;; Version: 1.1.0
 ;; Created: 22 December 2020
-;; Last modified: 21 July 2023
+;; Last modified: 29 July 2023
 ;; Package-Requires: ((emacs "27.1") (org "9.4"))
 ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp,
 
@@ -327,7 +327,8 @@ recommended to turn it on as part of Emacs initialization.
       (org-remark-highlights-load)
       (add-hook 'after-save-hook #'org-remark-save nil t)
       (add-hook 'org-remark-highlight-link-to-source-functions
-                #'org-remark-highlight-link-to-source-default 80))
+                #'org-remark-highlight-link-to-source-default 80)
+      (add-hook 'after-revert-hook #'org-remark-highlights-load))
      (t
       ;; Deactivate
       (when org-remark-highlights
@@ -336,7 +337,8 @@ recommended to turn it on as part of Emacs initialization.
       (setq org-remark-highlights nil)
       (remove-hook 'after-save-hook #'org-remark-save t)
       (remove-hook 'org-remark-highlight-link-to-source-functions
-                   #'org-remark-highlight-link-to-source-default))))
+                   #'org-remark-highlight-link-to-source-default)
+      (remove-hook 'after-revert-hook #'org-remark-highlights-load))))
 
 
 ;;;; Org-remark Menu
@@ -1385,12 +1387,11 @@ process."
   ;; "file". In this case, obsolete highlight overlays linger when you
   ;; switch from one file to another. Thus, we need to begin loading by
   ;; clearing the highlight overlays first.
-  ;;(org-remark-highlights-housekeep)
-  ;; In order to update the overlay, it is first gets deleted
-  ;; and newly loaded.  This way, we avoid duplicate of the same
+
+  ;; In order to update the highlight overlays, it is first gets deleted
+  ;; and newly loaded. This way, we avoid duplicate of the same
   ;; highlight.
-  (dolist (ov org-remark-highlights)
-    (org-remark-highlight-clear ov))
+  (org-remark-highlights-clear)
   ;; Loop highlights and add them to the current buffer
   (let (overlays) ;; highlight overlays
     (when-let* ((notes-filename (org-remark-notes-get-file-name))
@@ -1412,6 +1413,16 @@ process."
           ;; if there is no overlays loaded, return nil
           nil)))))
 
+(defun org-remark-highlights-clear ()
+  "Delete all highlights in the buffer.
+
+This function also set `org-remark-highlights' to nil."
+  (setq org-remark-highlights nil)
+  (org-with-wide-buffer
+   (dolist (ov (overlays-in (point-min) (point-max)))
+     (when (overlay-get ov 'org-remark-id)
+       (delete-overlay ov)))))
+
 (defun org-remark-highlights-get-positions (&optional reverse)
   "Return list of the beginning point of all visible highlights in this buffer.
 By default, the list is in ascending order.  If REVERSE is
@@ -1624,7 +1635,8 @@ function extends the behavior and looks for the word at 
point"
       (user-error "No region selected and the cursor is not on a word"))))
 
 (defun org-remark-string= (s1 s2)
-  "Like `string=' but remove newlines and spaces before compare."
+  "Like `string=' but remove newlines and spaces before compare.
+Return t if S1 and S2 are an identical string."
   (string=
    ;; Cater to the case when the text is divided by a newline
    ;; character \n. Remove all spaces and newline chars



reply via email to

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