From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eEkEHKzWXGCKXAAAgWs5BA (envelope-from ) for ; Thu, 25 Mar 2021 19:30:04 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id GImXF6zWXGDhfwAAbx9fmQ (envelope-from ) for ; Thu, 25 Mar 2021 18:30:04 +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 E82FD15629 for ; Thu, 25 Mar 2021 19:30:03 +0100 (CET) Received: from localhost ([::1]:59010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPUk6-0002Xl-CC for larch@yhetil.org; Thu, 25 Mar 2021 14:30:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPUgU-0000Xr-61 for emacs-orgmode@gnu.org; Thu, 25 Mar 2021 14:26:19 -0400 Received: from mout-p-101.mailbox.org ([2001:67c:2050::465:101]:46678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1lPUgQ-0006Em-GG for emacs-orgmode@gnu.org; Thu, 25 Mar 2021 14:26:17 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4F5tpT3lgnzQjxJ; Thu, 25 Mar 2021 19:26:09 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id Ha7ISgKKoXKS; Thu, 25 Mar 2021 19:26:03 +0100 (CET) From: leo@relevant-information.com To: emacs-orgmode@gnu.org Subject: [PATCH 1/1] org-src.el: Add option to delay fontification of source blocks Date: Thu, 25 Mar 2021 19:25:02 +0100 Message-Id: <20210325182502.107089-2-leo@relevant-information.com> In-Reply-To: <20210325182502.107089-1-leo@relevant-information.com> References: <20210325182502.107089-1-leo@relevant-information.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-SPAM-Probability: X-Rspamd-Score: -0.04 / 15.00 / 15.00 X-Rspamd-Queue-Id: 594CF17CC X-Rspamd-UID: 247dc5 Received-SPF: pass client-ip=2001:67c:2050::465:101; envelope-from=leo@relevant-information.com; helo=mout-p-101.mailbox.org X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, 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: Leo Okawa Ericson 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=1616697004; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QQMhPl92V+de1QISDaKyZB73XPhb08Pb1BNfL7mEDiU=; b=V2CQboTkTWaPlu9e2EPeoxKdSNDXukvpzhXpc4EUQA36ysnzdIZS+gnlyha4FQDBwBEZN4 4JbzqTW/kWvcWCpF4FeSyzJYMYrIVS8LMAMlhcTBWpchk+LgzrnoSZIIREpWSva+42lnZp cvmWzWduOFuYtJ3xE6Qg0L/QLHJUOBb0sOELQkVAANNllkj0mM++Jpp/osHsCiXO1oNYqa wbqthq4UFvdGhZhh1fJDP5chqftNgRIoPIQ0u7fBW5ZMCy829OeKGFJC062rOm6WQdhyEE L+sO3Pk2ybBIe7vqoSjMKzGeuD3dsRLSh8HNffvBj1SWoLJTe4fGJCC8wvqttg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616697004; a=rsa-sha256; cv=none; b=imMOAmZQUttCJ2jYRiB9bx4ndXXyT87zxOzbEkZvoRu6IZn4XxledGOpCW1Z31z1oSVVqV Bwkb2ZfhjmY1sHNJ1TqpluokYXBhyTs5QtCEm6l1l4sEchzl5zc2l83LkqOIed/n+ujIRU fA/AG2iZ/IyNIzFEQOkCofqJxVEoanfc2aHVc/KwHxlt4o7JAIDTLQTBGxReu0bk0/1tm3 VYhS6Y3YrIDugT+rkQ/Cqb6r4Sgtt/dR5pCE8LaFRarvj6zNm667VKHvJt8Wqnth7jm2Hm U7BkmrlCruQHmAaA7qnluuRB9AVyjGbXVqJYpPH4ALfctg++iK34De/PfdhcSQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=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: 2.58 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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: E82FD15629 X-Spam-Score: 2.58 X-Migadu-Scanner: scn0.migadu.com X-TUID: ewPot/lvwPBl From: Leo Okawa Ericson * lisp/org-src.el (org-src-font-lock-fontify-block): Add option to delay fontification of source blocks. If `org-src-font-lock-fontify-idle-delay' is non-nil fontification of code blocks is delayed until the user has become idle. Fontification of source blocks can be very slow. This will add an option for users to delay the fontification until they have become idle so that the typing delay is kept low. The trade-off is that there will be no syntax highlighting when the user is typing. --- lisp/org-src.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lisp/org-src.el b/lisp/org-src.el index 20acee4e6..b1446e105 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -584,11 +584,40 @@ (defun org-src--edit-element ;;; Fontification of source blocks +(defvar org-src-font-lock-fontify-idle-timer nil + "Idle timer to use for when fontifying with a timer.") + + +(defvar org-src-font-lock-fontify-idle-delay nil + "Duration of the delay until fontification of source blocks. +If non-nil, source blocks are fontified when the user has been +idle for `org-src-font-lock-fontify-idle-delay' seconds. This +means that instead of applying syntax highlighting when you type +it is delayed until you become idle. Not that when typing there +will be no fontification. +") (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." + (if org-src-font-lock-fontify-idle-delay + (progn + (when org-src-font-lock-fontify-idle-timer + (cancel-timer org-src-font-lock-fontify-idle-timer)) + (setq org-src-font-lock-fontify-idle-timer + (let ((buf (current-buffer))) + (run-with-idle-timer + org-src-font-lock-fontify-idle-delay + nil + (lambda () + (with-current-buffer buf + (org-src-font-lock-fontify-block-1 lang start end) + (when org-src-font-lock-fontify-idle-timer + (cancel-timer org-src-font-lock-fontify-idle-timer)) )))))) + (org-src-font-lock-fontify-block-1 lang start end))) + +(defun org-src-font-lock-fontify-block-1 (lang start end) (let ((lang-mode (org-src-get-lang-mode lang))) (when (fboundp lang-mode) (let ((string (buffer-substring-no-properties start end)) -- 2.25.1