python - 是否可以在 TextMate 中实现 Python 代码补全?

标签 python autocomplete text-editor textmate

PySmell似乎是一个很好的起点。

我认为这应该是可能的,PySmell 的 idehelper.py 完成了大部分复杂的工作,它应该只是给它当前行,提供补全(我的一点不确定),然后用选定的行替换该行。

>>> 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)'}]

它永远不会完美,但它会非常有用(即使只是为了完成 std​​lib 模块,它永远不会改变,所以你不必在添加函数时不断重新生成 PYSMELLTAGS 文件)


进展中!我已经具备完成的全部基础 - 几乎没有工作,但已经接近了..

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

将以下内容放在 TextMate 捆绑脚本中,设置“输入:整个文档”、“输出:作为文本插入”、“激活:等效键:alt+esc”、“范围选择器: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/
PYSMELLDICT = idehelper.findPYSMELLDICT("/Library/Python/2.5/site-packages/pysmell/blah")
options = idehelper.detectCompletionType(cur_file, orig_source, line_no, cur_col, "", PYSMELLDICT)
completions = idehelper.findCompletions(CUR_WORD, PYSMELLDICT, options)

if len(completions) > 0:
    new_word = completions[0]['word']
    new_word = new_word.replace(CUR_WORD, "", 1) # remove what user has already typed
    print new_word

然后我新建了一个python文档,输入“import url”,按alt+escape,就完成了“import urllib”!

正如我所说,这完全是一个正在进行的工作,所以不要使用它..


最后更新:

orestis 已将其集成到 PySmell 项目的代码中!任何进一步的摆弄都会发生on github

最佳答案

编辑:我实际上已经将您的代码放在上面并集成到一个命令中。它会正确显示一个完成列表供您选择。

您可以在这里获取它:http://github.com/orestis/pysmell/tree/master (点击下载并安装 python setup.py)。这很粗糙,但它有效。 - 请报告 http://code.google.com/p/pysmell/ 上的任何错误

--

大家好,我是 PySmell 的开发者。我也用Mac,所以如果你可以给我发一封电子邮件(联系信息在源代码中)你到目前为止的进展,我可以尝试整合它:)

哦,顺便说一句,它被称为 PySmell - 没有尾随 's' :)

关于python - 是否可以在 TextMate 中实现 Python 代码补全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/221339/

相关文章:

vim - 如何有效地使用 VIM 编辑英文文本?

Python - 将两个 Tif 文件附加到特定文件中

javascript - TypeError : $(. ..).easyAutocomplete 不是一个函数

ruby - Vim 详细介绍了 Rails 的自动完成功能

jquery - 如何更改 Yii CJuiAutoComplete 的输入类型?

c# - 适用于 .NET/Winforms 的完全托管文本编辑器组件

python - 使用 Python/lxml 和 XPath 检索属性名称和值

python - Twisted Web 代理帮助!

python - 我的dicts of dicts是否适用于这个Dijkstra算法?

text-editor - 相当于 Linux、Win 上的 BBEdit