Skip to content

Commit cce88b0

Browse files
author
Xudong Huang
committed
add gtags plugin
1 parent ef2a430 commit cce88b0

File tree

3 files changed

+791
-1
lines changed

3 files changed

+791
-1
lines changed

IDE.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ endif
3939

4040
if exists("g:neocomplcache_enable")
4141
Bundle 'Shougo/neocomplcache'
42-
Bundle 'Shougo/neosnippet'
42+
Bundle 'Shougo/neosnippet-snippets'
4343
if has("python")
4444
Bundle 'Rip-Rip/clang_complete'
4545
Bundle 'Shougo/neocomplcache-clang_complete'

plugin/gtags-cscope.vim

+271
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
" File: gtags-cscope.vim
2+
" Author: Tama Communications Corporation
3+
" Version: 0.4
4+
" Last Modified: January 16, 2011
5+
"
6+
" Copyright and license
7+
" ---------------------
8+
" Copyright (c) 2010, 2011 Tama Communications Corporation
9+
"
10+
" This file is part of GNU GLOBAL.
11+
"
12+
" This program is free software: you can redistribute it and/or modify
13+
" it under the terms of the GNU General Public License as published by
14+
" the Free Software Foundation, either version 3 of the License, or
15+
" (at your option) any later version.
16+
"
17+
" This program is distributed in the hope that it will be useful,
18+
" but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
" GNU General Public License for more details.
21+
"
22+
" You should have received a copy of the GNU General Public License
23+
" along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
"
25+
" Overview
26+
" --------
27+
" The gtags-cscope.vim plugin script integrates the GNU GLOBAL source code tag system
28+
" with Vim using cscope interface.
29+
"
30+
" Installation
31+
" ------------
32+
" Drop the file in your plugin directory or source it from your vimrc.
33+
" To use this script, you need the GNU GLOBAL-5.8 or later installed
34+
" in your machine.
35+
"
36+
" Usage
37+
" -----
38+
" First of all, you must execute gtags(1) at the root of source directory
39+
" to make tag files. Assuming that your source directory is '/var/src',
40+
" it is neccessary to execute the following commands.
41+
"
42+
" [Load vim]
43+
" $ cd /var/src
44+
" $ gtags
45+
" $ vim
46+
" [Load gtags-cscope]
47+
" :GtagsCscope <ENTER> (in vim command line)
48+
"
49+
" Basic command
50+
" -------------
51+
" Then you can use cs commands except for the 'd'(2) command.
52+
" Profitable commands are assigned to keys like follows:
53+
"
54+
" explanation command
55+
" ----------------------------------------------------------
56+
" Find symbol :cs find 0 or s
57+
" Find definition :cs find 1 or g
58+
" Find functions called by this function (not implemented)
59+
" Find reference :cs find 3 or c
60+
" Find text string :cs find 4 or t
61+
" Find egrep pattern :cs find 6 or e
62+
" Find path :cs find 7 or f
63+
" Find include file :cs find 8 or i
64+
"
65+
" You can move tag list using:
66+
" Go to the next tag :tn
67+
" Go to the previous tag :tp
68+
" Pop tag stack :pop
69+
"
70+
" About the other tag command, you can see the help like this:
71+
"
72+
" :h tagsrch
73+
"
74+
" Enhancing command
75+
" -----------------
76+
" You can use the context jump function. To use this function, put the cursor
77+
" on a word and type <C-\><C-\><C-]>.
78+
" If you can use mouse then please double click on the left button.
79+
" To pop tag, please type 'g' and click on the right button.
80+
"
81+
" Configure
82+
" ---------
83+
" You can use the following variables in $HOME/.vimrc.
84+
"
85+
" To use the default key/mouse mapping:
86+
" let GtagsCscope_Auto_Map = 1
87+
" To ignore letter case when searching:
88+
" let GtagsCscope_Ignore_Case = 1
89+
" To use absolute path name:
90+
" let GtagsCscope_Absolute_Path = 1
91+
" To deterring interruption:
92+
" let GtagsCscope_Keep_Alive = 1
93+
" If you hope auto loading:
94+
" let GtagsCscope_Auto_Load = 1
95+
" To use 'vim -t ', ':tag' and '<C-]>'
96+
" set cscopetag
97+
"
98+
if exists("loaded_gtags_cscope")
99+
finish
100+
endif
101+
if !has("cscope")
102+
call Error('This vim does not include cscope support.')
103+
finish
104+
endif
105+
"
106+
" global command name
107+
"
108+
let s:global_command = $GTAGSGLOBAL
109+
if s:global_command == ''
110+
let s:global_command = "global"
111+
endif
112+
if !exists("GtagsCscope_Auto_Load")
113+
let GtagsCscope_Auto_Load = 0
114+
endif
115+
if !exists("GtagsCscope_Auto_Map")
116+
let GtagsCscope_Auto_Map = 0
117+
endif
118+
if !exists("GtagsCscope_Use_Old_Key_Map")
119+
let GtagsCscope_Use_Old_Key_Map = 0
120+
endif
121+
if !exists("GtagsCscope_Quiet")
122+
let GtagsCscope_Quiet = 0
123+
endif
124+
if !exists("GtagsCscope_Ignore_Case")
125+
let GtagsCscope_Ignore_Case = 0
126+
endif
127+
if !exists("GtagsCscope_Absolute_Path")
128+
let GtagsCscope_Absolute_Path = 0
129+
endif
130+
if !exists("GtagsCscope_Keep_Alive")
131+
let GtagsCscope_Keep_Alive = 0
132+
endif
133+
134+
"
135+
" Display error message.
136+
"
137+
function! s:Error(msg)
138+
if (g:GtagsCscope_Quiet == 0)
139+
echohl WarningMsg |
140+
\ echomsg 'Gtags-cscope: ' . a:msg |
141+
\ echohl None
142+
endif
143+
endfunction
144+
145+
function! s:GtagsCscope_GtagsRoot()
146+
let cmd = s:global_command . " -pq"
147+
let cmd_output = system(cmd)
148+
if v:shell_error != 0
149+
if v:shell_error == 3
150+
call s:Error('GTAGS not found.')
151+
else
152+
call s:Error('global command failed. command line: ' . cmd)
153+
endif
154+
return ''
155+
endif
156+
return strpart(cmd_output, 0, strlen(cmd_output) - 1)
157+
endfunction
158+
159+
function! s:GtagsCscope()
160+
"
161+
" Get gtagsroot directory.
162+
"
163+
let gtagsroot = s:GtagsCscope_GtagsRoot()
164+
if gtagsroot == ''
165+
return
166+
endif
167+
"
168+
" Load gtags-cscope.
169+
"
170+
set csprg=gtags-cscope
171+
let s:command = "cs add " . gtagsroot . "/GTAGS"
172+
let s:option = ''
173+
if g:GtagsCscope_Ignore_Case == 1
174+
let s:option = s:option . 'C'
175+
endif
176+
if g:GtagsCscope_Absolute_Path == 1
177+
let s:option = s:option . 'a'
178+
endif
179+
if g:GtagsCscope_Keep_Alive == 1
180+
let s:option = s:option . 'i'
181+
endif
182+
if s:option != ''
183+
let s:command = s:command . ' . -' . s:option
184+
endif
185+
set nocscopeverbose
186+
exe s:command
187+
set cscopeverbose
188+
"
189+
" Key mapping
190+
"
191+
if g:GtagsCscope_Auto_Map == 1
192+
if g:GtagsCscope_Use_Old_Key_Map == 1
193+
" normal command
194+
:nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR>
195+
:nmap <C-\>t :cs find g <C-R>=expand("<cword>")<CR>
196+
:nmap <C-\>r :cs find c <C-R>=expand("<cword>")<CR>
197+
:nmap <C-\>g :cs find e <C-R>=expand("<cword>")<CR>
198+
:nmap <C-\>P :cs find f
199+
" Using 'CTRL-spacebar', the result is displayed in new horizontal window.
200+
:nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR>
201+
:nmap <C-@>t :scs find g <C-R>=expand("<cword>")<CR>
202+
:nmap <C-@>r :scs find c <C-R>=expand("<cword>")<CR>
203+
:nmap <C-@>g :scs find e <C-R>=expand("<cword>")<CR>
204+
:nmap <C-@>P :scs find f
205+
" Hitting CTRL-space *twice*, the result is displayed in new vertical window.
206+
:nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR>
207+
:nmap <C-@><C-@>t :vert scs find g <C-R>=expand("<cword>")<CR>
208+
:nmap <C-@><C-@>r :vert scs find c <C-R>=expand("<cword>")<CR>
209+
:nmap <C-@><C-@>g :vert scs find e <C-R>=expand("<cword>")<CR>
210+
:nmap <C-@><C-@>P :vert scs find f
211+
else
212+
"
213+
" The following key mappings are derived from 'cscope_maps.vim'.
214+
" (The 'd' command is not implemented in gtags-cscope.)
215+
"
216+
" normal command
217+
:nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
218+
:nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
219+
:nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
220+
:nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
221+
:nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
222+
:nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
223+
:nmap <C-\>i :cs find i <C-R>=expand("<cfile>")<CR><CR>
224+
":nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
225+
" Using 'CTRL-spacebar', the result is displayed in new horizontal window.
226+
:nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR>
227+
:nmap <C-@>g :scs find g <C-R>=expand("<cword>")<CR><CR>
228+
:nmap <C-@>c :scs find c <C-R>=expand("<cword>")<CR><CR>
229+
:nmap <C-@>t :scs find t <C-R>=expand("<cword>")<CR><CR>
230+
:nmap <C-@>e :scs find e <C-R>=expand("<cword>")<CR><CR>
231+
:nmap <C-@>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
232+
:nmap <C-@>i :scs find i <C-R>=expand("<cfile>")<CR><CR>
233+
":nmap <C-@>d :scs find d <C-R>=expand("<cword>")<CR><CR>
234+
" Hitting CTRL-space *twice*, the result is displayed in new vertical window.
235+
:nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
236+
:nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
237+
:nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
238+
:nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
239+
:nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
240+
:nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>
241+
:nmap <C-@><C-@>i :vert scs find i <C-R>=expand("<cfile>")<CR><CR>
242+
":nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>
243+
endif
244+
" tag command
245+
:nmap <C-\><C-n> :tn<CR>
246+
:nmap <C-\><C-p> :tp<CR>
247+
:nmap <C-n> :cn<CR>
248+
:nmap <C-p> :cp<CR>
249+
" Context search. See the --from-here option of global(1).
250+
:nmap <C-\><C-\><C-]> :cs find d <C-R>=expand("<cword>")<CR>:<C-R>=line('.')<CR>:%<CR>
251+
:nmap <2-LeftMouse> :cs find d <C-R>=expand("<cword>")<CR>:<C-R>=line('.')<CR>:%<CR>
252+
:nmap g<LeftMouse> :cs find d <C-R>=expand("<cword>")<CR>:<C-R>=line('.')<CR>:%<CR>
253+
:nmap <C-LeftMouse> :cs find d <C-R>=expand("<cword>")<CR>:<C-R>=line('.')<CR>:%<CR>
254+
" The following mappings are unnecessary, because you can use the default mapping.
255+
":nmap g<RightMouse> <C-t>
256+
":nmap <C-RightMouse> <C-t>
257+
" Short cut key
258+
:nmap <C-\><SPACE> :cs find<SPACE>
259+
:nmap <C-@><SPACE> :scs find<SPACE>
260+
:nmap <C-@><C-@><SPACE> :vert scs find<SPACE>
261+
:nmap <F2> :copen<CR>
262+
:nmap <F3> :cs find d <C-R>=expand("<cword>")<CR>:<C-R>=line('.')<CR>:%<CR>
263+
:nmap <F4> :cclose<CR>
264+
endif
265+
endfunction
266+
267+
if g:GtagsCscope_Auto_Load == 1
268+
call s:GtagsCscope()
269+
endif
270+
command! -nargs=0 GtagsCscope call s:GtagsCscope()
271+
let loaded_gtags_cscope = 1

0 commit comments

Comments
 (0)