From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YJsWAuxSI2HUXwAAgWs5BA (envelope-from ) for ; Mon, 23 Aug 2021 09:49:00 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id AMB+OetSI2HjfAAA1q6Kng (envelope-from ) for ; Mon, 23 Aug 2021 07:48:59 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3204D3516 for ; Mon, 23 Aug 2021 09:48:59 +0200 (CEST) Received: from localhost ([::1]:48774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mI4hV-0005av-GU for larch@yhetil.org; Mon, 23 Aug 2021 03:48:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mI4gm-0005an-A9 for emacs-orgmode@gnu.org; Mon, 23 Aug 2021 03:48:12 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:45572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mI4gk-0006NL-GQ for emacs-orgmode@gnu.org; Mon, 23 Aug 2021 03:48:12 -0400 Received: by mail-pj1-x102d.google.com with SMTP id f11-20020a17090aa78b00b0018e98a7cddaso1114629pjq.4 for ; Mon, 23 Aug 2021 00:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:references:user-agent:in-reply-to :message-id:mime-version; bh=sLvq6h5LD+95ARcNi/QhuoVNivQ/Swk2VjW0nqW/I2M=; b=BnSnAKLItSXQZx2MKRNy3QAMxC3zFVtbwKGzTYujKxai2GSNEVAgi90hJSZ29JPI/k nYk17vvUlHDd10J9F3HftE/UHlKYuXU1KiAFMkZ3jPcNfr7ZTl5T2MbURlb4rlc7e6h2 N2PbQxGGZXxT+3+oSe0SeEBga0KpI91gKs2noCodmWTN9rB4XbXQEsz2rHPExBVLWabQ 2O8gCOy6AFiBkoQExGTARWLVNm8cIZ5R6UMlCOyEwC+6nYXgdpYeJJo8lrgXVunUQWEu R9ugx1KhakXkb4VTJnjoSBv/RUS6tedz4qP0ssuyPZp3HuUxgVQATQG0jTWZ4fDIFWxX 56Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:references:user-agent :in-reply-to:message-id:mime-version; bh=sLvq6h5LD+95ARcNi/QhuoVNivQ/Swk2VjW0nqW/I2M=; b=ZL8rG+dllVAuJ0oB4c1PBdMg59w2KzxuUtWmQwIlLSlepwALNYuJP9pIYGGNT3zpdk f01sDbnK1gHQM1+BmyFF0MNonBVcZdx39f/iem8BwvIluVWvf2FiPjW8F/OVK5ThtZWS LLHdfvJrf8ooe8JMcBG5SKgpAGKhf2wDJWKhhjf6wwSnk5s6K7PfyCH0ERnwZwJQhKLZ +xyxQnEbqmrLl3FWmUft9mhJzNbWqipENfRApWWC1DK1osYmgFODprzU8qmYoE/ySGEA 0XpNI3cx1w74BqDt524u/YssZFJOL4PadgCeWbDelW0nCUuakcLv4vI476/SVHqQNRwF 17WA== X-Gm-Message-State: AOAM531cvqukkrbnkB0oGXEBL/mrUcPHv09A4KqglW+Ackb9y4IeqOl+ 2d3cBcDWKh/m1MRmyEau+DI= X-Google-Smtp-Source: ABdhPJzUEeug659Ncx9z1wcQCrWIHIeS1FEVU5geOPq3K+JsQGz/+f2w1J3LhkZcsaIacZb68hTyrg== X-Received: by 2002:a17:902:8543:b029:12d:461f:a6a8 with SMTP id d3-20020a1709028543b029012d461fa6a8mr27668339plo.1.1629704888885; Mon, 23 Aug 2021 00:48:08 -0700 (PDT) Received: from localhost (61-245-128-160.3df580.per.nbn.aussiebb.net. [61.245.128.160]) by smtp.gmail.com with ESMTPSA id k197sm14945562pfd.190.2021.08.23.00.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 00:48:08 -0700 (PDT) From: Timothy To: Tobias Zawada 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 References: <1100798379.523019.1629454049171@email.ionos.de> User-agent: mu4e 1.6.1; emacs 28.0.50 In-reply-to: <1100798379.523019.1629454049171@email.ionos.de> Message-ID: <87r1ektxe3.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=tecosaur@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1629704939; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=YZNXbhcFrs/Z2tXcCfE3jIQl4pFPiYMOtAKSRHrukJk=; b=dMXmFLzssPrOJWG/EuaGwXd+iAbpX/RQM6leXD6oIUpi5AWqD2cVGZs9Y9WMxCTGuF3w++ rZ+2AHt8a/jqxN6f80w8fZM9hmUSDjHTcFtG6MFsJviHJ+msT9IBdrqEniH4MOXnmU3+ki eUo3PrMN6ztvgdt1pCUXdA5xx7DBraH9GX4IMpwOLDDSLJgZ6pcNrfzlyOGNLmzo7gvp+M +zmefF6PaZqHZqCqIHhu/2icY+ho6RReaXcgFZ25sX5KQ7N2NMJ/ql/XAxmMLIPjWKCAFM PMdvvR+j2XEowJyr9uTkV0w7niTbpmCLnhO2kMDPObCwyTw4iGWo/WQ8kg/1Uw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629704939; a=rsa-sha256; cv=none; b=PfNJDWkG2KtL5dl0mURD6idWL/osE0jXYf0iWQLrYsBTeqFVTDZKg3gBRCwL7TytcAE4sm iWKUjNGm/sYKYHdfsi2wOEbJQ99UIp35DBSdqyKrrb7kX+mfPso/kvGcsRWB+xPKVj8boY xObC/0c06l3BKLh6vaDF4R9xD4ASpL0DSq09pKRMWTGbPpqg0IAHJUujU8sQSrmrAwGY8V zW09OP/lP4ftB3wOH47Vd/WmSa8OEXUld9oDYQQJgye/tQvDEu9sfwvdfqFSE5qAnlXEk0 /rQZpiKO5uP2W61/aw+VwjZy5gf6LY7ICenE0WyWPLzvGaqk3B7rwRW6nvSr7A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=BnSnAKLI; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: 0.54 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=BnSnAKLI; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 3204D3516 X-Spam-Score: 0.54 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9gghCloSHeIp --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Tobias, Thanks for your efforts. I have prepared a patch accordingly that wraps org-src-font-lock-fontify-block=E2=80=99s body with save-match-data (attach= ed). If I don=E2=80=99t hear anything bad about it in the next few days, I=E2=80= =99ll push it :) Please let me know if my commit message agrees with your understanding of t= he issue. All the best, Timothy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-src-Save-match-data-when-fontifying-src-block.patch >From c435fd41428b6eb4f9f7971e73ca0a422006461b Mon Sep 17 00:00:00 2001 From: TEC 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" --- 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)))))) ;;; Escape contents -- 2.32.0 --=-=-=--