For example, I'm writing a Lua file. I noticed that the table keys are not highlighted:

enter image description here

I'd like to make the table keys in a different color than values, like what Emacs does for YAML:

enter image description here

But I don't know how to configure it. I tried to enable eglot with a Lua langauge server, but it doesn't seen to affect how the syntax elements are highlighted.

1 Answer 1


Every buffer has one "major mode" which determines what Emacs will do to best support editing that particular language. See chapter 24.1 Major Modes in the Emacs manual for more information.

Emacs will tell you what mode a buffer is in if you type C-h m. (This will also show information about the minor modes.) Each mode makes different choices about what sort of syntax highlighting to do. This is called “font locking” in Emacs for historical reasons. See chapter 24.6 Font Lock Mode in the Emacs Lisp manual for more information.

The mode you are using might use treesitter, but it probably relies on the older regex–based font locking. A few modes may provide customizable options that control what is highlighted and what isn’t, but most do not. Therefore to change what is highlighted you will generally need to write code that tells font-lock-mode what to do.


To clarify, while language servers and the Language Server Protocol are useful for many things, they don’t help out at all when it comes to syntax highlighting.

  • I have eglot and language server on tho, does emacs use that for syntax highlighting? Or it's just for showing errors/warnings? Sep 12, 2023 at 5:24
  • 1
    The language server is an external program that tells you about errors and warnings. Eglot integrates messages from the language server to Emacs. The syntax highlighting comes from the major mode, which is completely independant of Eglot and the language server. If you are not happy with the syntax highlighting from your major mode, you can either write your own using font-lock-mode, as suggested in the answer, or you can use the package tree-sitter which enhances syntax highlighting and provide a more fine-grained control over it. Sep 12, 2023 at 6:51
  • @TristanRiehs I see. Thank you for the answer! Sep 12, 2023 at 12:53

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.