From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: How to "initiate" Org mode in a buffer Date: Fri, 10 Oct 2014 09:57:16 +0200 Message-ID: <871tqgfjc3.fsf@nicolasgoaziou.fr> References: <87k348karq.fsf@wmi.amu.edu.pl> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcV49-0003af-3k for emacs-orgmode@gnu.org; Fri, 10 Oct 2014 03:56:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcV41-0007zq-CA for emacs-orgmode@gnu.org; Fri, 10 Oct 2014 03:56:45 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:59515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcV41-0007yn-60 for emacs-orgmode@gnu.org; Fri, 10 Oct 2014 03:56:37 -0400 In-Reply-To: <87k348karq.fsf@wmi.amu.edu.pl> (Marcin Borkowski's message of "Fri, 10 Oct 2014 02:51:05 +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: Marcin Borkowski Cc: Org Mode Mailing List Hello, Marcin Borkowski writes: > I'm writing a function which does some (serious) modifications on an Org > file. I want it to save the results in some new file, so I'm (most > probably) going to create a new buffer, execute (org-mode) there, copy > the contents of the old one (insert-buffer-substring?) and then do my > stuff. You probably need to copy the contents before calling `org-mode' so it can properly initialize buffer local variables (e.g., #+TODO keywords). > However, "my stuff" depends on the (org) structure. Is there something > I should call /before/ I do (org-element-parse-buffer)? I want to do > something like > > (org-element-map (org-element-parse-buffer) '(headline) > #'my-stuff) (org-element-map (org-element-parse-buffer 'headline) 'headline ...) will be much faster. However, a better option may be to use `org-map-entries', which is more robust wrt buffer modifications. OTOH, `org-element-parse-buffer' should be considered if #'my-stuff operates on the AST. Then you would insert (org-element-interpret-data ast) in the new buffer. > Is that going to work reliably (on a newly-created buffer)? `org-element-parse-buffer' needs Org mode to be initialized. Regards, -- Nicolas Goaziou