Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks!

share|improve this question

1 Answer 1

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

;;;###autoload
(defun flyspell-prog-mode ()
  "Turn on `flyspell-mode' for comments and strings."
  (interactive)
  (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

 
discard

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.