pythonでvimpluginを書くサンプルとか
つーかvimを使い始めた人おおいなー!
某所にもいろいろかかれてますけどpythonで拡張できる。
で一番簡単なサンプル。
詳細はusr_41.txtとif_pyth.txtを読んでみてちょ。
細かいところはいろいろあるんだけどやっぱデバッグしにくい。
まあサンプルなのでこんな感じで
pyunit.vim
if exists("Pyunit_loaded")
delfun Pyunit
endif
let Pyunit_loaded = 1
let s:save_cpo = &cpo
set cpo&vim
function s:Pyunit(filename)
python << PYTHONEOF
import vim
import re
code = """
import unittest\n\n
"""
for buf in vim.current.buffer:
if re.match("^class ([a-zA-Z0-9_]*\()", buf):
m = re.match("^class ([a-zA-Z0-9_]*\()", buf)
className = m.groups(0)[0][:-1]
code += "class "+className+"Test(unittest.TestCase):\n\n"
code += " def setUp():\n"
code += " pass\n\n"
code += " def tearDown():\n"
code += " pass\n\n"
elif re.match(" def ([a-zA-Z0-9_]*\()", buf):
m = re.match(" def ([a-zA-Z0-9_]*\()", buf)
funcName = m.groups(0)[0][:-1]
code += " def test"+funcName+"():\n\n"
code += " pass\n\n"
code += """
if __name__ == "__main__":
unittest.main()
"""
f = open(filname, 'w')
f.write(code)
PYTHONEOF
endfunction
if !exists(':Pyunit')
command -nargs=? -complete=file Pyunit call <SID>Pyunit('<args>')
endif
let &cpo = s:save_cpoうわーてきとー。
というかvim.current.bufferぐらいしか使いようがないような。
:Pyunit <file名>
でunittestの雛形を作成。
django用のplugin書くならばなんだろな?
manage.pyのショートカットぐらいしかない?
pythonで書かれたsubversionクライアントなんかあればそいつと連携してdjangoProjectPluginってのもありなのかも。
(難しそうかも)
うくく。