Skip to content

analyticd/org-table-wrap-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Functions for wrapping and unwrapping org table content.

org-tables already have many useful functions that can be used to manipulate them: org-table-cut-region, org-table-copy-region, org-table-paste-rectangle, org-table-wrap-region

Also, org-tables column width can be constrained via, e.g., <30>, and then each cell edited with org-table-edit-field. Further, an org-table can be converted to a table.el table with C-c ~ and then use table.el’s functions to manipulate the table. Despite all this, I still wanted more.

Original inspiration: First answer at: org mode - Org tables: Wrap all fields in column to a given size - Emacs Stack Exchange

Original function works on this table (except that it doesn’t move hlines as it should):

1onea
2twob
3This is a long chunk of textc
4fourd
5Yet another long chunk of texte

Original function partly works (but swallows “four” line) on this table:

1onea
2twob
3This is a long chunk of textc
4fourd
5Yet another long chunk of texte

Original function barely works on this table:

1onea
2twob
3This is a long chunk of textc
4fourd
5Yet another long chunk of texte

My version of function works on all these tables correctly.

Possible configuration using use-package:

(use-package org-table-wrap-functions
  :load-path  /path/to/org-table-wrap-functions-repo-dir
  :bind (:map org-mode-map ("C-|" . 'org-table-column-wrap-to-point))
  :bind (:map org-mode-map ("C->" . 'org-table-unwrap-cell-region)))

Usage: I rarely use org-table-column-wrap-to-width, but I’ve included it in case someone wants to use it. I do use org-table-column-wrap-to-point with the binding shown above. I find that after using this and subsequently adding other long columns, rather than rewrapping the whole column (which works) I will use org-table-wrap-cell-at-point, which I have bound to ‘<evil-leader-key> C’ to tidy up the cell. If you wish to execute org-table-wrap-cell-at-point multiple times you can do so with ‘.’ if you use evil-mode. Be mindful that for large tables the column wrapping functions take a while to complete, but if you are patient they will complete.

Note also that the column wrap functions are smart enough to not break words apart as it uses org-wrap to do the heavy lifting. So, you can place your cursor inside a word and execute the column wrap functions and it will do what you expect.

Finally, you sometimes have need to unwrap a previously wrapped table cell. To do so, first highlight the text of the cell using either a normal region or a rectangle region, and then do M-x org-table-unwrap-cell-region.

If you are an evil-mode user, you’ll find it useful to know and use evil-visual-block and evil-delete to fix up some issues caused by wrapping more than one column.

The best overall solution I have found is to:

  1. Unwrap a cell by highlighting all the text in its region
  2. execute org-table-unwrap-cell-region, then
  3. remove empty table lines, i.e., rows, then
  4. convert to a table.el table via C-c ~ and then
  5. use C-u <number of chars width you'd like to shrink the cell by> M-x table-narrow-cell until you get the width for the column you want then
  6. (optional) convert the table back to an org-table via C-c ~ again and do any final tidying up to the table.

To wrap content in one cell I find repeated uses of M-<return>, org-table-wrap-region.

If you are only needing to wrap one column (and no others), then org-table-column-wrap-to-point or org-table-column-wrap-to-width are reliable.

Note that if your intent is to export your table, you are better off not wrapping text explicitly in org-tables and instead, perhaps, using the column constraint feature of org-tables, via <20>, to control the width.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published