PySmell có vẻ như là một điểm khởi đầu tốt.Có thể triển khai hoàn thành mã Python trong TextMate không?
Tôi nghĩ điều đó là có thể, idehelper.py
của PySmell thực hiện phần lớn nội dung phức tạp, nó chỉ là trường hợp cho nó dòng hiện tại, cung cấp số lần hoàn thành (bit mà tôi không chắc chắn) và sau đó thay thế các dòng với một trong những lựa chọn.
>>> 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)'}]
Nó sẽ không bao giờ hoàn hảo, nhưng nó sẽ là vô cùng hữu ích (ngay cả khi chỉ để hoàn thành các module stdlib, mà không bao giờ nên thay đổi, vì vậy bạn sẽ không phải liên tục tạo các tập tin PYSMELLTAGS bất cứ khi nào bạn thêm một chức năng)
Tiến trình! Tôi có utter-cơ bản hoàn thành vào nơi - hầu như không hoạt động, nhưng nó gần ..
Tôi chạy python pysmells.py /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/*.py -O /Library/Python/2.5/site-packages/pysmell/PYSMELLTAGS
Đặt sau trong một gói kịch bản TextMate, thiết lập "đầu vào: toàn bộ tài liệu", "đầu ra: chèn dưới dạng văn bản", "kích hoạt: chìa khóa tương đương: alt + esc", "phạm vi 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/
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
Sau đó, tôi đã thực hiện một tài liệu python mới, gõ "nhập khẩu urll" và nhấn alt + escape, và nó đã hoàn thành nó để "nhập urllib"!
Như tôi đã nói, nó hoàn toàn là một công việc theo tiến độ, do đó, không sử dụng nó chưa ..
Cập nhật lần cuối:
Orestis đã tích hợp này vào dự án của PySmell mã! Bất kỳ không quan trọng hơn nữa sẽ xảy ra on github
tôi vừa mới nhận thấy sự cam kết TextMate liên quan về dự án github. Tôi nghĩ rằng mã trông quen thuộc, nhưng tôi nghĩ đó là một sự trùng hợp ..: D – dbr