Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wip): introducing `org-remark-reveal-p' #90

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions org-remark.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

;; Author: Noboru Ota <me@nobiot.com>
;; Created: 22 December 2020
;; Last modified: 02 November 2024
;; Last modified: 03 November 2024

;; URL: https://github.com/nobiot/org-remark
;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp,
Expand Down Expand Up @@ -830,6 +830,8 @@ Return nil if not and outputs a message in the echo."
(org-remark-find-prev-highlight))))
(if p (progn
(goto-char p)
(when (and org-remark-reveal-p (org-invisible-p (point))
(org-remark--reveal-context)))
;; Setup the overriding keymap.
(unless overriding-terminal-local-map
(let ((prefix-keys (substring (this-single-command-keys) 0 -1))
Expand All @@ -842,6 +844,14 @@ Return nil if not and outputs a message in the echo."
(message "No visible highlights present in the buffer")
nil))))

(defun org-remark--reveal-context ()
(pcase-let
((`(,fn . ,ov)
(get-char-property-and-overlay (point) 'isearch-open-invisible)))
(cond ((and (functionp fn) ov) (funcall fn ov))
((and (derived-mode-p 'org-mode))
(org-fold-show-context 'link-search)))))

(defun org-remark-find-next-highlight ()
"Return the beg point of the next highlight.
Look through `org-remark-highlights' list."
Expand Down Expand Up @@ -1713,6 +1723,18 @@ This function also set `org-remark-highlights' to nil."
(when (overlay-get ov 'org-remark-id)
(delete-overlay ov)))))

(defvar-local org-remark-reveal-p nil)

(defun org-remark-reveal-activate-locally ()
(interactive)
(setq-local org-remark-reveal-p t)
(message "Org-remark-next/prev now show hidden highlighs."))

(defun org-remark-reveal-deactivate-locally ()
(interactive)
(setq-local org-remark-reveal-p nil)
(message "Org-remark-next/prev now keep hidden highlighs hidden."))

(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
Expand All @@ -1728,13 +1750,17 @@ If none, return nil."
(lambda (h)
(let ((p (overlay-start h)))
;; Checking if the p is visible or not
(if (or
(> p (point-max))
(< p (point-min))
;; When the highlight is within a visible folded
;; area, this function returns 'outline
(org-invisible-p p))
nil p)))
(cond ((or (> p (point-max)) (< p (point-min))) nil)
;; When the highlight is within a visible folded
;; area, this function returns 'outline

;; When `org-remark-reveal-p' is non-nil, invisible
;; highlights due to folding will be
;; revealed. Those highlights outside the narrowed
;; regions will remain hidden.
((org-invisible-p p)
(if org-remark-reveal-p p nil))
(t p))))
list))
(setq list (remove nil list))
(when list
Expand Down
Loading