jplindstrom / emacs-org-transform-tree-table

Transform an org-mode outline and its properties to a table format (org-table, CSV)
GNU General Public License v3.0
26 stars 4 forks source link

emacs-org-transform-tree-table

Transform an org-mode outline with properties to a table format (org-table, CSV), or the other way around.

This makes it possible to have an outline with properties and work with it in column view.

Then you can transform the outline to a table to share with others (export to CSV and open in Excel), and back again.

Note: This makes more sense if you start out from an org-mode tree, convert to a table and then convert back again. If you start out with a regular table and try to convert it into a tree, it won't have any of the org-mode tree stuff in it, so there's no useful structure there.

More about column view:

More about Excel:

Usage

From org tree, to table

;; Org outline to an org table
M-x org-transform-tree/org-table-buffer-from-outline

;; Org outline to CSV (or rather, tab-separated value)
M-x org-transform-tree/csv-table-buffer-from-outline

If the region is active, convert that part of the tree. Otherwise, if point is on an org heading, convert that heading and its subtree. Otherwise convert the buffer.

In the resulting table, row one is the column titles. The rest of the rows are property values.

Column one is the outline heading, and the rest are the properties in the order they first appear in the buffer.

However, all special properties (e.g. 'COLUMNS', '*_ALL') are placed after all the user properties (i.e. whatever properties the user has added to capture information).

Text content under a heading is also transformed and put in the first column.

Special values that can't be represented in an org table are escaped:

|                   ==> \vert{}
first leading space ==> non-breaking space (C-x 8 SPC)

From table, to org tree

;; From an org table to an org outline
M-x org-transform-table/org-tree-buffer-from-org-table

;; From CSV (tab separated) to an org outline
M-x org-transform-table/org-tree-buffer-from-csv

When converting from an org table, point must be on a table.

When converting CSV, convert the buffer.

Values escaped from any tree->table transformation are unescaped (see above).

Tiny example

This outline:

* Pages
  :PROPERTIES:
  :COLUMNS:  %30ITEM %10LOGIN %10ACCESS %10COST
  :END:
** About
   :PROPERTIES:
   :LOGIN:    No
   :ACCESS:   All
   :END:
** Products
   :PROPERTIES:
   :COLUMNS: %30ITEM %10Color
   :ACCESS:   All
   :LOGIN:    No
   :END:
*** Free Widget
    :PROPERTIES:
    :ACCESS:   All
    :LOGIN:    Yes
    :COLOR:    Green
    :END:

    This one is:
    - Awesome
    - Green
*** Paid Thingy
    :PROPERTIES:
    :ACCESS:   Paid
    :COST:     30
    :LOGIN:    Yes
    :COLOR:    Blue
    :END:

Transforms into:

| Heading          | LOGIN | ACCESS | COLOR | COST | COLUMNS                            |
| * Pages          |       |        |       |      | %30ITEM %10Login %10Access %10Cost |
| ** About         | No    | All    |       |      |                                    |
| ** Products      | No    | All    |       |      | %30ITEM %10Color                   |
| *** Free Widget  | Yes   | All    | Green |      |                                    |
|     This one is: |       |        |       |      |                                    |
|     - Awesome    |       |        |       |      |                                    |
|     - Green      |       |        |       |      |                                    |
| *** Paid Thingy  | Yes   | Paid   | Blue  |   30 |                                    |

Note that:

Installation

MELPA

Install org-transform-tree-table using MELPA like any other module.

Manually

Clone the repo into somewhere in the load-path.

git clone https://github.com/jplindstrom/emacs-org-transform-tree-table.git

and initialize with:

(require 'org-transform-tree-table)