* Need control over insertion point of variables in code blocks
@ 2011-07-22 7:22 Dirk Scharff
2011-07-22 7:34 ` Rainer M Krug
[not found] ` <87aac6u0rk.fsf@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: Dirk Scharff @ 2011-07-22 7:22 UTC (permalink / raw)
To: Org mailing list
[-- Attachment #1: Type: text/plain, Size: 1112 bytes --]
Hi
i just noticed that variables are assigned in the top of the exported code. That can be problematic in some situations:
#+source: the_test
#+begin_src python :var x=3 :tangle test.py :results output
from __future__ import division
print x
#+end_src
tangling results in:
x=3
from __future__ import division
print x
The problem with the result is simple:
SyntaxError: from __future__ imports must occur at the beginning of the file
To export this correctly I'd need the possibility to tell org-mode where the variables are supposed to be inserted. Is there a way to do this? I didn't find a keyword for this in the documentation.
A second problem I have at the moment lies with the execution of source-blocks in tables. What I'd like to do:
| argument | result |
| 1 | #ERROR |
| | |
#+TBLFM: $2=call_the_test(x=$<)
I guess I'm just doing something wrong here. Executing the #+Tblfm results in the error: "reference $< not found in buffer". How do I do the reference correctly in this case?
You can test both cases in the attached org-file.
[-- Attachment #2: testing.org --]
[-- Type: application/octet-stream, Size: 228 bytes --]
#+source: the_test
#+begin_src python :var x=3 :tangle test.py :results output
from __future__ import division
print x
#+end_src
| argument | result |
| 1 | #ERROR |
| | |
#+TBLFM: $2=call_the_test(x=$<)
[-- Attachment #3: Type: text/plain, Size: 3 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Need control over insertion point of variables in code blocks
2011-07-22 7:22 Need control over insertion point of variables in code blocks Dirk Scharff
@ 2011-07-22 7:34 ` Rainer M Krug
2011-07-22 7:55 ` Dirk Scharff
[not found] ` <87aac6u0rk.fsf@gnu.org>
1 sibling, 1 reply; 6+ messages in thread
From: Rainer M Krug @ 2011-07-22 7:34 UTC (permalink / raw)
To: Dirk Scharff; +Cc: Org mailing list
[-- Attachment #1: Type: text/plain, Size: 2017 bytes --]
On Fri, Jul 22, 2011 at 9:22 AM, Dirk Scharff
<dirk.scharff@googlemail.com>wrote:
> Hi
>
> i just noticed that variables are assigned in the top of the exported code.
> That can be problematic in some situations:
>
> #+source: the_test
> #+begin_src python :var x=3 :tangle test.py :results output
> from __future__ import division
> print x
> #+end_src
>
>
> tangling results in:
>
> x=3
> from __future__ import division
> print x
>
> The problem with the result is simple:
> SyntaxError: from __future__ imports must occur at the beginning of the
> file
>
> To export this correctly I'd need the possibility to tell org-mode where
> the variables are supposed to be inserted. Is there a way to do this? I
> didn't find a keyword for this in the documentation.
>
For tangling: you could put from __future__ imports into the :shebang and
use padline ":padline no", i.e.:
#+source: the_test
#+begin_src python :var x=3 :tangle test.py :results output :shebang from
__future__ imports :padline no
print x
#+end_src
which results in
from __future__ imports
print x
Keep in mind, that I have NEVER used python (although I should...).
Cheers,
Rainer
>
A second problem I have at the moment lies with the execution of
> source-blocks in tables. What I'd like to do:
>
> | argument | result |
> | 1 | #ERROR |
> | | |
> #+TBLFM: $2=call_the_test(x=$<)
>
> I guess I'm just doing something wrong here. Executing the #+Tblfm results
> in the error: "reference $< not found in buffer". How do I do the reference
> correctly in this case?
>
> You can test both cases in the attached org-file.
>
>
>
>
>
>
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax (F): +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer@krugs.de
Skype: RMkrug
[-- Attachment #2: Type: text/html, Size: 3000 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Need control over insertion point of variables in code blocks
2011-07-22 7:34 ` Rainer M Krug
@ 2011-07-22 7:55 ` Dirk Scharff
2011-07-22 8:02 ` Rainer M Krug
0 siblings, 1 reply; 6+ messages in thread
From: Dirk Scharff @ 2011-07-22 7:55 UTC (permalink / raw)
To: Rainer M Krug; +Cc: Org mailing list
[-- Attachment #1: Type: text/plain, Size: 1470 bytes --]
Hi
Am 22.07.2011 um 09:34 schrieb Rainer M Krug:
> For tangling: you could put from __future__ imports into the :shebang and use padline ":padline no", i.e.:
>
> #+source: the_test
> #+begin_src python :var x=3 :tangle test.py :results output :shebang from __future__ imports :padline no
> print x
> #+end_src
>
> which results in
>
> from __future__ imports
> print x
>
> Keep in mind, that I have NEVER used python (although I should…).
While I'd not call that a clean solution to the problem it will keep me going for now.
Thank you very much for pointing that possibility out, I haven't thought about trying to move the import statement.
As for python: its a nice language worth trying in my opinion ;)
With this i could do the table calculation manually by inserting 100-1000 call statements (in the real use case I need for my masters-thesis) but it would be really nice if i could use a table cell as argument for code-blocks.
> A second problem I have at the moment lies with the execution of source-blocks in tables. What I'd like to do:
>
> | argument | result |
> | 1 | #ERROR |
> | | |
> #+TBLFM: $2=call_the_test(x=$<)
>
> I guess I'm just doing something wrong here. Executing the #+Tblfm results in the error: "reference $< not found in buffer". How do I do the reference correctly in this case?
>
> You can test both cases in the attached org-file.
best regards,
Dirk
[-- Attachment #2: Type: text/html, Size: 2431 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Need control over insertion point of variables in code blocks
2011-07-22 7:55 ` Dirk Scharff
@ 2011-07-22 8:02 ` Rainer M Krug
0 siblings, 0 replies; 6+ messages in thread
From: Rainer M Krug @ 2011-07-22 8:02 UTC (permalink / raw)
To: Dirk Scharff; +Cc: Org mailing list
[-- Attachment #1: Type: text/plain, Size: 2172 bytes --]
On Fri, Jul 22, 2011 at 9:55 AM, Dirk Scharff
<dirk.scharff@googlemail.com>wrote:
> Hi
>
> Am 22.07.2011 um 09:34 schrieb Rainer M Krug:
>
> For tangling: you could put from __future__ imports into the :shebang and
> use padline ":padline no", i.e.:
>
> #+source: the_test
> #+begin_src python :var x=3 :tangle test.py :results output :shebang from
> __future__ imports :padline no
> print x
> #+end_src
>
> which results in
>
> from __future__ imports
> print x
>
> Keep in mind, that I have NEVER used python (although I should…).
>
>
> While I'd not call that a clean solution to the problem it will keep me
> going for now.
>
Agreed - but it works. Good.
>
> Thank you very much for pointing that possibility out, I haven't thought
> about trying to move the import statement.
>
> As for python: its a nice language worth trying in my opinion ;)
>
Sounds like it - I just need time.....
Cheers and good luck with your thesis,
Rainer
>
>
> With this i could do the table calculation manually by inserting 100-1000
> call statements (in the real use case I need for my masters-thesis) but it
> would be really nice if i could use a table cell as argument for
> code-blocks.
>
> A second problem I have at the moment lies with the execution of
>> source-blocks in tables. What I'd like to do:
>>
>> | argument | result |
>> | 1 | #ERROR |
>> | | |
>> #+TBLFM: $2=call_the_test(x=$<)
>>
>> I guess I'm just doing something wrong here. Executing the #+Tblfm results
>> in the error: "reference $< not found in buffer". How do I do the reference
>> correctly in this case?
>>
>> You can test both cases in the attached org-file.
>>
>
>
> best regards,
> Dirk
>
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax (F): +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer@krugs.de
Skype: RMkrug
[-- Attachment #2: Type: text/html, Size: 3687 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Need control over insertion point of variables in code blocks
[not found] ` <87aac6u0rk.fsf@gnu.org>
@ 2011-07-22 9:36 ` Dirk Scharff
2011-07-22 13:32 ` Bastien
0 siblings, 1 reply; 6+ messages in thread
From: Dirk Scharff @ 2011-07-22 9:36 UTC (permalink / raw)
To: Bastien; +Cc: Org mailing list
Hi Bastien,
thanks for pointing that out to me, I'm still new here and to org-mode in general (and I really like it!) ;)
I'll do that in the future. While a better solution to this would be nice, I'll not append this to this subject this time because I don't want to mess up the topic structure. I guess Eric will read this, because he didn't miss my mails from the other day either.
Besides I think the remaining question is more a table issue, than a babel one. (Well in fact its tables calling babel…) Perhaps I should repost the remaining question under a new subject? I'm still not used to this ;)
Best,
Dirk
Am 22.07.2011 um 11:23 schrieb Bastien:
> Hi Dirk,
>
> just a small reminder: please add [babel] in the subject line when
> the question is about Babel -- it makes sure Eric S. won't miss your
> email :)
>
> Best,
>
> --
> Bastien
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Need control over insertion point of variables in code blocks
2011-07-22 9:36 ` Dirk Scharff
@ 2011-07-22 13:32 ` Bastien
0 siblings, 0 replies; 6+ messages in thread
From: Bastien @ 2011-07-22 13:32 UTC (permalink / raw)
To: Dirk Scharff; +Cc: Org mailing list
Hi Dirk,
Dirk Scharff <dirk.scharff@googlemail.com> writes:
> Perhaps I should repost the remaining question under a new subject?
> I'm still not used to this ;)
The list is quite informal, but we try to stick to a
one-problem/one-thread policy -- it makes things easier.
Thanks!
--
Bastien
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-07-22 13:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-22 7:22 Need control over insertion point of variables in code blocks Dirk Scharff
2011-07-22 7:34 ` Rainer M Krug
2011-07-22 7:55 ` Dirk Scharff
2011-07-22 8:02 ` Rainer M Krug
[not found] ` <87aac6u0rk.fsf@gnu.org>
2011-07-22 9:36 ` Dirk Scharff
2011-07-22 13:32 ` Bastien
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).