26.15.7 Converting Between Plain Text and Tables

The command M-x table-capture captures plain text in a region and turns it into a table. Unlike M-x table-recognize (see Table Recognition), the original text does not need to have a table appearance; it only needs to have a logical table-like structure.

For example, suppose we have the following numbers, which are divided into three lines and separated horizontally by commas:

1, 2, 3, 4
5, 6, 7, 8
, 9, 10

Invoking M-x table-capture on that text produces this table:

+-----+-----+-----+-----+
|1    |2    |3    |4    |
+-----+-----+-----+-----+
|5    |6    |7    |8    |
+-----+-----+-----+-----+
|     |9    |10   |     |
+-----+-----+-----+-----+

M-x table-release does the opposite: it converts a table back to plain text, removing its cell borders.

One application of this pair of commands is to edit a text in layout. Look at the following three paragraphs:

table-capture is a powerful command.
Here are some things it can do:

Parse Cell Items   Using row and column delimiter regexps,
                   it parses the specified text area and
                   extracts cell items into a table.

Applying table-capture to a region containing the above text, with empty strings for the column and row delimiter regexps, creates a table with a single cell like the following one.

+----------------------------------------------------------+
|table-capture is a powerful command.                      |
|Here are some things it can do:                           |
|                                                          |
|Parse Cell Items   Using row and column delimiter regexps,|
|                   it parses the specified text area and  |
|                   extracts cell items into a table.      |
+----------------------------------------------------------+

We can then use the cell splitting commands (see Commands for Table Cells) to subdivide the table so that each paragraph occupies a cell:

+----------------------------------------------------------+
|table-capture is a powerful command.                      |
|Here are some things it can do:                           |
+-----------------+----------------------------------------+
|Parse Cell Items | Using row and column delimiter regexps,|
|                 | it parses the specified text area and  |
|                 | extracts cell items into a table.      |
+-----------------+----------------------------------------+

Each cell can now be edited independently without affecting the layout of other cells. When finished, we can invoke M-x table-release to convert the table back to plain text.