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

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

[elpa] externals/org-modern d54950fe0f 1/2: Prettify stars as a whole, F


From: ELPA Syncer
Subject: [elpa] externals/org-modern d54950fe0f 1/2: Prettify stars as a whole, Fix #106
Date: Thu, 9 Mar 2023 12:58:21 -0500 (EST)

branch: externals/org-modern
commit d54950fe0f68778b2c921131f4b59e00da395004
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Prettify stars as a whole, Fix #106
    
    - Unfortunately promotion/demotion does not trigger proper refontification.
    Therefore we install an `org-after-promote-entry-hook'.
    
    - org-modern-hide-stars=leading is incompatible with 
org-hide-leading-stars=t.
    Therefore org-hide-leading-stars is temporarily disabled in that case.
---
 org-modern.el | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/org-modern.el b/org-modern.el
index 74817b2617..10217d2776 100644
--- a/org-modern.el
+++ b/org-modern.el
@@ -333,6 +333,7 @@ the font.")
 (defvar-local org-modern--font-lock-keywords nil)
 (defvar-local org-modern--star-cache nil)
 (defvar-local org-modern--hide-stars-cache nil)
+(defvar-local org-modern--reset-hide-leading-stars nil)
 (defvar-local org-modern--checkbox-cache nil)
 (defvar-local org-modern--progress-cache nil)
 (defvar-local org-modern--table-sp-width 0)
@@ -481,9 +482,11 @@ the font.")
                                   (nth (logand i 1)
                                        org-modern--hide-stars-cache))))
     (when org-modern-star
-      (put-text-property end (1+ end) 'display
-                         (aref org-modern--star-cache
-                               (min (1- (length org-modern--star-cache)) 
level))))))
+      (put-text-property
+       (if (eq org-modern-hide-stars 'leading) beg end)
+       (1+ end) 'display
+       (aref org-modern--star-cache
+             (min (1- (length org-modern--star-cache)) level))))))
 
 (defun org-modern--table ()
   "Prettify vertical table lines."
@@ -658,11 +661,9 @@ the font.")
         (0 (org-modern--checkbox)))))
    (when (or org-modern-star org-modern-hide-stars)
      `(("^\\(\\**\\)\\* "
-        ,@(and (not (eq org-modern-hide-stars t))
-               (or org-modern-star (stringp org-modern-hide-stars))
-               '((0 (org-modern--star))))
-        ,@(and (eq org-modern-hide-stars 'leading) '((1 '(face nil invisible 
org-modern))))
-        ,@(and (eq org-modern-hide-stars t) '((0 '(face nil invisible 
org-modern)))))))
+        (0 ,(if (eq org-modern-hide-stars t)
+                ''(face nil invisible org-modern)
+              '(org-modern--star))))))
    (when org-modern-horizontal-rule
      `(("^[ \t]*-\\{5,\\}$" 0
         '(face org-modern-horizontal-rule display
@@ -750,9 +751,15 @@ the font.")
   "Modern looks for Org."
   :global nil
   :group 'org-modern
+  (when org-modern--reset-hide-leading-stars
+    (setq-local org-hide-leading-stars t
+                org-modern--reset-hide-leading-stars nil))
   (cond
    (org-modern-mode
     (add-to-invisibility-spec 'org-modern)
+    (when (and (eq org-modern-hide-stars 'leading) org-hide-leading-stars)
+      (setq-local org-modern--reset-hide-leading-stars t
+                  org-hide-leading-stars nil))
     (setq
      org-modern--star-cache
      (vconcat (mapcar #'org-modern--symbol org-modern-star))
@@ -774,6 +781,8 @@ the font.")
     (font-lock-add-keywords nil org-modern--font-lock-keywords)
     (setq-local font-lock-unfontify-region-function #'org-modern--unfontify)
     (add-hook 'pre-redisplay-functions #'org-modern--pre-redisplay nil 'local)
+    (add-hook 'org-after-promote-entry-hook #'org-modern--unfontify-line nil 
'local)
+    (add-hook 'org-after-demote-entry-hook #'org-modern--unfontify-line nil 
'local)
     (org-modern--update-label-face)
     (org-modern--update-fringe-bitmaps))
    (t
@@ -781,13 +790,19 @@ the font.")
     (font-lock-remove-keywords nil org-modern--font-lock-keywords)
     (font-lock-add-keywords nil org-font-lock-keywords)
     (setq-local font-lock-unfontify-region-function #'org-unfontify-region)
-    (remove-hook 'pre-redisplay-functions #'org-modern--pre-redisplay 'local)))
+    (remove-hook 'pre-redisplay-functions #'org-modern--pre-redisplay 'local)
+    (remove-hook 'org-after-promote-entry-hook #'org-modern--unfontify-line 
'local)
+    (remove-hook 'org-after-demote-entry-hook #'org-modern--unfontify-line 
'local)))
   (save-restriction
     (widen)
     (with-silent-modifications
       (org-modern--unfontify (point-min) (point-max)))
     (font-lock-flush)))
 
+(defun org-modern--unfontify-line ()
+  "Unfontify prettified elements on current line."
+  (org-modern--unfontify (pos-bol) (pos-eol)))
+
 (defun org-modern--unfontify (beg end &optional _loud)
   "Unfontify prettified elements between BEG and END."
   (let ((font-lock-extra-managed-props



reply via email to

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