Quite frequently, syntax highlighting in a given buffer is broken (i.e., a big fraction of the code is not highlighted). This is definitely not due to syntax errors, and the point at which highlighting stops quite often is in the middle of an identifier. Then, a revert-buffer regularly restores the highlighting. Of course, it is annoying to be forced to do so over and over again. What is the root cause of this, and how can one make the syntax highlighting more robust?

I observe this on python-mode buffers since I program almost exclusively in that language, but I have observed this in other modes, too.

  • 2
    Background information is missing here. What is your emacs-version (get value with M-x emacs-version RET? It looks like a bug as you describe it and therefore emacs-version can be relevant here. What is your system-type (get value with C-h v system-type RET)? Also the terminal type can be relevant for the question: M-: (terminal-name) RET. It would also be good if you added a minimal example where you observe the effect together with a recipe for problem reconstruction starting with emacs -Q.
    – Tobias
    Mar 24, 2020 at 12:51
  • 1
    What @Tobias said. If you see this with emacs -Q then please provide a step-by-step recipe to reproduce it. If not, bisect your init file to find the culprit.
    – Drew
    Mar 24, 2020 at 15:42
  • 1
    I will have a look at whether thinning out my .emacs helps. That said, I observe this problem since I use Emacs – this is since 2001. Mar 24, 2020 at 17:40

1 Answer 1


When there is an error in the syntax highlighting code, it is silently ignored by the font-lock package. When this happens, the buffer can be left in an unhighlighted state.

You can use the package font-lock-studio to investigate what happens, and catch errors in the font-lock code. It is a debugger that lets you step each part of the font-lock rules and if any rule triggers an error, the normal elisp debugger is invoked.

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.