How do I add fontification of additional keywords ? This does not work:

(add-hook 'c++-mode-hook
  (lambda ()
   '(("^\\(trn\\|def\\|mem\\)\\>" . 'font-lock-keyword-face)))))

I am using a variant of the C++ language, where trn def and mem are also kewywords and should be fontified as such (purple). The above code seems not to have any effect. They are instead fontified as types (green).

Using Emacs 26.1

  • A guess is that your font-lock entry conflicts with or is overridden by other font-lock entries that your mode inherits from c++-mode by being derived from it. Check the value of font-lock-keywords. I think you have a straight font-lock question, not a question about derived modes. If you instead try to add your entry to c++-mode, as a test, I suspect you'll encounter the same problem.
    – Drew
    Mar 20 at 0:32
  • @Drew my values do indeed end up in font-lock-keywords. Found out that it does indeed fontify but only if no c++-mode fontification has been triggered. So my question is rather how to I make my fontification higer priority. Mar 20 at 14:24
  • Please update your question to make that clear. Comments can be deleted at any time - questions need to stand on their own. Thx.
    – Drew
    Mar 20 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.