Subject: mailing-list for TeXmacs Users
List archive
From : "Adrian S." <address@hidden>- To: address@hidden
- Subject: [TeXmacs] preliminary work on the Python plugin.
- Date: Thu, 8 Mar 2012 14:02:50 -0700
- Authentication-results: spamcheck-ng1.citic74.net; dkim=pass (2048-bit key) address@concealed; dkim-asp=none
I did some experimentation with the Python plugin, which is broken mainly because it recieves from TeXmacs the whole code as one line, and it fails to guess the location of newlines... Basically, the current python plugin tries to guess that whenever there are two or more spaces, then it really is a newline, but even this does not work in the plugin...
I attach the file adrianpython.tar.gz with my attempt of a new plugin as well as a TeXmacs file comparing this new preliminary plugin and the curent one's behaviour. In the TeXmacs file, I point to some things that I need to do for the plugins to work...
I do not know if I will work on it during the weekend, as I need to do other things, but at least I understand more how it work. In spite of the nice properties of the current plugin, it does need serious fixing.
The problem I have is that I do not know how to tell when the stream comming from TeXmacs ends. One way would be using the input-done? command, which seems not to work, or to figure out a way to add an EOF to the TeXmacs input...
I hope this is helpful to someone.
Peace.
-Adrian.
<TeXmacs|1.0.7.14>
<style|generic>
<\body>
<doc-data|<doc-title|Preliminary Work on the Python Plugin>>
<center|<strong|THIS IS PRELIMINARY WORK, AND THE PLUGIN IS NOT READY!>>
<section|How to use it.>
Please use it to debug using the <verbatim|Tools-\<gtr\>Debug>, and then in
the new Debug menu, select <verbatim|Debug-\<gtr\>io>
<\itemize>
<item>Each entry must have at least two lines, the first one must be
non-empty
<item>No empty lines between pieces of code
<item>Comments are allowed
<item>The last line must be empty (This is to signal EOF)
</itemize>
<section|Things that need to be done.>
<\itemize>
<item>Figure out a way to signal EOF from texmacs
<\indent>
One way would be to use the ``input-done'', but currently this seems
not to work
</indent>
<item>Add what the other plugin had:
<\itemize>
<item>Tab completion
<item>Analysis of the output, so that if the return type was
postscritp, then render it accordingly into <TeXmacs>. This is
important, as it is a major feature for the SAGE plugin.
<item>Handle exceptions so that a crash in python leaves the plugin
alive
</itemize>
</itemize>
<section|How the current Python plugin (and hence the SAGE plugin) is
broken.>
Most of the broken behaviour is due to the lack of proper conversion of
newlines. \ The plugin for some reason is expecting <verbatim|"\\s"> as a
mark of a new line, and is not finding it...
The plugin works well for one liners, but for loops it either marks a bug,
does a different thing than what is expected, or, sometimes, does what is
expected. The behaviour is the one resulting from replacing the newlines by
spaces.
<\session|python|default>
<\output>
Welcome to Python
TeXmacs Python interface version 0.8.1. Ero Carrera (c) 2004
http://dkbza.org/tmPython.html
</output>
<\input|Python] >
#This is a comment
a=3
</input>
<\unfolded-io|Python] >
print a
<|unfolded-io>
Traceback (most recent call last):
NameError: name 'a' is not defined
</unfolded-io>
<\input|Python] >
a=3
</input>
<\unfolded-io|Python] >
print a
#This is a comment
print a+1
<|unfolded-io>
3
</unfolded-io>
<\unfolded-io|Python] >
for i in range(3):
\ \ \ for j \ in range(2):
\ \ \ \ \ \ \ print i,j
\ \ \ print "***"
print "###"
\;
<|unfolded-io>
Traceback (most recent call last):
\ \ File "tm_python", line 2
\ \ \ \ for j
\ \ \ \ \ \ \ \ ^
SyntaxError: invalid syntax
</unfolded-io>
<\unfolded-io|Python] >
for i in range(3):
\ \ \ for j \ in range(2):
\ \ \ \ \ \ \ print i,j;
\ \ \ print "***";
print "###";
<|unfolded-io>
Traceback (most recent call last):
\ \ File "tm_python", line 2
\ \ \ \ for j
\ \ \ \ \ \ \ \ ^
SyntaxError: invalid syntax
</unfolded-io>
<\unfolded-io|Python] >
for i in range(3):
\ \ \ for j in range(2):
print "hello"
<|unfolded-io>
hello
hello
hello
hello
hello
hello
</unfolded-io>
<\unfolded-io|Python] >
for i in range(3):
\ \ \ for j in range(2):
\ \ \ \ \ \ \ print "hello"
<|unfolded-io>
hello
hello
hello
hello
hello
hello
</unfolded-io>
<\input|Python] >
\;
</input>
</session>
<section|How the new preliminary plugin works...>
<\session|adrianpython|default>
<\output>
Welcome to Adrian's Python plugin
</output>
<\unfolded-io|Adrianpython] >
#This is a comment
a=3
\;
<|unfolded-io>
We enter into the loop
You entered:
#This is a comment
a=3
\;
Now, we will compile your code
We just evaluated it...
\;
</unfolded-io>
<\unfolded-io|Adrianpython] >
print a
#This is another comment
print a+1
\;
<|unfolded-io>
We enter into the loop
You entered:
print a
#This is another comment
print a+1
\;
Now, we will compile your code
3
4
We just evaluated it...
\;
</unfolded-io>
<\unfolded-io|Adrianpython] >
for i in range(3):
\ \ \ for j \ in range(2):
\ \ \ \ \ \ \ prin i,j
\ \ \ print "***"
print "###"
\;
<|unfolded-io>
We enter into the loop
You entered:
for i in range(3):
\ \ \ for j \ in range(2):
\ \ \ \ \ \ \ prin i,j
\ \ \ print "***"
print "###"
\;
Now, we will compile your code
<\errput>
Traceback (most recent call last):
\ \ File "/home/adrian/.TeXmacs/plugins/adrianpython/bin/tm_adrianpython",
line 42, in \<less\>module\<gtr\>
\ \ \ \ co = compile(text, 'tm_adrianpython', 'exec')
\ \ File "tm_adrianpython", line 3
\ \ \ \ prin i,j
\ \ \ \ \ \ \ \ \ ^
SyntaxError: invalid syntax
</errput>
<script-dead>
</unfolded-io>
<\unfolded-io|Adrianpython] >
for i in range(3):
\ \ \ for j \ in range(2):
\ \ \ \ \ \ \ print i,j
\ \ \ print "***"
print "###"
\;
<|unfolded-io>
We enter into the loop
You entered:
for i in range(3):
\ \ \ for j \ in range(2):
\ \ \ \ \ \ \ print i,j
\ \ \ print "***"
print "###"
\;
Now, we will compile your code
0 0
0 1
***
1 0
1 1
***
2 0
2 1
***
###
We just evaluated it...
\;
</unfolded-io>
<\input|Adrianpython] >
\;
</input>
</session>
\;
</body>
<\initial>
<\collection>
<associate|page-type|letter>
<associate|prog-scripts|maxima>
</collection>
</initial>
<\references>
<\collection>
<associate|auto-1|<tuple|1|?>>
<associate|auto-2|<tuple|2|?>>
<associate|auto-3|<tuple|3|?>>
<associate|auto-4|<tuple|4|?>>
</collection>
</references>
<\auxiliary>
<\collection>
<\associate|toc>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|How
to use it.> <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-1><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|How
the current Python plugin (and hence the SAGE plugin) is broken.>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-2><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|How
the new preliminary plugin works...>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-3><vspace|0.5fn>
</associate>
</collection>
</auxiliary>Attachment:
adrianpython.tar.gz
Description: GNU Zip compressed data
- [TeXmacs] preliminary work on the Python plugin., Adrian S., 03/08/2012
Archive powered by MHonArc 2.6.19.