From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id SNYZO9k09WGETAAAgWs5BA (envelope-from ) for ; Sat, 29 Jan 2022 13:36:41 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id KL03ONk09WHKHgEA9RJhRA (envelope-from ) for ; Sat, 29 Jan 2022 13:36:41 +0100 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 7405829DCC for ; Sat, 29 Jan 2022 13:36:41 +0100 (CET) Received: from localhost ([::1]:39694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nDmy7-0008Jp-Pa for larch@yhetil.org; Sat, 29 Jan 2022 07:36:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nDm3r-0004pm-3K for emacs-orgmode@gnu.org; Sat, 29 Jan 2022 06:38:31 -0500 Received: from [2607:f8b0:4864:20::1035] (port=36587 helo=mail-pj1-x1035.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nDm3p-00015H-9F; Sat, 29 Jan 2022 06:38:30 -0500 Received: by mail-pj1-x1035.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso13439784pjv.1; Sat, 29 Jan 2022 03:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HNxCzkPJi3bNJUx1StyZEgOnIZ8xBP8WiVW0Y1Ro97U=; b=ED58x18Qh755y3keugMSh2bzolNChNEPh8LcnsduAo6tdcZPKLeNaQFyqmd/yDBdVy eEprfzDcNTYFjW8wEA4nedx+reWWrzfJuJo9BieTP/Ppwf5iRteNMGvROQnHod7u+nbg MB+EQMYDBr0egaOvbl4+y4YTY97nwsfwFRl//8isn4wtJdiepwfKmmkAqZZvWuPpoTL2 dA6PcXTLYuYvMMpjvWKE+Xdf974l/2XKR+CUbqonbKXTKFXqmkhgiBY3sFd03XDwOdkj T+O87Ijf+g0YXYFTk68wXm+2CC7jfAgIGmV1SIWvYvAws6HMWr4ElE94fk1w3zqF2DVT Zxgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HNxCzkPJi3bNJUx1StyZEgOnIZ8xBP8WiVW0Y1Ro97U=; b=xdPiW/LFKqbVKZgoAlFVgrJ8WoRnoAM+lnUXGVzb0lzDKPvANdOTMTZk05SCTetBjT tOj2fRygH3BuO6H1misswjARNhlm+O3pDZE6mAOctTuj/sJ/ppymU+ScOx3TgovSD6xO Wb96HkEItbZ0Va1JSIn9picy6e/SJ4ih1XS+HK6WiI2GmGs4+qSFeHkbX7RkQAKsJM08 NVUW7s144qW7P+wK9iJSExAylq9JV5dctiYhVAPu39NMNH+6L3aKtUYIl7QETciWlOjE wtWweOP+G50dWtkIEKUNdQ2Zmu3LWfPtqZLynMVvP0yzqdXreYlwwhCIRk0VmWgGtCOf DZyQ== X-Gm-Message-State: AOAM533VrmNKMx6T5XW/aJ2vPyfi1Tzbmu1UCn0zENRhYp3AupwlLVCJ 9uEoNgxycUoOE7wLjaoCslfp446GQsXEiu/3 X-Google-Smtp-Source: ABdhPJziod53CsSS4rstyY9w/oOaoq9zWqmQPsvctGpNxtp+xwg53doJ69LsNDT3LA0BJazXC78epA== X-Received: by 2002:a17:902:b201:: with SMTP id t1mr13170220plr.145.1643456307647; Sat, 29 Jan 2022 03:38:27 -0800 (PST) Received: from localhost ([209.95.60.92]) by smtp.gmail.com with ESMTPSA id l14sm1994014pjf.1.2022.01.29.03.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 03:38:26 -0800 (PST) From: Ihor Radchenko To: Bastien , Kyle Meyer , Nicolas Goaziou , Karl Voit , Christian Heinrich , emacs-orgmode@gnu.org Subject: [PATCH 31/35] org-fold-core: Fix fontification inside folded regions Date: Sat, 29 Jan 2022 19:38:23 +0800 Message-Id: <81fc8cbc667466eea0ed15f1dcadd4c4f3dc3f70.1643454546.git.yantar92@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: <87y2cvloay.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.34.1" Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1035 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ihor Radchenko Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643459801; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=HNxCzkPJi3bNJUx1StyZEgOnIZ8xBP8WiVW0Y1Ro97U=; b=pkh+WnMamMosIh2CHk7WGoIs8hCZCFd9+K5ymUn0GEQ82eTi6lsH2JD0LHWsl/ktOEphXk 8dIqxV0uBwTZVoTufawAAdmfaxnP0ygJO1W39Ota+pTY2LiN+NmwFJPwCXaD5WBIMiMB5F c8D+GnFPC4ELRT0yLlADMrPCBUzQXbeYMheubOpbufJES1qSysYV8LCSlDakoXpBmIAgLq ///MK1WexhuA2LX61/10CZKLNSQJ5zWsh61im4iVzjZVtBaq5r3amKpnxkMXEIFNtxhYwD PHdcQCAt9ozlOdEoI8pBaeo7ddgzqiyhICAEARPeEGe2uLWw0IbDN0sH3+L8Bg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643459801; a=rsa-sha256; cv=none; b=KTkyKSwmdJOv5QGeLJBvBLM5ehQlohl+stCyhnAt8hsUVRwiw7E66XWIrfLTuS7/rT6ksn Ou2nYU4SGdpZPmbbzDe2s8KbGzmQbEnuw2DlVMeQ/kz2j2GLbF5NcJm7M9RkX93TdOz/FY MUUhVNbPyXv5ZIEKriz8ZwPwDRxqQmSlvGKfm7FzGN8b56/qLfuF1s+MlPGs2819LZpw7v 0Z9C4Lkz7zrAw7ZMhGtZqmvh/QEzaf7j4/K309HBzqcbzve7DBqAphWIvUfUFwxp2qv3mk Y31P1nTNc0oTDEKalLqq4tpm9vDgyrWrITaTvFP6XqYX89gvcgIIQ9KQIgiNmw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ED58x18Q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.33 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ED58x18Q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 7405829DCC X-Spam-Score: -3.33 X-Migadu-Scanner: scn1.migadu.com X-TUID: Taki7uGB5PFb This is a multi-part message in MIME format. --------------2.34.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit * 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(-) --------------2.34.1 Content-Type: text/x-patch; name="0031-org-fold-core-Fix-fontification-inside-folded-region.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0031-org-fold-core-Fix-fontification-inside-folded-region.patch" diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el index 121c6b5c4..edae316ff 100644 --- a/lisp/org-fold-core.el +++ b/lisp/org-fold-core.el @@ -746,7 +746,8 @@ (defun org-fold-core-initialize (&optional specs) (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 @@ (defun org-fold-core--buffer-substring-filter (beg end &optional delete) 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 db98dd149..867139742 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -39,6 +39,7 @@ (declare-function org-agenda-files "org" (&optional unrestricted archives)) (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)) @@ -1172,6 +1173,36 @@ (defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t 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 --------------2.34.1--