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