The problem with the IT industry is that we're drug-testing all the wrong people.

HOWTO make Emacs use soft word wrap like other editors!

Date/Time Permalink: 07/14/06 12:38:35 am
Category: HOWTOs and Guides

When editing text in Emacs, you have two choices. You can either peck happily away and let it wrap at the end of the line with an arrow or slash breaking between characters and completely ignoring the concept of words. Or you can turn on 'auto-fill-mode' and get word-wrapping, but it's a "hard" word-wrap - when you save the file, it's going to put a line-break at the end of each line within the paragraph. That will cause a hard-formatted paragraph in other editors, not a word-wrapped paragraph that will re-size to the window. But I wanted "soft" word-wrap so that I could share my work with other non-Emacs users!

This is one task that frustrated me no end. For the longest time, I scoured the Internet for the answer to this problem, and found plenty of other people griping about it, but no solution. Well, I finally uncovered the mystery solution in bits and pieces all over the place, and here it is for your convenience:

(1) Git the hither to here and save the file as 'longlines.el'.

(2) Become root and move it to your /usr/share/emacs/21.2/site-lisp/ directory. Be sure the permissions are rw-rw-r. Putting it in the plain /lisp/ directory won't work - that's for byte-compiled lisp files ending in .elc

(3) Open your '.emacs' file (that's a period followed by emacs in your home directory; if you don't have one, make one.) and add the following two lines to the end of the file:

(autoload 'longlines-mode "longlines.el" "Minor mode for editing long lines." t)
(add-hook 'text-mode-hook 'longlines-mode) #NOT sure if this line is necessary!

if you have a line earlier in your .emacs file that says something like "text-mode-hook turn-on-auto-fill", comment that line out - you won't need it.

(4) Save your .emacs file and restart Emacs. You can now activate it when you type "M-x text-mode". You can always activate auto-fill mode separately!

I've gotten this to work in both Emacs and Xemacs. And I'm damn glad to have this problem killed and nailed to the wall! Hoping you are the same...

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

blog comments powered by Disqus
suddenly the moon