From: tsd@tsdye.com (Thomas S. Dye)
To: Thorsten Jolitz <tjolitz@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Babel: reusing language-specific functions
Date: Tue, 07 Oct 2014 06:18:01 -1000 [thread overview]
Message-ID: <m28ukrlupy.fsf@tsdye.com> (raw)
In-Reply-To: <87zjd884j5.fsf@gmail.com> (Thorsten Jolitz's message of "Tue, 07 Oct 2014 14:09:50 +0200")
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Jarmo Hurri <jarmo.hurri@iki.fi> 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
next prev parent reply other threads:[~2014-10-07 16:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-07 11:46 Babel: reusing language-specific functions Jarmo Hurri
2014-10-07 12:09 ` Thorsten Jolitz
2014-10-07 16:18 ` Thomas S. Dye [this message]
2014-10-09 5:23 ` Jarmo Hurri
2014-10-10 2:11 ` Grant Rettke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m28ukrlupy.fsf@tsdye.com \
--to=tsd@tsdye.com \
--cc=emacs-orgmode@gnu.org \
--cc=tjolitz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.