Show More
@@ -7,7 +7,9 b' endif' | |||||
7 | python import socket |
|
7 | python import socket | |
8 | python import os |
|
8 | python import os | |
9 | python import vim |
|
9 | python import vim | |
|
10 | python from IPython.core.debugger import Pdb | |||
10 | python IPYSERVER = None |
|
11 | python IPYSERVER = None | |
|
12 | python reselect = True | |||
11 |
|
13 | |||
12 | python << EOF |
|
14 | python << EOF | |
13 | # do we have a connection to the ipython instance? |
|
15 | # do we have a connection to the ipython instance? | |
@@ -47,6 +49,70 b' def run_this_file():' | |||||
47 | send('run %s' % (vim.current.buffer.name,)) |
|
49 | send('run %s' % (vim.current.buffer.name,)) | |
48 | else: |
|
50 | else: | |
49 | raise Exception, "Not connected to an IPython server" |
|
51 | raise Exception, "Not connected to an IPython server" | |
|
52 | print "\'run %s\' sent to ipython" % vim.current.buffer.name | |||
|
53 | ||||
|
54 | def run_this_line(): | |||
|
55 | if check_server(): | |||
|
56 | send(vim.current.line) | |||
|
57 | print "line \'%s\' sent to ipython"% vim.current.line | |||
|
58 | else: | |||
|
59 | raise Exception, "Not connected to an IPython server" | |||
|
60 | ||||
|
61 | def run_these_lines(): | |||
|
62 | r = vim.current.range | |||
|
63 | if check_server(): | |||
|
64 | #send(str((vim.current.range.start,vim.current.range.end))) | |||
|
65 | for l in vim.current.buffer[r.start:r.end+1]: | |||
|
66 | send(str(l)+'\n') | |||
|
67 | #send(str(vim.current.buffer[vim.current.range.start:vim.current.range.end]).join("\n")) | |||
|
68 | #print "lines %d-%d sent to ipython"% (r.start,r.end) | |||
|
69 | else: | |||
|
70 | raise Exception, "Not connected to an IPython server" | |||
|
71 | ||||
|
72 | #reselect the previously highlighted block | |||
|
73 | if reselect: | |||
|
74 | vim.command("normal gv") | |||
|
75 | #vim lines start with 1 | |||
|
76 | print "lines %d-%d sent to ipython"% (r.start+1,r.end+1) | |||
|
77 | ||||
|
78 | def toggle_reselect(): | |||
|
79 | global reselect | |||
|
80 | reselect=not reselect | |||
|
81 | print "F9 will%sreselect lines after sending to ipython"% (reselect and " " or " not ") | |||
|
82 | ||||
|
83 | def set_breakpoint(): | |||
|
84 | if check_server(): | |||
|
85 | send("__IP.InteractiveTB.pdb.set_break('%s',%d)" % (vim.current.buffer.name, | |||
|
86 | vim.current.window.cursor[0])) | |||
|
87 | print "set breakpoint in %s:%d"% (vim.current.buffer.name, | |||
|
88 | vim.current.window.cursor[0]) | |||
|
89 | else: | |||
|
90 | raise Exception, "Not connected to an IPython server" | |||
|
91 | ||||
|
92 | def clear_breakpoint(): | |||
|
93 | if check_server(): | |||
|
94 | send("__IP.InteractiveTB.pdb.clear_break('%s',%d)" % (vim.current.buffer.name, | |||
|
95 | vim.current.window.cursor[0])) | |||
|
96 | print "clearing breakpoint in %s:%d" % (vim.current.buffer.name, | |||
|
97 | vim.current.window.cursor[0]) | |||
|
98 | else: | |||
|
99 | raise Exception, "Not connected to an IPython server" | |||
|
100 | ||||
|
101 | def clear_all_breakpoints(): | |||
|
102 | if check_server(): | |||
|
103 | send("__IP.InteractiveTB.pdb.clear_all_breaks()"); | |||
|
104 | print "clearing all breakpoints" | |||
|
105 | else: | |||
|
106 | raise Exception, "Not connected to an IPython server" | |||
|
107 | ||||
|
108 | def run_this_file_pdb(): | |||
|
109 | if check_server(): | |||
|
110 | send(' __IP.InteractiveTB.pdb.run(\'execfile("%s")\')' % (vim.current.buffer.name,)) | |||
|
111 | else: | |||
|
112 | raise Exception, "Not connected to an IPython server" | |||
|
113 | print "\'run %s\' using pdb sent to ipython" % vim.current.buffer.name | |||
|
114 | ||||
|
115 | #XXX: have IPYSERVER print the prompt (look at Leo example) | |||
50 | EOF |
|
116 | EOF | |
51 |
|
117 | |||
52 | fun! <SID>toggle_send_on_save() |
|
118 | fun! <SID>toggle_send_on_save() | |
@@ -62,6 +128,16 b' fun! <SID>toggle_send_on_save()' | |||||
62 | endfun |
|
128 | endfun | |
63 |
|
129 | |||
64 | map <silent> <F5> :python run_this_file()<CR> |
|
130 | map <silent> <F5> :python run_this_file()<CR> | |
65 | imap <silent> <C-F5> <ESC><F5>a |
|
131 | map <silent> <S-F5> :python run_this_line()<CR> | |
66 | map <F7> :call <SID>toggle_send_on_save()<CR> |
|
132 | map <silent> <F9> :python run_these_lines()<CR> | |
|
133 | map <silent> <S-F9> :python toggle_reselect()<CR> | |||
|
134 | map <silent> <C-F6> :python send('%pdb')<CR> | |||
|
135 | map <silent> <F6> :python set_breakpoint()<CR> | |||
|
136 | map <silent> <s-F6> :python clear_breakpoint()<CR> | |||
|
137 | map <silent> <F7> :python run_this_file_pdb()<CR> | |||
|
138 | map <silent> <s-F7> :python clear_all_breaks()<CR> | |||
|
139 | imap <C-F5> <ESC><F5>a | |||
|
140 | imap <S-F5> <ESC><S-F5>a | |||
|
141 | imap <silent> <F5> <ESC><F5>a | |||
|
142 | map <C-F5> :call <SID>toggle_send_on_save()<CR> | |||
67 | py connect() |
|
143 | py connect() |
General Comments 0
You need to be logged in to leave comments.
Login now