Computers & Software

Emacs Word Wrap Modes

I had problems sending posts to WordPress from weblogger on Emacs because of formatting errors. I have been using auto-fill-mode in Emacs to avoid lines extending off the screen. Auto-fill-mode works by inserting newline characters (ASCII 0A, C-j) at the end of each line. Turning off auto-fill-mode does not eliminate these characters. If you want to see for yourself, use auto-fill-mode to write something and then use hexl-mode to examine the buffer. You will see that instead of spaces between some words there are little periods, which are linefeed characters. You can also use whitespace-mode to see the same thing. The linefeed characters in this mode are dollar signs ($). Anyway, these characters completely mess up the formatting in WordPress, leaving you with a ragged right margin, and lines split in odd places. If you don’t use auto-fill-mode, all is well, but don’t try using it and then turning it off. The newlines are there to stay. You can remove them by search and replace (M-%), searching for linefeeds (use C-q C-j to enter a linefeed) and replacing with spaces. Unfortunately this also deletes legitimate paragraph splits. So I read about and started using longlines-mode. This mode inserts the linefeeds, but also removes them again when you toggle it off. Again you can demonstrate this effect by using whitespace-mode. Seems like just what you need to make text look better without causing permanent changes to your text file, and perfect for weblogger-mode.

Then I read about visual-line-mode. It seems to do the same thing as longline-mode, except it doesn’t insert the linefeeds into the text. It just wraps the text on the screen somehow without putting in the linefeeds. You can see what it does again by using whitespace-mode. So, that’s a wrap!

By mannd

I am a retired cardiac electrophysiologist who has worked both in private practice in Louisville, Kentucky and as a Professor of Medicine at the University of Colorado in Denver. I am interested not only in medicine, but also in computer programming, music, science fiction, fantasy, 30s pulp literature, and a whole lot more.

One reply on “Emacs Word Wrap Modes”

If you are wondering why I am complaining about ragged right margins above when all the posts have ragged right margins, I changed my blog WordPress theme after writing this, and the new theme includes a ragged right margin. So I don’t have to worry about the margin anymore, but the weird line breaks are still a problem that requires the above fix.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.