I use python-mode for my Python code, and every once in a while the syntax highlighter gets confused and thinks everything in the buffer is a string literal. This typically seems to happen when I create a docstring; for a few seconds after I type the quotes, everything after the cursor is highlighted as a string.

Is there any way to prevent this entirely? Or, if not, is there some way to make emacs/python-mode recover more quickly?

ed: To be clear, the incorrect highlighting persists even after the quotes have been closed and the buffer saved. But again, this is not every time, just sometimes.

  • 5
    Do you mean after you type the opening quotes? Because, in that case, the rest of the buffer is a (doc)string. You could solve this by having Emacs automatically insert the closing quotes after your cursor or something. Oct 23, 2014 at 20:20
  • No, the highlighting persists sometimes for several seconds after the quotes have been closed (though I don't currently have emacs insert those for me.)
    – abingham
    Oct 24, 2014 at 5:48
  • Ugh, something similar happens to me all the time when I'm in a REPL and I accidentally print a bunch of text. Not sure if it's related, but maybe this issue is more general than just python-mode. Oct 25, 2014 at 5:02
  • Interesting point. I tested out c++-mode a bit, and it seems to have the same behavior. If I leave a string literal "open" long enough, the remainder of the buffer gets highlighted as part of the string (which makes perfect sense.) After closing the literal, it can take several seconds for the highlighting to recover. It seems, then, that there's some timer telling emacs to re-parse/-highlight the buffer.
    – abingham
    Oct 25, 2014 at 11:45
  • Have you tried reporting this bug?
    – Dmitry
    Nov 9, 2014 at 10:03

1 Answer 1


When you modify the buffer, only the lines you modified get re-highlighted right away. If the modification affects highlighting of lines futher down, these get re-highlighted later via an idle timer (i.e. it happens after you stop typing).

This delay is controlled by jit-lock-context-time and defaults to 0.5s. Note that it really means "Emacs has been idle for half a second", so as long as you keep giving Emacs commands without leaving more than half a second between commands, the re-highlighting does not happen.

If you think it takes more than 0.5s and can come up with a recipe that triggers this excessive delay, then you'll want to M-x report-emacs-bug.

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.