Alex Stoddard
Alex Stoddard

Reputation: 8344

Viewing delimited columns in emacs

Is anyone aware of an emacs mode or function that will reformat a buffer holding a delimited file such that each delimiter (e.g. tab) defines a "column" with the width of each column set to the longest entry?

I can reset the tab-width variable but that makes all columns equal width. I would much prefer variable-width columns if possible (like how a spreadsheet program like excel would display such a file after resizing the columns).

Upvotes: 14

Views: 3184

Answers (3)

Alex Stoddard
Alex Stoddard

Reputation: 8344

Org-mode as suggested by huaiyuan did just what I wanted.

To give an example to others, after I installed org-mode I found the following to work well.

Open a new file in org-mode C-x C-f table.org and then M-x org-table-import to import the delimited file, and you're done.

The C-| command didn't work for me to convert pre-existing buffer contents into a table, it just inserted a new table, but I don't know org-mode yet.

Upvotes: 5

huaiyuan
huaiyuan

Reputation: 26539

Check out Org mode's table editor.

Upvotes: 14

scottfrazer
scottfrazer

Reputation: 17327

Let's assume your delimiter is TAB. Mark the whole buffer, then:

C-u M-x align-regexp \(\s-*\)TAB RET RET RET y

Where TAB in there is an actual tab char. See my similar answer here:

how to align arguments to functions in emacs?

Upvotes: 3

Related Questions