branch: externals/org-remark commit e27e0d6dadf37535fba960d3decb149984cac27f Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
feat: Add om/toggle for show/hide highlighters --- README.org | 10 +++++++-- marginalia.org | 30 +++++++++++++++++--------- org-marginalia.el | 63 ++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 79 insertions(+), 24 deletions(-) diff --git a/README.org b/README.org index 9db936cfa1..b641d6ae00 100644 --- a/README.org +++ b/README.org @@ -92,6 +92,9 @@ Move to the next highlight if any. If there is none below the cursor, and there - =om/prev= (=C-c n [= by default) :: Move to the previous highlight if any. If there is none above the cursor, and there is a highlight below, loop back to the bottom one. +- =om/toggle= :: +Toggle showing/hiding of highlighters in current buffer. It only affects the display of the highlighters. When hidden, highlights' locations are still kept tracked; thus, upon buffer-save the correct locations are still recorded in the marginalia file. + * Customizing - You can customize settings in the =org-marginalia= group. @@ -109,6 +112,9 @@ Move to the previous highlight if any. If there is none above the cursor, and th :TOC: :depth 0 :END: +** 0.0.3 +- feat: Add om/toggle for show/hide highlighters + ** 0.0.2 - feat: Add om/next and /prev - break: Change om/open-at-point to om/open @@ -131,9 +137,9 @@ Feedback welcome in this repo, or in [[https://org-roam.discourse.group/t/protot I am aiming to keep this package to be small and focused. I plan to add the following features, and probably consider it to be feature complete for my purposes. -1. =om/toggle-display= to toggle show/hide of highlights without losing them +1. DONE v0.0.3 =om/toggle= to toggle show/hide of highlights without losing them 2. =om/next= and =om/prev= to easily navigate highlighted regions in the buffer - This is done, but I would like to try a transient (don't want to repeat the prefix everytime). + This is done (v0.0.2), but I would like to try a transient (don't want to repeat the prefix everytime). * License diff --git a/marginalia.org b/marginalia.org index 0d5f673e89..fd9d2978eb 100644 --- a/marginalia.org +++ b/marginalia.org @@ -31,7 +31,7 @@ For listing, built-in `tabulated-list-mode` exists. Additionallly, hierarchy.el, -** Author +** Nobor :PROPERTIES: :marginalia-id: f323a57f :marginalia-source-beg: 143 @@ -45,19 +45,19 @@ For listing, built-in `tabulated-list-mode` exists. Additionallly, hierarchy.el, ** g . ,end) highlights)))))) [[file:~/local-repos/org-marginalia/org-marginalia.el][org-marginalia]] -** ion +** g (c :PROPERTIES: :marginalia-id: 3cf97a37 -:marginalia-source-beg: 14321 -:marginalia-source-end: 14325 +:marginalia-source-beg: 14606 +:marginalia-source-end: 14610 :END: [[file:~/local-repos/org-marginalia/org-marginalia.el][org-marginalia]] -** ;;;; Requirements +** variable-pitch f :PROPERTIES: :marginalia-id: c16e73f8 -:marginalia-source-beg: 5565 -:marginalia-source-end: 5582 +:marginalia-source-beg: 5850 +:marginalia-source-end: 5867 :END: [[file:~/local-repos/org-marginalia/org-marginalia.el][org-marginalia]] (defun om/list-highlights-positions () @@ -67,10 +67,20 @@ this file, as it is a utility function. This empty declation is necessary in to avoid the macro expansion from failing for `seq-find'.") -** nts +** h f :PROPERTIES: :marginalia-id: f55e13ab -:marginalia-source-beg: 5579 -:marginalia-source-end: 5582 +:marginalia-source-beg: 5864 +:marginalia-source-end: 5867 :END: [[file:~/local-repos/org-marginalia/org-marginalia.el][org-marginalia]] + +** remove-list-of-text-properties beg end +:PROPERTIES: +:marginalia-id: 74fd21ea +:marginalia-source-beg: 22373 +:marginalia-source-end: 22411 +:END: +[[file:~/local-repos/org-marginalia/org-marginalia.el][org-marginalia]] +Note that you can use markers directly wihtin add/remove-text-properties functions. +No need to replace specifically markers with points. diff --git a/org-marginalia.el b/org-marginalia.el index 24b1cb094d..e056b431ae 100644 --- a/org-marginalia.el +++ b/org-marginalia.el @@ -4,8 +4,8 @@ ;; Author: Noboru Ota <m...@nobiot.com> ;; URL: https://github.com/nobiot/org-marginalia -;; Version: 0.0.2 -;; Last modified: 2020-12-23T135735 +;; Version: 0.0.3 +;; Last modified: 2020-12-23T181011 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, writing, note-taking, margin-notes @@ -97,6 +97,11 @@ ;; Move to the previous highlight if any. If there is none above the cursor, ;; and there is a highlight below, loop back to the bottom one. +;; - =om/toggle= :: +;; Toggle showing/hiding of highlighters in current buffer. It only affects +;; the display of the highlighters. When hidden, highlights' locations are +;; still kept tracked; thus, upon buffer-save the correct locations are still +;; recorded in the marginalia file. ;;;; Customizing @@ -158,7 +163,7 @@ separate Org file" (defface om/highlighter '((((class color) (min-colors 88) (background light)) - :underline "#aecf90" :background "#ecf7ed" t) + :underline "#aecf90" :background "#ecf7ed") (((class color) (min-colors 88) (background dark)) :underline "#00422a" :background "#001904" :extend t)) "Face for highlighters." @@ -387,17 +392,25 @@ buffer, go back to the last one." (if (not om/highlights) (message "No highlights present in this buffer.") (goto-char (om/find-prev-highlight)))) -;; WIP -(defun om/toggle-display () - "WIP: Toggle showing/hiding of highlights in current bufer.") +(defun om/toggle () + "Toggle showing/hiding of highlighters in current buffer. +It only affects the display of the highlighters. The locations +are still kept tracked; thus, upon buffer-save the correct +locations are still recorded in the marginalia file." + (interactive) + (when-let ((highlights om/highlights)) + ;; Check the first highlight in the buffer + ;; If it's hidden, all hidden. Show them. + ;; If not, all shown. Hide them. + (if-let* ((beg (car (cdr (nth 0 highlights)))) + (hidden-p (get-char-property beg 'om/hidden))) + (om/show) + (om/hide)) + t)) ;;;; Functions ;;;;; Private -;; `om/make-highlight-marker' and other private utility functions; however, -;; macro expansion (?) in `om/mark' and others do not seem to understand that -;; they are declared in this file. `declare-function' didn't seem to work. -;; Until I figure out how to work with it, I will put this function here. (defun om/save-single-highlight (highlight title source-path) "Save a single HIGHLIGHT in the marginalia file with properties. @@ -471,7 +484,6 @@ If REVERSE is non-nil, return list in the descending order." (defun om/find-next-highlight () "Return the beg point of the next highlight. Look through `om/highlights' list." - (when-let ((points (om/list-highlights-positions))) ;; Find the first occurance of p > (point). If none, this means all the ;; points occur before the current point. Take the first one. Assume @@ -481,13 +493,40 @@ Look through `om/highlights' list." (defun om/find-prev-highlight () "Return the beg point of the previous highlight. Look through `om/highlights' list (in descending order)." - (when-let ((points (om/list-highlights-positions 'reverse))) ;; Find the first occurance of p < (point). If none, this means all the ;; points occur before the current point. Take the first one. Assume ;; `om/highlights' is sorted in the descending order . (seq-find (lambda (p) (< p (point))) points (nth 0 points)))) +(defun om/hide () + "Hide highlighters. +It will remove the font-lock-face of all the highlights, and add +'om/hidden property with value 't. It does not check the current +hidden state, thus not interactive. Use `om/toggle-display' +command to manually toggle the show/hide state." + (when-let ((highlights om/highlights)) + (dolist (highlight highlights) + (let ((beg (car (cdr highlight))) + (end (cdr (cdr highlight)))) + (remove-list-of-text-properties beg end '(font-lock-face)) + (add-text-properties beg end (list 'om/hidden t)))) + t)) + +(defun om/show () + "Show highlighters. +It adds the font-lock-face to all the highlighted text regions. +It does not check the current hidden state, thus not interactive. +Use `om/toggle-display' command to manually toggle the show/hide +state." + (when-let ((highlights om/highlights)) + (dolist (highlight highlights) + (let ((beg (car (cdr highlight))) + (end (cdr (cdr highlight)))) + (remove-list-of-text-properties beg end '(om/hidden)) + (add-text-properties beg end '(font-lock-face om/highlighter)))) + t)) + ;;;; Footer (provide 'org-marginalia)