Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using js2-mode with flyspell-prog-mode to spellcheck comments and strings.

When using jQuery, you use selectors like $("#something") or $('something else'). Can I configure flyspell to not spellcheck these strings? Basically, anything wrapped in $( and ). Handling jQuery( and ) would be cool, too, but I can probably manage that.

I found this question, which is similar, but I was unable to adapt it myself. How to exclude {{{ ... }}} in flyspell-mode and flyspell-buffer?


share|improve this question
up vote 0 down vote accepted

The short of it is you really can't, at least not without some serious hacking of flyspell and/or your major mode.

From the flyspell source

(defun flyspell-prog-mode ()
  "Turn on `flyspell-mode' for comments and strings."
  (setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify)
  (flyspell-mode 1)
  (run-hooks 'flyspell-prog-mode-hook))

The relevant line being where we set the flyspell-generic-check-word-p function to flyspell-generic-progmode-verify that function looks like this

(defun flyspell-generic-progmode-verify ()
  "Used for `flyspell-generic-check-word-p' in programming modes."
  (let ((f (get-text-property (point) 'face)))
    (memq f flyspell-prog-text-faces)))

Finally we need to look at flyspell-prog-text-faces

(defvar flyspell-prog-text-faces
  '(font-lock-string-face font-lock-comment-face font-lock-doc-face)
  "Faces corresponding to text in programming-mode buffers.")

So as can now be readily seen, flyspell is using the fontface of the text to verify what it has been typed as ( this is actually probably the most efficient way for flyspell to handle this problem. It means that it doesn't have to re-parse your code ).

Your options are either a custom version of flyspell-generic-progmode-verify to load into flyspell-generic-check-word-p or modifying the major mode such that it produces different faces for your various strings.

share|improve this answer
These are not the only options. Before (flyspell-prog-mode) you can simply (setq flyspell-prog-text-faces '(font-lock-comment-face font-lock-doc-face)) to disable strings. This works. – Andreas Spindler May 23 '13 at 12:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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