=== modified file 'docs/examples/core/ipy.vim' --- docs/examples/core/ipy.vim 2008-06-09 22:51:37 +0000 +++ docs/examples/core/ipy.vim 2010-04-25 11:53:32 +0000 @@ -7,7 +7,9 @@ python import socket python import os python import vim +python from IPython.Debugger import Pdb python IPYSERVER = None +python reselect = True python << EOF # do we have a connection to the ipython instance? @@ -47,6 +49,70 @@ send('run %s' % (vim.current.buffer.name,)) else: raise Exception, "Not connected to an IPython server" + print "\'run %s\' sent to ipython" % vim.current.buffer.name + +def run_this_line(): + if check_server(): + send(vim.current.line) + print "line \'%s\' sent to ipython"% vim.current.line + else: + raise Exception, "Not connected to an IPython server" + +def run_these_lines(): + r = vim.current.range + if check_server(): + #send(str((vim.current.range.start,vim.current.range.end))) + for l in vim.current.buffer[r.start:r.end+1]: + send(str(l)+'\n') + #send(str(vim.current.buffer[vim.current.range.start:vim.current.range.end]).join("\n")) + #print "lines %d-%d sent to ipython"% (r.start,r.end) + else: + raise Exception, "Not connected to an IPython server" + + #reselect the previously highlighted block + if reselect: + vim.command("normal gv") + #vim lines start with 1 + print "lines %d-%d sent to ipython"% (r.start+1,r.end+1) + +def toggle_reselect(): + global reselect + reselect=not reselect + print "F9 will%sreselect lines after sending to ipython"% (reselect and " " or " not ") + +def set_breakpoint(): + if check_server(): + send("__IP.InteractiveTB.pdb.set_break('%s',%d)" % (vim.current.buffer.name, + vim.current.window.cursor[0])) + print "set breakpoint in %s:%d"% (vim.current.buffer.name, + vim.current.window.cursor[0]) + else: + raise Exception, "Not connected to an IPython server" + +def clear_breakpoint(): + if check_server(): + send("__IP.InteractiveTB.pdb.clear_break('%s',%d)" % (vim.current.buffer.name, + vim.current.window.cursor[0])) + print "clearing breakpoint in %s:%d" % (vim.current.buffer.name, + vim.current.window.cursor[0]) + else: + raise Exception, "Not connected to an IPython server" + +def clear_all_breakpoints(): + if check_server(): + send("__IP.InteractiveTB.pdb.clear_all_breaks()"); + print "clearing all breakpoints" + else: + raise Exception, "Not connected to an IPython server" + +def run_this_file_pdb(): + if check_server(): + send(' __IP.InteractiveTB.pdb.run(\'execfile("%s")\')' % (vim.current.buffer.name,)) + else: + raise Exception, "Not connected to an IPython server" + print "\'run %s\' using pdb sent to ipython" % vim.current.buffer.name + + #XXX: have IPYSERVER print the prompt (look at Leo example) EOF fun! toggle_send_on_save() @@ -62,6 +128,16 @@ endfun map :python run_this_file() -imap a -map :call toggle_send_on_save() +map :python run_this_line() +map :python run_these_lines() +map :python toggle_reselect() +map :python send('%pdb') +map :python set_breakpoint() +map :python clear_breakpoint() +map :python run_this_file_pdb() +map :python clear_all_breaks() +imap a +imap a +imap a +map :call toggle_send_on_save() py connect()