[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] How to "initiate" Org mode in a buffer
From: |
Nicolas Goaziou |
Subject: |
Re: [O] How to "initiate" Org mode in a buffer |
Date: |
Fri, 10 Oct 2014 09:57:16 +0200 |
Hello,
Marcin Borkowski <address@hidden> 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