alright, here's how you do the completion with gedit. It's not that it
stopped working, it's just a bug i hadn't noticed before. There a
quite a few flaws -- help appreciated if you know a way to improve on
this ! so currently:
-- only the last word on the line can be completed (true, it's usually
the one you're typing!)
-- annoyingly, after the completion gedit goes to the next line (get
used to pressing backspace right after the hotkey for completion !)
-- discovered recently: it doesn't work on the first line of the
document !!
so in tools/external tools, create a script with input= current line,
output= insert at cursor position (note: current line really returns
the current paragraph... and something buggy on the first line).
the code is:
-----------------------------------------------------
#!/usr/bin/env python
#find the last word:
from sys import stdin
s= stdin.read()
word= s.split()[-1]
#read the doc file:
from commands import getoutput
docfile= "/home/pedro/.sage/sage_doc"
cmd= "cat " + docfile + " | grep \"def " + word + "\""
poss= getoutput(cmd).split("\n")
#complete:
import re
regexp= re.compile("def (" + word + ".*)\(")
choices= [ regexp.search(s) for s in poss]
choices= filter(lambda x: x is not None, choices)
choices= [x.groups()[0] for x in choices]
if len(choices) > 0:
def gcd(s,t):
i= 0
m=min(len(s), len(t))
while i<m and s[i] == t[i]:
i=i+1
return s[:i]
common= reduce(gcd, choices)
if len(common) > len(word):
print common[len(word) - len(common):],
---------------------------------------------------------------------
if you want to display all possibilities for completion, choose a
second hotkey close to the previous one (eg i use F3 and shift + F3)
and create another script with input= current line, output=bottom
panel, and code:
--------------------------------------------------------------------
#!/usr/bin/env python
#!/usr/bin/env python
#find the last word:
from sys import stdin
s= stdin.read()
word= s.split()[-1]
#read the doc file:
from commands import getoutput
docfile= "/home/pedro/.sage/sage_doc"
cmd= "cat " + docfile + " | grep \"def " + word + "\""
poss= getoutput(cmd).split("\n")
#complete:
import re
regexp= re.compile("def (" + word + ".*)\(")
choices= [ regexp.search(s) for s in poss]
choices= filter(lambda x: x is not None, choices)
choices= [x.groups()[0] for x in choices]
for choice in choices:
print choice
-----------------------------------------------------------------
if there were a massive popular demand (say five people), i could turn
this into a proper gedit plugin rather than a trick using external
tools. Let me know what you think !
pierre
On Oct 10, 11:18 am, Pierre <[EMAIL PROTECTED]> wrote:
> > Do you have these changes posted somewhere? I'd like to try it out, if
> > possible.
>
> er, no, but here are a few hints. First try
>
> sage -grep "def" | grep "def " >~/.sage/sage_doc
>
> so you have a file in your .sage folder containing all the lines in
> SAGE's code containing the word "def " (i don't know why sage -grep
> "def " with a space does not work, the second grep is here to fix the
> problem).
>
> then in tools/external tools i add a script "quick sage
> documentation" whose input is "current selection" and output "bottom
> pannel", and which contains:
>
> ----------------------------------
> #!/usr/bin/env python
>
> from sys import stdin
> from commands import getoutput
> name= stdin.read()
> cmd= "cat /home/my_home_folder_here/.sage/sage_doc | grep \"def " +
> name + "\""
>
> s= getoutput(cmd)
> print s
> ----------------------------------
>
> so if i select MatrixSpace and run that tool, the bottom panel
> displays
>
> matrix/matrix_space.py:def MatrixSpace(base_ring, nrows, ncols=None,
> sparse=False):
>
> You may want to script to have "current word" as its input but
> careful, underscores are understood as word separators.
>
> In order to get the full documentation, i've added the following
> script, whose execution is pretty slow but it works: the bottom panel
> displays the whole thing. So in tools/external tools, add a script
> "full sage doc" with the same input and output containing
> -----------------------------------
> #!/usr/bin/env python
> from sys import stdin
> word= stdin.read()
> from commands import getoutput
> cmd= "echo " + word + "? | sage"
> print getoutput(cmd)
> -----------------------------------
> so it just runs "echo MatrixSpace? | sage" when MatrixSpace is
> selected, and prints it in the bottom panel.
>
> i'll write again about the completion trick (i've tried to play with
> it recently and it doesn't work anymore!)
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---