From: Timothy <tecosaur@gmail.com>
To: Tobias Zawada <i_inbox@tn-home.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Bug: org-src-font-lock-fontify-block should be wrapped with save-match-data [9.3.7 (9.3.7-4-gba6ca7-elpaplus @ mixed installation! /mnt/c/Users/toz/Weiterbildung/Soft/Emacs/ and /mnt/c/Users/toz/.emacs.d/elpa/org-plus-contrib-20200615/)
Date: Mon, 23 Aug 2021 15:45:17 +0800 [thread overview]
Message-ID: <87r1ektxe3.fsf@gmail.com> (raw)
In-Reply-To: <1100798379.523019.1629454049171@email.ionos.de>
[-- Attachment #1: Type: text/plain, Size: 358 bytes --]
Hi Tobias,
Thanks for your efforts. I have prepared a patch accordingly that wraps
org-src-font-lock-fontify-block’s body with save-match-data (attached).
If I don’t hear anything bad about it in the next few days, I’ll push it :)
Please let me know if my commit message agrees with your understanding of the
issue.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-Save-match-data-when-fontifying-src-block.patch --]
[-- Type: text/x-patch, Size: 4409 bytes --]
From c435fd41428b6eb4f9f7971e73ca0a422006461b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 23 Aug 2021 15:09:24 +0800
Subject: [PATCH] org-src: Save match data when fontifying src block
* lisp/org-src.el (org-src-font-lock-fontify-block): Since
`org-src-font-lock-fontify-block' modifies match data during
fontification, when called in `org-fontify-meta-lines-and-blocks-1' by
`font-lock-fontify-region' the text property font-lock-multiline is
applied to text from the beginning to the last match. Since there is a
difference in buffer sizes, the match data is invalid and problematic.
This issue can drastically slow down editing operations in large source
blocks. This can be avoided simply by wrapping `save-match-data' around
`org-src-font-lock-fontify-block'.
Reported by: "Tobias Zawada" <i_inbox@tn-home.de>
<https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00307.html>
---
lisp/org-src.el | 69 +++++++++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 34 deletions(-)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 4698c6dd2..ce33e1f54 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -586,40 +586,41 @@ (defun org-src-font-lock-fontify-block (lang start end)
"Fontify code block.
This function is called by emacs automatic fontification, as long
as `org-src-fontify-natively' is non-nil."
- (let ((lang-mode (org-src-get-lang-mode lang)))
- (when (fboundp lang-mode)
- (let ((string (buffer-substring-no-properties start end))
- (modified (buffer-modified-p))
- (org-buffer (current-buffer)))
- (remove-text-properties start end '(face nil))
- (with-current-buffer
- (get-buffer-create
- (format " *org-src-fontification:%s*" lang-mode))
- (let ((inhibit-modification-hooks nil))
- (erase-buffer)
- ;; Add string and a final space to ensure property change.
- (insert string " "))
- (unless (eq major-mode lang-mode) (funcall lang-mode))
- (org-font-lock-ensure)
- (let ((pos (point-min)) next)
- (while (setq next (next-property-change pos))
- ;; Handle additional properties from font-lock, so as to
- ;; preserve, e.g., composition.
- (dolist (prop (cons 'face font-lock-extra-managed-props))
- (let ((new-prop (get-text-property pos prop)))
- (put-text-property
- (+ start (1- pos)) (1- (+ start next)) prop new-prop
- org-buffer)))
- (setq pos next))))
- ;; Add Org faces.
- (let ((src-face (nth 1 (assoc-string lang org-src-block-faces t))))
- (when (or (facep src-face) (listp src-face))
- (font-lock-append-text-property start end 'face src-face))
- (font-lock-append-text-property start end 'face 'org-block))
- (add-text-properties
- start end
- '(font-lock-fontified t fontified t font-lock-multiline t))
- (set-buffer-modified-p modified)))))
+ (save-match-data
+ (let ((lang-mode (org-src-get-lang-mode lang)))
+ (when (fboundp lang-mode)
+ (let ((string (buffer-substring-no-properties start end))
+ (modified (buffer-modified-p))
+ (org-buffer (current-buffer)))
+ (remove-text-properties start end '(face nil))
+ (with-current-buffer
+ (get-buffer-create
+ (format " *org-src-fontification:%s*" lang-mode))
+ (let ((inhibit-modification-hooks nil))
+ (erase-buffer)
+ ;; Add string and a final space to ensure property change.
+ (insert string " "))
+ (unless (eq major-mode lang-mode) (funcall lang-mode))
+ (org-font-lock-ensure)
+ (let ((pos (point-min)) next)
+ (while (setq next (next-property-change pos))
+ ;; Handle additional properties from font-lock, so as to
+ ;; preserve, e.g., composition.
+ (dolist (prop (cons 'face font-lock-extra-managed-props))
+ (let ((new-prop (get-text-property pos prop)))
+ (put-text-property
+ (+ start (1- pos)) (1- (+ start next)) prop new-prop
+ org-buffer)))
+ (setq pos next))))
+ ;; Add Org faces.
+ (let ((src-face (nth 1 (assoc-string lang org-src-block-faces t))))
+ (when (or (facep src-face) (listp src-face))
+ (font-lock-append-text-property start end 'face src-face))
+ (font-lock-append-text-property start end 'face 'org-block))
+ (add-text-properties
+ start end
+ '(font-lock-fontified t fontified t font-lock-multiline t))
+ (set-buffer-modified-p modified))))))
\f
;;; Escape contents
--
2.32.0
next prev parent reply other threads:[~2021-08-23 7:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-20 10:07 Bug: org-src-font-lock-fontify-block should be wrapped with save-match-data [9.3.7 (9.3.7-4-gba6ca7-elpaplus @ mixed installation! /mnt/c/Users/toz/Weiterbildung/Soft/Emacs/ and /mnt/c/Users/toz/.emacs.d/elpa/org-plus-contrib-20200615/) Tobias Zawada
2021-08-23 7:45 ` Timothy [this message]
2021-08-24 16:57 ` Maxim Nikulin
2021-08-25 8:07 ` What happened to ./contrib? Martin Steffen
2021-08-25 8:44 ` Tim Cross
2021-08-25 11:47 ` Maxim Nikulin
2021-08-25 11:56 ` Bug: org-src-font-lock-fontify-block should be wrapped with save-match-data [9.3.7 (9.3.7-4-gba6ca7-elpaplus @ mixed installation! /mnt/c/Users/toz/Weiterbildung/Soft/Emacs/ and /mnt/c/Users/toz/.emacs.d/elpa/org-plus-contrib-20200615/) Maxim Nikulin
2021-08-31 11:28 ` Timothy
2021-08-25 4:05 Tobias Zawada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1ektxe3.fsf@gmail.com \
--to=tecosaur@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=i_inbox@tn-home.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).