* How to "initiate" Org mode in a buffer
@ 2014-10-10 0:51 Marcin Borkowski
2014-10-10 7:57 ` Nicolas Goaziou
0 siblings, 1 reply; 2+ messages in thread
From: Marcin Borkowski @ 2014-10-10 0:51 UTC (permalink / raw
To: Org Mode Mailing List
Hi list,
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.
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)
Is that going to work reliably (on a newly-created buffer)?
TIA,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to "initiate" Org mode in a buffer
2014-10-10 0:51 How to "initiate" Org mode in a buffer Marcin Borkowski
@ 2014-10-10 7:57 ` Nicolas Goaziou
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2014-10-10 7:57 UTC (permalink / raw
To: Marcin Borkowski; +Cc: Org Mode Mailing List
Hello,
Marcin Borkowski <mbork@wmi.amu.edu.pl> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-10 7:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-10 0:51 How to "initiate" Org mode in a buffer Marcin Borkowski
2014-10-10 7:57 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.