Pymacs problem

Discussion in 'Python' started by Skip Montanaro, Oct 21, 2004.

  1. 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
    Skip Montanaro, Oct 21, 2004
    #1
    1. Advertising

  2. On Thu, 21 Oct 2004 10:56:09 -0500, Skip Montanaro wrote:

    > 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
    Alberto Griggio, Oct 21, 2004
    #2
    1. Advertising

  3. 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
    Skip Montanaro, Oct 21, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandre Fayolle

    pymacs problem on load

    Alexandre Fayolle, Jun 27, 2003, in forum: Python
    Replies:
    1
    Views:
    874
    =?iso-8859-1?q?Fran=E7ois_Pinard?=
    Jun 27, 2003
  2. =?iso-8859-1?Q?Fran=E7ois?= Pinard

    NEW MAINTAINER for Pymacs

    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Sep 17, 2004, in forum: Python
    Replies:
    0
    Views:
    318
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Sep 17, 2004
  3. =?iso-8859-1?Q?Fran=E7ois?= Pinard

    Re: NEW MAINTAINER for Pymacs [corrected]

    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Sep 24, 2004, in forum: Python
    Replies:
    2
    Views:
    317
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Sep 24, 2004
  4. pber

    pymacs + dbus

    pber, Sep 7, 2005, in forum: Python
    Replies:
    0
    Views:
    366
  5. Grant

    pymacs

    Grant, May 8, 2007, in forum: Python
    Replies:
    0
    Views:
    373
    Grant
    May 8, 2007
Loading...

Share This Page