1

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!

Murph
  • 179

1 Answers1

0

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.

zellio
  • 306