Code Monkey home page Code Monkey logo

emacs-org-transform-tree-table's Introduction

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:

  • People who aren't Emacs users tend to use it a lot.

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:

  • The special property COLUMNS are out on the right, to be out of the way when the table is being edited in e.g. Excel or Open Office.

  • The transformation is only 99% round-trip safe since there might be some reordering of properties taking place. Also, org-mode insists on reporting property names in uppper-case, so if you have mixed-case properties they will be mangled :/

  • It's possible to have many COLUMNS declarations for different parts of the tree. Some of them might be repeated at a lower level. Useful techniques to keep them in sync:

    • Multiple cursors
    • M-x iedit
    • Search and replace
  • Each line of text under a heading turns into a row.

  • The indentation / whitespace in the text has a leading non-breaking-space to keep the layout inside the table.

  • The outline can also be written to a tab-separated value buffer, which can be opened in e.g. Excel.

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)

emacs-org-transform-tree-table's People

Contributors

jplindstrom avatar syohex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

emacs-org-transform-tree-table's Issues

Perhaps tag a release?

I've found this occasionally useful---so thanks for developing it!---and was wondering if it might not make sense to tag a release so that melpa-stable will pick it up?

Wrong number of arguments error

Thanks for making this package!

I'm using helm spacemacs. When I copy your example table:

| 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 |                                    |

then I can call org-transform-table/org-tree-buffer-from-org-table, and the example outline is generated.

However, when I copy and paste the example outline, I cannot generate a table, and I have the same problem with another outline I've made.

I get helm-M-x: Wrong number of arguments: (0 . 2), 3.

Seems odd that it will work on a table, but not on an outline.

Thanks for any ideas!

the cases are not conserved

Hi
consider please the following sequence

| Heading         | User | Email | Phone |
| * First entry   |      |       |       |
| ** Second entry |      |       |       |
| ** Third entry  |      |       |       |


| Heading         | User  | Email           | Phone |
| * First entry   | Mike  | [email protected]  |  1234 |
| ** Second entry | Joe   | [email protected]   |  5678 |
| ** Third entry  | Linda | [email protected] |  9012 |

that get transformed to

* First entry
  :PROPERTIES:
  :User:     Mike
  :Email:    [email protected]
  :Phone:    1234
  :END:
** Second entry
   :PROPERTIES:
   :User:     Joe
   :Email:    [email protected]
   :Phone:    5678
   :END:
** Third entry
   :PROPERTIES:
   :User:     Linda
   :Email:    [email protected]
   :Phone:    9012
   :END:

case conserved, but when again toggling back

| Heading         | USER  | EMAIL           | PHONE |
| * First entry   | Mike  | [email protected]  |  1234 |
| ** Second entry | Joe   | [email protected]   |  5678 |
| ** Third entry  | Linda | [email protected] |  9012 |

case is not saved

that is a bit annoying, any change to change it?

regards

Uwe Brauer

if a tree contains a list it is nicely converted to a table, however when converting back the list structure is destroyed

Hi
consider

* Heading
** First
** second
   1. Start a list
   2. Second item
      a. subitem

that is converted to

| Heading            |
| * Heading          |
| ** First           |
| ** second          |
|    1. Start a list |
|    2. Second item  |
|       a. subitem   |

however this is converted back to

* Heading
** First
** second
1. Start a list
2. Second item
a. subitem

so the list structure is lost.
Any change to save it?
regards
Uwe Brauer

how to make it work?

Hello,

I would like to know if you can help me on how to use your package. I have
this file. I open it in, activate org-mode, I do M-: (require 'org-transform-tree-table) then M-x org-transform-table/org-tree-buffer-from-csv, but I get an error:
Before first headline at position 29 in buffer reviews.txt-tree.csv . I also tried in csv-mode, and with other files. Your package seems very interesting to me, but I don't know how to use it.

What am I doing wrong? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.