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: Re: region-based face-remapping Date: Sat, 6 Jan 2024 09:04:16 -0500 Message-ID: <9868C681-2DEA-4C49-813D-C120D3381980@gmail.com> References: <83y1d7zy8s.fsf@gnu.org> <3592E8C5-35FF-44FF-88ED-B458303BF15A@gmail.com> <83edeyzjgp.fsf@gnu.org> <83cyuhy483.fsf@gnu.org> <837ckow5st.fsf@gnu.org> <7eadd722-69eb-43dc-a091-6330d25d93d9@gutov.dev> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_D4F5824A-391F-4821-886A-7DE7656B14A7" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12134"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 06 15:05:19 2024 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 1rM7Id-0002vu-Nx for ged-emacs-devel@m.gmane-mx.org; Sat, 06 Jan 2024 15:05:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rM7I4-0003eh-5I; Sat, 06 Jan 2024 09:04:44 -0500 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 1rM7Hy-0003eS-SP for emacs-devel@gnu.org; Sat, 06 Jan 2024 09:04:38 -0500 Original-Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM7Hp-0001il-GR; Sat, 06 Jan 2024 09:04:31 -0500 Original-Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-67f83812a32so3274706d6.3; Sat, 06 Jan 2024 06:04:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704549868; x=1705154668; darn=gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=sc1oO/e11ehHr6/bHkXUguhSCuN7N2gAJR+vjMofEDk=; b=a2+YSeMW7O7rqye839KiXWKxpYPTOVgq0KB3qp45enSxfqBtjTijAlcHcO1+G/BON+ GM63x2JbNTyL1YBN0ufI2aPJvAkMblAz04KHNGu1YIzg1DKC9tmzLmn4eztKYyVFCMXm 9ADZjwl50faj0Ndv0qg6gxLECl1/GJd6IIzU90RtjhxQinOqd0KyUzUoVSu0NsHNKQgB 4/qFKN2rpjQ77ASCQ0AY+TUspjx8Wxp8+5s27Ao4yWBnmyxXadlZTKGQjWnn4MWH0wqE Dq/dDaaZj0kMJlnbtOaspLCEyrTJpZCd5j95ZyCaf9lPdh58HhCaaU7Raol76dRXVjS/ CFAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704549868; x=1705154668; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sc1oO/e11ehHr6/bHkXUguhSCuN7N2gAJR+vjMofEDk=; b=ARubjktdxL5JJLvD4JVudJLvc0UwVey4Kan9kCtNWrqs6Og5EM1pU4K059r9k6RuOg LfBy7Xldb0m+NLSdqzpOKKXRz9Lhvc/NhGGT+xNeZOfVu6dZCeDUYimVi0I9shTErM4k ZTidBhn7unbCd6XVqHbBlA28uY1IZTjglzGIGezZtrm/P9XYGclze70qaKeiE0yETNHg joXzY9w9G4sRHOVGRBm4qv/ciXJ6qQzBT441bIVSitdhBe1ASFwBLrNuJpWIZjjABr8T LdrAJypaxMvDezr8zTyo68KcOMmcOfGOUB3hJl5QeLZ//AIXxWbwQOAnayQhp48h/bxJ EgsQ== X-Gm-Message-State: AOJu0YxJ1Aifb06yRElwUfeyo9netc1KloBtOwwPLtrsgt985ygHyNMV 0pJzfwYOqb2QgdZafzUnEXaTYzbGJ+ovyQ== X-Google-Smtp-Source: AGHT+IEe+bVsyUqvyGf9QIDGIixblRBz9OgLnKzWH29KTiarnlxhUE6s20Mw3zkqCfKY70wj2UYjKg== X-Received: by 2002:ad4:594d:0:b0:67a:de61:443b with SMTP id eo13-20020ad4594d000000b0067ade61443bmr1050328qvb.28.1704549867603; Sat, 06 Jan 2024 06:04:27 -0800 (PST) Original-Received: from smtpclient.apple (cm-24-53-187-34.buckeyecom.net. [24.53.187.34]) by smtp.gmail.com with ESMTPSA id cu9-20020a05621417c900b0067f2d12353bsm1405351qvb.78.2024.01.06.06.04.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jan 2024 06:04:27 -0800 (PST) In-Reply-To: <7eadd722-69eb-43dc-a091-6330d25d93d9@gutov.dev> X-Mailer: Apple Mail (2.3774.300.61.1.2) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2a; envelope-from=jdtsmith@gmail.com; helo=mail-qv1-xf2a.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314628 Archived-At: --Apple-Mail=_D4F5824A-391F-4821-886A-7DE7656B14A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 5, 2024, at 11:35=E2=80=AFAM, Dmitry Gutov = wrote: >=20 > On 05/01/2024 10:19, Eli Zaretskii wrote: >>> I=E2=80=99m sure there could be lots of uses of this type of = functionality, but =E2=80=9Cenhance the focus on one region >>> of importance=E2=80=9D seems like a very common one. For example, = you might imagine dim/gray version of >>> all the font-lock faces outside the =E2=80=9Ctreesitter region of = interest=E2=80=9D and bright ones inside. Whenever that >>> TS-prescribed region changes, an overlay with a =E2=80=98face-remap = property gets moved. >> The question I suggest to ponder is whether simpler, less general = ways >> to implement these features are "good enough". For example, changing >> the appearance of a region of text can be handled by moving an = overlay >> there with a suitable face definition and high priority; changing the >> appearance of text around point can be handled by a special variable >> which the display engine will consider when working on text around >> point; >=20 > An overlay with face and higher priority would override most faces in = the region, wouldn't it? Unless it just sets the background, in which = case we already have this capability. >=20 > JD, have you considered it? E.g. set the default face's background to = some darker color and use an overlay which sets background to a lighter = one. I=E2=80=99ve definitely considered =E2=80=9Cre-style all of one = particular face attribute=E2=80=9D options like this and none I=E2=80=99ve= found are suitable in my case (though perhaps for the = TS-current-context example I gave this could be a decent option). The = best analogy is the one I just offered in my reply to Eli: changing the = class of an HTML element and having subsets of styled text within it = automatically updated, thanks to the inheritance capabilities of CSS = (not that that=E2=80=99s an explicit model for Emacs to emulate; just = conveying the idea).=20 > But if that's not sufficient, we could use a hook similar to what you = (Eli) mentioned in the other subthread. Except instead of having a = functions for face properties, it could be a global function that would = be called on a "realized" plist of face attributes and return the = adjusted one, for the point. The upside is that the display code won't = have to look for another text property (and where its intervals start = and end). I see, so that function could look at some properties at point and = decide whether to alter or =E2=80=9Clet stand=E2=80=9D the computed = faces. I believe that would work and is obviously rather flexible, but = it sounds even more general than the =E2=80=98face-remap property = approach. > The downside, though, is that the realized plist might no be = cache-able (the function can return a different value based on any = number of conditions, right?). Right. I don=E2=80=99t know how the caching is done, but I=E2=80=99d = expect this would be harder. Imagine for example every other invocation = of this =E2=80=9Cfinal-face-remap-function=E2=80=9D you propose changes = from :foreground =E2=80=9Cblue=E2=80=9D to :foreground =E2=80=9Cred=E2=80=9D= (ok not a very useful example, but illustrative). Can the face merge = code notice this repetition and keep the cache valid? =20 --Apple-Mail=_D4F5824A-391F-4821-886A-7DE7656B14A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Jan 5, 2024, at 11:35=E2=80=AFAM, Dmitry Gutov = <dmitry@gutov.dev> wrote:

On 05/01/2024 10:19, Eli = Zaretskii wrote:
I=E2=80=99m sure there could be lots of uses of this type = of functionality, but =E2=80=9Cenhance the focus on one region
of = importance=E2=80=9D seems like a very common one.  For example, you = might imagine dim/gray version of
all the font-lock faces outside the = =E2=80=9Ctreesitter region of interest=E2=80=9D and bright ones inside. =  Whenever that
TS-prescribed region changes, an overlay with a = =E2=80=98face-remap property gets moved.
The question I = suggest to ponder is whether simpler, less general ways
to implement = these features are "good enough".  For example, changing
the = appearance of a region of text can be handled by moving an = overlay
there with a suitable face definition and high priority; = changing the
appearance of text around point can be handled by a = special variable
which the display engine will consider when working = on text around
point;

An overlay with face and = higher priority would override most faces in the region, wouldn't it? = Unless it just sets the background, in which case we already have this = capability.

JD, have you considered it? E.g. set the default = face's background to some darker color and use an overlay which sets = background to a lighter = one.

I=E2=80=99ve = definitely considered =E2=80=9Cre-style all of one particular face = attribute=E2=80=9D options like this and none I=E2=80=99ve found are = suitable in my case (though perhaps for the TS-current-context example I = gave this could be a decent option).  The best analogy is the one I = just offered in my reply to Eli: changing the class of an HTML element = and having subsets of styled text within it automatically updated, = thanks to the inheritance capabilities of CSS (not that that=E2=80=99s = an explicit model for Emacs to emulate; just conveying the = idea). 

But = if that's not sufficient, we could use a hook similar to what you (Eli) = mentioned in the other subthread. Except instead of having a functions = for face properties, it could be a global function that would be called = on a "realized" plist of face attributes and return the adjusted one, = for the point. The upside is that the display code won't have to look = for another text property (and where its intervals start and = end).

I see, so that = function could look at some properties at point and decide whether to = alter or =E2=80=9Clet stand=E2=80=9D the computed faces.  I believe = that would work and is obviously rather flexible, but it sounds = even more general than the =E2=80=98face-remap property = approach.

The = downside, though, is that the realized plist might no be cache-able (the = function can return a different value based on any number of conditions, = right?).

Right.   I don=E2=80=99= t know how the caching is done, but I=E2=80=99d expect this would be = harder.  Imagine for example every other invocation of this = =E2=80=9Cfinal-face-remap-function=E2=80=9D you propose changes from = :foreground =E2=80=9Cblue=E2=80=9D to :foreground =E2=80=9Cred=E2=80=9D = (ok not a very useful example, but illustrative).  Can the face = merge code notice this repetition and keep the cache valid? =  

= --Apple-Mail=_D4F5824A-391F-4821-886A-7DE7656B14A7--