38

visual-line-mode is very useful to wrap lines with the window size changing without inserting any newlines. But in org-mode, it also wraps the headline and source blocks which is a little bit annoying.

So here comes my question: How can I turn off visual-line-mode for org-heading and source blocks permanently in org-mode?

Andrew Swann
  • 3,436
  • 2
  • 15
  • 43
Leu_Grady
  • 2,420
  • 1
  • 17
  • 27
  • 1
    If it is possible to both wrap `(setq word-wrap t)` **and** truncate `(setq truncate-lines t`) different portions of the same buffer, I'll definitely make this thread one of my favorites! – lawlist Jan 16 '15 at 07:14
  • @lawlist So you mean it is impossible to make it in org-mode? – Leu_Grady Jan 16 '15 at 07:15
  • I'm certainly no expert, but I've always thought the two are mutually exclusive -- however, there are some really bright forum participants -- so let's hear what the experts have to say! – lawlist Jan 16 '15 at 07:16
  • 2
    Lol, you are a expert on emacs in my mind, lol. Okay, let's expect solvable answers! – Leu_Grady Jan 16 '15 at 07:23
  • 1
    Here is an idea that I use, but it is not what you had in mind. I have the default in the buffer as being `(setq truncate-lines t)` and `(setq word-wrap nil)`. When I edit any entry or if I just want to zoom-in/focus on one entry in particular, I have it set to narrow to subtree, at which time it wraps with `visual-line-mode` -- aka `(setq word-wrap t)` and `(setq truncate-lines nil)`. When I finish editing, it widens and goes back to truncated lines. – lawlist Jan 16 '15 at 07:24
  • Another idea would be to fold / hide the remainder of a source-code block or heading that extends beyond a set number of characters or columns (e.g., equal to window-edge), which can be unfolded. Not built-in (to my limited knowledge), but doable with a little (?) programming effort. – lawlist Jan 16 '15 at 07:32
  • 2
    I'm pretty sure there is no way to inhibit word wrap for some regions only, e.g. via text properties. Report it as bug. Of course, one might rationalize that code lines shouldn't be that long in the first place. As for headlines (and lists), `org-indent-mode' looks pretty nice. – olaf b Mar 13 '15 at 19:05

3 Answers3

20

Another solution is to use adaptive-wrap-prefix-mode.

This way you'll see the full header and source but it will wrap nicely indented.

With visual-line-mode:

enter image description here

With visual-line-mode and adaptive-wrap-prefix-mode:

enter image description here

Jordon Biondo
  • 12,332
  • 2
  • 41
  • 62
4

The package phscroll written by misohena perfectly solved the problem. It adds overlays to beginning/end of line if the width of elements like org-table exceeds the length, while keeps the line-wraps work.

Currently it only supports org-table, but theoretically it can be extended to almost all org elements.

Leu_Grady
  • 2,420
  • 1
  • 17
  • 27
1

This is a good question! The same issue applies when you have an Org table that is wider than fill-column. What I do is open the section in an indirect buffer with org-tree-to-indirect-buffer i.e. C-c C-x b. And in the indirect buffer, I disable visual-line-mode for editing that section.

D. Smith
  • 11
  • 1
  • This pin-points also my major problem with `adaptive-wrap-prefix-mode`. Pityingly the solution is cumbersome. But, that is not your fault. – Tobias Mar 09 '18 at 08:38
  • @Tobias I made a new command that narrow the table while turning on `truncate-lines`, then you can enjoy the unwrapped table, which is pretty nice. – Leu_Grady Sep 10 '20 at 09:44