Subject: bug#71345: Feature: unleash font-lock's secret weapon; handle Qfontified = non-nil

From: Stefan Monnier <[email-masked]>
Date: Mon, 03 Jun 2024 21:44:36 -0400

> Thanks.  Very interesting approach, recycling the existing Qfontified
> handler.  I wonder though, if you have several different unrelated functions
> calling `jit-lock-flush' with different FONTIFICATION-FUNCTION's prior to
> jit-lock-fontify-now running on a region, won't they step on each other?

Not if `jit-lock.el` handles it correctly, no.

> I.e it seems that you would need to look for existing
> jit-lock-already-fontified+fontified=nil properties over the region
> mentioned in jit-lock-flush and subtract the passed FONTIFICATION-FUNCTION
> from the various values already found there.

Yes, of course.

> Of course you'd also need to handle the case where you "subtract it
> all the way to nil".

I don't think you'd need to do anything special for this case.

> That starts to sound like a lot of property slinging, which might even
> dominate the work done.

Indeed, this amount of work could become significant.  It's my main
worry, but I don't have a clear feel for how serious it would be
in practice.

We could try and unify `fontified` and `jit-lock-already-fontified` by
having a `fontified-done-value` variable and making the redisplay call
jit-lock whenever `fontified` has a value that's not-eq from
`fontified-done-value`.

So jit-lock would set `fontified-done-value` to the list of backends.

> I imagine that the functions may also need a way to opt-out of "deferred
> contextual refontification", for example if they add some other
> properties/overlays orthogonal to face.

`jit-lock.el` already has that info (it's the second arg to
`jit-lock-register`), but it currently doesn't keep track of it
individually for each backend.

        Stefan