In my particular case, I've been trying for several months to achieve
a scheme for position-dependent additional fontification based on treesitter
scope: think font-lock, but respondent not just to the contents of the
buffer, but also the location of point within it. My particular application
is drawing treesitter scope-aware indentation bars. There are many other
applications you could envision, including many discussed here
(e.g. bug#22404).
I've been meaning to add support for that to jit-lock.
Here's the design I have in mind:
From the outside, only one change, i.e. a new function
(jit-lock-flush BEG END FONTIFICATION-FUNCTION)
where FONTIFICATION-FUNCTION is the exact same function that was passed
to `jit-lock-register` (and is thus used as a kind of identifier of the
corresponding backend).
So in your case, when the position-dependent highlighting needs to be
updated, you'd request it by calling `jit-lock-flush`.
The way it would be implemented inside `jit-lock.el` is that
`jit-lock-flush` would set `fontified` to nil over that whole region,
but before that it would scan the region for those places where
`fontified` is non-nil, and set the `jit-lock-already-fontified` property
to the list of currently active backends (minus FONTIFICATION-FUNCTION),
so as to remember that while this region does require jit-lock action
those backends don't need to be called.