Can't properly disable flyspell in org mode

1.1k views Asked by At

I set up emacs to turn flyspell on by default for text mode using

(add-hook 'flyspell-mode-hook 'flyspell-buffer)
(add-hook 'text-mode-hook 'flyspell-mode)

I would like to disable it automatically in org mode files, and I did manage to disable it using a lambda function in the org mode hook:

(add-hook 'org-mode-hook (lambda () (flyspell-mode -1)))

This works, but the syntax highlight changes that flyspell did still remain, and interfere with org mode's syntax highlight. I also see in the minibuffer that flyspell does run when I visit that file, so apparently it is turned off only afterwards. How do I turn it off in such a way that would leave no trace of it in the org mode file, or better yet not run at all?

2

There are 2 answers

2
fniessen On

Regarding the first question (remove the highlightings), the following call should do it:

(flyspell-delete-all-overlays)

However, are you really, really, really sure you want to disable flyspell in Org mode??? Is there a really, really, really good reason for that?

If yes, shouldn't you solve that one, instead of trying the above?

7
AudioBubble On

You can selectively enable flyspell in text-mode hook by checking the major-mode. The following will enable flyspell in text-mode and its derived modes except org-mode

(add-hook 'flyspell-mode-hook 'flyspell-buffer)

(add-hook 'text-mode-hook (lambda ()
                                 (when (not (equal major-mode 'org-mode))
                                   (flyspell-mode t))))