Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exempt code chunks in an Sweave document from emacs spell check

Tags:

emacs

r

sweave

In a Sweave document, code chunks in R are set off from the main text like so:

Catz are well known for their fur & pur. 

<<echo = false>>=
catz <- 1 + 2 
@

I'd like to run spell check for the LaTeX part (and flag "Catz") but have it skip the code chunks (not flag "catz"). In a long document, hitting "SPC" for each "misspelling" in the code section gets tedious.

like image 891
John Horton Avatar asked Nov 27 '11 17:11

John Horton


1 Answers

Try adding this to your emacs init file:

(add-to-list 'ispell-skip-region-alist '("^<<.*>>=" . "^@"))

Edit (Re Michael Hoffman's comments):

If Flyspell is enabled, these two additional expressions will also be needed:

(defun flyspell-eligible ()
  (let ((p (point)))
    (save-excursion
      (cond ((re-search-backward (ispell-begin-skip-region-regexp) nil t)
             (ispell-skip-region (match-string-no-properties 0))
             (< (point) p))
            (t)))))

(put 'latex-mode 'flyspell-mode-predicate 'flyspell-eligible)

For other modes, replace the latex-mode in the last expression with the appropriate major mode names.

like image 151
huaiyuan Avatar answered Sep 22 '22 15:09

huaiyuan