James Cherti has a quick tip worth reviewing if you’re not familiar with highlighting keywords in your source code. The idea is simple; you merely add the regexes for the keywords that you want to highlight to a font-lock-add-keywords
call.
The normal way of doing that is to add the font-lock-add-keywords
call to a function and invoke the function from a hook function for wherever you want it to take effect. In Cherti’s case he wants it to take effect in all his programming buffers so he adds it to the prog-mode-hook
.
When I read Cherti’s post it seemed vaguely familiar so I checked my init.el
and discovered that long ago before I really knew what I was doing, I added some silly Elisp macro I wrote to the list of keywords to be added to Elisp buffers. I did it just as Cherti suggests but added it to the emacs-lisp-mode-hook
and lisp-onteraction-mode-hook
instead of prog-mode-hook
.
In any event, it you want to emphasize certain tags in your code, it’s easy to do. You can specify where they should be emphasized by adding the call to specific hook functions. The font-lock-add-keywords
function also allows you to adjust the font face for the keywords if you’d like. See Cherti’s post or the documentation for details.