From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: finding a parent node Date: Tue, 02 Jul 2013 11:40:35 +0200 Message-ID: <87a9m55mgc.fsf@gmail.com> References: <87hagdo0ni.fsf@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utx50-0001mx-7E for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 05:41:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Utx4t-0000Og-Ob for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 05:40:58 -0400 Received: from plane.gmane.org ([80.91.229.3]:49465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utx4t-0000OM-I3 for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 05:40:51 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Utx4p-0000K5-Ns for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 11:40:47 +0200 Received: from g231232231.adsl.alicedsl.de ([92.231.232.231]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Jul 2013 11:40:47 +0200 Received: from tjolitz by g231232231.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Jul 2013 11:40:47 +0200 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: emacs-orgmode@gnu.org l.stelmach@samsung.com (Ɓukasz Stelmach) writes: Hello, > What is the best way to iterate over ((great)*grand)?parent headlines of > the current one (at point), that meets some criteria. not an answer to your question, but rather a related question I wanted to post anyway, so I do it in this thread: simple-test.org: #+begin_src org * header 1 :PROPERTIES: :CUSTOM_ID: XYZ22 :END: * header 2 [2013-06-28 Fr 11:01] ** subheader 1 Some text ** subheader 2 More text and a table | label | col1 | col2 | |--------+------+------| | string | 3 | 4 | Text and a src-block #+begin_src emacs-lisp (+ 3 4) #+end_src #+end_src parse buffer: #+begin_src emacs-lisp (progn (goto-char (point-max)) (newline 2) (insert (format "%s" (with-current-buffer (find-file-noselect "/path/to/simple-test.org") (setq tree (org-element-parse-buffer))))) ) #+end_src excerpts form parse-tree: #+begin_src emacs-lisp (org-data nil ;; first headline (headline (:raw-value header 1 :begin 1 :end55 :pre-blank0 :hiddenp outline :contents-begin 12 :contents-end 55 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil :CUSTOM_ID XYZ22 :CATEGORY simple-test :title (header 1) :parent #0) (section (:begin 12 :end 55 :contents-begin 12 :contents-end 55 :post-blank 0 :parent #1) (property-drawer (:begin 12 :end 55 :hiddenp outline :contents-begin 27 :contents-end 47 :post-blank 0 :post-affiliated 12 :parent #2) (node-property (:key CUSTOM_ID :value XYZ22 :begin 27 :end 47 :post-blank 0 :parent #3))))) ;; second headline (headline (:raw-value header 2 :begin 55 :end 295 :pre-blank 0 :hiddenp outline :contents-begin 66 :contents-end 295 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil :CATEGORY simple-test :title (header 2) :parent #0) (section (:begin 66 :end 90 :contents-begin 66 :contents-end 90 :post-blank 0 :parent #1) (paragraph (:begin 66 :end 90 :contents-begin 66 :contents-end 90 :post-blank 0 :post-affiliated 66 :parent #2) (timestamp (:type inactive :raw-value [2013-06-28 Fr 11:01] :year-start 2013 :month-start 6 :day-start 28 :hour-start 11 :minute-start 1 :year-end 2013 :month-end 6 :day-end 28 :hour-end 11 :minute-end 1 :begin 68 :end 89 :post-blank 0 :parent #3)) )) ...) ) #+end_src now I can use `org-element-map' to access the elements and their attributes: #+begin_src emacs-lisp (insert (format "\n\n%s" (org-element-map tree 'timestamp '(lambda (X) (org-element-property :raw-value X))))) ;; => ([2013-06-28 Fr 11:01]) #+end_src this gives me the first timestamp element and its property list: #+begin_src emacs-lisp (setq stamp1 (org-element-map tree 'timestamp 'identity nil t)) #+end_src but for further processing I always struggle with the :parent attribute and the circularities in the list. I often would like to use just a sublist like this, with :parent being a Link or ID and not the parent object that refers to its parent object and so on ... #+begin_src emacs-lisp (timestamp (:type inactive :raw-value [2013-06-28 Fr 11:01] :year-start 2013 :month-start 6 :day-start 28 :hour-start 11 :minute-start 1 :year-end 2013 :month-end 6 :day-end 28 :hour-end 11 :minute-end 1 :begin 68 :end 89 :post-blank 0 :parent <>)) #+end_src I tried to use the NO-RECURSION arg of `org-element-map' for this, but often the parent is a headline or section, and then 'org-element-map' doesn't enter headlines or sections and returns nil, i.e. the timestamp is never found. Is there a way - using the parser/export framework toolbox - to avoid these circularities, i.e. to either ignore the :parent attribute or better replace the list object in it by something else that nevertheless identifies the parent unmistakenly? I know that with special bookkeeping while walking the tree one can deal with these circularities, maybe I'm just new to this stuff, but I feel they make the usual processing of such a nested list a bit complicated. -- cheers, Thorsten