From mboxrd@z Thu Jan 1 00:00:00 1970 From: tsd@tsdye.com (Thomas S. Dye) Subject: Re: Babel: reusing language-specific functions Date: Tue, 07 Oct 2014 06:18:01 -1000 Message-ID: References: <87d2a4w199.fsf@iki.fi> <87zjd884j5.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbXTc-0000d1-Oa for emacs-orgmode@gnu.org; Tue, 07 Oct 2014 12:19:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbXTT-0003wz-5j for emacs-orgmode@gnu.org; Tue, 07 Oct 2014 12:19:04 -0400 Received: from gproxy4-pub.mail.unifiedlayer.com ([69.89.23.142]:60064) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1XbXTS-0003we-VD for emacs-orgmode@gnu.org; Tue, 07 Oct 2014 12:18:55 -0400 In-Reply-To: <87zjd884j5.fsf@gmail.com> (Thorsten Jolitz's message of "Tue, 07 Oct 2014 14:09:50 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Thorsten Jolitz Cc: emacs-orgmode@gnu.org Thorsten Jolitz writes: > Jarmo Hurri writes: > >> Greetings. >> >> I have a very basic Babel question, but I can not extract the solution >> from the manual. >> >> I have a language-specific function - in this case Asymptote, but it >> could be e.g. C as well - that I want to use in a number of different >> source blocks of the same language in an Org file. How do I accomplish >> this? >> >> Currently my solution is to write the function into an external source >> file, and include the file in the source blocks. But that looks ugly, >> and is sort of against the Org-mode way of doing things: all code in the >> same place for completeness and convenience. >> >> How can I achieve what I want? > > try something like this: > > #+NAME: foo > #+BEGIN_SRC emacs-lisp > (defun foo (x) (+ x 2)) > #+END_SRC > > #+results: foo > : foo > #+BEGIN_SRC emacs-lisp :var fun=foo > (funcall (intern fun) 3) > #+END_SRC > > #+results: > : 5 Or, perhaps use the noweb syntax. #+NAME: foo #+BEGIN_SRC emacs-lisp (defun foo (x) (+ x 2)) #+END_SRC #+results: foo : foo #+begin_src emacs-lisp :noweb yes <> (foo 3) #+end_src #+results: : 5 hth, Tom -- Thomas S. Dye http://www.tsdye.com