From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eHyeNcGjm2GIZwAAgWs5BA (envelope-from ) for ; Mon, 22 Nov 2021 15:05:53 +0100 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 WGNFMcGjm2FpQAAAB5/wlQ (envelope-from ) for ; Mon, 22 Nov 2021 14:05:53 +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 24BA021EB6 for ; Mon, 22 Nov 2021 15:05:53 +0100 (CET) Received: from localhost ([::1]:43156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mp9x9-0003kx-2Z for larch@yhetil.org; Mon, 22 Nov 2021 09:05:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp9vX-0003hc-7F for emacs-orgmode@gnu.org; Mon, 22 Nov 2021 09:04:11 -0500 Received: from [2607:f8b0:4864:20::430] (port=42547 helo=mail-pf1-x430.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mp9vU-0006WL-R2 for emacs-orgmode@gnu.org; Mon, 22 Nov 2021 09:04:10 -0500 Received: by mail-pf1-x430.google.com with SMTP id u80so4551968pfc.9 for ; Mon, 22 Nov 2021 06:04:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:references:user-agent:in-reply-to :message-id:mime-version; bh=JYMIo4TXfwNbWaqCVJQErIqGYuPO8LUaiI2IjAjwZ70=; b=hoTOmlZYcVO0a7EFPX7Wf2zDkIFJeBlZsSpu+QGkeVoLdsoxUvJboBOqY6fmFWBEC9 X11GEMFh9JPk64/sgUB8j+P0ApyjYS8envUGmBQFSWl4x3MQ6v4dI67w5NL6pBtfxXo/ iPHvq2KUt2eQ64bSLBxoKfMMextiWN38UDAXi/SglJMyqVxJA3gCow+6grkpLGJh4+hA pJi8XCCF9SIQ1gsc7Nu23ZEtG7Eom9hFEacaIUkGfjxuBTQ1JwZROuvxE1XvSYFtp96B WgFCmjVJZLuoMhMrV8mlen5ndtSgHSaCIrimBOkmaE/i1cwn35MTvVn7LsvCAYPxy3Z6 m55g== 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:references:user-agent :in-reply-to:message-id:mime-version; bh=JYMIo4TXfwNbWaqCVJQErIqGYuPO8LUaiI2IjAjwZ70=; b=4gpnbrxZxC6vpXMAdw7eOLpTfgnL6E+C3PwHVIpr+TFoLzvKG8e4y4Dw2Nl/X7c2ju SYUqB2aQhjwGKGgIyureikzLOkznlgMhSOxYRZWIc2hdgdC6/Mj6K3JUNrkCg8lSuTs+ b3SH2W1aFY9L+fffjdovyKnfTazgAnPjx4zJeQHRKU8op9SLw/0SQTRSspIlH9NQNBcZ SOUoGjwTBgmqtcy+Qn7V8/tn3ztJLmntWfiKGbQBZNqcOVLZbNbOUw2ewqC/MtNtCuQL tEa60KDVmeIRSZXun6Z24ObKWj1GhezouilJl8kXTaE57ZO2Ddq0VaATkAy5s/Ph4syl tATw== X-Gm-Message-State: AOAM532hWb19v71Ntgh91gn1T4xPaLZ+Vk2Ri9pwWt+VVfMvDTJjo4jg +ctJIj/yY+4/Ue8PxOICXvE= X-Google-Smtp-Source: ABdhPJxzsGdJkPjI/pQ+fHgbsWInf3CPWBTaIT10UKwUoaWAMv5D+S3vijsiHSvtyZ+d1aR+DCVEbA== X-Received: by 2002:a63:914a:: with SMTP id l71mr12802073pge.224.1637589846958; Mon, 22 Nov 2021 06:04:06 -0800 (PST) Received: from localhost (61-245-128-160.3df580.per.nbn.aussiebb.net. [61.245.128.160]) by smtp.gmail.com with ESMTPSA id n1sm8705029pfj.193.2021.11.22.06.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 06:04:05 -0800 (PST) From: Timothy To: Ihor Radchenko Subject: Re: [PATCH] Fontification for inline src blocks Date: Mon, 22 Nov 2021 21:43:23 +0800 References: <87pmzf4bd0.fsf@gmail.com> <87o86d7g05.fsf@gmail.com> <875ysk76bo.fsf@gmail.com> <87a6hwpeew.fsf@localhost> User-agent: mu4e 1.6.9; emacs 28.0.50 In-reply-to: <87a6hwpeew.fsf@localhost> Message-ID: <87zgpw5lt9.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::430 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=tecosaur@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, 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 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: org-mode-email 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=1637589953; 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=C9DNf28ElQ6NdSLYtcipASZ+mRszwiqBe0Kc/lUtzLg=; b=B+GSDl8yGXH4UjfM4GH0pA6xzLuakrYVuXTlGrXmi0e/qh5cu6LDC3xhADmNGo9LBcQuC7 9I6gQkalQ0HN9gzqPkTvNZlY8PmxmcDFppBf7f2YK9hAjuDEaujBisIhQ5eofYMqUquamh GU3bN3vGAAxh0XfwAVpF0Eg/gv3rwitwsws1+MDrlHGo/8KIncos34F3gGMX7GRxfWyPcS VcE3HbiFrrmye5gnWCwoA22+fSvRS9XwpK2oC2LypnS+1T1lUS2yZP5be5GI1dpz+LJtQx PNChxg2o9blNp5bjnJAsefhwRzJz8YEQ3ZvSjl0JXjqOVANs8bCVBP1fHfNDFQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637589953; a=rsa-sha256; cv=none; b=IEPXg0sH2Wkv480SLjrq+5xszXwwpWQN/dE3HnKiUuUlZubTKhpDo1x1R+zq/zEVtJRpBy sVvX0qtFFpxNkfTc70MYb+ru4p02bDZCkDz+wbqkfSatnGdI7s8/SOzihlFUqXDUiGVyJq JDxIxdvMMP05q5OaPE+KBed2ouSXbx+f2h0QtL56MQmeaBVQmn94qa9NG51f7mBA7JV7sF jMIPFVBFzhQOK74Jg2+R9/qWZ1AckvIM39GY5vzc3Q8ALkgbgslVAOofPEZCMvTbOVFs3D y0wc5/UUqctd0ft9Vb+1dFV/ajK+5GbrEqWIU7bd4gs2ByCZj6WBhhMVS4lQ6Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=hoTOmlZY; 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: -1.78 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=hoTOmlZY; 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: 24BA021EB6 X-Spam-Score: -1.78 X-Migadu-Scanner: scn1.migadu.com X-TUID: fgMLSohUN4vD --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Ihor, > I have some comments. See below. Thanks for going through this, and for all your help previously. I appreciate it :) >> (org-inline-src-fontify-max-length): Create a variable to limit the >> maximum length of an inline-src block fontified, to protect from lag >> spikes (e.g. when typing out src_lang{ and half of the buffer is >> fontified). > > I do not like this. Even with this variable, some part of buffer may be > spuriously fontified. Maybe you just verify that you are at actual > inline-src block by examining org-element-context? The description may need updating, as that=E2=80=99s a tad inaccurate. That= value actually limits how far forwards a paired paren is searched for. There=E2= =80=99s no spurious fontification. >> +(defun org-fontify-inline-src-blocks (limit) >> + =E2=80=9CTry to apply `org-fontify-inline-src-blocks-1=E2=80=99.=E2= =80=9D >> + (condition-case nil >> + (progn >> + (org-fontify-inline-src-blocks-1 limit) >> + (org-fontify-inline-src-results limit)) > > org-fontify-inline-src-results is not defined in this patch. Ah. Thanks for catching this! >> + (font-lock-append-text-property lang-beg lang-end =E2=80=99face= =E2=80=99org-meta-line) >> + (font-lock-append-text-property beg lang-beg =E2=80=99face =E2= =80=99shadow) >> + (font-lock-append-text-property beg lang-end =E2=80=99face =E2= =80=99org-inline-src-block) > > Is there some special reason why you apply both =E2=80=99shadow and > =E2=80=99org-inline-src-block? What about =E2=80=99org-meta-line face? Ma= ybe > =E2=80=99org-meta-line should not be hard-coded? I think there=E2=80=99s an argument for more faces that can be made because= of element like this, but it comes down to the idea that in a `src_lang[options]{conte= nt}' construct `src_' is effectively visual noise, particularly once fortificati= on occurs and it=E2=80=99s obvious that it=E2=80=99s inline code even without = it. So, I find it nicest if it=E2=80=99s faded, which `shadow' does. Also applying `org-inlin= e-src-block' allows for a consistent background colour across the whole construct. >> + (setq pt (goto-char lang-end)) >> + ;; `org-element=E2=80=93parse-paired-brackets=E2=80=99 doesn=E2= =80=99t take a limit, so to >> + ;; prevent it searching the entire rest of the buffer we tempor= arily >> + ;; narrow the active region. >> + (save-restriction >> + (narrow-to-region beg (min (point-max) >> + limit >> + (+ lang-end org-inline-src-fontify= -max-length))) >> + (when (ignore-errors (org-element=E2=80=93parse-paired-bracke= ts ?\[)) >> + (font-lock-append-text-property pt (point) =E2=80=99face = =E2=80=99org-inline-src-block) >> + (setq pt (point))) >> + (when (ignore-errors (org-element=E2=80=93parse-paired-bracke= ts ?\{)) > > It looks like you are repeating the job of org-element-context here. Why > don=E2=80=99t you just get the proper object? IIRC `org-element-context' doesn=E2=80=99t separate out the `src_', `lang',= `[options]', and `{content}' of an inline source code block (which we want). >> + (remove-text-properties pt (point) =E2=80=99(face nil)) >> + (font-lock-append-text-property pt (1+ pt) =E2=80=99face = =E2=80=99(org-block shadow)) > > Do you really intend to use =E2=80=99org-block and =E2=80=99shadow faces = here? Not > =E2=80=99org-inline-src-block? Ah, that was an oversight. Thanks for catching that, changed to `(org-inline-src-block shadow)'. >> +(defcustom org-inline-src-prettify-results t > > Looks like a stray defcustom. At least, it is not mentioned in the > commit message and not used within the patch. Removed. > Best, > Ihor Thanks again! See an updated patch attached. All the best, Timothy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-src-Implement-native-inline-src-fontification.patch >From 08fff19eb6242339f9fe5549de0bc54520a3d603 Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 13 Jul 2021 02:43:29 +0800 Subject: [PATCH] org-src: Implement native inline src fontification * lisp/org-src.el (org-fontify-inline-src-blocks, org-fontify-inline-src-blocks-1): Create a function to search the buffer up to a limit for inline src blocks. Light fontification is applied to matched inline src blocks. When `org-src-fontify-natively' is set, `org-src-font-lock-fontify-block' is applied to the content. * lisp/org.el (org-set-font-lock-defaults): Add `org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which is locally bound inside `org-set-font-lock-defaults'. (org-inline-src-fontify-max-length): Create a variable to limit the maximum length of an inline-src block fontified, to protect from lag spikes (e.g. when typing out src_lang{ and half of the buffer is fontified). * lisp/org-faces.el: Introduce a new face `org-inline-src-block' which inherits from `org-block' by default. --- lisp/org-faces.el | 4 ++++ lisp/org-src.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 9 +++++++++ 3 files changed, 57 insertions(+) diff --git a/lisp/org-faces.el b/lisp/org-faces.el index b151045a9..272762789 100644 --- a/lisp/org-faces.el +++ b/lisp/org-faces.el @@ -459,6 +459,10 @@ (defface org-block-end-line '((t (:inherit org-block-begin-line))) "Face used for the line delimiting the end of source blocks." :group 'org-faces) +(defface org-inline-src-block '((t (:inherit org-block))) + "Face used for inline source blocks as a whole." + :group 'org-faces) + (defface org-verbatim '((t (:inherit (fixed-pitch shadow)))) "Face for fixed-with text like code snippets." :group 'org-faces diff --git a/lisp/org-src.el b/lisp/org-src.el index 51dde602d..fc9ddc27e 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -654,6 +654,50 @@ (defun org-src-font-lock-fontify-block (lang start end) '(font-lock-fontified t fontified t font-lock-multiline t)) (set-buffer-modified-p modified))))) +(defun org-fontify-inline-src-blocks (limit) + "Try to apply `org-fontify-inline-src-blocks-1'." + (condition-case nil + (org-fontify-inline-src-blocks-1 limit) + (error (message "Org mode fontification error in %S at %d" + (current-buffer) + (line-number-at-pos))))) + +(defun org-fontify-inline-src-blocks-1 (limit) + "Fontify inline src_LANG blocks, from `point' up to LIMIT." + (let ((case-fold-search t) + (initial-point (point))) + (while (re-search-forward "\\_