3

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?

3

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.

  • 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 3 '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

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