emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug: Revert orgtbl-create-or-convert-from-region [6.33x]


From: Daniel Hornung
Subject: Re: [O] Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
Date: Mon, 5 Aug 2013 11:49:52 +0200
User-agent: KMail/1.13.6 (Linux/2.6.38-16-generic; KDE/4.6.5; x86_64; ; )

On Monday, August 05, 2013 11:16:55 Thorsten Jolitz wrote:
> Daniel Hornung <address@hidden> writes:
> > I think one great way to increase the usefulness of org-mode would be a
> > function which turns a table into a csv or tsv block of text again.
> > 
> > I assume that the functionality exists already in org-table-export, I
> > would just wish for this to be exposed as a function which converts the
> > table in place instead of writing it into a new file (org-table-export
> > does not allow overwriting the current file).
> > 
> > This would finally give a comfortable way to edit tsv or csv tables
> > without hassles in emacs.
> 
> Would you need something more sophisticated than this?
> 
> #+TBLNAME: tbl
> 
> | header 1 | header 2 | header 3 |
> |
> |----------+----------+----------|
> |
> | label1   |        3 |       99 |
> | label2   |        2 |       66 |
> | label3   |        7 |      231 |
> 
> #+TBLFM: $3=$2*33
> 
> #+HEADER: :var table=tbl :hlines no
> #+HEADER: :results list verbatim
> #+begin_src emacs-lisp
> (defun tbl2csv (table-as-lisp)
>   (mapconcat
>    (lambda (row)
>      (mapconcat
>       (lambda (cell)
>          (format "%s" cell))
>       row ","))
>    table-as-lisp ","))
> 
> (tbl2csv table)
> #+end_src
> 
> #+results:
> : "header 1,header 2,header 3,label1,3,99,label2,2,66,label3,7,231"
> 
> --
> cheers,
> Thorsten

The idea looks OK, although I did not get it to run with C-x C-e (copied the 
content into a new buffer, entered org-mode and executed the elisp code).  For 
more specific handling of e.g. strings, the code used in
http://orgmode.org/w/?p=org-mode.git;a=blob;f=lisp/org-table.el;hb=HEAD#l601
looks more like it could be used already, though. Plus, it allows to specify 
the column and row separators (e.g. "\t" and "\n").

Cheers,
Daniel

-- 
Max-Planck-Institute for Dynamics and Self-Organization
Laboratory for Fluid Dynamics, Pattern Formation and Biocomplexity
Biomedical Physics Group

Am Fassberg 17
D-37077 Goettingen

(+49) 551 5176 373

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]