MapaDoSite ModificaçõesRecentes Notícias SeçãoElisp HowTo

TransposeParagraphAsTable

I (MarkArmstrong) frequently edit big space-separated text tables. The hardest thing to to in emacs is edit table columns, as most emacs commands operate most efficiently in a line-oriented nature.

I have tried to use the various other modes and functions for aligning text and working with tables as found in this wiki, but they really bog down when tables get big (hundreds or thousands of rows and columns) for one or more of the following reasons:

In contrast, I find that a simple transpose and align function allows emacs to function well as a table editor even in basic text mode. Most importantly, once a table has been transposed, the powerful line-oriented editing commands can now operate effectively on columns. Also, once the table has been aligned, even the builtin rectangle edit commands become more useful for editing columns.

The below command will act upon the paragraph containing the point in any text document. It will interpret that paragraph as a text table by splitting the lines using the split-string function. It will then replace that paragraph with its transpose with columns left-aligned. Column widths are determined by the maximum element size in each column. If the table is not rectangular then missing elements are replaced with “.”.

I find no need for a separate align-only command since that can be achieved simply by transposing twice.

Example:

a bbbb c       a    1 4
1 2       -->  bbbb 2 5
4 5 6          c    . 6

Here is what to put in your init.el:

  (require 'transpar)
  (global-set-key (kbd "C-c C-x") 'transpose-paragraph-as-table)

Here is the code: transpar.el.


CategoryEditing CategoryAlignment CategoryTables