0

I have an org file with headlines and subheadlines containing tables. Each table has a name (i.e. each table starts with a #+name: tablename header). I'd like to generate a list containing all tables names as strings. ("tablename-1" "tablename-2" ... "tablename-n").

For Example, parsing the given file filename.org:

* Level 1
** level 2 alpha
   #+name: alpha
   |--------+--------|
   | Letter | Number |
   |--------+--------|
   | A      |      1 |
   | B      |      2 |
   |--------+--------|
** Level 2 beta
   #+name: beta
   |--------+--------|
   | Letter | Number |
   |--------+--------|
   | C      |      3 |
   | D      |      4 |
   |--------+--------|
*** level 3
   #+name: l3
    |--------+--------|
    | Letter | Number |
    |--------+--------|
    | E      |      5 |
    | F      | 6      |
    |--------+--------|

Would produce the following list:

("alpha" "beta" "l3")

I have tried:

(let ((x (org-element-parse-buffer 'table))) 
  (org-element-map x 'table 
    (lambda (y) (org-element-property :name y))))

but it doesn't work...

1

But you are on the right track. The only mistake is that you are passing the wrong argument to org-element-parse-buffer (see its doc string with C-h f org-element-parse-buffer to see what arguments it takes). In this case, just call it without any arguments:

(org-element-map (org-element-parse-buffer) 'table (lambda (element) (org-element-property :name  element)))

will do it.

2
  • Thanks. There's a missing parenthesis at the end.
    – crocefisso
    Dec 21 '21 at 15:00
  • Yes, thanks. Fixed.
    – NickD
    Dec 21 '21 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.