[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] How do I specify the language for a :results code block
From: |
Alan Schmitt |
Subject: |
Re: [O] How do I specify the language for a :results code block |
Date: |
Sat, 30 Nov 2013 11:52:56 +0100 |
User-agent: |
mu4e 0.9.9.6pre2; emacs 24.3.1 |
Hello Thomas and Charles,
address@hidden writes:
> A simple example: generate code in sh that is run in emacs-lisp
This is almost what I want, with two differences: I don't want to run
the generated code, but to pretty-print it, and I want to do this with
another language than emacs-lisp.
> #+name: make-elisp
> #+BEGIN_SRC sh :exports none :var fun="+"
> echo "(" $fun "1 2)"
> #+END_SRC
>
> #+BEGIN_SRC emacs-lisp :noweb yes :exports results
> <<make-elisp()>>
> #+END_SRC
>
> #+RESULTS:
> : 3
>
> #+BEGIN_SRC emacs-lisp :noweb yes :exports results
> <<make-elisp("-")>>
> #+END_SRC
>
> #+RESULTS:
> : -1
>
> #+BEGIN_SRC emacs-lisp :noweb yes :exports results
> <<make-elisp("list")>>
> #+END_SRC
>
> #+RESULTS:
> | 1 | 2 |
I tried this, but I cannot make it fit my purpose. What I want is a
function that will create an org mode source block to be exported as
nicely formatted source code.
Here is what I tried:
#+name: fetchcoq
#+BEGIN_SRC sh :exports none :var f="demo.v"
head $f
#+END_SRC
#+BEGIN_SRC coq :noweb yes :exports code
<<fetchcoq("demo.v")>>
#+END_SRC
If I export this, I get a block with lists, as if the results of
"fetchcoq" was translated into an elisp data structure:
,----
| (("Definition toto : forall x" "exists y" "x = y.") ("" "" "") ("Lemma foo:
forall x" "x=x." ""))
`----
I tried this alternate approach, to directly generate the block:
#+name: fetchcoq2
#+BEGIN_SRC sh :exports none :results raw :var f="demo.v"
echo "#+BEGIN_SRC coq"
head $f
echo
echo "#+END_SRC"
#+END_SRC
#+call: fetchcoq2("demo.v")
But then I get a result like this, with extra quoting:
#+RESULTS:
: #+BEGIN_SRC coq
: Definition toto : forall x, exists y, x = y.
:
: Lemma foo: forall x, x=x.
: #+END_SRC
I feel like I'm missing something obvious. ":results code" is exactly
what I want (put the results in a SRC block), but I don't know how to
specify the headers of the generated code block.
Thanks,
Alan