adding first vim code+
[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 sys.path.append("/home/shuber/projekte/pygdb/")
20
21 import GdbTerminal
22 import MainControlWindow
23 import StatusWindow
24
25
26 #Breakpoint positions: List of dictionaries of form {"signnum" : , "file" : , "lineno":, "cond" : }
27 gdbBps = []
28 signnum = 0
29 clientcmd = ""
30
31 gdbterm = None
32 mainctrlwnd = None
33 statuswnd = None
34 gdbthread = None
35
36
37
38 def gdbLaunch():
39 global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
40
41 if gdbterm == None:
42
43 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
44 gdbterm = GdbTerminal.GdbTerminal(clientcmd)
45 mainctrlwnd = MainControlWindow.MainControlWindow(gdbterm, quitonclose=False)
46 statuswnd = StatusWindow.StatusWindow(mainctrlwnd, gdbterm, quitonclose=False)
47 gdbterm.initialize()
48
49
50 for bp in gdbBps:
51 statuswnd.breakpointsFrame.addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
52
53 gtk.main()
54 gtk.main()
55 print "hello"
56 #mainctrlwnd.hide()
57 #statuswnd.hide()
58
59
60 def gdbToggleBreakpoint(lineno=None, file=None):
61 global gdbBps
62
63 #Set lineno and file if not already set
64 if lineno==None:
65 lineno = vim.current.window.cursor[0]
66 if file==None:
67 file = vim.current.window.buffer.name
68
69 #Determine index of breakpoint
70 bpidx = gdbGetBreakpoint( file, lineno )
71
72 #Remove the breakpoint
73 if bpidx != None:
74 vim.command("sign unplace %(signnum)d" % gdbBps[bpidx])
75 del gdbBps[bpidx]
76
77 #Create the breakpoint
78 else:
79 #Determine a sign number
80 signnum = gdbNewSignnum()
81
82 #Create breakpoint and add sign
83 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : None}
84 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
85 gdbBps += [b]
86
87
88 def gdbBreakpointCond(lineno=None, file=None, cond=None):
89 global gdbBps
90
91 #Set lineno and file if not already set
92 if lineno==None:
93 lineno = vim.current.window.cursor[0]
94 if file==None:
95 file = vim.current.window.buffer.name
96
97 #Determine index of breakpoint
98 bpidx = gdbGetBreakpoint( file, lineno )
99
100 #Remove the breakpoint
101 if bpidx != None:
102 if cond == None:
103 cond = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
104 gdbBps[bpidx]["cond"] = cond
105
106 else:
107 #Determine a sign number
108 signnum = gdbNewSignnum()
109
110 #Get condition
111 if cond == None:
112 cond = vim.eval("input('Breakpoint condition: ', '')")
113
114 #Create breakpoint and add sign
115 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
116 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
117 gdbBps += [b]
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