domingo, 22 de fevereiro de 2009

VIM: Adicionar e remover python breakpoints.

Adicione ao .vimrc:

python << EOF
import vim
def SetBreakpoint():
import re
nLine = int( vim.eval( 'line(".")'))

strLine = vim.current.line
strWhite = re.search( '^(\s*)', strLine).group(1)

vim.current.buffer.append(
"%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
{'space':strWhite, 'mark': '#' * 30}, nLine - 1)

for strLine in vim.current.buffer:
if strLine == "import pdb":
break
else:
vim.current.buffer.append( 'import pdb', 0)
vim.command( 'normal j1')

vim.command( 'map :py SetBreakpoint()')

def RemoveBreakpoints():
import re

nCurrentLine = int( vim.eval( 'line(".")'))

nLines = []
nLine = 1
for strLine in vim.current.buffer:
if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':
nLines.append( nLine)
nLine += 1

nLines.reverse()

for nLine in nLines:
vim.command( 'normal %dG' % nLine)
vim.command( 'normal dd')
if nLine < nCurrentLine:
nCurrentLine -= 1

vim.command( 'normal %dG' % nCurrentLine)

vim.command( 'map :py RemoveBreakpoints()')
EOF

Teclando F7 e Shift+F7 é possível inserir e remover os breakpoints.

Para compilar/executar o código basta:

:!python %

Fonte: http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/

Nenhum comentário:

Postar um comentário