~bzg/org-mode

b03ece433b10f17e71cd48f857119e9a3b290899 — Ihor Radchenko a month ago 17072a4
org-fold: Optimize fontification of link folds

* lisp/org-fold-core.el (org-fold-core--specs): Add new folding spec -
:font-lock.  When non-nil, enable re-fontification of the folds.
(org-fold-core-region): Only trigger re-fontification when the folding
spec has :font-lock property.
* lisp/org-fold.el (org-fold-initialize): Only enable re-fontification
of folded outlines, drawers, and blocks.
2 files changed, 23 insertions(+), 15 deletions(-)

M lisp/org-fold-core.el
M lisp/org-fold.el
M lisp/org-fold-core.el => lisp/org-fold-core.el +20 -15
@@ 381,6 381,9 @@ The following properties are known:
                       `buffer-invisibility-spec' will be used as is.
                       Note that changing this property from nil to t may
                       clear the setting in `buffer-invisibility-spec'.
- :font-lock        :: non-nil means that newlines after the fold should
                       be re-fontified upon folding/unfolding.  See
                       `org-activate-folds'.
- :alias            :: a list of aliases for the SPEC-SYMBOL.
- :fragile          :: Must be a function accepting two arguments.
                       Non-nil means that changes in region may cause


@@ 1043,18 1046,19 @@ If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
       ;; last as per Emacs defaults.  This makes :extend faces span
       ;; past the ellipsis.  See bug#65896.  The face properties are
       ;; assigned via `org-activate-folds'.
       (when (equal ?\n (char-after from))
         (font-lock-flush from (1+ from)))
       (when (equal ?\n (char-after to))
         (font-lock-flush to (1+ to)))
       (dolist (region (org-fold-core-get-regions :from from :to to :specs spec))
         (when (equal ?\n (char-after (cadr region)))
           (font-lock-flush (cadr region) (1+ (cadr region))))
         ;; Re-fontify beginning of the fold - we may
         ;; unfold inside an existing fold, with FROM begin a newline
         ;; after spliced fold.
         (when (equal ?\n (char-after (car region)))
           (font-lock-flush (car region) (1+ (car region)))))
       (when (or (not spec) (org-fold-core-get-folding-spec-property spec :font-lock))
         (when (equal ?\n (char-after from))
           (font-lock-flush from (1+ from)))
         (when (equal ?\n (char-after to))
           (font-lock-flush to (1+ to)))
         (dolist (region (org-fold-core-get-regions :from from :to to :specs spec))
           (when (equal ?\n (char-after (cadr region)))
             (font-lock-flush (cadr region) (1+ (cadr region))))
           ;; Re-fontify beginning of the fold - we may
           ;; unfold inside an existing fold, with FROM begin a newline
           ;; after spliced fold.
           (when (equal ?\n (char-after (car region)))
             (font-lock-flush (car region) (1+ (car region))))))
       (when (eq org-fold-core-style 'overlays)
         (if org-fold-core--keep-overlays
             (mapc


@@ 1118,9 1122,10 @@ If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
	     (remove-text-properties from to (list (org-fold-core--property-symbol-get-create spec) nil)))))
       ;; Re-calculate trailing faces for all the folds revealed
       ;; by unfolding or created by folding.
       (dolist (region (org-fold-core-get-regions :from from :to to :specs spec))
         (when (equal ?\n (char-after (cadr region)))
           (font-lock-flush (cadr region) (1+ (cadr region)))))))))
       (when (or (not spec) (org-fold-core-get-folding-spec-property spec :font-lock))
         (dolist (region (org-fold-core-get-regions :from from :to to :specs spec))
           (when (equal ?\n (char-after (cadr region)))
             (font-lock-flush (cadr region) (1+ (cadr region))))))))))

(cl-defmacro org-fold-core-regions (regions &key override clean-markers relative)
  "Fold every region in REGIONS list in current buffer.

M lisp/org-fold.el => lisp/org-fold.el +3 -0
@@ 255,6 255,7 @@ Also, see `org-fold-catch-invisible-edits'."
      (:ellipsis . ,ellipsis)
      (:fragile . ,#'org-fold--reveal-outline-maybe)
      (:isearch-open . t)
      (:font-lock . t)
      ;; This is needed to make sure that inserting a
      ;; new planning line in folded heading is not
      ;; revealed.  Also, the below combination of :front-sticky and


@@ 267,6 268,7 @@ Also, see `org-fold-catch-invisible-edits'."
      (:ellipsis . ,ellipsis)
      (:fragile . ,#'org-fold--reveal-drawer-or-block-maybe)
      (:isearch-open . t)
      (:font-lock . t)
      (:front-sticky . t)
      (:alias . ( block center-block comment-block
                  dynamic-block example-block export-block


@@ 276,6 278,7 @@ Also, see `org-fold-catch-invisible-edits'."
      (:ellipsis . ,ellipsis)
      (:fragile . ,#'org-fold--reveal-drawer-or-block-maybe)
      (:isearch-open . t)
      (:font-lock . t)
      (:front-sticky . t)
      (:alias . (drawer property-drawer)))
     ,org-link--description-folding-spec