emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: tsd@tsdye.com (Thomas S. Dye)
To: suvayu ali <fatkasuvayu+linux@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Selective export of Babel code blocks
Date: Mon, 18 Jun 2012 09:05:46 -1000	[thread overview]
Message-ID: <m1pq8wigol.fsf@tsdye.com> (raw)
In-Reply-To: <CAMXnza0bU6R0ZyCeammSSkg8dH+cn3QaSJKP5CGCneBq4zuCMA@mail.gmail.com> (suvayu ali's message of "Mon, 18 Jun 2012 19:16:39 +0200")

suvayu ali <fatkasuvayu+linux@gmail.com> writes:

> Hi Thomas,
>
> On Mon, Jun 18, 2012 at 7:11 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>> #+CALL: clean-up() :exports none
>>
>> This way, the original code block will be exported and subsequent calls
>> should not be.
>
> I think John's use case requires other code blocks "using" the common
> code block. Can a "CALL" be done from inside a codeblock?
>
> That said, your post gave me an idea; how about defining a function in
> the first code block and then using that in the other blocks. This would
> require the session feature of course. :)
Hi Suvayu,

Yes, there are several ways to accomplish John's goal, depending on how
he wants to structure the R code and whether or not he wants to preserve
state with one or more sessions.

I don't think it is possible to use #+CALL: inside a code block.  For
that, there is noweb syntax.  So, for John's recent code, this should
work with or without sessions:

#+name: preamble
#+begin_src R
   tikzDevice("export-file-name.tex")
#+end_src

#+begin_src R :noweb yes
   <<preamble>>
   ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src


The :noweb header argument can take several values to control when these
noweb references are expanded.  Many of these don't show in the Org-mode
manual on Worg.  Here they are in org.texi:

The @code{:noweb} header argument controls expansion of ``noweb'' syntax
references (see @ref{Noweb reference syntax}) when the code block is
evaluated, tangled, or exported.  The @code{:noweb} header argument can have
one of the five values: @code{no}, @code{yes}, @code{tangle}, or
@code{no-export} @code{strip-export}.

@itemize @bullet
@item @code{no}
The default.  ``Noweb'' syntax references in the body of the code block will
not be expanded before the code block is evaluated, tangled or exported.
@item @code{yes}
``Noweb'' syntax references in the body of the code block will be
expanded before the code block is evaluated, tangled or exported.
@item @code{tangle}
``Noweb'' syntax references in the body of the code block will be expanded
before the code block is tangled.  However, ``noweb'' syntax references will
not be expanded when the code block is evaluated or exported.
@item @code{no-export}
``Noweb'' syntax references in the body of the code block will be expanded
before the block is evaluated or tangled.  However, ``noweb'' syntax
references will not be expanded when the code block is exported.
@item @code{strip-export}
``Noweb'' syntax references in the body of the code block will be expanded
before the block is evaluated or tangled.  However, ``noweb'' syntax
references will not be removed when the code block is exported.
@item @code{eval}
``Noweb'' syntax references in the body of the code block will only be
expanded before the block is evaluated.
@end itemize

So, John might be satisfied with something like this:

#+begin_src R :noweb no-export
   <<preamble>>
   ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

  parent reply	other threads:[~2012-06-18 19:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-18 14:53 Selective export of Babel code blocks John Hendy
2012-06-18 16:08 ` suvayu ali
2012-06-18 16:50   ` John Hendy
2012-06-18 17:08     ` suvayu ali
2012-06-18 17:37       ` William LÉCHELLE
2012-06-18 17:11 ` Thomas S. Dye
2012-06-18 17:16   ` suvayu ali
2012-06-18 17:31     ` John Hendy
2012-06-18 18:06       ` Andreas Leha
2012-06-18 19:05     ` Thomas S. Dye [this message]
2012-06-19 12:55       ` suvayu ali
2012-06-19 13:36         ` John Hendy

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=m1pq8wigol.fsf@tsdye.com \
    --to=tsd@tsdye.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=fatkasuvayu+linux@gmail.com \
    /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).