vimエディタでcscopeは自動的にcscopeをロードします.outファイルのメソッド
8928 ワード
方法1:vimプラグイン-autoload_cscope.vim
手順:
プラグインダウンロードアドレス:autoload_cscope.vimダウンロード後、
メリット:
誰かがメンテナンスしていて(でも久しぶりに更新したようで)、安定しています.
欠点:
補足:
以下にコードを貼り付けて、ダウンロードに成功しない場合は、空のファイルに直接コピーし、
方法2:.vimrcスクリプト法
手順:
メリット
ターゲットディレクトリの下にあるすべてのファイルに有効です.
欠点
現時点では欠点は発見されていない.
手順:
プラグインダウンロードアドレス:autoload_cscope.vimダウンロード後、
autoload_cscope.vim
は~/.vim/plugin
ディレクトリの下に置かれ、そのディレクトリがなければ1つ作成し、端末を再開すればよい.メリット:
誰かがメンテナンスしていて(でも久しぶりに更新したようで)、安定しています.
欠点:
*.c/*.h
などのコードファイルにのみ有効であり、Makefileなどの補助ファイルには無効です.補足:
以下にコードを貼り付けて、ダウンロードに成功しない場合は、空のファイルに直接コピーし、
autoload_cscope.vim
と名前を変更して、上記の方法で処理すればいいです." Vim global plugin for autoloading cscope databases.
" Last Change: Wed Jan 26 10:28:52 Jerusalem Standard Time 2011
" Maintainer: Michael Conrad Tadpol Tilsra
" Revision: 0.5
if exists("loaded_autoload_cscope")
finish
endif
let loaded_autoload_cscope = 1
" requirements, you must have these enabled or this is useless.
if( !has('cscope') || !has('modify_fname') )
finish
endif
let s:save_cpo = &cpo
set cpo&vim
" If you set this to anything other than 1, the menu and macros will not be
" loaded. Useful if you have your own that you like. Or don't want my stuff
" clashing with any macros you've made.
if !exists("g:autocscope_menus")
let g:autocscope_menus = 1
endif
"==
" windowdir
" Gets the directory for the file in the current window
" Or the current working dir if there isn't one for the window.
" Use tr to allow that other OS paths, too
function s:windowdir()
if winbufnr(0) == -1
let unislash = getcwd()
else
let unislash = fnamemodify(bufname(winbufnr(0)), ':p:h')
endif
return tr(unislash, '\', '/')
endfunc
"
"==
" Find_in_parent
" find the file argument and returns the path to it.
" Starting with the current working dir, it walks up the parent folders
" until it finds the file, or it hits the stop dir.
" If it doesn't find it, it returns "Nothing"
function s:Find_in_parent(fln,flsrt,flstp)
let here = a:flsrt
while ( strlen( here) > 0 )
if filereadable( here . "/" . a:fln )
return here
endif
let fr = match(here, "/[^/]*$")
if fr == -1
break
endif
let here = strpart(here, 0, fr)
if here == a:flstp
break
endif
endwhile
return "Nothing"
endfunc
"
"==
" Cycle_macros_menus
" if there are cscope connections, activate that stuff.
" Else toss it out.
" TODO Maybe I should move this into a seperate plugin?
let s:menus_loaded = 0
function s:Cycle_macros_menus()
if g:autocscope_menus != 1
return
endif
if cscope_connection()
if s:menus_loaded == 1
return
endif
let s:menus_loaded = 1
set csto=0
set cst
silent! map s :cs find s =expand("")
silent! map g :cs find g =expand("")
silent! map d :cs find d =expand("")
silent! map c :cs find c =expand("")
silent! map t :cs find t =expand("")
silent! map e :cs find e =expand("")
silent! map f :cs find f =expand("")
silent! map i :cs find i =expand("")
if has("menu")
nmenu &Cscope.Find.Symbols
\ :cs find s =expand("")
nmenu &Cscope.Find.Definitiong
\ :cs find g =expand("")
nmenu &Cscope.Find.Calledd
\ :cs find d =expand("")
nmenu &Cscope.Find.Callingc
\ :cs find c =expand("")
nmenu &Cscope.Find.Assignmentt
\ :cs find t =expand("")
nmenu &Cscope.Find.Egrepe
\ :cs find e =expand("")
nmenu &Cscope.Find.Filef
\ :cs find f =expand("")
nmenu &Cscope.Find.Includingi
\ :cs find i =expand("")
" nmenu &Cscope.Add :cs add
" nmenu &Cscope.Remove :cs kill
nmenu &Cscope.Reset :cs reset
nmenu &Cscope.Show :cs show
" Need to figure out how to do the add/remove. May end up writing
" some container functions. Or tossing them out, since this is supposed
" to all be automatic.
endif
else
let s:menus_loaded = 0
set nocst
silent! unmap s
silent! unmap g
silent! unmap d
silent! unmap c
silent! unmap t
silent! unmap e
silent! unmap f
silent! unmap i
if has("menu") " would rather see if the menu exists, then remove...
silent! nunmenu Cscope
endif
endif
endfunc
"
"==
" Unload_csdb
" drop cscope connections.
function s:Unload_csdb()
if exists("b:csdbpath")
if cscope_connection(3, "out", b:csdbpath)
let save_csvb = &csverb
set nocsverb
exe "cs kill " . b:csdbpath
set csverb
let &csverb = save_csvb
endif
endif
endfunc
"
"==
" Cycle_csdb
" cycle the loaded cscope db.
function s:Cycle_csdb()
if exists("b:csdbpath")
if cscope_connection(3, "out", b:csdbpath)
return
"it is already loaded. don't try to reload it.
endif
endif
let newcsdbpath = s:Find_in_parent("cscope.out",s:windowdir(),$HOME)
" echo "Found cscope.out at: " . newcsdbpath
" echo "Windowdir: " . s:windowdir()
if newcsdbpath != "Nothing"
let b:csdbpath = newcsdbpath
if !cscope_connection(3, "out", b:csdbpath)
let save_csvb = &csverb
set nocsverb
exe "cs add " . b:csdbpath . "/cscope.out " . b:csdbpath
set csverb
let &csverb = save_csvb
endif
"
else " No cscope database, undo things. (someone rm-ed it or somesuch)
call s:Unload_csdb()
endif
endfunc
" auto toggle the menu
augroup autoload_cscope
au!
au BufEnter *.[chly] call Cycle_csdb() | call Cycle_macros_menus()
au BufEnter *.cc call Cycle_csdb() | call Cycle_macros_menus()
au BufUnload *.[chly] call Unload_csdb() | call Cycle_macros_menus()
au BufUnload *.cc call Unload_csdb() | call Cycle_macros_menus()
augroup END
let &cpo = s:save_cpo
方法2:.vimrcスクリプト法
手順:
~/.vimrc
ファイルに以下の内容を追加して保存すればよい.""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope cscope.out
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set csverb
set cspc=3
"add any database in current dir
if filereadable("cscope.out")
cs add cscope.out
"else search cscope.out elsewhere
else
let cscope_file=findfile("cscope.out",".;")
let cscope_pre=matchstr(cscope_file,".*/")
if !empty(cscope_file) && filereadable(cscope_file)
set nocsverb
exe "cs add" cscope_file cscope_pre
set csverb
endif
endif
endif
メリット
ターゲットディレクトリの下にあるすべてのファイルに有効です.
Makefile
などの補助書類などが含まれています.欠点
現時点では欠点は発見されていない.