Visual Wrap Prefix Mode

As I wrote yesterday, a lot of really interesting posts popped up all of a sudden and I speculated that I might have to break my rule about not covering items that Sacha has already mentioned. I’m giving myself leave to mention at least one more post from last week.

Bozhidar Batsov has a nice post that explores Emacs line wrapping. As he says, there are basically two ways of doing that:

  1. Hard wrapping that inserts an actual newline in the text to wrap the line at the logical screen width
  2. Soft wrapping with visual-line-mode that doesn’t change the actual text but changes the representation on screen

The problem with visual-line-mode is that it doesn’t respect the indentation context and merely wraps the line at the logical screen edge, which can make the screen representation of the text seem strange. Happily, all this is fixed in Emacs 30 with visual-wrap-prefix-mode that automatically computes the indentation context and indents the text appropriately.

I never noticed this problem before, probably because I turn on visual-line-mode only for prose buffers, never for code buffers. If you are going to export those prose buffers, you really want visual-line-mode so that the text will display correctly on any screen.

Still, I was interested in visual-wrap-prefix-mode because I had never seen the bad wrapping described by Batsov. My writing is mostly straight prose without a lot of fancy indenting such as you might get with, say, poetry. The only time it comes up is with lists like the one above. When I turned visual-wrap-prefix-mode for this buffer, it did indent the subsequent lines of each item but I never really noticed the bad indentation before because it gets rendered correctly when I export it.

In any event, you should definitely take a look at Batsov’s post if you’re having word wrap problems.

This entry was posted in General and tagged . Bookmark the permalink.