emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Marcin Borkowski <mbork@wmi.amu.edu.pl>
Cc: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: How to "initiate" Org mode in a buffer
Date: Fri, 10 Oct 2014 09:57:16 +0200	[thread overview]
Message-ID: <871tqgfjc3.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87k348karq.fsf@wmi.amu.edu.pl> (Marcin Borkowski's message of "Fri, 10 Oct 2014 02:51:05 +0200")

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

      reply	other threads:[~2014-10-10  7:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10  0:51 How to "initiate" Org mode in a buffer Marcin Borkowski
2014-10-10  7:57 ` Nicolas Goaziou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871tqgfjc3.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=mbork@wmi.amu.edu.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).