The fact that it does not in buffer *scratch*
suggests that it is a problem with the current mode. There are two main possibilities:
What @wvcvw suggested: check what the syntax class of chars
2
and3
is.The
font-lock-keywords
already defined for the mode interact with your code -- e.g., they override it. Try adding'APPEND
as a third arg tofont-lock-add-keywords
. Try addingt
as aHIGHLIGHT
expression to your highlighter sexp (see the doc). That should let your highlighting override any that might already be there otherwise.
BTW, you say it does not work in a "text buffer", but what does that mean? From emacs -Q
, evaluating your code in a buffer in text-mode
shows that it does work. Investigate what your "text buffer" mode is and try the suggestions above (both bullets if necessary, but try the second one first).