From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MFJCMSjZX2BRBQAAgWs5BA (envelope-from ) for ; Sun, 28 Mar 2021 03:17:28 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id sKYPKyjZX2A6MgAAbx9fmQ (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 1C0C3264DF for ; Sun, 28 Mar 2021 03:17:27 +0200 (CEST) Received: from localhost ([::1]:44222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQK3Q-0002CL-UB for larch@yhetil.org; Sat, 27 Mar 2021 21:17:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPTey-0008RU-8W for emacs-orgmode@gnu.org; Thu, 25 Mar 2021 13:20:40 -0400 Received: from mout-p-102.mailbox.org ([2001:67c:2050::465:102]:51430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1lPTev-0005mM-Qg for emacs-orgmode@gnu.org; Thu, 25 Mar 2021 13:20:40 -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-102.mailbox.org (Postfix) with ESMTPS id 4F5sLq2frczQjkp; Thu, 25 Mar 2021 18:20:35 +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 AhoPxo-Odu0D; Thu, 25 Mar 2021 18:20:32 +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:19:41 +0100 Message-Id: <20210325171941.101077-2-git@relevant-information.com> In-Reply-To: <20210325171941.101077-1-git@relevant-information.com> References: <20210325171941.101077-1-git@relevant-information.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-SPAM-Probability: ** X-Rspamd-Score: 1.54 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2E9CC1867 X-Rspamd-UID: 1c7db4 Received-SPF: pass client-ip=2001:67c:2050::465:102; envelope-from=git@relevant-information.com; helo=mout-p-102.mailbox.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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-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=gGx0805V03xCIo/aXK273s6djg2Jmouy2idOr9AqEE1fjVczp41EXanhb7CiQM5c7FXaZp modekhQJuwtqbtFmpetN6o6oku6TRAiqVxL6ooujxzh/TDVPaqiN0gKfDsC1V37dpX7/iO zPbhHmAbvIbPaokZ/QBLnEQL1XbVVztPImBrud+iNCVkYqaVCaPvrhQNzdWkm1oa5YXP/Q XyvP59b07S/bG2FiWFTJX5IKChBRxfBkPuuwBFQ0pPDq2H7KSQxPAkx/6ipLjt7CQQlNtc kEB8bdMo2uRT/Ld+THd99qHjkhiBkA1oev3HG/dBW2Sr5+HqSoxpo+bQHAqXeA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616894247; a=rsa-sha256; cv=none; b=bs35Sy3YET0mlUCKt4WaffPhuuxadljg2O+qPtc2Ir/piYT9mphc2w9qCjdTtXO5qGUHDb mtq01HxmfohnEL3RgVxJ5mQWUwSoGTBgAbMR6UFqJb1pb/mebEhuirSjt6o9yQpUFzLgeI RpoRCz6NZvn9hIBCiIcqxbcxIn9SJ8MCuWfEPqjLtV/lKmlgTz4mh5dgTkzvMsHVehF7LL kqwfLqJipNFN/fDU5GvAm2LFuVU8Xbqw0oDhUUcX0q2YItOtnT/8ClBx9zUFASXXOvREGd ycOS7xNg2K8nReWVSJl8QGNfZkQfcWIOnWaJzbqBO7VqnkGYFy3hOuSwUYFPlw== 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: 1C0C3264DF X-Spam-Score: 3.58 X-Migadu-Scanner: scn0.migadu.com X-TUID: nSaAmEi561gL * 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