From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: org-export: how to copy the parsed tree? Date: Sat, 01 Mar 2014 22:02:55 +0100 Message-ID: <878ustpr7k.fsf@gmail.com> References: <87wqgeemto.fsf@gmail.com> <87vbvyp2v5.fsf@gmail.com> <87ob1pepzh.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJr3S-0004uD-G3 for emacs-orgmode@gnu.org; Sat, 01 Mar 2014 16:02:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJr3K-0007BY-1g for emacs-orgmode@gnu.org; Sat, 01 Mar 2014 16:02:42 -0500 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:35938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJr3J-0007AP-RR for emacs-orgmode@gnu.org; Sat, 01 Mar 2014 16:02:33 -0500 Received: by mail-wi0-f173.google.com with SMTP id bs8so1992200wib.0 for ; Sat, 01 Mar 2014 13:02:33 -0800 (PST) In-Reply-To: <87ob1pepzh.fsf@gmail.com> (Vitalie Spinu's message of "Sat, 01 Mar 2014 10:24:50 -0800") 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: Vitalie Spinu Cc: emacs-orgmode@gnu.org Vitalie Spinu writes: > Thanks Nocolas. I need to copy only a subtree associated with a > headline. In a nutshell I need to "flatten" the tree of headlines for > the csv type exporter. That is, I need to replicate the parent headlines > across the children. For example > > * H1 > bla bla > ** HA > some text > ** HB > some other text > > would translate into > > * H1 > bla bla > ** HA > some text > * H1 > bla bla > ** HB > some other text > > I played with org-element-extract-element, org-element-set-contents and > org-element-insert-before but failed a big deal. In this case, I think I would build the tree, since data is duplicated (e.g. "* H1"), not moved. > Main problem seems to be the lack of uniform interface to handle parents > in connection to secondary elements (which I don't understand at this > point). There is no such thing as "secondary elements". I think you mean "secondary strings". This is some parsed data that doesn't belong to the main hierarchy in the tree. I don't think any interface problem for :parent property. You simply use `org-element-property' and `org-element-put-property'. > Is headline a secondary element? No. A headline is a full-fledged element. But, besides its contents, it contains additional data (its title) which is Org syntax and therefore qualifies as a secondary string. > The :parent seems to be stored in 2 places for the headline, in the > headline itself and in the :title. You are wrong. Headline's parent is stored only in the :parent property of the headline. You get it with: (org-element-property :parent headline) Within `:title', `:parent' property refers to the parent of the objects contained in :title, which is the headline itself: (eq (org-element-property :parent ;; The first object in the :title property. (car (org-element-property :title headline))) headline) => t There is only one parent per object/element/string. > Most of the org code uses org-element-put-property and > org-element-property to access the parent but some code like > org-element-extract-element uses :parent from :title. `org-element-extract-element' checks if the element/object you're removing belong to a secondary string or to the contents of the current element. Moreover, this function removes the :parent property, so you shouldn't bother about where it came from. > This makes it difficult to program as there are no explicit > getter/setter for the parent. See above. > BTW, is there a way to pretty print the org tree? I think that's the > main barrier for me in understanding how it all works. Use `pp' and set both `print-level' and `print-circle' accordingly. Regards, -- Nicolas Goaziou