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