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" "~")))

(load-file user-init-file)
(load-file custom-file)
(global-linum-mode t)

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

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

;;; Transparency
 ;;(set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>]))
 (set-frame-parameter (selected-frame) 'alpha '(85 50))
 (add-to-list 'default-frame-alist '(alpha 85 50))

;;; Auto fill to wrap long lines
(add-hook 'text-mode-hook 'turn-on-auto-fill)

Where am I wrong ?

2 Answers 2


According to Emacs FAQ you can 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 to enable auto-fill mode 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, 2012 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, 2012 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, 2012 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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .