From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cbMRMijZX2DKBwAAgWs5BA (envelope-from ) for ; Sun, 28 Mar 2021 03:17:28 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id aFr0KijZX2CUOAAAB5/wlQ (envelope-from ) for ; Sun, 28 Mar 2021 01:17:28 +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 2EA6B1022F for ; Sun, 28 Mar 2021 03:17:27 +0200 (CEST) Received: from localhost ([::1]:44220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQK3P-0002CK-VJ for larch@yhetil.org; Sat, 27 Mar 2021 21:17:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPU1x-0001kc-Ba for emacs-orgmode@gnu.org; Thu, 25 Mar 2021 13:44:25 -0400 Received: from mout-p-101.mailbox.org ([80.241.56.151]:10180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1lPU1u-0001tW-CW for emacs-orgmode@gnu.org; Thu, 25 Mar 2021 13:44:25 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (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 4F5stD0RjBzQjxP; Thu, 25 Mar 2021 18:44:20 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id dnhA4RWocYoc; Thu, 25 Mar 2021 18:44:18 +0100 (CET) From: Leo Okawa Ericson 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 18:43:41 +0100 Message-Id: <20210325174341.104985-2-git@relevant-information.com> In-Reply-To: <20210325174341.104985-1-git@relevant-information.com> References: <20210325174341.104985-1-git@relevant-information.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-SPAM-Probability: ** X-Rspamd-Score: 1.57 / 15.00 / 15.00 X-Rspamd-Queue-Id: BEEA717FB X-Rspamd-UID: 0218b6 Received-SPF: pass client-ip=80.241.56.151; 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-Mailman-Approved-At: Sat, 27 Mar 2021 21:16:27 -0400 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=1616894247; 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=TfCiBCcB2R1JG5ihF0IlC27LvCE4dqxg2J2TXR8FIQw=; b=kCyLhx6kxCIss6SSK3MxSjyzo7ryL1l+sXMt+tG8wt5p1RTnDBWDRccBS1TC3rMFfvoRdR eH/kI+RuUhKOBLDO/2HlYWJDN1mNYKfmWO68c+b90FGaMJarIJc7lw5/xAhjUFJ4r92oPG bi3oUPf00KM87WQEne2cxmfqA8HkRItn0hyrXlZ9Or18Em/9Ws06Copn44tZ+OZUfTrUyo SIZl/qEN2ulqbZx2jFFjje191N6ZScKjOylolIYb4PkZm/6B1rBKvLvLHiOAIIvkrQk4ax Mjlnl+YwjDmXQVJP+vw2AuEkdZEAm008wH/+x32BPQHk2/mbn3KfJNCAMMBFkA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616894247; a=rsa-sha256; cv=none; b=quR/BtpcpGLjDIZEblgnVPDm2xL2BR2AzNriVlQAMu3cuwhxdJccqL0JWPl1ZGrCa19aHC Mgniuw/I+UVnW1EKyQxuvB2GTx6wCu0X7wpAhdaIJ02rmXW7/MGTZongqvo7nGn3h+HBBA TDq6d2Sq9n5sAD+GI3w9KBNWKXmEUWStHyYuMag2StrRGQzDNS6Ga5L7EuCeKYHwK5tXVq HPshMgIwVMveLWWIPV9UA62Fa7VUHSf44wf/3TZeLRwOQ+kESlvbUIFj0ExrZeK7vrB1CL M86SoZwqU3xY37+awzgZaWdHHyHzMs6DvajbMZJQN4BXg5RbsmlQz/qCCL1IlA== ARC-Authentication-Results: i=1; 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-Spam-Score: 3.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: 2EA6B1022F X-Spam-Score: 3.58 X-Migadu-Scanner: scn0.migadu.com X-TUID: 1+NnplQEoYcX * 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