Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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")
(split-window-horizontally)

;;; 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 ?

share|improve this question

migrated from stackoverflow.com Sep 14 '12 at 23:43

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

up vote 3 down vote accepted

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)
share|improve this answer
    
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)
share|improve this answer

You must log in to answer this question.

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