Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cscope_maps: add gtags support for cscope_maps #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

epheien
Copy link

@epheien epheien commented May 20, 2024

cscope has not been updated for a long time, so supporting gtags is a must-do

@bqv
Copy link

bqv commented Nov 25, 2024

@ludovicchabant merge?

@smemsh
Copy link

smemsh commented Nov 25, 2024

Isn't there already g:gtags_cscope? With gutentags_plus it seems to work ok, you do need to make your own maps though. I'm using this:

" 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 = 1

and 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 END

works for me without any patch. I am not sure if I'd need the maps if I didn't set g:gutentags_plus_nomap. Also I'm not certain if this is solving the same problem as this PR? but I'm using gtags-cscope and it seems to work ok.

@bqv
Copy link

bqv commented Nov 25, 2024

cscope_maps is for the purpose of neovim, where things don't quite work well

@epheien
Copy link
Author

epheien commented Nov 27, 2024

The cscope integration has been removed from nvim.
And cscope_map.nvim is an implementation of a relatively mature solution in plug-in form.

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.

@bqv
Copy link

bqv commented Nov 27, 2024

Can gtags be made to place its files in gutentags_cache_dir, not the project root?

@smemsh
Copy link

smemsh commented Dec 2, 2024

Can gtags be made to place its files in gutentags_cache_dir, not the project root?

it looks like the patch uses gutentags#get_cachefile() which does seem to use the cache dir if defined

@bqv
Copy link

bqv commented Dec 2, 2024

My bad, dodgy config. I had

g:gutentags_cscope_executable_maps = 'gtags-cscope'

rather than

'gtags'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants