emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eike <eike@eknet.org>
To: org-mode <emacs-orgmode@gnu.org>
Subject: Re: accessing properties in org-element-parse-buffer tree
Date: Sat, 30 Aug 2014 21:07:46 +0200	[thread overview]
Message-ID: <87mwalzt7g.fsf@ithaka.home> (raw)
In-Reply-To: <87ppfhzweg.fsf@ithaka.home>


Hello again

it seems that I messed up my testing variables… I always had just one
headline and thus the list of lists had always one element that I then
extracted with `car'. So `car' must be removed:

#+begin_src emacs-lisp
  (defun collect-props (tree)
    (org-element-map tree 'headline
      (lambda (hl)
        (when (eq 2 (org-element-property :level hl)) ; want only level-2 properties
          (org-element-map hl 'node-property
            (lambda (np)
              (cons (org-element-property :key np)
                    (org-element-property :value np))))))))
#+end_src

I'd still be curious if there are other/better ways to do that; or is
this idiomatic usage of provided org functions?

Thanks again and kind regards
Eike

Eike writes:

> Hello list,
>
> I want to ask for help regarding elisp and org-elements. I like to
> access the properties of all my headlines and I created the following
> function (tree is the parsed tree) that collects them into an a-list:
>
> #+begin_src emacs-lisp
>   (defun collect-props (tree)
>     (car (org-element-map tree 'headline
>            (lambda (hl)
>              (when (eq 2 (org-element-property :level hl)) ; want only level-2 properties
>                (org-element-map hl 'node-property
>                  (lambda (np)
>                    (cons (org-element-property :key np)
>                          (org-element-property :value np)))))))))
> #+end_src
>
> I'm not very confident about this, is this ok? Is there a better way?
> For example, the first car looks strange, and I don't know how to get
> rid of it.
>
> Thanks you very much in advance!!!
> Kind regards
> Eike

--
gpg: AD7AC35E
finger print: 137F BB0B 1639 D25F DC5D  E59C B412 C5F5 AD7A C35E

  reply	other threads:[~2014-08-30 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-30 18:03 accessing properties in org-element-parse-buffer tree Eike
2014-08-30 19:07 ` Eike [this message]
2014-08-30 19:41 ` Thorsten Jolitz
2014-08-30 20:20   ` Eike
2014-08-30 22:10     ` Thorsten Jolitz
2014-08-31  2:08 ` Eric Abrahamsen
2014-08-31  9:12   ` Eike

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mwalzt7g.fsf@ithaka.home \
    --to=eike@eknet.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).