# How to automatically wrap long lines in emacs?

I just tried Gnu emacs 23 automatic long line wrapping feature using M-x auto-fill-mode. it works perfectly. Now I modified my .emacs file as following to have this feature always turned on but it doesn't work ...

;;; Xemacs backwards compatibility file
(setq user-init-file
(expand-file-name "init.el"
(expand-file-name ".xemacs" "~")))
(setq custom-file
(expand-file-name "custom.el"
(expand-file-name ".xemacs" "~")))

(global-linum-mode t)

;;; Scrollbar on the right
(set-scroll-bar-mode 'right)

;;; Open help file
(find-file "/home/manu/These/Docs/Emacs-Shortcuts")
(split-window-horizontally)

;;; Transparency
;;(set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>]))
(set-frame-parameter (selected-frame) 'alpha '(85 50))

;;; Auto fill to wrap long lines


Where am I wrong ?

-

## migrated from stackoverflow.comSep 14 '12 at 23:43

This question came from our site for professional and enthusiast programmers.

According to Emacs FAQ you to turn on auto-fill mode just for text-mode (for general text files)

(add-hook 'text-mode-hook 'turn-on-auto-fill)


If you want auto-fill mode on globally (for all modes) add this line to your ini file:

(setq-default auto-fill-function 'do-auto-fill)

-
Thanks !! Just one more question, I conclude that tex files (the ones I am working with now) are not considered as general text files. It sounds strange, no ? –  Manuel Selva Sep 14 '12 at 8:04
No.Text mode is a major mode for editing files of text in a human language. Files which have names ending in the extension .txt are usually opened in Text mode Emacs text-mode –  hostmaster Sep 14 '12 at 8:30
In your case it is most likely latex-mode which is default mode for editing tex/latex files in emacs –  hostmaster Sep 14 '12 at 8:33

Emacs 23 has visual-line-mode, which does not change the text, but instead wraps long lines on word boundaries when the buffer is displayed. For some kinds of document this is better than auto-fill-mode, which changes the text, and so loses the distinction between "soft" and "hard" line breaks.

You can automatically turn on visual-line-mode in the same way as auto-fill-mode, for example:

(add-hook 'text-mode-hook 'turn-on-visual-line-mode)

-