From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Selective font-locking? Date: Sun, 11 Apr 2021 11:27:39 -0400 Message-ID: <7A948673-E156-42BA-BA50-E91986908BB5@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_618A0B4C-CC06-4C87-B4AF-9C3B1D0188F5" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33612"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 11 17:28:28 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVc0h-0008da-KX for ged-emacs-devel@m.gmane-mx.org; Sun, 11 Apr 2021 17:28:27 +0200 Original-Received: from localhost ([::1]:48508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVc0g-0004xZ-K4 for ged-emacs-devel@m.gmane-mx.org; Sun, 11 Apr 2021 11:28:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVc02-0004Wx-9I for emacs-devel@gnu.org; Sun, 11 Apr 2021 11:27:47 -0400 Original-Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]:33401) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lVbzz-0003cd-Nj for emacs-devel@gnu.org; Sun, 11 Apr 2021 11:27:45 -0400 Original-Received: by mail-io1-xd34.google.com with SMTP id a11so8781231ioo.0 for ; Sun, 11 Apr 2021 08:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=NIpeMlwYkRVyPgvCjlDCF1vA/rYH6dxglU/2So1byvw=; b=oUff8Dy7yjCQvrSs64qfZZSoDL3jEe9dnVGkiOmpd8JS5+WSY+oMQA+UodM0iG9raG /Ksvrv4phTUzZbAdI9DarvQZX0xZfSBrOXOpcHVqu3Vu58ZM5rx2gwETwJ3piSbMsuOj yVlAm+2t9UMQnWtAq+wBBMm+GpDLomum56KqMJQnRay4JL2D9QFLjH+1JY3l66Q0I0Vv jw4ghJeRTHEWBm/yLhbXkRE2XA18qBmk2zHgjacpw2ubKjiLJREpS8NvIgJU6u9/fCOp uG7TPKngJffHgXToFNEV7TaL6Yxt4xzetfp29HkDxsFuIfM9Z+ps+y95Mbl8oIqy3CdW HlxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=NIpeMlwYkRVyPgvCjlDCF1vA/rYH6dxglU/2So1byvw=; b=VWPMi5zc8brZP84nVATZd9I7cilq7Zz9EfZAKw/lDTvcVY65j8hTkeKOuE18vLivTM o/cRphwhOAnl1OUFZSUkDbYbc8FIsbos90YrG8Lu+hotb1jF0jiKCJT2ivy+HEEAOpDU ni5q7FmuuS+PnHa/J3lshh82ywBVd5lP0qSe2CnCRp/76EKxI31VVRGmTbrKcy/GZxWb IKMbsx97coUe78SdgPSMDzW5taNj//0vbLX6FQRWGRYOLw4IEw2TTVcU5WGpnZGJT/Ws QNd0EkZv9bNLiGnekgW0spBVKFtjBzdB4BFs6UEe5twA/QqUoj2SOdsz4RfVF0/4e9Xh 6CLQ== X-Gm-Message-State: AOAM532Id5G+egsD9d8TDXNMSmoX4lVjiDsM4Ek4N1KMD1fq3rguxvPj RVqvGIYvQCiOhvglGgnydemB1hEX9QZOkQ== X-Google-Smtp-Source: ABdhPJxH/QglqnYZuQAsCa47m6SvFFOm3y6M/dRvudS8iSkyqTWjJPhU4H8pcBAYwEBBzi0NOzE9lA== X-Received: by 2002:a6b:9156:: with SMTP id t83mr10468960iod.62.1618154860898; Sun, 11 Apr 2021 08:27:40 -0700 (PDT) Original-Received: from [192.168.0.121] (cm-134-228-54-223.buckeyecom.net. [134.228.54.223]) by smtp.gmail.com with ESMTPSA id b15sm4175527ilm.25.2021.04.11.08.27.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Apr 2021 08:27:40 -0700 (PDT) X-Mailer: Apple Mail (2.3608.120.23.2.4) Received-SPF: pass client-ip=2607:f8b0:4864:20::d34; envelope-from=jdtsmith@gmail.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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_FROM=0.001, HTML_MESSAGE=0.001, 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-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267888 Archived-At: --Apple-Mail=_618A0B4C-CC06-4C87-B4AF-9C3B1D0188F5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 What is the current state of applying font-lock to only portions of a = buffer? I=E2=80=99ve seen font-lock+ which allows adding a = =E2=80=98font-lock-ignore=E2=80=99 property, but it redefines font-lock = functions and so may not be reliable long term. =20 To make this concrete, here=E2=80=99s a usage case. I=E2=80=99m = currently extending python mode to include support for multiline input. = Here is how python mode currently fontifies the text being input at a = shell prompt: In a post-command-hook, after every change, copies the entire input = after the prompt, sans properties, to a hidden =E2=80=9Cfont-lock=E2=80=9D= buffer with python-mode enabled. Calls font-lock-ensure, which refontifies this entire buffer. Copies all the newly updated text properties back into the shell input. So: super inefficient. For single lines of input, this is "fast = enough". Once you have multi-line input with hundreds of lines or more, = this incurs 50-100ms latency for each and every insertion, deletion, = etc. For a good approximation of how typing with this amount of = latency feels, eval the following in *scratch*: (add-hook 'post-self-insert-hook (lambda () (sleep-for 0.1) ) = nil t) #1 is readily fixed by using an after-change-function which only updates = the relevant text from the shell to the hidden buffer. But #2 is the = real killer, taking 70ms or more to completely re-fontify a decent sized = block of input. Adding region beg/end to font-lock-ensure doesn=E2=80=99t= work; how do you know if a change occurred in a long string, for = example? But then, why bother round-tripping text out to a special-use buffer = anyway, vs. just letting font-lock operate in-situ in the shell buffer = itself using python-mode=E2=80=99s fairly simple font-lock-defaults. The = only thing needed to make this work is asking font-lock to ignore all = the text with =E2=80=98field of =E2=80=98output? =20 It seems what would be ideal is tying font-lock-defaults to specific = =E2=80=98field properties, so that only text with a given =E2=80=98field = (or not matching a given =E2=80=98field) is fontified according to the = matching set of font-lock rules (with no field specifier matching all = text). This would make mixed multi-mode buffer fontification fairly = straightforward.=20 I=E2=80=99m sure this is simple-minded given the complexities font-lock = has to solve, but there has to be a better solution than re-fontifying = everything after each character is typed!= --Apple-Mail=_618A0B4C-CC06-4C87-B4AF-9C3B1D0188F5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
What = is the current state of applying font-lock to only portions of a buffer? = I=E2=80=99ve seen font-lock+ which allows adding a = =E2=80=98font-lock-ignore=E2=80=99 property, but it redefines font-lock = functions and so may not be reliable long term.  

To make this concrete, = here=E2=80=99s a usage case.  I=E2=80=99m currently extending = python mode to include support for multiline input.  Here is how = python mode currently fontifies the text being input at a shell = prompt:
  1. In a = post-command-hook, after every change, copies the entire input after the = prompt, sans properties, to a hidden =E2=80=9Cfont-lock=E2=80=9D buffer = with python-mode enabled.
  2. Calls font-lock-ensure, = which refontifies this entire buffer.
  3. Copies all the = newly updated text properties back into the shell = input.
So: super inefficient.  For = single lines of input, this is "fast enough".  Once you have = multi-line input with hundreds of lines or more, this incurs 50-100ms = latency for each and every insertion, deletion, etc.   For a good = approximation of how typing with this amount of latency feels, eval the = following in *scratch*:

(add-hook 'post-self-insert-hook = (lambda () (sleep-for 0.1) ) nil t)

#1 is readily fixed by using an = after-change-function which only updates the relevant text from the = shell to the hidden buffer.  But #2 is the real killer, taking 70ms = or more to completely re-fontify a decent sized block of input. =  Adding region beg/end to font-lock-ensure doesn=E2=80=99t work; = how do you know if a change occurred in a long string, for = example?

But = then, why bother round-tripping text out to a special-use buffer anyway, = vs. just letting font-lock operate in-situ in the shell buffer itself = using python-mode=E2=80=99s fairly simple font-lock-defaults. The only = thing needed to make this work is asking font-lock to ignore all the = text with =E2=80=98field of =E2=80=98output?  

It seems what would be ideal is tying font-lock-defaults to = specific =E2=80=98field properties, so that only text with a given = =E2=80=98field (or not matching a given =E2=80=98fi= eld) is fontified according to the matching set of font-lock rules (with = no field specifier matching all text). This would make mixed multi-mode = buffer fontification fairly straightforward. 

I=E2=80=99m sure this is simple-minded given = the complexities font-lock has to solve, but there has to be a = better solution than re-fontifying everything after each character = is typed!
= --Apple-Mail=_618A0B4C-CC06-4C87-B4AF-9C3B1D0188F5--