When editing Markdown files (.md, .mdwn, etc.) and Mediawiki files (.mw), I almost always need to have flyspell-mode loaded. How to have that automatically happen via configuration?

4 Answers 4


Put this in your .emacs:

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

It will enable flyspell-mode whenever markdown-mode is entered; i.e. when you open markdown files.

  • Adding (add-hook 'markdown-mode-hook 'flyspell-mode) had no effect AFAICT. After restarting Emacs and opening a .mdwn file, the mini-buffer shows the Markdown-mode is automatically enabled, but not the flyspell-mode.
    – qazwsx
    Commented Oct 10, 2015 at 18:05
  • 1
    Revisiting this thread after two years, now in Emacs 25.2, your solution seems to work now. I verified that Flyspell mode is turned on by restarting Emacs, opening a new file test.md, and seeing that Flyspell is listed in M-x describe-mode.
    – qazwsx
    Commented Jun 11, 2017 at 20:52

There are two answers recommending adding flyspell-mode as a markdown-mode-hook function. Perhaps the problem is that flyspell-mode is a toggle. There is also turn-on-flyspell, defined like so:

(defun turn-on-flyspell ()
  "Unconditionally turn on Flyspell mode."
  (flyspell-mode 1))

This is a built-in function which accomplishes the same thing as in marcanuy's answer.

So, this should do what you want, unconditionally:

(add-hook 'markdown-mode-hook 'turn-on-flyspell)
(add-hook 'mediawiki-mode-hook 'turn-on-flyspell)
  • 1
    To avoid those problems, minor modes were changed years ago so that calling foo-mode from Elisp (e.g. via a major mode hook) just turns the mode ON rather than doing the toggling that happens via that function is called interactively. So no: you don't need to resort to turn-on-foo-mode (these functions are relics from the time before I made this change).
    – Stefan
    Commented Jun 11, 2017 at 0:49
  • Thanks for clarifying, @Stefan. I wondered why qazwsx had trouble with using the minor mode function directly. I also didn't realize at first that this was a two-year-old thread :) Commented Jun 11, 2017 at 20:48

Base on Trebuchette's answer:

(add-hook 'markdown-mode-hook 'flyspell-mode)
(add-hook 'mediawiki-mode-hook 'flyspell-mode)

But if you want to turn on flyspell-mode while editing text files in various major-modes, you can just use:

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

this will works because markdown-mode and mediawiki-mode are base on text-mode. Analogously, we use prog-mode-hook to setup common programming environment.

  • Adding (add-hook 'text-mode-hook 'flyspell-mode) to .emacs has no effect when I restarted Emacs and opened a .mdwn file. The .mdwn file did triggered Markdown-mode though.
    – qazwsx
    Commented Oct 10, 2015 at 18:02

I was looking for the same and finally found a solution that works:

(dolist (hook '(markdown-mode-hook))
      (add-hook hook (lambda () (flyspell-mode 1))))

Tested in GNU Emacs 25.1

Not tested this but should also work for other modes like mediawiki:

(dolist (hook '(markdown-mode-hook mediawiki-mode-hook))
      (add-hook hook (lambda () (flyspell-mode 1))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.