|
@@ -746,7 +746,8 @@ future org buffers."
|
|
|
(add-hook 'clone-indirect-buffer-hook #'org-fold-core-decouple-indirect-buffer-folds nil 'local)
|
|
|
;; Optimise buffer fontification to not fontify folded text.
|
|
|
(when (eq font-lock-fontify-region-function #'font-lock-default-fontify-region)
|
|
|
- (setq-local font-lock-fontify-region-function 'org-fold-core-fontify-region))
|
|
|
+ (setq-local font-lock-fontify-region-function 'org-fold-core-fontify-region)
|
|
|
+ (add-to-list 'font-lock-extra-managed-props 'org-fold-core-fontified))
|
|
|
;; Setup killing text
|
|
|
(setq-local filter-buffer-substring-function #'org-fold-core--buffer-substring-filter)
|
|
|
(if (and (boundp 'isearch-opened-regions)
|
|
@@ -1429,35 +1430,47 @@ The arguments and return value are as specified for `filter-buffer-substring'."
|
|
|
return-string))
|
|
|
|
|
|
;;; Do not fontify folded text until needed.
|
|
|
-
|
|
|
+(defvar org-fold-core--force-fontification nil
|
|
|
+ "Let-bind this variable to t in order to force fontification in
|
|
|
+folded regions.")
|
|
|
(defun org-fold-core-fontify-region (beg end loudly &optional force)
|
|
|
"Run `font-lock-default-fontify-region' in visible regions."
|
|
|
- (let ((pos beg) next
|
|
|
- (org-fold-core--fontifying t))
|
|
|
- (while (< pos end)
|
|
|
- (setq next (org-fold-core-next-folding-state-change
|
|
|
- (if force nil
|
|
|
- (let (result)
|
|
|
- (dolist (spec (org-fold-core-folding-spec-list))
|
|
|
- (when (and (not (org-fold-core-get-folding-spec-property spec :visible))
|
|
|
- (org-fold-core-get-folding-spec-property spec :font-lock-skip))
|
|
|
- (push spec result)))
|
|
|
- result))
|
|
|
- pos
|
|
|
- end))
|
|
|
- (while (and (not (catch :found
|
|
|
- (dolist (spec (org-fold-core-get-folding-spec 'all next))
|
|
|
- (when (org-fold-core-get-folding-spec-property spec :font-lock-skip)
|
|
|
- (throw :found spec)))))
|
|
|
- (< next end))
|
|
|
- (setq next (org-fold-core-next-folding-state-change nil next end)))
|
|
|
- (save-excursion
|
|
|
- (font-lock-default-fontify-region pos next loudly)
|
|
|
- (save-match-data
|
|
|
- (unless (<= pos (point) next)
|
|
|
- (run-hook-with-args 'org-fold-core-first-unfold-functions pos next))))
|
|
|
- (put-text-property pos next 'org-fold-core-fontified t)
|
|
|
- (setq pos next))))
|
|
|
+ (with-silent-modifications
|
|
|
+ (let ((pos beg) next
|
|
|
+ (force (or force org-fold-core--force-fontification))
|
|
|
+ (org-fold-core--fontifying t)
|
|
|
+ (skip-specs
|
|
|
+ (let (result)
|
|
|
+ (dolist (spec (org-fold-core-folding-spec-list))
|
|
|
+ (when (and (not (org-fold-core-get-folding-spec-property spec :visible))
|
|
|
+ (org-fold-core-get-folding-spec-property spec :font-lock-skip))
|
|
|
+ (push spec result)))
|
|
|
+ result)))
|
|
|
+ ;; Move POS to first visible point within BEG..END.
|
|
|
+ (while (and (catch :found
|
|
|
+ (dolist (spec (org-fold-core-get-folding-spec 'all pos))
|
|
|
+ (when (org-fold-core-get-folding-spec-property spec :font-lock-skip)
|
|
|
+ (throw :found spec))))
|
|
|
+ (< pos end))
|
|
|
+ (setq pos (org-fold-core-next-folding-state-change nil pos end)))
|
|
|
+ (when force (setq pos beg next end))
|
|
|
+ (while (< pos end)
|
|
|
+ (unless force
|
|
|
+ (setq next (org-fold-core-next-folding-state-change skip-specs pos end)))
|
|
|
+ ;; Move to the end of the region to be fontified.
|
|
|
+ (while (and (not (catch :found
|
|
|
+ (dolist (spec (org-fold-core-get-folding-spec 'all next))
|
|
|
+ (when (org-fold-core-get-folding-spec-property spec :font-lock-skip)
|
|
|
+ (throw :found spec)))))
|
|
|
+ (< next end))
|
|
|
+ (setq next (org-fold-core-next-folding-state-change nil next end)))
|
|
|
+ (save-excursion
|
|
|
+ (font-lock-default-fontify-region pos next loudly)
|
|
|
+ (save-match-data
|
|
|
+ (unless (<= pos (point) next)
|
|
|
+ (run-hook-with-args 'org-fold-core-first-unfold-functions pos next))))
|
|
|
+ (put-text-property pos next 'org-fold-core-fontified t)
|
|
|
+ (setq pos next)))))
|
|
|
|
|
|
(defun org-fold-core-update-optimisation (beg end)
|
|
|
"Update huge buffer optimisation between BEG and END.
|