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

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

[elpa] externals/org-remark 32149d5135 25/67: fix: Exclude pdfs from def


From: ELPA Syncer
Subject: [elpa] externals/org-remark 32149d5135 25/67: fix: Exclude pdfs from default file type #57
Date: Sat, 22 Jul 2023 06:59:01 -0400 (EDT)

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

    fix: Exclude pdfs from default file type #57
    
    The fix is applied to more generic case, not specific to PDF files.
    Unlike epub files via nov-mode or websites via eww-mode, pdf-view-mode
    buffers are actually visiting buffers. And yet, it is also derived from
    special-mode, which means the buffers visited are meant to be read-only.
    
    The fix implemented is to add a check to
    'org-remark-source-find-file-name'. It now does the following:
    
    1. Check whether or not the source buffer visited is derived from
    special-mode.
    
    2. If so, its notes buffer should be found by a mode-specific function,
    not passing buffer-file-name
---
 org-remark-global-tracking.el | 12 ++++++----
 org-remark.el                 | 52 ++++++++++++++++++++++---------------------
 2 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/org-remark-global-tracking.el b/org-remark-global-tracking.el
index b963085f49..43c6d68449 100644
--- a/org-remark-global-tracking.el
+++ b/org-remark-global-tracking.el
@@ -99,9 +99,12 @@ When the current buffer is visiting a file, the name of 
marginal
 notes file will be \"FILE-notes.org\", adding \"-notes.org\" as a
 suffix to the file name without the extension."
   (if buffer-file-name
-      (concat (file-name-sans-extension
-               (file-name-nondirectory (org-remark-source-find-file-name)))
-              "-notes.org")
+      (let ((source-filename (org-remark-source-find-file-name)))
+        (when (and (stringp source-filename)
+                   (file-exists-p source-filename))
+          (concat (file-name-sans-extension
+                   (file-name-nondirectory source-filename))
+                  "-notes.org")))
     ;; If buffer is not visiting a file, a default file name.  If this
     ;; file name is not suitable, either override the function or set
     ;; the user option to a custom function.
@@ -141,7 +144,8 @@ This function is meant to be added to `find-file-hook' by
 We use this filename to identify the source buffer in all
 operations related to marginal notes.
 Assumes that we are currently in the source buffer."
-  (let ((filename (or buffer-file-name
+  (let ((filename (or (and (not (derived-mode-p 'special-mode))
+                           buffer-file-name)
                       (run-hook-with-args-until-success
                        'org-remark-source-find-file-name-functions))))
     filename))
diff --git a/org-remark.el b/org-remark.el
index d41b4a346e..f51706dbf9 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -731,7 +731,8 @@ round-trip back to the notes file."
         (id (if id id (substring (org-id-uuid) 0 8)))
         (filename (org-remark-source-find-file-name)))
     (if (not filename)
-        (message "org-remark: Highlights not saved; buffer is not supported")
+        (message (format "org-remark: Highlights not saved.\
+ This buffer (%s) is not supported" (symbol-name major-mode)))
       (org-with-wide-buffer
        (overlay-put ov 'face (if face face 'org-remark-highlighter))
        (while properties
@@ -1292,30 +1293,31 @@ configuration.  It automatically turns on 
`org-remark-mode'.
 Otherwise, do not forget to turn on `org-remark-mode' manually to
 load the highlights"
   ;; Loop highlights and add them to the current buffer
-  (let ((notes-buf (find-file-noselect (org-remark-notes-get-file-name)))
-        (source-buf (current-buffer))
-        (overlays)) ;; highlight overlays
-    (dolist (highlight (org-remark-highlights-get notes-buf) overlays)
-      (let* ((location (plist-get highlight :location))
-             (beg (car location))
-             (end (cdr location))
-             (id (plist-get highlight :id))
-             (ov (org-remark-find-overlay-in beg end id)))
-        ;; In order to update the overlay, it is first gets deleted
-        ;; and newly loaded.  This way, we avoid duplicate of the same
-        ;; highlight.
-
-        ;; FIXME Currently the when clause is used to guard against
-        ;; the case wheremarkre a highlight overlay is not found.  It should
-        ;; be an edge case but the highlight could have moved to a
-        ;; completely new location where the old location does not
-        ;; overlap with the new location at all.
-        (when ov (org-remark-highlight-clear ov))
-        (push (org-remark-highlight-load highlight) overlays)))
-    (unless update (org-remark-notes-setup notes-buf source-buf))
-    (run-hook-with-args 'org-remark-highlights-after-load-hook
-                        overlays notes-buf))
-  t)
+  (let (overlays) ;; highlight overlays
+    (when-let* ((notes-filename (org-remark-notes-get-file-name))
+                (notes-buf (find-file-noselect notes-filename))
+                (source-buf (current-buffer)))
+      (dolist (highlight (org-remark-highlights-get notes-buf) overlays)
+        (let* ((location (plist-get highlight :location))
+               (beg (car location))
+               (end (cdr location))
+               (id (plist-get highlight :id))
+               (ov (org-remark-find-overlay-in beg end id)))
+          ;; In order to update the overlay, it is first gets deleted
+          ;; and newly loaded.  This way, we avoid duplicate of the same
+          ;; highlight.
+
+          ;; FIXME Currently the when clause is used to guard against
+          ;; the case wheremarkre a highlight overlay is not found.  It should
+          ;; be an edge case but the highlight could have moved to a
+          ;; completely new location where the old location does not
+          ;; overlap with the new location at all.
+          (when ov (org-remark-highlight-clear ov))
+          (push (org-remark-highlight-load highlight) overlays)))
+      (unless update (org-remark-notes-setup notes-buf source-buf))
+      (run-hook-with-args 'org-remark-highlights-after-load-hook
+                          overlays notes-buf)
+      t)))
 
 (defun org-remark-highlights-get-positions (&optional reverse)
   "Return list of the beginning point of all visible highlights in this buffer.



reply via email to

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