I want to load flyspell-mode and execute flyspell-buffer automatically after emacs loaded a tex file. I tried the following which loads flyspell-mode but doesn't seem to execute flyspell-buffer. What would be the proper way to to this? How do I have to change it if I want it on every file not just on LaTeX-files?

(setq ispell-program-name "hunspell")
(setq ispell-local-dictionary "de_DE")
(setq ispell-local-dictionary-alist
      '(("de_DE" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil nil nil utf-8)
    ("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil nil nil utf-8)

(add-hook 'LaTeX-mode-hook 'turn-on-flyspell)
(add-hook 'LaTeX-mode-hook 'flyspell-buffer)
  • 1
    I have similar problems, flyspell checks for errors but asynchronously (it does not immediately flag errors but only if I scroll to a nearby location). Maybe you can try one from the following to see if it helps: find-file-hooks, after-save-hook, before-save-hook, and auto-save-hook? I have the following but it is often very slow: (add-hook 'before-save-hook #'flyspell-buffer). Commented Feb 10, 2016 at 17:36
  • @SwarnenduBiswas What does the # mean in this context?
    – student
    Commented Feb 10, 2016 at 17:47
  • @student See emacs.stackexchange.com/questions/3595/…
    – JeanPierre
    Commented Feb 10, 2016 at 19:28
  • @student This post explains why is it beneficial to sharp-quote symbols that are functions endlessparentheses.com/…. Commented Feb 11, 2016 at 17:15

1 Answer 1


It suffices to properly choose and trickily chain hooks.

(add-hook 'text-mode-hook #'flyspell-mode)
(add-hook 'flyspell-mode-hook #'flyspell-local-vars)
(defun flyspell-local-vars ()
  (add-hook 'hack-local-variables-hook #'flyspell-buffer))

(add-hook 'flyspell-mode-hook #'flyspell-buffer) would do the job, but it would use the default dictionary.

  • The last add-hook should be local otherwise flyspell-buffer will be run on all buffer you open after opening a text-mode buffer. IOW it should be (add-hook 'hack-local-variables #'flyspell-buffer nil 'local).
    – Stefan
    Commented Apr 25, 2020 at 11:34

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.