- moving pygdb path to .gvimrc
[pygdb.git] / pygdb.vim
1 "shuber, 2008-06-08
2
3 if ! exists("g:pygdb")
4
5 let g:pygdb = 1
6 let s:ScriptLocation = expand("<sfile>")
7
8
9 python << >>
10
11 import gtk
12 import os
13 import string
14 import sys
15 import threading
16 import vim
17
18 import Configuration
19
20
21
22 #Breakpoint positions: List of dictionaries of form
23 #{"signnum" : , "file" : , "lineno":, "cond" : }
24 gdbBps = []
25 signnum = 0
26 clientcmd = ""
27
28 def gdbLaunch():
29 global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
30
31
32 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
33
34
35 if clientcmd.strip()=="":
36 print "No command given!"
37 return
38
39 #Add the breakpoints to the configuration
40 conf = Configuration.Configuration()
41 conf.load(".pygdb.conf")
42 for bp in gdbBps:
43 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
44 conf.store(".pygdb.conf")
45
46 vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd))
47
48
49 def gdbToggleBreakpoint(lineno=None, file=None):
50 global gdbBps
51
52 #Set lineno and file if not already set
53 if lineno==None:
54 lineno = vim.current.window.cursor[0]
55 if file==None:
56 file = getCurrentFile()
57
58 #Determine index of breakpoint
59 bpidx = gdbGetBreakpoint( file, lineno )
60
61 #Remove the breakpoint
62 if bpidx != None:
63 vim.command("sign unplace %(signnum)d" % gdbBps[bpidx])
64 del gdbBps[bpidx]
65
66 #Create the breakpoint
67 else:
68 #Determine a sign number
69 signnum = gdbNewSignnum()
70
71 #Create breakpoint and add sign
72 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : None}
73 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
74 gdbBps += [b]
75
76
77 def gdbBreakpointCond(lineno=None, file=None, cond=None):
78 global gdbBps
79
80 #Set lineno and file if not already set
81 if lineno==None:
82 lineno = vim.current.window.cursor[0]
83 if file==None:
84 file = getCurrentFile()
85
86 #Determine index of breakpoint
87 bpidx = gdbGetBreakpoint( file, lineno )
88
89 #Remove the breakpoint
90 if bpidx != None:
91 if cond == None:
92 cond = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
93 gdbBps[bpidx]["cond"] = cond
94
95 else:
96 #Determine a sign number
97 signnum = gdbNewSignnum()
98
99 #Get condition
100 if cond == None:
101 cond = vim.eval("input('Breakpoint condition: ', '')")
102
103 #Create breakpoint and add sign
104 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
105 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
106 gdbBps += [b]
107
108
109 def getCurrentFile():
110 return vim.current.window.buffer.name
111
112
113
114 def gdbNewSignnum():
115 global signnum
116 signnum += 1
117 return signnum
118
119
120 def gdbGetBreakpoint(file, lineno):
121 for i in range(len(gdbBps)):
122 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
123 return i
124 return None
125
126
127 >>
128
129
130 highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black
131
132 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
133 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
134
135
136
137 command! GDBLaunch :python gdbLaunch()
138 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
139 command! GDBBreakpointCond :python gdbBreakpointCond()
140
141
142
143 function! GDBMapDefaults()
144 nmap <silent> <F5> :GDBLaunch<CR>
145 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
146 nmap <silent> <F9> :GDBBreakpointCond<CR>
147 endfunction
148
149
150
151 endif
152
153