4

When I'm writing in org-mode I want it to automatically handle the creation of new lines similar to MS Word.

Can anyone recommend an .emacs config that will only apply to org-mode?

Drew
  • 75,699
  • 9
  • 109
  • 225
Philip Kirkbride
  • 557
  • 5
  • 14

1 Answers1

4

This will work:

(add-hook 'org-mode-hook '(lambda () (setq fill-column 80)))
(add-hook 'org-mode-hook 'auto-fill-mode)

It enables a minor mode called auto-fill-mode that does exactly what you asked and sets the column where the line break happens to 80 (only for org-mode!).

EDIT:

To be consistent with Emacs Manual you could use

(add-hook 'org-mode-hook '(lambda () (setq fill-column 80)))
(add-hook 'org-mode-hook 'turn-on-auto-fill)

Even though I'm not sure what is the difference between both of them.

Vitorqb
  • 88
  • 6
  • In earlier Emacs versions `xxx-mode` toggled a minor mode, so minor modes often provided an additional function `turn-on-xxx-mode`. However, in newer versions of Emacs, `xxx-mode` only toggles a mode when called interactively -- so that it should be possible to add it to a hook. – Lindydancer Sep 03 '17 at 18:44
  • Thanks. I add the two lines to my init.el. After I reload init.el by M-x load-file, it doesn't work. Even I further reopen a file in a new buffer, and switch to org-mode, still not work. May I ask how to make the change take effective? – Tim Oct 18 '18 at 12:41
  • Can it be run after each save? – alper Aug 01 '22 at 22:21