From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [org-babel] Dynamic Tangle? Date: Mon, 13 Dec 2010 13:58:39 -0700 Message-ID: <871v5lgzk0.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=54591 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PSFTs-0004tY-Sk for emacs-orgmode@gnu.org; Mon, 13 Dec 2010 15:58:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PSFTr-0001hb-3j for emacs-orgmode@gnu.org; Mon, 13 Dec 2010 15:58:48 -0500 Received: from mail-px0-f179.google.com ([209.85.212.179]:48991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PSFTq-0001hM-VN for emacs-orgmode@gnu.org; Mon, 13 Dec 2010 15:58:47 -0500 Received: by pxi20 with SMTP id 20so1896054pxi.38 for ; Mon, 13 Dec 2010 12:58:46 -0800 (PST) In-Reply-To: (Nathan Neff's message of "Mon, 6 Dec 2010 22:57:58 -0600") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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 ) footing=$(cat<> 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 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 > <> > 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 <