First some disambiguation:
This Endless Parentheses page demonstrates how to use
ispell-skip-region-alist
to skip=code=
and=verbatim=
blocks with ispell…(defun endless/org-ispell () "Configure `ispell-skip-region-alist' for `org-mode'." (make-local-variable 'ispell-skip-region-alist) (add-to-list 'ispell-skip-region-alist '(org-property-drawer-re)) (add-to-list 'ispell-skip-region-alist '("~" "~")) (add-to-list 'ispell-skip-region-alist '("=" "=")) (add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC"))) (add-hook 'org-mode-hook #'endless/org-ispell)
…however,
flyspell
does not useispell-skip-region-alist
.This question on Emacs SX demonstrates how to skip flyspell checking for source blocks…
;; 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)))
…but not for inline code and verbatim region.
How can I achieve the ispell
solution for flyspell
, where Flyspell skips any regions surrounded by ~
or =
? Generally I use these for things like variable names, which naturally tend to fail spellchecking.
flyspell-incorrect-hook
is only for light weight and generic setup. See my updated answer – chen bin Jan 16 '20 at 10:09#'org+-flyspell-skip-code
is added buffer locally toflyspell-incorrect-hook
. So there is no interference with other major modes. Let the OP decide whether the performance is a killer argument. Aspell is a background process that keeps running when it is started once. Therefore there is not so much overhead as one would guess at the first sight. – Tobias Jan 16 '20 at 10:23flyspell-generic-check-word-predicate
which is buffer local out of box so user has not chance to to make the mistake. Besides,flyspell-incorrect-hook
is executed AFTER the predicate. So it can't override predicate's logic. – chen bin Jan 16 '20 at 10:32flyspell-generic-check-word-predicate
should be used. I had a look intoorg-compat.el
. There stands(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
. This should make flyspell work correctly out of the box. Maybe, we should help Matthew in a chat to identify the problem with his org version. – Tobias Jan 16 '20 at 11:53(setq flyspell-generic-check-word-predicate org-mode-flyspell-verify)
inorg-mode-hook
– chen bin Jan 16 '20 at 12:05~code~
and=verbatim=
. Thank you! – Rudolf Adamkovic May 15 '21 at 22:44