cscope_maps: add gtags support for cscope_maps#360
cscope_maps: add gtags support for cscope_maps#360epheien wants to merge 2 commits intoludovicchabant:masterfrom
Conversation
|
@ludovicchabant merge? |
|
Isn't there already " we want gscope, ie gutentags_plus, to manage cscope for us
let g:gutentags_auto_add_gtags_cscope = 0
let g:gutentags_auto_add_cscope = 0
let g:gutentags_auto_add_pycscope = 0
" ...
let g:gutentags_modules = []
if executable('ctags') | let g:gutentags_modules += ['ctags'] | endif
if executable('gtags') | let g:gutentags_modules += ['gtags_cscope']
elseif executable('cscope') | let g:gutentags_modules += ['cscope'] | endif
if empty(g:gutentags_modules) | let g:gutentags_dont_load = 1 | endif
" ...
" manage our own maps
let g:gutentags_plus_nomap = 1and then for my maps: "
" like the cscope interface, but uses gutentags-generated db
"
if !exists("g:gscope_done") | let g:gscope_done = 1 | else | finish | endif
if !has("cscope") || !has("channel") | finish | endif
nnoremap csa <plug>GscopeFindAssign
nnoremap csc <plug>GscopeFindCallingFunc
nnoremap csd <plug>GscopeFindCalledFunc
nnoremap cse <plug>GscopeFindEgrep
nnoremap csf <plug>GscopeFindFile
nnoremap csg <plug>GscopeFindDefinition
nnoremap csi <plug>GscopeFindInclude
nnoremap css <plug>GscopeFindSymbol
nnoremap cst <plug>GscopeFindText
nnoremap csz <plug>GscopeFindCtag
" cs[acdefgistz]/:
"
function! s:GsgAbbrev(cschar) abort
return (((getcmdtype() == ":" && (getcmdline() =~ ('^cs' . a:cschar)))
\ ? 'GscopeFind ' : 'cs') . a:cschar)
endfunction
let s:chars = "acdefgistz"
"if !has('patch-8.2.2658') | finish | endif " :for x in String
"for s:abb in s:chars
for s:abb in split(s:chars, '\zs')
exec 'cnoreabbrev <expr> cs' . s:abb . ' <SID>GsgAbbrev("' . s:abb . '")'
endfor
" cs[rhuk]/:
"
function! s:GsAbbrev(cschar, cmd) abort
return ((getcmdtype() == ":" && (getcmdline() =~ ('^cs' . a:cschar)))
\ ? a:cmd : ('cs' . a:cschar))
endfunction
for [cschar, cmd] in [
\ ['r', 'call gutentags#rescan()'],
\ ['h', 'call Gscope_menu()'],
\ ['u', 'GutentagsUpdate'],
\ ['k', 'GscopeKill'],
\ ]
let s:abb = 'cs' . cschar
let s:abbfunc = 'GsAbbrev("' . cschar . '", "' . cmd . '")'
let s:gsfunc = expand('<SID>') . s:abbfunc
exec 'nnoremap ' . s:abb . ' :' . cmd . '<return>'
exec 'cnoreabbrev <expr> ' . s:abb . ' ' . s:gsfunc
endfor
" menu for csh
"
function! Gscope_menu ()
echo
\"gscope find:\n"
\" (a)ssigns find places this is assigned to\n"
\" (c)allers find functions calling this function\n"
\" (d)epends find functions this one depends on\n"
\" (e)grep find this egrep pattern\n"
\" (f)ile find this file\n"
\" (g)lobal find this definition\n"
\" (i)nclude find files #including this file\n"
\" (s)ymbol find this C symbol\n"
\" (t)o find assignments to\n"
\" (z)tags find matching ctags\n"
\"? "
let gotchar = getchar()
execute "normal cs" . nr2char(gotchar)
endf
" gutentags_plus takes care of 'cscope add' and db management. restart every
" time we change working directory. this lets us start with an empty buffer
"
if !has('patch-8.0.1459') | finish | endif
augroup DirChangedGroup
au!
autocmd DirChanged global
\ if exists('*gutentags#rescan') | call gutentags#rescan() | endif
augroup ENDworks for me without any patch. I am not sure if I'd need the maps if I didn't set |
|
cscope_maps is for the purpose of neovim, where things don't quite work well |
|
The cscope integration has been removed from nvim. I see that the patch related to cscope_map has been merged into the main branch, but it only supports cscope and not gtags, which doesn't seem very reasonable, so I made this PR to support gtags. |
|
Can gtags be made to place its files in gutentags_cache_dir, not the project root? |
it looks like the patch uses |
|
My bad, dodgy config. I had g:gutentags_cscope_executable_maps = 'gtags-cscope'rather than 'gtags' |
radiantshaw
left a comment
There was a problem hiding this comment.
Nice work on this. Just added one comment for my understanding of how this works.
| endif | ||
| endfunction | ||
|
|
||
| function! gutentags#cscope_maps#generate_gtags(proj_dir, tags_file, gen_opts) abort |
There was a problem hiding this comment.
Does this also build the inverted index? Apologies if it already does. I'm new to writing/reading Vim plugins.
There was a problem hiding this comment.
After adding this comment, I realised that I can just check this behaviour by running it locally. I'll do that and then resolve this comment.
cscope has not been updated for a long time, so supporting gtags is a must-do