emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [org-babel] Dynamic Tangle?
@ 2010-12-07  4:57 Nathan Neff
  2010-12-13 20:58 ` Eric Schulte
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Neff @ 2010-12-07  4:57 UTC (permalink / raw)
  To: emacs-orgmode

I'm preparing a presentation and I'm getting using tangle to show code /and/
produce working code examples -- this is really cool.

It is possible to define a "template" and pass code blocks to it?
For example: (Using pseudo-org-babel-code for brevity)

#+template
header code
<<code_that_is_passed_to_me>>
footer code

#+example1 :render #+template with 1111111
1111111111

#+example2 :render #+template with 222222
222222222

The tangled output would be:

header code
11111111111
footer code

header code
2222222222
footer code

I'm already able to use org-babel like below, but I have to
put a <<footer>> and a <<header>> in each code block.

Here's my existing setup:
#+header
header code

#+footer
footer code

#+example1
<<header>>    <-- I have to specify these <<header>> and <<footer>> in
each code block
11111111111
<<footer>>

#+example2
<<header>>
2222222222
<<footer>>

Thanks again for org-babel -- I'll post my presentation when I get it done.

--Nate

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [org-babel] Dynamic Tangle?
  2010-12-07  4:57 [org-babel] Dynamic Tangle? Nathan Neff
@ 2010-12-13 20:58 ` Eric Schulte
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Schulte @ 2010-12-13 20:58 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

Hi Nathan,

The easiest way I can think of to accomplish templates would be through
some abuse of code block evaluation.  Maybe something like the following
would work...

** tangle templates
#+source: template-heading
#+begin_src emacs-lisp
  some stuff here
#+end_src

#+source: template-footing
#+begin_src emacs-lisp
  some other stuff here
#+end_src

#+source: template
#+begin_src sh :results output :noweb yes :var body="body stuff"
heading=$(cat<<EOF
<<template-heading>>
EOF
)
footing=$(cat<<EOF
<<template-footing>>
EOF
)
echo $heading
echo "$body"
echo $footing
#+end_src

#+call: template[:noweb yes](body="something new")

#+results: template[:noweb yes](body="something new")
: some stuff here
: something new
: some other stuff here

I hope this makes sense, and isn't too gross looking, for a really clean
implementation the template function could be located in a different org
file using the library of babel.

Note, that this relies upon an improvement to variable escaping that I
just pushed up to the latest version in git.

Best -- Eric

Nathan Neff <nathan.neff@gmail.com> writes:

> I'm preparing a presentation and I'm getting using tangle to show code /and/
> produce working code examples -- this is really cool.
>
> It is possible to define a "template" and pass code blocks to it?
> For example: (Using pseudo-org-babel-code for brevity)
>
> #+template
> header code
> <<code_that_is_passed_to_me>>
> footer code
>
> #+example1 :render #+template with 1111111
> 1111111111
>
> #+example2 :render #+template with 222222
> 222222222
>
> The tangled output would be:
>
> header code
> 11111111111
> footer code
>
> header code
> 2222222222
> footer code
>
> I'm already able to use org-babel like below, but I have to
> put a <<footer>> and a <<header>> in each code block.
>
> Here's my existing setup:
> #+header
> header code
>
> #+footer
> footer code
>
> #+example1
> <<header>>    <-- I have to specify these <<header>> and <<footer>> in
> each code block
> 11111111111
> <<footer>>
>
> #+example2
> <<header>>
> 2222222222
> <<footer>>
>
> Thanks again for org-babel -- I'll post my presentation when I get it done.
>
> --Nate
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-12-13 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-07  4:57 [org-babel] Dynamic Tangle? Nathan Neff
2010-12-13 20:58 ` Eric Schulte

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).