emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Babel: reusing language-specific functions


From: Thomas S. Dye
Subject: Re: [O] Babel: reusing language-specific functions
Date: Tue, 07 Oct 2014 06:18:01 -1000

Thorsten Jolitz <address@hidden> writes:

> Jarmo Hurri <address@hidden> 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>>
(foo 3)
#+end_src

#+results:
: 5

hth,
Tom

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



reply via email to

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