I am working on a corporate installation. They have emacs, and it has tcl mode. The issue is that the command lassign is not highlighted, unlike, for example, set, or return.

What that I would like, is that w/o changing the original, installed, Tcl-Mode ELISP code, add lassign (and others) to the list/dict that are highlighted.

1 Answer 1


You can do this using the function font-lock-add-keywords. It takes two arguments, the first is the major mode to extend. Alternatively, you can pass nil which mean the current buffer, which is useful if you call the function from a hook. The second is a list of font-lock keywords. This is a special data structure described in the documentation of the variable font-lock-keywords.

For example, it could look like:

(defun my-c-mode-hook ()
  (font-lock-add-keywords nil
    '(("\\_<\\(k[A-Z0-9][a-zA-Z0-9_]*\\)\\_>" (0 font-lock-constant-face)))))
(add-hook 'c-mode-hook #'my-c-mode-hook)

The font-lock keyword match words like kThisIsAConstant using a regular expression (or regexp). The 0 mean that the entire match should be highlighted and font-lock-constant-face is used to highlight the match


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.