[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Local face remapping
From: |
Eli Zaretskii |
Subject: |
Re: Local face remapping |
Date: |
Thu, 05 Oct 2023 08:32:54 +0300 |
> From: JD Smith <jdtsmith@gmail.com>
> Date: Wed, 4 Oct 2023 14:48:22 -0400
> Cc: emacs-devel@gnu.org
>
>
> > On Oct 4, 2023, at 12:54 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > Use different faces?
>
> Ha. Yes, of course you can can find and replace all the relevant faces in a
> region, but given that face-remapping-alist already does this efficiently for
> the entire buffer, I had hoped a similar region-constrained / overlay-based
> functionality might exist. I’ll take that as a no :).
Let me help you understand the situation better.
In Emacs, faces are defined per-frame. That is, each frame can have a
different definition of the same face symbol.
face-remapping-alist doesn't (and cannot) change that simple fact, so
it is a trick: it creates new faces based on default faces, in a way
that is buffer-local. This works (btw, not in all places) because the
display engine consults the buffer-local value of face-remapping-alist
each time it needs to realize a face for display. If that variable is
non-nil, and the face to be realized is mentioned in the alist, then
the display engine generates a new face on the fly and uses that new
face for display.
So, if you want face-remapping that depends on buffer positions, you
will need to change the implementation of face-remapping: instead of a
simple alist, we will probably need to also allow a function returning
such an alist, and the C code will need to be taught to deal with
the situation where face-remapping-alist's value is a function.
My suggestion to use different faces just does explicitly what
face-remapping-alist does implicitly.