When using js-mode (or js2-mode) on Emacs 25.1 (in Debian 9) to edit some large files, any attempt to insert text after some "random" point in the file fails with an elisp stack trace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  c-literal-limits(nil nil t)
  call-interactively(c-context-line-break nil nil)

Why and how can it be fixed?


It turned out that my personal config (and those of the people I tested this with) manually bound C-m to c-context-line-break in js-mode. So the right answer is to not do this (and leave it as newline-and-indent.) Silly me.

Original "workaround":

The looking-at(nil) gave a pretty good hint that this was a cc-mode regex left unset by js-mode and js2-mode. An Edebug session quickly showed that the culprit was c-block-comment-start-regexp.

So, to fix it, I just defined that variable in a hook in ~/.emacs. For example, for js-mode:

(add-hook 'js-mode-hook (lambda () (setq c-block-comment-start-regexp "/\\*")))
  • 1
    Arguably, the bug is that js-mode uses c-context-line-break even tho it's not a "cc-mode". – Stefan Feb 18 '18 at 0:05
  • This might be worth reporting to maintainers of js-mode. – DoMiNeLa10 Feb 18 '18 at 14:56
  • @DoMiNeLa10: Good point. I've sent the maintainer a note. – Brad Spencer Feb 18 '18 at 17:45
  • Ha, and guess what. It turns out that it's my configuration (and those of everyone else I had try this out, by chance) that binds C-m to c-context-line-break! Oops. Well, I guess I'll fix this the right way by not doing that. – Brad Spencer Feb 18 '18 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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