2

About 15-20 minutes into using emacs my syntax highlighting stops dynamically updating. Instead any new text just uses the color of the text right before it.

Any ideas on how to debug this issue or any work arounds? Running M-x global-font-lock-mode (x2) properly refreshes it, but it doesn't re-enable the dynamic syntax highlighting.

The only way to solve the issue I've found is to kill my emacs server and start a new server, but the issue eventually crops up again.

Here are some screenshots of Python code which shows the behavior.

Here it is properly highlighted:

enter image description here

This is what new code looks like after it stops working:

enter image description here

And here's how it looks after running M-x font-lock-mode (x2):

enter image description here

2 Answers 2

2

This is normally a sign that some error occurred during font-locking. I suggest you look at the *Messages* buffer soon after the highlighting stops updating dynamically (it should contain some error message about it).

You can try and get more info about the error with:

M-x font-lock-debug-mode RET
M-x toggle-debug-on-error RET

Or with

M-x toggle-debug-on-error RET
M-: (setq font-lock-support-mode nil) RET
M-x font-lock-mode RET
M-x font-lock-mode RET

[ I.e. re-start font-lock so it pays attention to the new value of font-lock-support-mode. ]

After that, try and reproduce the problem which should then give you a backtrace.

1
  • Another alternative is to use package github.com/Lindydancer/font-lock-studio -- it's a debugger for font-lock keywords. If you step or run the keywords inside font-lock-studio (and debug-on-error or non-nil), the elisp debugger will start if it encounters a problem with a font-lock keyword. Jul 20, 2018 at 19:01
1

Also check the variable inhibit-modification-hooks (docs). If your case is like mine, font-lock gets stuck because an error occurs in one of the modification hook functions (... not even necessarily font-lock itself), and, as a consequence:

If an unhandled error happens in running these functions, the variable's value remains nil. That prevents the error from happening repeatedly and making Emacs nonfunctional.

... but then also, after-modification functions aren't called anymore, font lock doesn't work automatically, and you won't get stack traces from the code that was actually broken, until you restart emacs, or, more conveniently:

(setq inhibit-modification-functions nil)

You can then proceed with Stefan's methods for debugging afterwards!

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.