;; 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\\)")
(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.
flyspell-incorrect-hook is not the good place for per major mode configuration because it's shared by all major modes. So the heavy weight configuration code in one major mode could impact other major modes if the per major mode code is placed in
flyspell has already provided
flyspell-generic-check-word-predicate which is "Function providing per-mode customization over which words are flyspelled". It's buffer local variable so it safe to use out of box.
Screenshot of its definition from
Besides, the predicate is more flexible than the hook because the predicate is tested at first. So if the predicate claims a word is not a typo, the hook will not be executed. Here is the screenshot of
Actually, the default value of
The reason I advice
org-mode-flyspell-verify is I'm lazy. I could change the value of the predicate to my own function which calls
(defun org-mode-hook-setup ()
(let* ((rlt (org-mode-flyspell-verify)))
;; do whatever on rlt below this line
(message "rlt=%s" rlt)
(add-hook 'org-mode-hook 'org-mode-hook-setup)