2 " Author: Charles E. Campbell, Jr.
5 " Usage: :CS[!] [cdefgist]
10 " ---------------------------------------------------------------------
12 " ---------------------------------------------------------------------
14 if !has("cscope") || &cp || exists("g:loaded_cecscope") || v:version < 700
17 let g:loaded_cecscope= "v2"
19 " ---------------------------------------------------------------------
20 " Public Interface: {{{1
21 com! -nargs=* CS call s:Cscope(<bang>0,<f-args>)
22 com! -nargs=? CSH call s:CscopeHelp(<q-args>)
23 com! -bang -nargs=* CSL call s:Cscope(4+<bang>0,<f-args>)
24 com! -bang -nargs=* CSS call s:Cscope(2+<bang>0,<f-args>)
25 com! -nargs=0 CSR call s:CscopeReset()
27 " ---------------------------------------------------------------------
30 " ---------------------------------------------------------------------
32 " Usage: :CS[ls][!] [sgctefid]
33 " !: use vertical split
38 " s (symbol) find all references to the token under cursor
39 " g (global) find global definition(s) of the token under cursor
40 " c (calls) find all calls to the function name under cursor
41 " t (text) find all instances of the text under cursor
42 " e (egrep) egrep search for the word under cursor
43 " f (file) open the filename under cursor
44 " i (includes) find files that include the filename under cursor
45 " d (called) find functions that function under cursor calls
46 fun! s:Cscope(mode,...)
47 " call Dfunc("Cscope(mode=".a:mode.") a:0=".a:0)
50 " call Decho("style=".style)
53 " use cscope and ctags for ctrl-], :ta, etc
54 " check cscope for symbol definitions before using ctags
57 if !executable("cscope")
58 echohl Error | echoerr "can't execute cscope!" | echohl None
59 " call Dret("Cscope : can't execute cscope")
63 " add/build cscope database
66 " show message whenver any cscope database added
70 " decide if cs/scs and vertical/horizontal
83 " restore previous efm
84 if exists("b:cscope_efm")
85 let &efm= b:cscope_efm
91 echohl Error | echoerr "(Cscope) mode=".a:mode." not supported" | echohl None
98 elseif style =~ '[fi]'
99 let word= expand("<cfile>")
101 let word= expand("<cword>")
105 " call Decho("exe ".mode." find f ".word)
106 exe mode." find f ".word
108 " call Decho("exe ".mode." find i ^".word."$")
109 exe mode." find i ^".word."$"
111 " call Decho("exe ".mode." find ".style." ".word)
112 exe mode." find ".style." ".word
117 if !exists("b:cscope_efm")
118 let b:cscope_efm= &efm
119 setlocal efm=%C\ \ \ \ \ \ \ \ \ \ \ \ \ %m
120 setlocal efm+=%I\ %#%\\d%\\+\ %#%l\ %#%f\ %m
121 setlocal efm+=%-GChoice\ number\ %.%#
122 setlocal efm+=%-G%.%#line\ \ filename\ /\ context\ /\ line
123 setlocal efm+=%-G%.%#Cscope\ tag:\ %.%#
128 if has("menu") && has("gui_running") && &go =~ 'm'
129 exe 'silent! unmenu '.g:DrChipTopLvlMenu.'Cscope.Restore\ Error\ Format'
130 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Restore\ Error\ Format :CSL!'."<cr>"
138 " call Dret("Cscope")
141 " ---------------------------------------------------------------------
144 " call Dfunc("CscopeAdd()")
145 let s:cscopedatabase="undefined"
147 " specify cscope database in current directory
148 " or use whatever the CSCOPE_DB environment variable says to
149 if filereadable("cscope.out")
150 " call Decho("adding <cscope.out>")
151 let s:cscopedatabase= "cscope.out"
153 elseif $CSCOPE_DB != "" && filereadable($CSCOPE_DB)
154 " call Decho("adding $CSCOPE_DB<".expand("$CSCOPE_DB").">")
155 let s:cscopedatabase= expand("$CSCOPE_DB")
157 elseif executable("cscope")
158 " call Decho("using cscope ".expand("%"))
159 let s:cscopedatabase= expand("%")
160 call system("cscope -b ".s:cscopedatabase)
162 if !filereadable("cscope.out")
163 echohl WarningMsg | echoerr "(Cscope) can't find cscope database" | echohl None
166 echohl WarningMsg | echoerr "(Cscope) can't find cscope database" | echohl None
168 " call Dret("CscopeAdd : added <".s:cscopedatabase.">")
171 " ---------------------------------------------------------------------
173 fun! s:CscopeHelp(...)
174 " call Dfunc("CscopeHelp() a:0=".a:0)
175 if a:0 == 0 || a:1 == ""
176 echo "CS [cdefgist] : cscope"
177 echo "CSL[!] [cdefgist] : locallist style (! restores efm)"
178 echo "CSS[!] [cdefgist] : split window and use cscope (!=vertical split)"
179 echo "CSR : reset/rebuild cscope database"
180 let styles="!cdefgist"
182 " call Decho("styles<".styles.">")
183 call s:CscopeHelp(strpart(styles,0,1))
184 let styles= strpart(styles,1)
186 " call Dret("CscopeHelp : all")
188 elseif a:1 == '!' | echo "! split vertically"
189 elseif a:1 == 'c' | echo "c (calls) find functions calling function under cursor"
190 elseif a:1 == 'd' | echo "d (called) find functions called by function under cursor"
191 elseif a:1 == 'e' | echo "e (egrep) egrep search for the word under cursor"
192 elseif a:1 == 'f' | echo "f (file) open the file named under cursor"
193 elseif a:1 == 'g' | echo "g (global) find global definition(s) of word under cursor"
194 elseif a:1 == 'i' | echo "i (includes) find files that #include file named under cursor"
195 elseif a:1 == 's' | echo "s (symbol) find all references to the word under cursor"
196 elseif a:1 == 't' | echo "t (text) find all instances of the word under cursor"
197 else | echo a:1." not supported"
200 " call Dret("CscopeHelp : on <".a:1.">")
203 " ---------------------------------------------------------------------
205 fun! CscopeMenu(type)
206 " call Dfunc("CscopeMenu(type=".a:type.")")
207 if !exists("g:DrChipTopLvlMenu")
208 let g:DrChipTopLvlMenu= "DrChip."
210 if !exists("s:installed_menus")
211 exe "menu ".g:DrChipTopLvlMenu."Cscope.Help :CSh\<cr>"
213 if exists("s:installed_menus")
214 " silent! unmenu DrChipCscope
215 exe 'silent! unmenu '.g:DrChipTopLvlMenu.'Cscope.Use\ Messages\ Display'
216 exe 'silent! unmenu '.g:DrChipTopLvlMenu.'Cscope.Use\ Horiz\ Split\ Display'
217 exe 'silent! unmenu '.g:DrChipTopLvlMenu.'Cscope.Use\ Vert\ Split\ Display'
218 exe 'silent! unmenu '.g:DrChipTopLvlMenu.'Cscope.Use\ Quickfix\ Display'
222 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Horiz\ Split\ Display :call CscopeMenu(2)'."<cr>"
223 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Vert\ Split\ Display :call CscopeMenu(2)'."<cr>"
224 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Quickfix\ Display :call CscopeMenu(2)'."<cr>"
227 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Messages\ Display :call CscopeMenu(2)'."<cr>"
228 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Horiz\ Split\ Display :call CscopeMenu(2)'."<cr>"
229 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Vert\ Split\ Display :call CscopeMenu(2)'."<cr>"
232 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Messages\ Display :call CscopeMenu(2)'."<cr>"
233 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Horiz\ Split\ Display :call CscopeMenu(2)'."<cr>"
234 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Quickfix\ Display :call CscopeMenu(2)'."<cr>"
237 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Messages\ Display :call CscopeMenu(2)'."<cr>"
238 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Horiz\ Split\ Display\ :call CscopeMenu(2)'."<cr>"
239 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Use\ Quickfix\ Display :call CscopeMenu(2)'."<cr>"
242 if exists("s:installed_menus")
243 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Find\ functions\ which\ call\ word\ under\ cursor'
244 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Find\ functions\ called\ by\ word\ under\ cursor'
245 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Egrep\ search\ for\ word\ under\ cursor'
246 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Open\ file\ under\ cursor'
247 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Find\ globally\ word\ under\ cursor'
248 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Find\ files\ that\ include\ word\ under\ cursor'
249 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Find\ all\ references\ to\ symbol\ under\ cursor'
250 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Find\ all\ instances\ of\ text\ under\ cursor'
251 exe 'unmenu '.g:DrChipTopLvlMenu.'Cscope.Reset'
252 exe 'silent! unmenu '.g:DrChipTopLvlMenu.'Cscope.Restore\ Error\ Format'
255 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Find\ functions\ which\ call\ word\ under\ cursor<tab>:CS\ c :'.cmd.'\ c'."<cr>"
256 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Find\ functions\ called\ by\ word\ under\ cursor<tab>:CS\ d :'.cmd.'\ d'."<cr>"
257 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Egrep\ search\ for\ word\ under\ cursor<tab>:CS\ e :'.cmd.'\ e'."<cr>"
258 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Open\ file\ under\ cursor<tab>:CS\ f :'.cmd.'\ f'."<cr>"
259 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Find\ globally\ word\ under\ cursor<tab>:CS\ g :'.cmd.'\ g'."<cr>"
260 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Find\ files\ that\ include\ word\ under\ cursor<tab>:CS\ i :'.cmd.'\ i'."<cr>"
261 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Find\ all\ references\ to\ symbol\ under\ cursor<tab>:CS\ s :'.cmd.'\ s'."<cr>"
262 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Find\ all\ instances\ of\ text\ under\ cursor<tab>:CS\ t :'.cmd.'\ t'."<cr>"
263 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Reset<tab>:CSr :CSr'."<cr>"
264 if exists("b:cscope_efm")
265 exe 'menu '.g:DrChipTopLvlMenu.'Cscope.Restore\ Error\ Format :CSL!'."<cr>"
268 let s:installed_menus= 1
269 " call Dret("CscopeMenu")
272 " ---------------------------------------------------------------------
275 " call Dfunc("CscopeReset()")
276 call system("cscope -b *.[ch]")
278 " call Dret("CscopeReset")
281 " ---------------------------------------------------------------------
282 " Install Menus: {{{1
283 if !exists("s:installed_menus") && has("menu") && has("gui_running") && &go =~ 'm'
287 " ---------------------------------------------------------------------