Pymacs problem

S

Skip Montanaro

I'm trying to use the Pymacs bridge to add a symbol completion facility to
Emacs's python-mode. Neither the Python nor Emacs Lisp portions are all
that complex, but I'm having trouble passing a list of strings from Emacs
Lisp into Python. On the Emacs Lisp side it looks like this:

(pymacs-load "pycomplete")

(defun py-complete ()
(interactive)
(pycomplete-pycomplete (py-symbol-near-point)
(py-find-global-imports)))

(py-find-global-imports) returns a (Lisp) list of strings, e.g.:

("import time", "import sys")

On the Python side I have this function:

def pycomplete(s, imports=None):
completions = get_all_completions(s, imports)
dots = s.split(".")
return os.path.commonprefix([k[len(dots[-1]):] for k in completions])

Unfortunately, the imports arg does not come across as a Python list of
strings (s does come across the bridge as a normal Python string). Its
repr() prints out like this:

lisp('("import time")')

What do I need to do to convert that object into a true Python list of
strings? I'm afraid I don't quite understand the description of the lisp
object in the Pymacs docs. I tried imports.value() but that just gave me

(aref pymacs-lisp 0)

Any help appreciated...

Skip
 
A

Alberto Griggio

I'm trying to use the Pymacs bridge to add a symbol completion facility to
Emacs's python-mode.

This sound quite cool! :)

What do I need to do to convert that object into a true Python list of
strings? I'm afraid I don't quite understand the description of the lisp
object in the Pymacs docs. I tried imports.value() but that just gave me

(aref pymacs-lisp 0)

Any help appreciated...

Disclaimer: so far I've only played with Pymacs a little bit, I'm by no
means an expert. Anyway, from the manual:

"""
Proper Emacs Lisp lists, those for which the cdr of last cell is nil, are
normally transmitted opaquely to Python. If pymacs-forget-mutability is
set, or if Python later asks for these to be expanded, proper Emacs Lisp
lists get converted into Python lists, if we except the empty list, which
is always converted as Python None. In the other direction, Python lists
are always converted into proper Emacs Lisp lists.
"""

So, maybe try

(defun py-complete ()
(interactive)
(let ((pymacs-forget-mutability t))
(pycomplete-pycomplete (py-symbol-near-point)
(py-find-global-imports))))

HTH,
Alberto
 
S

Skip Montanaro

Alberto> So, maybe try

Alberto> (defun py-complete ()
Alberto> (interactive)
Alberto> (let ((pymacs-forget-mutability t))
Alberto> (pycomplete-pycomplete (py-symbol-near-point)
Alberto> (py-find-global-imports))))

Thanks. Worked like a charm...

Skip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top