all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: JD Smith <jdtsmith@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: region-based face-remapping
Date: Sat, 06 Jan 2024 16:27:04 +0200	[thread overview]
Message-ID: <83sf3asfk7.fsf@gnu.org> (raw)
In-Reply-To: <8B06B532-A445-43AE-883D-C9E5CF5DB870@gmail.com> (message from JD Smith on Sat, 6 Jan 2024 08:53:22 -0500)

> From: JD Smith <jdtsmith@gmail.com>
> Date: Sat, 6 Jan 2024 08:53:22 -0500
> Cc: emacs-devel@gnu.org
> 
>  This makes sense, thanks.  In the ‘face-remap property scenario, the number of such ‘face
>  property-change positions doesn’t actually change.
> 
>  I don't think this is true. If the 'face-remap' property changes at
>  some buffer position, the realized faces need to change there,
>  although the 'face' property didn't change. So with the 'face-remap'
>  property, we'd need to arrange for face-merging also where the
>  'face-remap' property changes, not only where the 'face' property
>  changes.
> 
> I wondered about that.  Since I don’t know emacs internals, I am (blissfully?) unaware of how close at
> hand the information of (get-text-property (point) 'face-remap) is.  Since a typical buffer has maybe
> N=hundreds of ‘face changes, this puts an approximate upper limit on the number of sensible ‘face +
> ‘face-remap changes: 2N.  Much more likely would be just a handful of ‘face-remap changes.  So I
> doubt the overhead of “additional merging” would be significant.  Of course you have to find these
> special points, but already you must find ‘face and ‘font-lock-face (and others?).

I only wrote the above because you said that "the number of such
'face' property changes will not change".  I'm saying that it _will_
change, and moreover, that the display engine will need to search for
this new property, in addition to the properties it searches for
already.  Whether this will add significantly to the processing
requirements, I don't know, because I don't have a clear idea what
application-level features you have in mind.  I do know that, like the
proverbial wisdom of "640KB should be enough for everyone", any
assumptions in Emacs that some feature will be used only "a little"
eventually becomes false.  We have ample examples of that:

  . the number of overlays in a buffer, which recently caused us to
    radically change how overlays are stored
  . the number of faces on a frame, which recently caused us to
    radically change how a frame's faces are stored

and there are other examples.

>  How many faces do you have defined on that frame?  I'm guessing not
>  many, or maybe they are all almost identical (differ in only one or
>  two simple attributes).
> 
>  Right now it’s just a couple of faces (remove one face-remap, add another).  If I had
>  access to a
>  ‘face-remap property, I could imagine maybe 10 faces at most being affected as point
>  changes. 
>  Each face would change by one or two attributes like foreground, stipple, etc.  
> 
>  What matters is the total number of named faces defined for the frame,
>  not the number of faces affected by face-remap.
> 
> I define the faces on the fly based on max indentation depth, but in practice it’s of order 5 more than
> the normal contingent of a dozen or so font-lock-faces.  So not a huge number.

Maybe not in your use patterns, but some users here reported many
hundreds of faces on each frame.  It is the reason why we changed
frame-face-alist to use a hash table instead.

With many faces defined for a frame, recomputing all of them is a
process that visibly slows down certain operations in Emacs.

>  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; 
> 
> Indeed I have pondered this for several months and found nothing suitable.  Do you have any specific
> approaches to consider, which would allow you to selectively affect the appearance of certain small
> ranges of text within a (much) larger region of text?  The problem is, the region is well known, but
> changing the appearance everywhere within it is not suitable to the problem at hand.  I could
> obviously scrub through the entire region on the fly replacing face properties as I go (including inside
> ‘display properties), but that’s painful and probably too slow for interactive use.

I cannot be of more help here without understanding better what kinds
of application-level features you want to support.  Until now, you
only described that in very general terms.

>  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; etc.  
> 
> I’m afraid I don’t understand your “special variable to consider for text around point” idea.  Can you
> give an example of how this could work in practice?  How would such a variable be updated and
> associated with text, if not via text properties?

It could be a buffer-local variable, which defines the size of the
region around point where the faces should change their appearance,
and how to change the appearance.  The display engine then could take
that into consideration when processing buffer positions around point.

Whether this makes sense depends on the applications you have in mind.

> If you have other simpler ideas in mind that would allow turning on and off a latent “plane” of varying
> face information within a region of text (information which, I should have mentioned, could easily be
> computed and pre-applied by font-lock), I’d be very glad to hear them.
> 
> In the world of CSS, you’d do this quite simply by (say) updating the class of the div which wraps your
> text of interest, and having special styling for, e.g., "alternate bold" and "alternate italic”, which is only
> activated when the “alternate” class is applied:
> 
>  <div class=“normal”>
> 
>  This is <i>some italic text</i> and <b>some bold</b> text.  This is unrelated text.
> 
>  </div>
> 
>  In CSS
> 
>  .alternate b {...}
>  .alternate i {…}
> 
>  (In JS later:)
> 
>   myDiv.classList.add('alternate');

You are describing how to specify the effect, whereas I'm bothered by
the implementation which could support that.  Faces in Emacs are
specific to the entire frame, and we have face-remapping to change
that within limits buffer-locally.  We don't currently have any
infrastructure that allows the faces to change on a finer resolution,
except if the Lisp program modifies the 'face' text properties or
defines overlays with 'face' properties.



  reply	other threads:[~2024-01-06 14:27 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02  0:22 region-based face-remapping JD Smith
2024-01-02 13:00 ` Eli Zaretskii
2024-01-02 15:49   ` JD Smith
2024-01-03 12:31     ` Eli Zaretskii
2024-01-03 12:40       ` Dmitry Gutov
2024-01-03 13:42         ` Eli Zaretskii
2024-01-04  0:07           ` Dmitry Gutov
2024-01-04  7:05             ` Eli Zaretskii
2024-01-05  3:49               ` Dmitry Gutov
2024-01-05  8:50                 ` Eli Zaretskii
2024-01-05 14:18                   ` Dmitry Gutov
2024-01-05 14:34                     ` Eli Zaretskii
2024-01-05 16:25                       ` Dmitry Gutov
2024-01-03 23:15       ` JD Smith
2024-01-04  6:58         ` Eli Zaretskii
2024-01-05  0:51           ` JD Smith
2024-01-05  8:19             ` Eli Zaretskii
2024-01-05 16:35               ` Dmitry Gutov
2024-01-06 14:04                 ` JD Smith
2024-01-06 13:53               ` JD Smith
2024-01-06 14:27                 ` Eli Zaretskii [this message]
2024-01-06 14:56                   ` JD Smith
2024-01-08 17:28                     ` Eli Zaretskii
2024-01-07  3:41                 ` Dmitry Gutov
2024-01-15 19:55     ` Stefan Monnier via Emacs development discussions.
2024-01-15 20:19       ` Eli Zaretskii
2024-01-15 20:25         ` Eli Zaretskii
2024-01-15 20:36         ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2024-01-08 21:49 JD Smith
2024-01-09 13:03 ` Eli Zaretskii
2024-01-09 14:15   ` Stefan Monnier
2024-01-09 20:20     ` JD Smith
2024-01-10 12:36       ` Eli Zaretskii
2024-01-09 20:20     ` JD Smith
2024-01-15 20:17       ` Stefan Monnier via Emacs development discussions.
2024-01-09 21:31   ` JD Smith
2024-01-10 12:44     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83sf3asfk7.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=jdtsmith@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.