There is highlight-blocks-mode which is very nice, but it highlights only blocks based on parens matching. I would like to add support of semantic blocks too.
For example to treat case
, try / catch
, lambda
and other expressions as blocks and highlight code inside them.
I've readed about syntax tables, but they seem only work with syntax, and can't help me with my problem.
Is there something in Elisp I can use for this task?
There is an official language mode (I want this for Erlang now), and it has list of keywords, but I think it uses them for indentation and highlighting only.
Emacs's major modes usually do not include a complete parser for the language they support. For indentation purpose they do need to perform some amount of parsing, but it's usually done in a partial and superficial way only.
Major modes based on SMIE tend to fare a little better in this because the approach taken by SMIE is to clearly divide the indenter's task into parsing on one side and indentation rules on the other, so the parsing side is usually more complete and thorough. This said, it's still usually incomplete or approximate.
So for major modes based on SMIE, you could use smie-backard-sexp
and smie-forward-sexp
to find the enclosing "semantic blocks".