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.bugs Subject: bug#71345: Feature: unleash font-lock's secret weapon; handle Qfontified = non-nil Date: Wed, 5 Jun 2024 14:13:50 -0400 Message-ID: <73306B69-0314-4FCA-9894-A9B401333D3F@gmail.com> References: <8A929E16-AF10-4D2B-AD71-AEAD4435F016@gmail.com> <1F2B8726-7594-494F-AB9D-08C48B7BCC43@gmail.com> <798B70AF-69BD-479E-992E-5CE9B4924820@gmail.com> <86o78fk4ye.fsf@gnu.org> <865xunjqfb.fsf@gnu.org> <86zfrzi8et.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38997"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71345@debbugs.gnu.org, Stefan Monnier , dmitry@gutov.dev To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 05 20:16:24 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1sEvBQ-0009zP-98 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Jun 2024 20:16:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEvAv-0004P9-LL; Wed, 05 Jun 2024 14:15:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEvAr-0004OI-AC for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 14:15:50 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sEvAq-0000dD-Pk for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 14:15:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sEvB4-0000B3-Fe for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 14:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: JD Smith Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Jun 2024 18:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71345 X-GNU-PR-Package: emacs Original-Received: via spool by 71345-submit@debbugs.gnu.org id=B71345.1717611325599 (code B ref 71345); Wed, 05 Jun 2024 18:16:02 +0000 Original-Received: (at 71345) by debbugs.gnu.org; 5 Jun 2024 18:15:25 +0000 Original-Received: from localhost ([127.0.0.1]:54420 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sEvAS-00009a-GA for submit@debbugs.gnu.org; Wed, 05 Jun 2024 14:15:24 -0400 Original-Received: from mail-qv1-f51.google.com ([209.85.219.51]:43364) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sEvAP-00009I-Vd for 71345@debbugs.gnu.org; Wed, 05 Jun 2024 14:15:23 -0400 Original-Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6ae259b1c87so10155206d6.1 for <71345@debbugs.gnu.org>; Wed, 05 Jun 2024 11:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717611242; x=1718216042; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aSeQTNPYvM3KItAJ5ioxJZV9+kPXThYrVU8aVR/GCTM=; b=D9OJoi6rixevWcrIhs+FCq2BZjgZkYYsh1opdBz8tRtqgOzc+pFPTWkdW+cEIRdQy5 8LecKSHcuHnU3/4HoGygDzmd953+dG7ad3QqPIFYqQusLB/ZUnByOMwbD4wwisOt6rR+ aALbr1wUrDzStS4ws2MNylqv8heVimiV152jNSYieM+aL6vaCMSLs2xuh5mi1GqFRQzU reMRj0WIzEKcDinoTBLGiN02I+mDmc2eEAmbaAYcqRHBkuIPS1NOyzX+0W1Dfxte8cdF p9yzML3XUtaD3IO509h2rIEFjhLK3LBIPkY1T43cjoldwR+YucFz5IaHpVLi9znmtsk5 4iZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717611242; x=1718216042; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aSeQTNPYvM3KItAJ5ioxJZV9+kPXThYrVU8aVR/GCTM=; b=W17K0I1HZAA94753r5XJtmgEYCfl0Kx2JvKmQuzYlNGFAMNZBCoN8KsSPh2N+ZjfWX cFvRRrr1+Iewt3XUNcGj3irZ+DXfvEmUdPGRJ7MCPmpOGmEaSr43AvrM5DjHihzLVtR5 D7c//ZdbuD8WM9L8eeWHx+O3tSH2Owo9Bo14w+AuRJxyYUOJOrmXZ6JdDH6WdsU/3Y5I FiEVw3hF1x4+ium2dTBvk0kxIcpwG/zK0p5eSMNFCmS+SDTDxkzPOd4M63MpwF6fjObn 50HMSNW8EWbswkMUnzgPfq3qTyQXmAgXyLU6aJpLRT2UL3bZQxwR8VIG8yhBt/83FLIy bGow== X-Forwarded-Encrypted: i=1; AJvYcCUkc33+v27V/TMVigmGF333lCB+U7OXFTeEeo6XnaAgHhLFgq8i/evH9N5kGJTdV74xYVCwiNWfcmf8/q07xrBflVjjuCU= X-Gm-Message-State: AOJu0YzXd5gHdoWr7PPvvDw4kaYbTrmhldSxCMbFikNZPhriA0Vx2kys wNYJDePZoxFdtkJnpu2sZpqUXP8rsfBXp3rNDVAJ0LhAS9XrQ3cZ X-Google-Smtp-Source: AGHT+IFiVpH0Uk0lY45Ce9meow1YYYhjsIeyJobl6Sv+06gJY6J67nqZSRMNiNR9PmPxIpzXp0NpNw== X-Received: by 2002:a05:6214:318f:b0:6af:c320:5f16 with SMTP id 6a1803df08f44-6b04bfecac5mr9610556d6.7.1717611242177; Wed, 05 Jun 2024 11:14:02 -0700 (PDT) Original-Received: from smtpclient.apple ([131.183.131.33]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b0044bb4b9sm10063316d6.111.2024.06.05.11.14.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2024 11:14:01 -0700 (PDT) In-Reply-To: <86zfrzi8et.fsf@gnu.org> X-Mailer: Apple Mail (2.3774.500.171.1.1) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286634 Archived-At: > On Jun 5, 2024, at 1:52=E2=80=AFPM, Eli Zaretskii = wrote: >=20 >> From: Stefan Monnier >> Cc: jdtsmith@gmail.com, 71345@debbugs.gnu.org, dmitry@gutov.dev >> Date: Wed, 05 Jun 2024 12:59:08 -0400 >>=20 >>>> But the highlighting is done "once and for all" (at least until the = next >>>> command), so if you want it to be different in different windows = (to >>>> reflect the different values of `point` in those windows) you'll = need >>>> overlays with the `window` property because the highlighting will = not be >>>> re-done in the middle of redisplay when we go from one window to = another. >>>=20 >>> In that case, we are in trouble anyway, because the "once and for = all" >>> highlighting could be (by sheer luck) be done by display code that >>> doesn't run as part of redisplay, but as part of something else, = like >>> vertical-motion. >>=20 >> I can't see why that would be a problem. >>=20 >> The highlighting code run from `jit-lock` will usually not be able to >> use `point` (or `window-point`) directly. Instead, that highlighter >> will need to keep track of the windows' points elsewhere "manually" = via >> hooks like `post-command-hook` or `pre-redisplay-functions` and then >> rely on that info when performing the highlighting. >=20 > You say you don't see a problem, but then describe a solution for a > problem you don't see? ;-). Yes, if the code run from jit-lock will = use some private variable > instead of point, it can get away,=20 But you must use a PCH or related hook if you want point movement to be = reflected in real time (or after a short delay, for me). Since jit-lock = is never driven by changes in point, only by fontified=3Dnil appearing = somewhere in the text, I don't see how point-dependent highlighting = could ever be achieved other than via a command hook saving to a private = variable of some kind. =20 > but such a code will need to be > written in an extremely disciplined manner, like nothing else in Emacs > (except, perhaps, the inner parts of redisplay code in C), because > what is more natural than call functions and APIs under the assumption > that point is where it's expected to be? In practice I am doing this already. It works quite well and is not too = onerous to keep track of. You basically: - start a timer in a PCH - once it fires, query treesitter for the enclosing node of interest at = point - if that node has changed, save the new node boundaries and flush the = union of the old and new nodes - font-lock does the rest The only problem I'm really facing is that last step: outside of actual = text changes, font-lock is wastefully refontifying everything, when only = a small amount of work was needed. Stefan has a very good idea for a = cooperative jit-lock capability, where multiple jit-lock backends can = sometimes do their work independently, which could in principle solve = this.=