* Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
@ 2013-08-05 7:49 Daniel Hornung
2013-08-05 9:16 ` Thorsten Jolitz
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Hornung @ 2013-08-05 7:49 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: Text/Plain, Size: 2091 bytes --]
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen. You don't know how to make a good report? See
http://orgmode.org/manual/Feedback.html#Feedback
Your bug report will be posted to the Org-mode mailing list.
------------------------------------------------------------------------
[Feature request]
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.
-----------------------------------------------------------------------
Emacs : GNU Emacs 23.2.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.4)
of 2011-04-04 on crested, modified by Debian
Package: Org-mode version 6.33x
current state:
==============
(setq
org-after-todo-state-change-hook '(org-clock-out-if-current)
org-export-preprocess-hook '(org-export-blocks-preprocess)
org-tab-first-hook '(org-hide-block-toggle-maybe)
org-src-mode-hook '(org-src-mode-configure-edit-buffer)
org-confirm-shell-link-function 'yes-or-no-p
org-agenda-before-write-hook '(org-agenda-add-entry-text)
org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-
cycle-show-empty-lines
org-optimize-window-after-visibility-change)
org-mode-hook '(#[nil "\300\301\302\303\304$\207" [org-add-hook change-major-
mode-hook org-show-block-all append local] 5])
org-confirm-elisp-link-function 'yes-or-no-p
org-occur-hook '(org-first-headline-recenter)
)
--
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 #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-05 7:49 Bug: Revert orgtbl-create-or-convert-from-region [6.33x] Daniel Hornung
@ 2013-08-05 9:16 ` Thorsten Jolitz
2013-08-05 9:49 ` Daniel Hornung
0 siblings, 1 reply; 9+ messages in thread
From: Thorsten Jolitz @ 2013-08-05 9:16 UTC (permalink / raw)
To: emacs-orgmode
Daniel Hornung <daniel.hornung@ds.mpg.de> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-05 9:16 ` Thorsten Jolitz
@ 2013-08-05 9:49 ` Daniel Hornung
2013-08-05 13:26 ` Thorsten Jolitz
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Hornung @ 2013-08-05 9:49 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: Text/Plain, Size: 2091 bytes --]
On Monday, August 05, 2013 11:16:55 Thorsten Jolitz wrote:
> Daniel Hornung <daniel.hornung@ds.mpg.de> 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 #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-05 9:49 ` Daniel Hornung
@ 2013-08-05 13:26 ` Thorsten Jolitz
2013-08-05 14:07 ` Thorsten Jolitz
2013-08-05 14:19 ` Nick Dokos
0 siblings, 2 replies; 9+ messages in thread
From: Thorsten Jolitz @ 2013-08-05 13:26 UTC (permalink / raw)
To: emacs-orgmode
Daniel Hornung <daniel.hornung@ds.mpg.de> writes:
> On Monday, August 05, 2013 11:16:55 Thorsten Jolitz wrote:
>> Daniel Hornung <daniel.hornung@ds.mpg.de> 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).
Mmh...it works here ... the table looks a bit distorted in your post ...
> 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").
In tbl2csv, one could replace the two hardcoded "," with function args
'col-separator' and 'row-separator'.
Or use something like this:
#+begin_src emacs-lisp
(defun tj/insert-exported-table (&optional insertion-point file)
(let ((tmp-file (or file (make-temp-file "foo")))
(insert-point (or insertion-point (1+ (org-table-end)))))
(org-table-export tmp-file "orgtbl-to-csv")
(goto-char insert-point)
(insert-file-contents tmp-file)))
#+end_src
#+results:
: tj/insert-exported-table
then do 'M-: (tj/insert-exported-table)' on this table:
| header 1 | header 2 | header 3 |
|----------+----------+----------|
| label1 | 3 | 99 |
| label2 | 2 | 66 |
| label3 | 7 | 231 |
header 1,header 2,header 3
label1,3,99
label2,2,66
label3,7,231
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-05 13:26 ` Thorsten Jolitz
@ 2013-08-05 14:07 ` Thorsten Jolitz
2013-08-05 14:19 ` Nick Dokos
1 sibling, 0 replies; 9+ messages in thread
From: Thorsten Jolitz @ 2013-08-05 14:07 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Or use something like this:
>
> #+begin_src emacs-lisp
> (defun tj/insert-exported-table (&optional insertion-point file)
> (let ((tmp-file (or file (make-temp-file "foo")))
> (insert-point (or insertion-point (1+ (org-table-end)))))
> (org-table-export tmp-file "orgtbl-to-csv")
> (goto-char insert-point)
> (insert-file-contents tmp-file)))
> #+end_src
actually, to make it more useful, it should be expanded to something like:
#+begin_src emacs-lisp
(defun tj/insert-exported-table (&optional insertion-point format file)
"Insert table exportet to FILE with function FORMAT.
Insertion position is either below the exportet table or INSERTION-POINT."
(interactive
(cond
((equal current-prefix-arg nil) nil)
((equal current-prefix-arg '(4))
(list
(read-number "Insertion Point: ")))
((equal current-prefix-arg '(16))
(list
(read-number "Insertion Point: ")
;; enter without double quotes
(read-string "Format: ")))
(t
(list
(read-number "Insertion Point: ")
(read-string "Format: ")
(ido-read-file-name "File: ")))))
(let ((tmp-file (or file (make-temp-file "foo")))
(insert-point (or insertion-point (1+ (org-table-end))))
(fmt (or format "orgtbl-to-csv")))
(org-table-export tmp-file fmt)
(save-excursion
(goto-char insert-point)
(insert-file-contents tmp-file))))
#+end_src
#+results:
: tj/insert-exported-table
do 'M-x tj/insert-exported-table' on this table:
| header 1 | header 2 | header 3 |
|----------+----------+----------|
| label1 | 3 | 99 |
| label2 | 2 | 66 |
| label3 | 7 | 231 |
header 1,header 2,header 3
label1,3,99
label2,2,66
label3,7,231
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-05 13:26 ` Thorsten Jolitz
2013-08-05 14:07 ` Thorsten Jolitz
@ 2013-08-05 14:19 ` Nick Dokos
2013-08-07 8:49 ` Daniel Hornung
1 sibling, 1 reply; 9+ messages in thread
From: Nick Dokos @ 2013-08-05 14:19 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Daniel Hornung <daniel.hornung@ds.mpg.de> writes:
>
>> On Monday, August 05, 2013 11:16:55 Thorsten Jolitz wrote:
>>> Daniel Hornung <daniel.hornung@ds.mpg.de> 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).
>
> Mmh...it works here ... the table looks a bit distorted in your post ...
>
>> 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").
>
> In tbl2csv, one could replace the two hardcoded "," with function args
> 'col-separator' and 'row-separator'.
>
> Or use something like this:
>
> #+begin_src emacs-lisp
> (defun tj/insert-exported-table (&optional insertion-point file)
> (let ((tmp-file (or file (make-temp-file "foo")))
> (insert-point (or insertion-point (1+ (org-table-end)))))
> (org-table-export tmp-file "orgtbl-to-csv")
> (goto-char insert-point)
> (insert-file-contents tmp-file)))
> #+end_src
>
> #+results:
> : tj/insert-exported-table
>
> then do 'M-: (tj/insert-exported-table)' on this table:
>
> | header 1 | header 2 | header 3 |
> |----------+----------+----------|
> | label1 | 3 | 99 |
> | label2 | 2 | 66 |
> | label3 | 7 | 231 |
>
> header 1,header 2,header 3
> label1,3,99
> label2,2,66
> label3,7,231
There are orgtbl-to-tsv and orgtbl-to-csv (and orgtbl-to-generic which
the first two call) functions in org: it should be possible to use them
and avoid reinventing wheels.
--
Nick
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
@ 2013-08-06 5:28 Rustom Mody
2013-08-06 5:31 ` Rustom Mody
0 siblings, 1 reply; 9+ messages in thread
From: Rustom Mody @ 2013-08-06 5:28 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]
I was writing up what I could make out of having program-files with inline
tables.
The example is done for python. It is exactly what the OP wants but close
enough so giving it here.
This file shows two approaches for making python data structures from
orgtbl with both sender and receiver in same file.
The first table is made with single line comments
The second table is made using python's triple-quote feature
The third is the recipient for both/either of the above
To try out orgtbl minor mode needs to be active after python mode is active.
Also it does not quite work for org 6.33
---------------------------
For the first use M-x orgtbl-toggle-comment followed by C-c C-c (inside the
table) to send to recipient, followed by another M-x orgtbl-toggle-comment
For the second only C-c C-c in the sender table is sufficient
------------------------------------cut here
------------------------------------
# #+ORGTBL: SEND marks orgtbl-to-generic :sep ","
# | abe | 1 | 2 | 3 | 4 | 10 |
# | beth | 3 | 1 | 5 | 7 | 16 |
# | cathy | 5 | 6 | 7 | 5 | 23 |
# #+TBLFM: $6=$2+$3+$4+$5
orig_table = """
#+ORGTBL: SEND marks orgtbl-to-generic :lfmt " \"%s\": [%s,%s,%s,%s,%s],"
:llfmt " \"%s\": [%s,%s,%s,%s,%s]"
| abe | 1 | 2 | 3 | 4 | 10 |
| beth | 9 | 1 | 5 | 9 | 24 |
| cathy | 5 | 6 | 7 | 5 | 23 |
#+TBLFM: $6=$2+$3+$4+$5
"""
stud_db = {
# BEGIN RECEIVE ORGTBL marks
abe,1,2,3,4,10
beth,3,1,5,7,16
cathy,5,6,7,5,23
# END RECEIVE ORGTBL marks
}
----------------------- cut here -----------------------------
--
http://www.the-magus.in
http://blog.languager.org
[-- Attachment #2: Type: text/html, Size: 1985 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-06 5:28 Rustom Mody
@ 2013-08-06 5:31 ` Rustom Mody
0 siblings, 0 replies; 9+ messages in thread
From: Rustom Mody @ 2013-08-06 5:31 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
On Tue, Aug 6, 2013 at 10:58 AM, Rustom Mody <rustompmody@gmail.com> wrote:
> I was writing up what I could make out of having program-files with inline
> tables.
> The example is done for python. It is exactly what the OP wants but close
> enough
>
That was intended to be "NOT exactly what the OP wants..."
[-- Attachment #2: Type: text/html, Size: 568 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
2013-08-05 14:19 ` Nick Dokos
@ 2013-08-07 8:49 ` Daniel Hornung
0 siblings, 0 replies; 9+ messages in thread
From: Daniel Hornung @ 2013-08-07 8:49 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: Text/Plain, Size: 600 bytes --]
On Monday, August 05, 2013 16:19:57 Nick Dokos wrote:
> There are orgtbl-to-tsv and orgtbl-to-csv (and orgtbl-to-generic which
> the first two call) functions in org: it should be possible to use them
> and avoid reinventing wheels.
Exactly, for someone with more elisp fu than myself this is probably pretty
simple to create and to bind to, say, C-c \.
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 #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-08-07 8:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-05 7:49 Bug: Revert orgtbl-create-or-convert-from-region [6.33x] Daniel Hornung
2013-08-05 9:16 ` Thorsten Jolitz
2013-08-05 9:49 ` Daniel Hornung
2013-08-05 13:26 ` Thorsten Jolitz
2013-08-05 14:07 ` Thorsten Jolitz
2013-08-05 14:19 ` Nick Dokos
2013-08-07 8:49 ` Daniel Hornung
-- strict thread matches above, loose matches on Subject: below --
2013-08-06 5:28 Rustom Mody
2013-08-06 5:31 ` Rustom Mody
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).