19

Imagine an org buffer in Emacs like:

* Title

Some text describing the title and the codew (sic) and whatnot.

#+BEGIN_SRC emacs_lisp
(setq backup-by-copying t)
#+END_SRC

I want flyspell to check the org buffer (and catch the spelling error in it) but ignore the content between the #+BEGIN_SRC and #+END_SRC marks. How does one go about that?

  • 2
    It looks like someone will need to write up some code using the flyspell-generic-check-word-predicate, if that hasn't already been invented. Here is a related thread for flyspell using the flyspell-generic-check-word-predicate: superuser.com/a/345461/206164 ; and, here is a semi-related thread for ispell using ispell-skip-region-alist, but not relating to flyspell: emacs.stackexchange.com/a/2103/2287 – lawlist Feb 18 '15 at 6:54
  • can emacs.stackexchange.com/a/2103/2609 help? – Name Feb 18 '15 at 12:48
  • This question is a dupe of that one emacs.stackexchange.com/questions/450/… – grettke Feb 18 '15 at 16:53
  • 1
    @grettke: Seems like a dupe, but it's not. Changing the settings for Ispell does not actually solve the problem in Flyspell. At least not when I tried it. – Brian Z Feb 19 '15 at 7:25
  • It works out of the box in v8.3 when you require ox. – rasmus Feb 19 '15 at 16:15
12
;; NO spell check for embedded snippets
(defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
  (let* ((rlt ad-return-value)
         (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\|example\\|quote\\)")
         (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\|example\\|quote\\)")
         (case-fold-search t)
         b e)
    (when ad-return-value
      (save-excursion
        (setq b (re-search-backward begin-regexp nil t))
        (if b (setq e (re-search-forward end-regexp nil t))))
      (if (and b e (< (point) e)) (setq rlt nil)))
    (setq ad-return-value rlt)))

Please note ispell-skip-region-alist is NOT used by flyspell.

Test on Emacs24.3, 24.4, 24.5, 25.1 with builtin org-mode

Most users turn on flyspell by default. So above code is enough.

But I don't enable flyspell-mode in org file. I prefer manually M-x flyspell-buffer again and again. So I need (flyspell-mode 1) (flyspell-mode -1) in org-mode-hook. Yes, turn on then turn off flyspell-mode. The purpose is to make sure the org-mode's default predicate is loaded.

  • I suggest adding quote to the regexp, such as: ` (begin-regexp "^[ \t]*#\\+begin_\(src\\|html\\|latex\\|quote\)") (end-regexp "^[ \t]*#\\+end_\(src\\|html\\|latex\\|quote\)")` – prjorgensen Jun 26 '15 at 1:23

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.