From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eike Subject: Re: accessing properties in org-element-parse-buffer tree Date: Sat, 30 Aug 2014 21:07:46 +0200 Message-ID: <87mwalzt7g.fsf@ithaka.home> References: <87ppfhzweg.fsf@ithaka.home> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNo79-0005W2-22 for emacs-orgmode@gnu.org; Sat, 30 Aug 2014 15:15:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XNo71-00008X-AJ for emacs-orgmode@gnu.org; Sat, 30 Aug 2014 15:15:07 -0400 Received: from ns.km31707.keymachine.de ([87.118.120.70]:41582 helo=eknet.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNo71-000078-4B for emacs-orgmode@gnu.org; Sat, 30 Aug 2014 15:14:59 -0400 Received: from 84-73-222-131.dclient.hispeed.ch (EHLO ithaka.home.eknet.org) ([84.73.222.131]) by km31707 (JAMES SMTP Server ) with ESMTPA ID 621925480 for ; Sat, 30 Aug 2014 21:14:58 +0200 (CEST) In-reply-to: <87ppfhzweg.fsf@ithaka.home> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: org-mode Hello again it seems that I messed up my testing variables=E2=80=A6 I always had just o= ne 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 p= roperties (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 le= vel-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