I am writing a font-lock rule that calls a function to decide what face to apply to a symbol. Here's a simplified version:
("\\(?1:\\s_+\\)" (1 (the-function 1)))
The problem is that this function needs to generate some data that is just a little bit slow to compute. So, when jit-font-lock starts calling this function for every symbol in the visible buffer, the lag is noticeable.
setq this “slightly-expensive” data to a variable,
(setq data-cache (generate-data))
the-function could just use
data-cache instead of calling
generate-data every time. But then I would have to jump through some
non-trivial hoops to make sure that this cache is always properly
Q: Does the font-lock engine offer help in this regard? How can I make
sure it only runs
(generate-data) once per redisplay?
Ideally, I would like to specify something like “let-bind
the return value of
(generate-data)”. This way I would know that
this cache was never outdated.