|
From: | JD Smith |
Subject: | font-lock and FACENAME eval: doc (+API) |
Date: | Fri, 2 Feb 2024 18:21:54 -0500 |
Especially now with treesitter, there are many examples where font-lock would be a good solution to a problem, but you want to do more than just apply faces to text. You may want to alter 'display properties, hide regions, add other embellishments, etc. I've long noticed a usage of the font-lock API that seems to go nearly unmentioned in the docs, and which I've used myself (highlight added):
You'll often find font-lock-keywords with the following form (here from org-modern): `((,org-list-full-item-re (3 (org-modern--checkbox) nil t)))) Here FACENAME = (org-modern--checkbox). This just delegates all the work of setting text properties on the associated text to the FACENAME form, which evals a function call. This raises a few issues; i) Is it not inefficient to evaluate (some-func) vs. calling it directly in performane-sensitive font-locking code? ii) Should this behavior be documented in some way? I was endlessly confused by this common pattern when I was studying font-lock, since the docs do not allude to it at all. ii) If not, should some explicit hook functionality be added to font-lock's API, to open up for other uses its exceptional ability to treat only the text in need of updating? |
[Prev in Thread] | Current Thread | [Next in Thread] |