awth13 / org-appear

Toggle visibility of hidden Org mode element parts upon entering and leaving an element
MIT License
375 stars 19 forks source link

Add support to hide macro markers #40

Open m-h-b-tu opened 2 years ago

m-h-b-tu commented 2 years ago

Org can hide the macro markers using org-hide-macro-markers. This patch adds those to org-appear. I am sorry, I cannot make a pull request because of authentication issues.

diff --git a/org-appear.el b/org-appear.el
index 9541e62..d97bc15 100644
--- a/org-appear.el
+++ b/org-appear.el
@@ -88,6 +88,12 @@ Does not have an effect if `org-hidden-keywords' is nil."
   :type 'boolean
   :group 'org-appear)

+(defcustom org-appear-automacros nil
+  "Non-nil enables automatic toggling of macro markers.
+Does not have an effect if `org-hide-macro-markers' is nil."
+  :type 'boolean
+  :group 'org-appear)
+
 (defcustom org-appear-delay 0.0
   "Seconds of delay before toggling an element."
   :type 'number
@@ -149,7 +155,8 @@ nil if the cursor was not on an element.")
               superscript))
    (entity-elements '(entity))
    (link-elements '(link))
-   (keyword-elements '(keyword)))
+   (keyword-elements '(keyword))
+   (macro-elements '(macro)))

     ;; HACK: is there a better way to do this?
     (setq-local org-appear--prev-elem nil)
@@ -162,6 +169,8 @@ nil if the cursor was not on an element.")
       (setq org-appear-elements (append org-appear-elements entity-elements)))
     (when (and org-link-descriptive org-appear-autolinks)
       (setq org-appear-elements (append org-appear-elements link-elements)))
+    (when (and org-hide-macro-markers org-appear-automacros)
+      (setq org-appear-elements (append org-appear-elements macro-elements)))
     (when (and org-hidden-keywords org-appear-autokeywords)
       (setq org-appear-elements (append org-appear-elements keyword-elements)))))

@@ -290,6 +299,8 @@ Return nil if element cannot be parsed."
              'link)
             ((eq elem-type 'keyword)
              'keyword)
+            ((eq elem-type 'macro)
+             'macro)
             (t nil)))
     (elem-start (org-element-property :begin elem))
     (elem-end (org-element-property :end elem))
@@ -307,11 +318,13 @@ Return nil if element cannot be parsed."
           :visible-start ,(pcase elem-tag
                 ('emph (1+ elem-start))
                 ('script elem-content-start)
-                ('link (or elem-content-start (+ elem-start 2))))
+                ('link (or elem-content-start (+ elem-start 2)))
+                ('macro (or elem-content-start (+ elem-start 3))))
           :visible-end ,(pcase elem-tag
                   ('emph (1- elem-end-real))
                   ('script elem-content-end)
-                  ('link (or elem-content-end (- elem-end-real 2))))))))
+                  ('link (or elem-content-end (- elem-end-real 2)))
+                  ('macro (or elem-content-end (- elem-end-real 3))))))))

 (defun org-appear--show-invisible (elem)
   "Silently remove invisible property from invisible parts of element ELEM."
awth13 commented 2 years ago

Hi, @m-h-b-tu! Thank you for the suggestion and code!

I didn't know about the macro replacement feature in Org but, after reading up on it, your patch seems very useful indeed. I am going to test it and add it to the package.

m-h-b-tu commented 2 years ago

That sounds great.

I use the patch in the form of advices on a daily basis without any problem.

ilupin commented 1 year ago

Hi, @awth13 I have used the patch for a while and it works well. Could it be merged? Thanks.