From 1de0397c71e753b77b42e227bb2e2a7214b0697b Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 4 Mar 2013 17:07:26 +0100 Subject: [PATCH] [vim] plugin for cscope in python --- .vim/plugin/autotags.vim | 23 ++++++++++++++++++++++- .vim/plugin/cscope.vim | 20 +++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/.vim/plugin/autotags.vim b/.vim/plugin/autotags.vim index ee722b8..3b3a579 100644 --- a/.vim/plugin/autotags.vim +++ b/.vim/plugin/autotags.vim @@ -1,4 +1,4 @@ -" This script is a wrapper for ctags and cscope, so tags for all languages +" autotags plugin: a wrapper for ctags and cscope, so tags for all languages " supported by ctags can be build (cscope is additionally used for C/C++). " Tags are stored in a separate directory and don't clog you project tree @@ -183,6 +183,12 @@ fun! s:AutotagsInit() let g:autotags_cscope_exe = "cscope" endif + if !exists("g:autotags_pycscope_cmd") + let g:autotags_pycscope_pyt = "/soft/Python-2.7.3.i686/bin/python" + let g:autotags_pycscope_scr = "~/.vim/plugin/pycscope.py" + let g:autotags_pycscope_cmd = g:autotags_pycscope_pyt . " " . g:autotags_pycscope_scr + endif + if !exists("g:autotags_cscope_file_extensions") let g:autotags_cscope_file_extensions = ".cpp .cc .cxx .m .hpp .hh .h .hxx .c .idl .java" endif @@ -344,6 +350,16 @@ fun! s:AutotagsGenerate(sourcedir, tagsdir) \ "nice -15 " . g:autotags_cscope_exe . " -b -q -k") endif endif + echomsg system("cd " . shellescape(l:cscopedir) . " && " . + \ " nice -15 find " . shellescape(a:sourcedir) . + \ " -not -regex '.*/\\..*' " . + \ " -not -regex '.*/\\%.*' " . + \ " -name '*.py' " . + \ " -fprint cscope_py.files") + if getfsize(l:cscopedir . "/cscope_py.files") > 0 + echomsg system("cd " . shellescape(l:cscopedir) . " && " . + \ "nice -15 " . g:autotags_pycscope_cmd . " -i cscope_py.files -f cscope_py.out" ) + endif endfun fun! s:AutotagsReload(tagsdir) @@ -381,6 +397,11 @@ fun! s:AutotagsLoad(tagsdir) if filereadable(l:cscopedb) exe "cs add " . l:cscopedb endif + + let l:cscopepydb = a:tagsdir . "/cscope_py.out" + if filereadable(l:cscopepydb) + exe "cs add " . l:cscopepydb + endif endfun fun! s:AutotagsIsLoaded() diff --git a/.vim/plugin/cscope.vim b/.vim/plugin/cscope.vim index fd25c0e..f851a6c 100644 --- a/.vim/plugin/cscope.vim +++ b/.vim/plugin/cscope.vim @@ -1,5 +1,5 @@ -" -" cscope (a tool to browse through C source files ) keymaping +" cscope keymaping plugin +" (a tool to browse through C source files) " " if compiled with --enable-cscope @@ -9,6 +9,19 @@ if has("cscope") endif let g:loaded_cscope = 1.0 + function! GoToDefinition() + try + execute "cscope find g " . expand("") + catch /:E259:/ + try + execute "tag " . expand("") + catch /:E257:/ + execute "normal! gd" + execute "nohlsearch" + endtry + endtry + endfunction + " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t' set cscopetag " use ctags before cscope @@ -34,7 +47,8 @@ if has("cscope") nmap :cscope find s =expand("") nmap :scscope find s =expand("") " go to definition with F6 and split with shift+F6 and use ctags with alt+shift+F6 - nmap :cscope find g =expand("") + "nmap :cscope find g =expand("") + nmap :call GoToDefinition() nmap :scscope find g =expand("") nmap :tag =expand("") " go to calls with F7 and split with shift+F7