I generally want font-locking only for comments and strings. This would seem easy to do: customize the relevant font lock faces to make them identical to default
. That unfortunately is not satisfactory, because many other places which actually benefit from some highlighting (dired, org, probably magit) reuse the font lock faces.
The next best solution seems to be adding some buffer-local face remaps in prog-mode
buffers. I've been using this for some time, and it mostly works fine.
One problem with this approach is that the font lock colors "leak" into other buffers that copy the original buffer's content (since my face remaps are buffer local). This is particularly bad for Swiper, consult-lines and the like, since the superposition of match highlights with the font locking becomes quite disconcerting (to me at least).
Is there a (simple, major-mode indepedent) way to tell font-lock-mode
to actually not add any face properties except for those I want?
font-lock-keywords
tonil
. Or hopefully someone will provide a simple answer. (The opposite, getting only search-based and not also syntactic (strings, comments), is easily obtainable.)font-lock-keywords
is the way to do it! It also removes a few nice little things, like the distinction of docstring from regular ones and f-strings in Python, but this can be fixed by scrutinizing the content offont-lock-keywords
.