When visual-line mode is enabled, words wrap at the window edge. When the window is wide, this makes much too long of a line for comfortable reading. To fix that I have found visual-fill-column-mode
, which makes it so that words wrap at a 70-column boundary even if the window is wider than that. However, it does this by setting the right margin for the entire window. There are situations where I don't want this wrapping to apply to the entire window.
One example is when editing Markdown or latex documents which mix prose sections with preformatted code sections -- wrapping into a 70-column region makes the prose sections easier to read but breaks lines in code, making them harder to read.
Another example is in org-mode or similar documents that have deeply nested outline structure. A paragraph at the top level gets a normal column width, but a paragraph that is deeply indented (with adaptive-wrap-prefix-mode) gets formatted in a very narrow, tall region -- for documents like this I would prefer that both left and right margins moved with the indent level.
I did find there is a "right-margin" text property in addition to the window property. You can mark a region, then M-: (put-text-property (mark) (point) 'right-margin 20)
. Then if you M-q
on that region, it will wrap into a narrower column. But this only affects the result of M-q
, and not the appearance of word-wrap / visual-line-mode. I also tried the obsolete longlines-mode but it also does not seem to respect the text property.
Any solutions I am overlooking?