Alex Rivera | Logout

Is it possible to implement Python code-completion in TextMate?

Asked 2008-10-21T09:54:58.807
21

PySmell seems like a good starting point.

I think it should be possible, PySmell's idehelper.py does a majority of the complex stuff, it should just be a case of giving it the current line, offering up the completions (the bit I am not sure about) and then replacing the line with the selected one.

>>> import idehelper
>>> # The path is where my PYSMELLTAGS file is located:
>>> PYSMELLDICT = idehelper.findPYSMELLDICT("/Users/dbr/Desktop/pysmell/")
>>> options = idehelper.detectCompletionType("", "" 1, 2, "", PYSMELLDICT)
>>> completions = idehelper.findCompletions("proc", PYSMELLDICT, options)
>>> print completions
[{'dup': '1', 'menu': 'pysmell.pysmell', 'kind': 'f', 'word': 'process', 'abbr': 'process(argList, excluded, output, verbose=False)'}]

It'll never be perfect, but it would be extremely useful (even if just for completing the stdlib modules, which should never change, so you wont have to constantly regenerate the PYSMELLTAGS file whenever you add a function)


Progressing! I have the utter-basics of completion in place - barely works, but it's close..

I ran python pysmells.py /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/*.py -O /Library/Python/2.5/site-packages/pysmell/PYSMELLTAGS

Place the following in a TextMate bundle script, set "input: entire document", "output: insert as text", "activation: key equivalent: alt+esc", "scope selector: source.python"

#!/usr/bin/env python

import os
import sys
from pysmell import idehelper

CUR_WORD = os.environ.get("TM_CURRENT_WORD")

cur_file = os.environ.get("TM_FILEPATH")
orig_source = sys.stdin.read()
line_no = int(os.environ.get("TM_LINE_NUMBER"))
cur_col = int(os.environ.get("TM_LINE_INDEX"))

# PYSMELLS is currently in site-packages/pysmell/
PYSM
Edit
Report

2 Answers

1

It's not perfect, but you can give it a try: http://mtod.org/tempy

answered 2009-01-09T14:04:59.867
0

In TextMate PHP has a simple auto-completion in form of hardcoded set of function names. Sounds as ugly as PHP, but in practice it's good enough to be useful.

answered 2008-10-21T22:59:10.190

Your Answer