[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 3da1b2d240 31/44: org-fold-core: Fix fontification
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 3da1b2d240 31/44: org-fold-core: Fix fontification inside folded regions |
Date: |
Mon, 25 Apr 2022 07:57:58 -0400 (EDT) |
branch: externals/org
commit 3da1b2d240f8e208c248c61d4505bd0dc1ee85dc
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>
org-fold-core: Fix fontification inside folded regions
* lisp/org-fold-core.el (org-fold-core-initialize): Declare
`org-fold-core-fontified' text property for font-lock.
(org-fold-core--force-fontification): New variable controlling forced
fontification inside folded regions.
(org-fold-core-fontify-region): Fix cases when BEG is inside folded
region. Respect `org-fold-core--force-fontification'.
* lisp/org-macs.el (org-with-forced-fontification): New macro.
(org-buffer-substring-fontified):
(org-looking-at-fontified): Do not rely on jit-lock. Use
`org-fold-core-fontified' text property to determine whether text is
already fontified.
---
lisp/org-fold-core.el | 69 ++++++++++++++++++++++++++++++---------------------
lisp/org-macs.el | 31 +++++++++++++++++++++++
2 files changed, 72 insertions(+), 28 deletions(-)
diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el
index 121c6b5c48..edae316ff4 100644
--- a/lisp/org-fold-core.el
+++ b/lisp/org-fold-core.el
@@ -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.
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index a1d514d501..5e67281018 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -39,6 +39,7 @@
(declare-function org-fold-show-context "org-fold" (&optional key))
(declare-function org-fold-save-outline-visibility "org-fold" (use-markers
&rest body))
(declare-function org-fold-next-visibility-change "org-fold" (&optional pos
limit ignore-hidden-p previous-p))
+(declare-function org-fold-core-with-forced-fontification "org-fold" (&rest
body))
(declare-function org-fold-folded-p "org-fold" (&optional pos limit
ignore-hidden-p previous-p))
(declare-function string-collate-lessp "org-compat" (s1 s2 &optional locale
ignore-case))
@@ -1178,6 +1179,36 @@ so values can contain further %-escapes if they are
define later in TABLE."
org-emphasis t)
"Properties to remove when a string without properties is wanted.")
+(defvar org-fold-core--force-fontification)
+(defmacro org-with-forced-fontification (&rest body)
+ "Run BODY forcing fontification of folded regions."
+ (declare (debug (form body)) (indent 1))
+ `(unwind-protect
+ (progn
+ (setq org-fold-core--force-fontification t)
+ ,@body)
+ (setq org-fold-core--force-fontification nil)))
+
+(defun org-buffer-substring-fontified (beg end)
+ "Return fontified region between BEG and END."
+ (when (bound-and-true-p jit-lock-mode)
+ (org-with-forced-fontification
+ (when (text-property-not-all beg end 'org-fold-core-fontified t)
+ (save-match-data (font-lock-fontify-region beg end)))))
+ (buffer-substring beg end))
+
+(defun org-looking-at-fontified (re)
+ "Call `looking-at' RE and make sure that the match is fontified."
+ (prog1 (looking-at re)
+ (when (bound-and-true-p jit-lock-mode)
+ (org-with-forced-fontification
+ (when (text-property-not-all
+ (match-beginning 0) (match-end 0)
+ 'org-fold-core-fontified t)
+ (save-match-data
+ (font-lock-fontify-region (match-beginning 0)
+ (match-end 0))))))))
+
(defsubst org-no-properties (s &optional restricted)
"Remove all text properties from string S.
When RESTRICTED is non-nil, only remove the properties listed
- [elpa] externals/org 2249f4d7e5 42/44: org-fold-core-fontify-region: Remove unused variable, (continued)
- [elpa] externals/org 2249f4d7e5 42/44: org-fold-core-fontify-region: Remove unused variable, ELPA Syncer, 2022/04/25
- [elpa] externals/org 407104459b 44/44: org-fold: Honour `org-fold-show-context-detail' for isearch, ELPA Syncer, 2022/04/25
- [elpa] externals/org 219bc6c2d3 37/44: org-fold-core-fontify-region: Fix cases when fontification is not registered, ELPA Syncer, 2022/04/25
- [elpa] externals/org a6eab82fd6 16/44: Obsolete old function names that are now in org-fold, ELPA Syncer, 2022/04/25
- [elpa] externals/org f813f10818 26/44: Rename remaining org-force-cycle-archived → org-cycle-force-archived, ELPA Syncer, 2022/04/25
- [elpa] externals/org 2e3566e1e9 28/44: org-string-width: Handle undefined behaviour in older Emacs, ELPA Syncer, 2022/04/25
- [elpa] externals/org 240a14988f 24/44: Fix typo: delete-duplicates → delete-dups, ELPA Syncer, 2022/04/25
- [elpa] externals/org 52a0ef94c9 23/44: Backport contributed commits, ELPA Syncer, 2022/04/25
- [elpa] externals/org baffebbc33 25/44: Fix bug in org-get-heading, ELPA Syncer, 2022/04/25
- [elpa] externals/org e8d8db63a0 19/44: Restore old visibility behaviour of org-refile, ELPA Syncer, 2022/04/25
- [elpa] externals/org 3da1b2d240 31/44: org-fold-core: Fix fontification inside folded regions,
ELPA Syncer <=
- [elpa] externals/org d048c153dd 08/44: org-string-width: Reimplement to work with new folding, ELPA Syncer, 2022/04/25
- [elpa] externals/org fa7530c7b4 09/44: Rename old function call to use org-fold, ELPA Syncer, 2022/04/25
- [elpa] externals/org 312f39a05d 41/44: org-string-width: Do not remove face info when PIXELS is non-nil, ELPA Syncer, 2022/04/25
- [elpa] externals/org 0bca8bc418 30/44: org-fold-show-set-visibility: Fix edge case when folded region is at BOB, ELPA Syncer, 2022/04/25
- [elpa] externals/org a8f4270ac1 21/44: org-manual: Update to new org-fold function names, ELPA Syncer, 2022/04/25
- [elpa] externals/org 0daa209a74 29/44: org-string-width: Work around `window-pixel-width' bug in old Emacs, ELPA Syncer, 2022/04/25
- [elpa] externals/org d2775da08d 35/44: test-ol/org-toggle-link-display: Fix compatibility with old Emacs, ELPA Syncer, 2022/04/25
- [elpa] externals/org 24c1c877cf 43/44: org-fold-core-fontify-region: Calculate jit-lock-bounds accurately, ELPA Syncer, 2022/04/25
- [elpa] externals/org 17e762426d 18/44: Move `org-buffer-list' to org-macs.el, ELPA Syncer, 2022/04/25
- [elpa] externals/org 3fba34900e 27/44: Fix org-fold--hide-drawers--overlays, ELPA Syncer, 2022/04/25