add vim conf files
[arrow.git] / conf_slk120 / vim / _vim / plugin / cecscope.vim
bloba9cc4fb5d3e2b2263fbc8059167449d72dc6ab13
1 " cecscope.vim:
2 "  Author: Charles E. Campbell, Jr.
3 "  Date:   Feb 07, 2006
4 "  Version: 2
5 "  Usage:  :CS[!]  [cdefgist]
6 "          :CSL[!] [cdefgist]
7 "          :CSS[!] [cdefgist]
8 "          :CSH     (gives help)
9 "          :CSR
10 " ---------------------------------------------------------------------
12 " ---------------------------------------------------------------------
13 " Load Once: {{{1
14 if !has("cscope") || &cp || exists("g:loaded_cecscope") || v:version < 700
15  finish
16 endif
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 " ---------------------------------------------------------------------
28 "  Functions: {{{1
30 " ---------------------------------------------------------------------
31 " Cscope: {{{2
32 "   Usage: :CS[ls][!]  [sgctefid]
33 " !: use vertical split
35 " -----
36 " style
37 " -----
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)
48   if a:0 >= 1
49    let style= a:1
50 "   call Decho("style=".style)
51   endif
52   if !&cscopetag
53    " use cscope and ctags for ctrl-], :ta, etc
54    " check cscope for symbol definitions before using ctags
55    set cscopetag csto=0
57    if !executable("cscope")
58     echohl Error | echoerr "can't execute cscope!" | echohl None
59 "    call Dret("Cscope : can't execute cscope")
60     return
61    endif
63    " add/build cscope database
64    call s:CscopeAdd()
66    " show message whenver any cscope database added
67    set cscopeverbose
68   endif
70   " decide if cs/scs and vertical/horizontal
71   if a:mode == 0
72    let mode= "cs"
73   elseif a:mode == 1
74    let a:mode= "vert cs"
75   elseif a:mode == 2
76    let mode= "scs"
77   elseif a:mode == 3
78    let mode= "vert scs"
79   elseif a:mode == 4
80    let mode= "silent cs"
81    redir! > cscope.qf
82   elseif a:mode == 5
83    " restore previous efm
84    if exists("b:cscope_efm")
85     let &efm= b:cscope_efm
86     unlet b:cscope_efm
87    endif
88 "   call Dret("Cscope")
89    return
90   else
91    echohl Error | echoerr "(Cscope) mode=".a:mode." not supported" | echohl None
92 "   call Dret("Cscope")
93    return
94   endif
96   if a:0 == 2
97    let word= a:2
98   elseif style =~ '[fi]'
99    let word= expand("<cfile>")
100   else
101    let word= expand("<cword>")
102   endif
104   if style == 'f'
105 "   call Decho("exe ".mode." find f ".word)
106    exe mode." find f ".word
107   elseif style == 'i'
108 "   call Decho("exe ".mode." find i ^".word."$")
109    exe mode." find i ^".word."$"
110   else
111 "   call Decho("exe ".mode." find ".style." ".word)
112    exe mode." find ".style." ".word
113   endif
115   if a:mode == 4
116    redir END
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:\ %.%#
124     setlocal efm+=%-G
125    endif
126    lg cscope.qf
127    silent! lope 5
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>"
131    endif
132   endif
133   if has("folding")
134    silent! norm! zMzxz.
135   else
136    norm! z.
137   endif
138 "  call Dret("Cscope")
139 endfun
141 " ---------------------------------------------------------------------
142 " CscopeAdd: {{{2
143 fun! s:CscopeAdd()
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"
152    cs add 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")
156    cs add $CSCOPE_DB
157   elseif executable("cscope")
158 "   call Decho("using cscope ".expand("%"))
159    let s:cscopedatabase= expand("%")
160    call system("cscope -b ".s:cscopedatabase)
161    cs add cscope.out
162    if !filereadable("cscope.out")
163     echohl WarningMsg | echoerr "(Cscope) can't find cscope database" | echohl None
164    endif
165   else
166    echohl WarningMsg | echoerr "(Cscope) can't find cscope database" | echohl None
167   endif
168 "  call Dret("CscopeAdd : added <".s:cscopedatabase.">")
169 endfun
171 " ---------------------------------------------------------------------
172 " CscopeHelp: {{{2
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"
181    while styles != ""
182 "       call Decho("styles<".styles.">")
183         call s:CscopeHelp(strpart(styles,0,1))
184         let styles= strpart(styles,1)
185    endwhile
186 "   call Dret("CscopeHelp : all")
187    return
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"
198   endif
200 "  call Dret("CscopeHelp : on <".a:1.">")
201 endfun
203 " ---------------------------------------------------------------------
204 " CscopeMenu: {{{2
205 fun! CscopeMenu(type)
206 "  call Dfunc("CscopeMenu(type=".a:type.")")
207   if !exists("g:DrChipTopLvlMenu")
208    let g:DrChipTopLvlMenu= "DrChip."
209   endif
210   if !exists("s:installed_menus")
211    exe "menu ".g:DrChipTopLvlMenu."Cscope.Help  :CSh\<cr>"
212   endif
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'
219   endif
220   if a:type == 1
221    let cmd= "CS"
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>"
225   elseif a:type == 2
226    let cmd= 'CSL'
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>"
230   elseif a:type == 3
231    let cmd= 'CSS'
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>"
235   elseif a:type == 4
236    let cmd= 'CSS!'
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>"
240   endif
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'
253   endif
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>"
266   endif
268   let s:installed_menus= 1
269 "  call Dret("CscopeMenu")
270 endfun
272 " ---------------------------------------------------------------------
273 " CscopeReset: {{{2
274 fun! s:CscopeReset()
275 "  call Dfunc("CscopeReset()")
276   call system("cscope -b *.[ch]")
277   cscope reset
278 "  call Dret("CscopeReset")
279 endfun
281 " ---------------------------------------------------------------------
282 "  Install Menus: {{{1
283 if !exists("s:installed_menus") && has("menu") && has("gui_running") && &go =~ 'm'
284  call CscopeMenu(1)
285 endif
287 " ---------------------------------------------------------------------
288 " Modelines: {{{1
289 " vim: fdm=marker