1
0
Fork 0
mirror of synced 2024-11-23 01:05:34 -05:00

add taglist & vim-cscope

This commit is contained in:
Max-bazinga 2017-04-10 21:02:38 +08:00
parent f58d67271a
commit d6f8b51568
7 changed files with 6711 additions and 0 deletions

View file

@ -0,0 +1,18 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=273
The "Tag List" plugin is a source code browser plugin for Vim and
provides an overview of the structure of source code files and allows
you to efficiently browse through source code files for different
programming languages. You can visit the taglist plugin home page for
more information:
http://vim-taglist.sourceforge.net
You can subscribe to the taglist mailing list to post your questions
or suggestions for improvement or to report bugs. Visit the following
page for subscribing to the mailing list:
http://groups.yahoo.com/group/taglist/
For more information about using this plugin, after installing the
taglist plugin, use the ":help taglist" command.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,54 @@
# Introduction
Cscove(new name for this plugin, since cscope.vim is used too widely.) is a
smart cscope helper for vim.
It will try to find a proper cscope database for current file, then connect to
it. If there is no proper cscope database for current file, you are prompted to
specify a folder with a string like --
Can not find proper cscope db, please input a path to create cscope db for.
Then the plugin will create cscope database for you, connect to it, and find
what you want. The found result will be listed in a location list window. Next
time when you open the same file or other file that the cscope database can be
used for, the plugin will connect to the cscope database automatically. You
need not take care of anything about cscope database.
When you have a file edited/added in those folders for which cscope databases
have been created, cscove will automatically update the corresponding database.
Cscove frees you from creating/connecting/updating cscope database, let you
focus on code browsing.
# Example settings
The default key mappings has been removed from the plugin itself, since users
may prefer different choices.
So to use the plugin, you must define your own key mappings first.
Below is the minimum key mappings.
nnoremap <leader>fa :call CscopeFindInteractive(expand('<cword>'))<CR>
nnoremap <leader>l :call ToggleLocationList()<CR>
Some optional key mappings to search directly.
" s: Find this C symbol
nnoremap <leader>fs :call CscopeFind('s', expand('<cword>'))<CR>
" g: Find this definition
nnoremap <leader>fg :call CscopeFind('g', expand('<cword>'))<CR>
" d: Find functions called by this function
nnoremap <leader>fd :call CscopeFind('d', expand('<cword>'))<CR>
" c: Find functions calling this function
nnoremap <leader>fc :call CscopeFind('c', expand('<cword>'))<CR>
" t: Find this text string
nnoremap <leader>ft :call CscopeFind('t', expand('<cword>'))<CR>
" e: Find this egrep pattern
nnoremap <leader>fe :call CscopeFind('e', expand('<cword>'))<CR>
" f: Find this file
nnoremap <leader>ff :call CscopeFind('f', expand('<cword>'))<CR>
" i: Find files #including this file
nnoremap <leader>fi :call CscopeFind('i', expand('<cword>'))<CR>
# Screencast
Please note that line number changes in location list after file saved.
![cscove.vim](https://brookhong.github.io/assets/images/cscove.gif)

View file

@ -0,0 +1,155 @@
*cscove.txt* cscove, a smart cscope helper for vim. *cscove*
1. About cscove |cscove-about|
2. Key Mappings |cscove-keymappings|
3. Functions |cscove-funtions|
4. Commands |cscove-commands|
5. Options |cscove-options|
=============================================================================
1. ABOUT cscove ~
*cscove-about*
Cscove(new name for this plugin, since cscope.vim is used too widely.) is a
smart cscope helper for vim.
It will try to find a proper cscope database for current file, then connect to
it. If there is no proper cscope database for current file, you are prompted to
specify a folder with a string like --
Can not find proper cscope db, please input a path to create cscope db for.
Then the plugin will create cscope database for you, connect to it, and find
what you want. The found result will be listed in a location list window. Next
time when you open the same file or other file that the cscope database can be
used for, the plugin will connect to the cscope database automatically. You
need not take care of anything about cscope database.
When you have a file edited/added in those folders for which cscope databases
have been created, cscove will automatically update the corresponding database.
Cscove frees you from creating/connecting/updating cscope database, let you
focus on code browsing.
=============================================================================
2. KEY MAPPINGS ~
*cscove-keymappings*
The default key mappings has been removed from the plugin itself, since users
may prefer different choices.
So to use the plugin, you must define your own key mappings first.
Below is the minimum key mappings.
nnoremap <leader>fa :call CscopeFindInteractive(expand('<cword>'))<CR>
nnoremap <leader>l :call ToggleLocationList()<CR>
Some optional key mappings to search directly.
" s: Find this C symbol
nnoremap <leader>fs :call CscopeFind('s', expand('<cword>'))<CR>
" g: Find this definition
nnoremap <leader>fg :call CscopeFind('g', expand('<cword>'))<CR>
" d: Find functions called by this function
nnoremap <leader>fd :call CscopeFind('d', expand('<cword>'))<CR>
" c: Find functions calling this function
nnoremap <leader>fc :call CscopeFind('c', expand('<cword>'))<CR>
" t: Find this text string
nnoremap <leader>ft :call CscopeFind('t', expand('<cword>'))<CR>
" e: Find this egrep pattern
nnoremap <leader>fe :call CscopeFind('e', expand('<cword>'))<CR>
" f: Find this file
nnoremap <leader>ff :call CscopeFind('f', expand('<cword>'))<CR>
" i: Find files #including this file
nnoremap <leader>fi :call CscopeFind('i', expand('<cword>'))<CR>
=============================================================================
3. FUNCTIONS ~
*cscove-functions*
The plugin provides three public functions.
CscopeFind({querytype}, {pattern})
search your {pattern} with {querytype} in the database suitable
for current file.
CscopeFindInteractive({pattern})
provide an interactive interface for finding what you want.
CscopeUpdateDB()
update all existing cscope databases in case that you disable cscope
database auto update.
ToggleLocationList()
toggle the location list for found results.
=============================================================================
4. Commands ~
*cscove-commands*
You may need these commands sometimes.
*CscopeList*
List all existing cscope databases that cscove has created for you.
:CscopeList
Here is example output from |:CscopeList|
ID LOADTIMES PATH
*1337668712 3 /works/vim/src
'*' means the db has been connected.
ID id of the db.
LOADTIMES how many times this db has ever been used.
PATH which folder the db is for.
*CscopeClear*
Remove the database for specified folder or all existing cscope databases that
cscove has created for you if no folder provided.
You can use <Tab> for completion.
:CscopeClear <full_path>
:CscopeClear
=============================================================================
5. OPTIONS ~
*cscove-options*
*'g:cscope_open_location'*
Use this option to stop opening location list after searching
let g:cscope_open_location = 0
*'g:cscope_auto_update'*
Use this option to disable cscope database auto update.
let g:cscope_auto_update = 0
Then you can update your cscope databases manually by:
call CscopeUpdateDB()
*'g:cscope_silent'*
Use this option to toggle messages for database updated.
let g:cscope_silent = 1
*'g:cscope_cmd'*
Use the option to specify the path to cscope excutalbe, if it is not in PATH.
let g:cscope_cmd = '/home/brook/bin/cscope'
*'g:cscope_split_threshold'*
Specify a number. If total files found for a directory exceeds it, then a
separated cscope database will be created for modified/added files to avoid
long time for updating cscope database.
let g:cscope_split_threshold = 9999
*'g:cscope_interested_files'*
Specify the extentions you want to include when building cscope database, the
default extentions are listed in interested.txt.
let g:cscope_interested_files = '\.c$\|\.cpp$\|\.h$\|\.hpp'
*'g:cscope_ignored_dir'*
Specify the sub directories you want to exclude when building cscope database, for
example:
let g:cscope_ignored_dir = 'node_modules$\|dist$'
*'g:cscope_preload_path'*
Preload path settings help you to load some common libraries by default. For example,
let g:cscope_preload_path="/usr/include/c++/;/works/phplib/trunk/php"
" vim: set expandtab sts=2 ts=2 sw=2 tw=78 ft=help norl:

View file

@ -0,0 +1,375 @@
" vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab foldmethod=marker
" Copyright: Copyright (C) 2012-2015 Brook Hong
" License: The MIT License
"
if !exists('g:cscope_silent')
let g:cscope_silent = 0
endif
if !exists('g:cscope_auto_update')
let g:cscope_auto_update = 1
endif
if !exists('g:cscope_open_location')
let g:cscope_open_location = 1
endif
if !exists('g:cscope_split_threshold')
let g:cscope_split_threshold = 10000
endif
function! s:echo(msg)
if g:cscope_silent == 0
echo a:msg
endif
endfunction
function! ToggleLocationList()
let l:own = winnr()
lw
let l:cwn = winnr()
if(l:cwn == l:own)
if &buftype == 'quickfix'
lclose
elseif len(getloclist(winnr())) > 0
lclose
else
echohl WarningMsg | echo "No location list." | echohl None
endif
endif
endfunction
if !exists('g:cscope_cmd')
if executable('cscope')
let g:cscope_cmd = 'cscope'
else
call <SID>echo('cscope: command not found')
finish
endif
endif
if !exists('g:cscope_interested_files')
let files = readfile(expand("<sfile>:p:h")."/interested.txt")
let g:cscope_interested_files = join(map(files, 'v:val."$"'), '\|')
endif
let s:cscope_vim_dir = substitute($HOME,'\\','/','g')."/.cscope.vim"
let s:index_file = s:cscope_vim_dir.'/index'
function! s:GetBestPath(dir)
let f = substitute(a:dir,'\\','/','g')
let bestDir = ""
for d in keys(s:dbs)
if stridx(f, d) == 0 && len(d) > len(bestDir)
let bestDir = d
endif
endfor
return bestDir
endfunction
function! s:ListFiles(dir)
let d = []
let f = []
let cwd = a:dir
let sl = &l:stl
try
while cwd != ''
let a = split(globpath(cwd, "*"), "\n")
for fn in a
if getftype(fn) == 'dir'
if !exists('g:cscope_ignored_dir') || fn !~? g:cscope_ignored_dir
call add(d, fn)
endif
elseif getftype(fn) != 'file'
continue
elseif fn !~? g:cscope_interested_files
continue
else
if stridx(fn, ' ') != -1
let fn = '"'.fn.'"'
endif
call add(f, fn)
endif
endfor
let cwd = len(d) ? remove(d, 0) : ''
sleep 1m | let &l:stl = 'Found '.len(f).' files, finding in '.cwd | redrawstatus
endwhile
catch /^Vim:Interrupt$/
catch
echo "caught" v:exception
endtry
sleep 1m | let &l:stl = sl | redrawstatus
return f
endfunction
function! s:RmDBfiles()
let odbs = split(globpath(s:cscope_vim_dir, "*"), "\n")
for f in odbs
call delete(f)
endfor
endfunction
function! s:FlushIndex()
let lines = []
for d in keys(s:dbs)
call add(lines, d.'|'.s:dbs[d]['id'].'|'.s:dbs[d]['loadtimes'].'|'.s:dbs[d]['dirty'])
endfor
call writefile(lines, s:index_file)
endfunction
function! s:CheckNewFile(dir, newfile)
let id = s:dbs[a:dir]['id']
let cscope_files = s:cscope_vim_dir."/".id.".files"
let files = readfile(cscope_files)
if len(files) > g:cscope_split_threshold
let cscope_files = s:cscope_vim_dir."/".id."_inc.files"
if filereadable(cscope_files)
let files = readfile(cscope_files)
else
let files = []
endif
endif
if count(files, a:newfile) == 0
call add(files, a:newfile)
call writefile(files, cscope_files)
endif
endfunction
function! s:_CreateDB(dir, init)
let id = s:dbs[a:dir]['id']
let cscope_files = s:cscope_vim_dir."/".id."_inc.files"
let cscope_db = s:cscope_vim_dir.'/'.id.'_inc.db'
if ! filereadable(cscope_files) || a:init
let cscope_files = s:cscope_vim_dir."/".id.".files"
let cscope_db = s:cscope_vim_dir.'/'.id.'.db'
if ! filereadable(cscope_files)
let files = <SID>ListFiles(a:dir)
call writefile(files, cscope_files)
endif
endif
exec 'cs kill '.cscope_db
redir @x
exec 'silent !'.g:cscope_cmd.' -b -i '.cscope_files.' -f'.cscope_db
redi END
if @x =~ "\nCommand terminated\n"
echohl WarningMsg | echo "Failed to create cscope database for ".a:dir.", please check if " | echohl None
else
let s:dbs[a:dir]['dirty'] = 0
exec 'cs add '.cscope_db
endif
endfunction
function! s:CheckAbsolutePath(dir, defaultPath)
let d = a:dir
while 1
if !isdirectory(d)
echohl WarningMsg | echo "Please input a valid path." | echohl None
let d = input("", a:defaultPath, 'dir')
elseif (len(d) < 2 || (d[0] != '/' && d[1] != ':'))
echohl WarningMsg | echo "Please input an absolute path." | echohl None
let d = input("", a:defaultPath, 'dir')
else
break
endif
endwhile
let d = substitute(d,'\\','/','g')
let d = substitute(d,'/\+$','','')
return d
endfunction
function! s:InitDB(dir)
let id = localtime()
let s:dbs[a:dir] = {}
let s:dbs[a:dir]['id'] = id
let s:dbs[a:dir]['loadtimes'] = 0
let s:dbs[a:dir]['dirty'] = 0
call <SID>_CreateDB(a:dir, 1)
call <SID>FlushIndex()
endfunction
function! s:LoadDB(dir)
cs kill -1
exe 'cs add '.s:cscope_vim_dir.'/'.s:dbs[a:dir]['id'].'.db'
if filereadable(s:cscope_vim_dir.'/'.s:dbs[a:dir]['id'].'_inc.db')
exe 'cs add '.s:cscope_vim_dir.'/'.s:dbs[a:dir]['id'].'_inc.db'
endif
let s:dbs[a:dir]['loadtimes'] = s:dbs[a:dir]['loadtimes']+1
call <SID>FlushIndex()
endfunction
" 0 -- loaded
" 1 -- cancelled
function! s:AutoloadDB(dir)
let ret = 0
let m_dir = <SID>GetBestPath(a:dir)
if m_dir == ""
echohl WarningMsg | echo "Can not find proper cscope db, please input a path to generate cscope db for." | echohl None
let m_dir = input("", a:dir, 'dir')
if m_dir != ''
let m_dir = <SID>CheckAbsolutePath(m_dir, a:dir)
call <SID>InitDB(m_dir)
call <SID>LoadDB(m_dir)
else
let ret = 1
endif
else
let id = s:dbs[m_dir]['id']
if cscope_connection(2, s:cscope_vim_dir.'/'.id.'.db') == 0
call <SID>LoadDB(m_dir)
endif
endif
return ret
endfunction
function! s:updateDBs(dirs)
for d in a:dirs
call <SID>_CreateDB(d, 0)
endfor
call <SID>FlushIndex()
endfunction
function! s:clearDBs(dir)
cs kill -1
if a:dir == ""
let s:dbs = {}
call <SID>RmDBfiles()
else
let id = s:dbs[a:dir]['id']
call delete(s:cscope_vim_dir."/".id.".files")
call delete(s:cscope_vim_dir.'/'.id.'.db')
call delete(s:cscope_vim_dir."/".id."_inc.files")
call delete(s:cscope_vim_dir.'/'.id.'_inc.db')
unlet s:dbs[a:dir]
endif
call <SID>FlushIndex()
endfunction
function! s:listDBs()
let dirs = keys(s:dbs)
if len(dirs) == 0
echo "You have no cscope dbs now."
else
let s = [' ID LOADTIMES PATH']
for d in dirs
let id = s:dbs[d]['id']
if cscope_connection(2, s:cscope_vim_dir.'/'.id.'.db') == 1
let l = printf("*%d %10d %s", id, s:dbs[d]['loadtimes'], d)
else
let l = printf(" %d %10d %s", id, s:dbs[d]['loadtimes'], d)
endif
call add(s, l)
endfor
echo join(s, "\n")
endif
endfunction
function! s:loadIndex()
let s:dbs = {}
if ! isdirectory(s:cscope_vim_dir)
call mkdir(s:cscope_vim_dir)
elseif filereadable(s:index_file)
let idx = readfile(s:index_file)
for i in idx
let e = split(i, '|')
if len(e) == 0
call delete(s:index_file)
call <SID>RmDBfiles()
else
let db_file = s:cscope_vim_dir.'/'.e[1].'.db'
if filereadable(db_file)
if isdirectory(e[0])
let s:dbs[e[0]] = {}
let s:dbs[e[0]]['id'] = e[1]
let s:dbs[e[0]]['loadtimes'] = e[2]
let s:dbs[e[0]]['dirty'] = (len(e) > 3) ? e[3] :0
else
call delete(db_file)
endif
endif
endif
endfor
else
call <SID>RmDBfiles()
endif
endfunction
function! s:preloadDB()
let dirs = split(g:cscope_preload_path, ';')
for m_dir in dirs
let m_dir = <SID>CheckAbsolutePath(m_dir, m_dir)
if ! has_key(s:dbs, m_dir)
call <SID>InitDB(m_dir)
endif
call <SID>LoadDB(m_dir)
endfor
endfunction
function! CscopeFind(action, word)
let dirtyDirs = []
for d in keys(s:dbs)
if s:dbs[d]['dirty'] == 1
call add(dirtyDirs, d)
endif
endfor
if len(dirtyDirs) > 0
call <SID>updateDBs(dirtyDirs)
endif
let dbl = <SID>AutoloadDB(expand('%:p:h'))
if dbl == 0
try
exe ':lcs f '.a:action.' '.a:word
if g:cscope_open_location == 1
lw
endif
catch
echohl WarningMsg | echo 'Can not find '.a:word.' with querytype as '.a:action.'.' | echohl None
endtry
endif
endfunction
function! CscopeFindInteractive(pat)
call inputsave()
let qt = input("\nChoose a querytype for '".a:pat."'(:help cscope-find)\n c: functions calling this function\n d: functions called by this function\n e: this egrep pattern\n f: this file\n g: this definition\n i: files #including this file\n s: this C symbol\n t: this text string\n\n or\n <querytype><pattern> to query `pattern` instead of '".a:pat."' as `querytype`, Ex. `smain` to query a C symbol named 'main'.\n> ")
call inputrestore()
if len(qt) > 1
call CscopeFind(qt[0], qt[1:])
elseif len(qt) > 0
call CscopeFind(qt, a:pat)
endif
call feedkeys("\<CR>")
endfunction
function! s:onChange()
if expand('%:t') =~? g:cscope_interested_files
let m_dir = <SID>GetBestPath(expand('%:p:h'))
if m_dir != ""
let s:dbs[m_dir]['dirty'] = 1
call <SID>FlushIndex()
call <SID>CheckNewFile(m_dir, expand('%:p'))
redraw
call <SID>echo('Your cscope db will be updated automatically, you can turn off this message by setting g:cscope_silent 1.')
endif
endif
endfunction
function! CscopeUpdateDB()
call <SID>updateDBs(keys(s:dbs))
endfunction
if exists('g:cscope_preload_path')
call <SID>preloadDB()
endif
if g:cscope_auto_update == 1
au BufWritePost * call <SID>onChange()
endif
set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-
function! s:listDirs(A,L,P)
return keys(s:dbs)
endfunction
com! -nargs=? -complete=customlist,<SID>listDirs CscopeClear call <SID>clearDBs("<args>")
com! -nargs=0 CscopeList call <SID>listDBs()
call <SID>loadIndex()

View file

@ -0,0 +1,62 @@
\.as
\.asm
\.au3
\.bat
\.c
\.c++
\.cc
\.cfg
\.clj
\.cmd
\.coffee
\.conf
\.config
\.cpp
\.cs
\.csv
\.cxx
\.dtd
\.go
\.h
\.h++
\.hh
\.hpp
\.hs
\.html
\.hxx
\.ini
\.java
\.js
\.json
\.jsp
\.l
\.m
\.mc
\.md
\.mhtml
\.mi
\.mysql
\.php
\.pl
\.pm
\.py
\.r
\.rb
\.rc
\.ru
\.sbt
\.scala
\.sh
\.sql
\.swift
\.tex
\.txt
\.vbs
\.vim
\.xml
\.xsd
\.y
\.yml
autohandler
config
dhandler