Skip to content

Commit

Permalink
fix: Highlights overlay can get added to unsupported buffer
Browse files Browse the repository at this point in the history
Before this fix, a highlight could be added to an unsupported buffer
such as *scratch* buffer. When you try to remove it, you get an error
message. This is all confusing.

Now with this fix, trying to add a highlight in an unnsupported buffer,
you only get a message and the overlay is not to be added.
  • Loading branch information
nobiot committed Sep 29, 2024
1 parent eb79350 commit ef98c27
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions org-remark.el
Original file line number Diff line number Diff line change
Expand Up @@ -749,19 +749,18 @@ not part of the undo tree. You can undo the deletion in the
marginal notes buffer and then save it to sync the highlight back
in the source."
(interactive "d\nP")
(let* ((ov (org-remark-find-dwim point))
(id (overlay-get ov 'org-remark-id)))
(when (and ov id)
;; Remove the highlight overlay and id. If there is more than one,
;; remove only one. It should be last-in-first-out in general but
;; overlays functions don't guarantee it (when delete
;; (org-remark-open point :view-only))
(org-remark-highlight-clear ov)
;; Update the notes file accordingly
(org-remark-notes-remove id delete)
(org-remark-highlights-housekeep)
(org-remark-highlights-sort)
t)))
(and-let* ((ov (org-remark-find-dwim point))
(id (overlay-get ov 'org-remark-id)))
;; Remove the highlight overlay and id. If there is more than one,
;; remove only one. It should be last-in-first-out in general but
;; overlays functions don't guarantee it (when delete
;; (org-remark-open point :view-only))
(org-remark-highlight-clear ov)
;; Update the notes file accordingly
(org-remark-notes-remove id delete)
(org-remark-highlights-housekeep)
(org-remark-highlights-sort)
t))

(defun org-remark-delete (point &optional arg)
"Delete the highlight at POINT and marginal notes for it.
Expand Down Expand Up @@ -966,11 +965,14 @@ round-trip back to the notes file."
(when org-remark-highlights-hidden (org-remark-highlights-show))
(org-with-wide-buffer
(let* ((org-remark-type (plist-get properties 'org-remark-type))
(ov (org-remark-highlight-make-overlay beg end face org-remark-type))
;;(make-overlay beg end nil :front-advance))
;; UUID is too long; does not have to be the full length
(id (if id id (substring (org-id-uuid) 0 8)))
(filename (org-remark-source-find-file-name)))
(filename (org-remark-source-find-file-name))
;; Add highlight overlay only when filename is assigned.
(ov (when filename
(org-remark-highlight-make-overlay
beg end face org-remark-type))))
(if (not filename)
(message (format "org-remark: Highlights not saved.\
This buffer (%s) is not supported" (symbol-name major-mode)))
Expand Down

0 comments on commit ef98c27

Please sign in to comment.