emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Tangling without clutter?


From: Viktor Rosenfeld
Subject: Re: [O] Tangling without clutter?
Date: Thu, 15 Mar 2012 07:25:47 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

Hi Jos'h,

have you looked at the :session header argument? I use it to define
environment variables in bash that are used in later code blocks.

Something like this:

#+BEGIN_SRC sh :session foo
export W="world."
#+END_SRC

#+RESULTS:

#+BEGIN_SRC sh :session foo
echo Hello $W
#+END_SRC

If these code blocks are executed in order, the latter returns "Hello
world."

Not sure though, how it interacts with Python.

Cheers,
Viktor

Jos'h Fuller wrote:

> Hi!
> 
> > > It seems like I almost need some variant of the "tangle" argument to
> > > :noweb where syntax references are expanded for evaluation, but not
> > > for anything else.
> > >
> > 
> > Why would you want to tangle out a python src file with an un-expanded
> > noweb reference?  Either way, who am I to judge.  I've just added a new
> > "eval" option to the noweb header argument which will expand noweb
> > references *only* during interactive evaluation.
> 
> Please allow me to explain, I think it's a legitimate use case...
> 
> I would like to provide a listing of a Python function, then later in the 
> document show a demonstration of how it's used. I just did this when 
> preparing some documentation for another programmer who is porting an 
> application between languages. 
> 
> So I listed the function, then after a discussion, I had a demonstration of 
> how to use the function. I wanted the output from the demonstration to be 
> "live", generated from the demonstration code. Therefore, I needed to 
> reference the function defined above. Unfortunately, the reference was 
> expanded during export so that the same block of code appeared /twice/, 
> presenting the reader with something like this:
> 
> : Here's a function:
> :  def gorking():
> :   return "gork"
> :
> : Here's how to use the function:
> :  def gorking():
> :   return "gork"
> :
> :  print gorking()
> : 
> : Which gives us:
> :  gork
> 
> As you can see, it's rather clumsy to have the function in the output twice. 
> It's not too bad for this example, but anything more than a few lines becomes 
> quite a distraction! This would have been preferable:
> 
> : Here's a function:
> :  def gorking():
> :   return "gork"
> :
> : Here's how to use the function:
> :  <<function-gorking>>
> : 
> :  print gorking()
> : 
> : Which gives us:
> :  gork
> 
> The original %.org file would look like this:
> 
> : Here's a function:
> :  #+name: function-gorking
> :  #+begin_src python :tangle yes
> :  def gorking():
> :   return "gork"
> :  #+end_src
> :
> : Here's how to use the function:
> :  #+name: function-gorking-demo
> :  #+begin_src python :tangle yes
> :  <<function-gorking>>
> :
> :  print gorking()
> :  #+end_src
> : 
> : Which gives us:
> :  #+results: function-gorking-demo
> :  gork
> 
> Does that explain it better?
> 
> Thanks!
> 
> Jos'h
> 
> 
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]