* Babel: reusing language-specific functions
@ 2014-10-07 11:46 Jarmo Hurri
2014-10-07 12:09 ` Thorsten Jolitz
0 siblings, 1 reply; 5+ messages in thread
From: Jarmo Hurri @ 2014-10-07 11:46 UTC (permalink / raw)
To: emacs-orgmode
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?
All the best,
Jarmo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Babel: reusing language-specific functions
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
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Jolitz @ 2014-10-07 12:09 UTC (permalink / raw)
To: emacs-orgmode
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
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Babel: reusing language-specific functions
2014-10-07 12:09 ` Thorsten Jolitz
@ 2014-10-07 16:18 ` Thomas S. Dye
2014-10-09 5:23 ` Jarmo Hurri
0 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2014-10-07 16:18 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Babel: reusing language-specific functions
2014-10-07 16:18 ` Thomas S. Dye
@ 2014-10-09 5:23 ` Jarmo Hurri
2014-10-10 2:11 ` Grant Rettke
0 siblings, 1 reply; 5+ messages in thread
From: Jarmo Hurri @ 2014-10-09 5:23 UTC (permalink / raw)
To: emacs-orgmode
tsd@tsdye.com (Thomas S. Dye) writes:
>> Jarmo Hurri <jarmo.hurri@iki.fi> writes:
>>> 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?
> 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
Yes, this is a perfect solution. You can use noweb to include any code
block, not only function definitions. Thanks!
Jarmo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Babel: reusing language-specific functions
2014-10-09 5:23 ` Jarmo Hurri
@ 2014-10-10 2:11 ` Grant Rettke
0 siblings, 0 replies; 5+ messages in thread
From: Grant Rettke @ 2014-10-10 2:11 UTC (permalink / raw)
To: Jarmo Hurri; +Cc: emacs-orgmode@gnu.org
That is a great option when you want to run *without* a session.
That is also a nice approach when you are using plantuml and do not
want to use a single external file
and include it all over the place.
On Thu, Oct 9, 2014 at 12:23 AM, Jarmo Hurri <jarmo.hurri@iki.fi> wrote:
> tsd@tsdye.com (Thomas S. Dye) writes:
>
>>> Jarmo Hurri <jarmo.hurri@iki.fi> writes:
>>>> 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?
>> 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
>
> Yes, this is a perfect solution. You can use noweb to include any code
> block, not only function definitions. Thanks!
>
> Jarmo
>
>
--
Grant Rettke
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-10-10 2:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-10-09 5:23 ` Jarmo Hurri
2014-10-10 2:11 ` Grant Rettke
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).