Line wrapping in Org mode

Line wrapping in Org mode doesn’t feel right to me. I always struggle with all the different elements org has to offer. A common setting to rule them all won’t fit here. While I like to wrap text at the edge of the frame1, I hate to break source code and tables. Both of them just look terrible and get unusable once broken. They should be truncated instead and take as much space as they need.

A good max length for paragraphs would be between 80 and 120 characters per line they say. But I don’t like to fill and unfill paragraphs all the time. It would be the same as manually breaking lines, which ends up in a nightmare with different widths, faces and font sizes. If I could use CSS to tell Emacs how to break lines, I would do exactly like I do on this page:

body {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

pre {
    overflow: auto;
}

There is already a discussion on the mailing list about a smarter way of word wrapping:

[…] I have actually put in a feature request into Emacs for a property `truncate-line’, to be able to control this line by line. I got positive feedback, but I don’t know when any of the developers finds time to implement it - I cannot do that myself.

But this issue has never been solved properly. I don’t know how other people deal with. I got used to edit source blocks in their own buffer. It is convenient but also required to get indentation right. Thus I prefer to truncate these buffers and hide2 all kind of blocks in my org files by default.

(with-eval-after-load 'org
  (add-hook 'org-mode-hook 'visual-line-mode)
  (add-hook 'org-mode-hook 'org-hide-block-all)
  (add-hook 'org-src-mode-hook 'toggle-truncate-lines))

It works quite well for source code but tables usually do not use such blocks. To wrap them I need to use dynamic blocks and write a command to edit them in their own buffer.

TODO org-table-edit-table

I need to use advise functions to modify the default behaviour of C-c ' while the mark is being on a table and determine between formulas. With C-h k I got to know which command above shortcut is bind to, where it is defined and how the function looks like. I could also load org from source to create a patch and contribute to the core.

(defun org-table-edit-table()
  "Edit an entire table in its own buffer"
  (interactive)
  ...
  (prin1 (org-element-context)))

The Org Element API provides tools to get the current context and its beginning and ending positions, those I can pass on to buffer-substring to create a new buffer and insert into.

Footnotes:

1

Visual line mode allows to navigate lines how they visually appear on the screen rather than the logical way. When using evil-mode you’ve to make sure to set evil-respect-visual-line-mode before.

2

The visibility can also be changed with in-buffer settings or toggled manually all at once with org-hide-block-all and org-show-block-all.