emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] manipulate org tables using emacs-lisp


From: Thorsten Jolitz
Subject: Re: [O] manipulate org tables using emacs-lisp
Date: Sat, 01 Oct 2016 18:32:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Alan Schmitt <address@hidden> writes:

Hi Alan,

> On 2016-09-30 22:52, Thorsten Jolitz <address@hidden> writes:
>
>>> Are there functions for manipulating org-tables using emacs-lisp? More
>>> precisely, I would like to refer to a table by its name, read some cells
>>> (either by position or by matching some given text with some text in the
>>> first row/column), and write in some cells.
>>
>> ,----[ C-h f org-table-to-lisp RET ]
>> | org-table-to-lisp is an autoloaded compiled Lisp function in
>> | ‘../org-mode/lisp/org-table.el’.
>> | 
>> | (org-table-to-lisp &optional TXT)
>> | 
>> | Convert the table at point to a Lisp structure.
>> | The structure will be a list.  Each item is either the symbol ‘hline’
>> | for a horizontal separator line, or a list of field values as strings.
>> | The table is taken from the parameter TXT, or from the buffer at point.
>> | 
>> | [back]
>> `----
>>
>> returns the table as a nested list you can map with lots of Elisp
>> functions (like mapcar). 
>>
>> Ex.:
>>
>> | my | tab |
>> |  1 |   2 |
>>
>> =>
>>
>> (("my" "tab") ("1" "2"))
>
> This is very useful, thank you. But how do I go to a named table? I
> found org-babel-goto-named-block, but nothing for tables.

you can try

,----[ C-h f org-table-map-tables RET ]
| org-table-map-tables is a compiled Lisp function in
| ‘../org-mode/lisp/org.el’.
| 
| (org-table-map-tables FUNCTION &optional QUIETLY)
| 
| Apply FUNCTION to the start of all tables in the buffer.
| 
| [back]
`----

to go to all tables in the buffer, then inside FUNCTION you would need
to check first if the table is named and is the one your are looking
for. If so, get the table as list, work on the list, and insert the new
table replacing the old one (org-dp-create-table inserts a table when
given a nested list). 
Finally move point to the end of the inserted table, so the mapping
function can continue.

PS
org-element and org-dp allow you to do these things too, maybe even
more comfortably if you are familiar with these libraries. But right now
I'm not really able to give you a working example in reasonable time.

-- 
cheers,
Thorsten




reply via email to

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