11

I can't find what can be added to init file to enable automatic spell check by default.

Automatic spell checking (Flyspell) can be enabled from menu -- may be there is a way to learn how menu entry work?

Braiam
  • 1
  • 11
  • 47
  • 78
Onlyjob
  • 5,692
  • 2
  • 35
  • 35
  • 1
    I'm not sure if this is a programming question. Doesn't sound like it. Try super user? (vim user here, can't help either way) – dequis Apr 09 '13 at 01:42
  • 2
    Of course it is a programming question because you can only do it programmatically. Here is an [answer how to do it](http://stackoverflow.com/questions/6860750/how-to-enable-flyspell-mode-in-emacs-for-all-files-and-all-major-modes/6861176#6861176). – Onlyjob Apr 09 '13 at 01:45
  • 1
    Yeah, I'm aware that emacs uses lisp, but it still sounds like you want to use a feature of your editor instead of coding something. Anyway, is that answer what you were looking for? If so, you should close this answer or edit it into something else. – dequis Apr 09 '13 at 01:51

1 Answers1

20

I have the following in my init.el:

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

That covers my editing needs just fine.

Hooks are like 'events' or the observer pattern if you're used to OOP: they're lists of functions that get run at certain points. One of the main ways you customise Emacs is by adding your own functions to these hooks.

Most modes in Emacs call a hook when they're enabled. prog-mode is the mode from which programming modes are derived, so adding functions to prog-mode-hook customises all programming modes.

The best reference for this stuff is the built-in Emacs Lisp manual (C-h r or M-x info-emacs-manual). It has sections on Emacs Lisp programming, including a chapter on hooks.

Chris Barrett
  • 3,383
  • 17
  • 21
  • 2
    Thank you. I also added `(setq ispell-dictionary "british")` to choose default dictionary. – Onlyjob Apr 09 '13 at 06:42
  • I found that your workaround do not work with many file types. For example `emacs foo.log` will not have spell checker on when `emacs foo.log.txt` will. The following apparently work for all files: `(add-hook 'find-file-hooks 'turn-on-flyspell)` – Onlyjob Apr 09 '13 at 06:48