dotfiles

Configuration for the software I use.
git clone https://git.jaderune.net/jbauer/dotfiles
Log | Files | Refs | README | LICENSE

cscope.vim (3210B)


      1 " Cscope module for Gutentags
      2 
      3 if !has('cscope')
      4     throw "Can't enable the cscope module for Gutentags, this Vim has ".
      5                 \"no support for cscope files."
      6 endif
      7 
      8 " Global Options {{{
      9 
     10 if !exists('g:gutentags_cscope_executable')
     11     let g:gutentags_cscope_executable = 'cscope'
     12 endif
     13 
     14 if !exists('g:gutentags_scopefile')
     15     let g:gutentags_scopefile = 'cscope.out'
     16 endif
     17 
     18 if !exists('g:gutentags_auto_add_cscope')
     19     let g:gutentags_auto_add_cscope = 1
     20 endif
     21 
     22 if !exists('g:gutentags_cscope_build_inverted_index')
     23     let g:gutentags_cscope_build_inverted_index = 0
     24 endif
     25 
     26 " }}}
     27 
     28 " Gutentags Module Interface {{{
     29 
     30 let s:runner_exe = gutentags#get_plat_file('update_scopedb')
     31 let s:unix_redir = (&shellredir =~# '%s') ? &shellredir : &shellredir . ' %s'
     32 let s:added_dbs = []
     33 
     34 function! gutentags#cscope#init(project_root) abort
     35     let l:dbfile_path = gutentags#get_cachefile(
     36                 \a:project_root, g:gutentags_scopefile)
     37     let b:gutentags_files['cscope'] = l:dbfile_path
     38 
     39     if g:gutentags_auto_add_cscope && filereadable(l:dbfile_path)
     40         if index(s:added_dbs, l:dbfile_path) < 0
     41             call add(s:added_dbs, l:dbfile_path)
     42             silent! execute 'cs add ' . fnameescape(l:dbfile_path)
     43         endif
     44     endif
     45 endfunction
     46 
     47 function! gutentags#cscope#generate(proj_dir, tags_file, gen_opts) abort
     48     let l:cmd = [s:runner_exe]
     49     let l:cmd += ['-e', g:gutentags_cscope_executable]
     50     let l:cmd += ['-p', a:proj_dir]
     51     let l:cmd += ['-f', a:tags_file]
     52     let l:file_list_cmd =
     53         \ gutentags#get_project_file_list_cmd(a:proj_dir)
     54     if !empty(l:file_list_cmd)
     55         let l:cmd += ['-L', '"' . l:file_list_cmd . '"']
     56     endif
     57     if g:gutentags_cscope_build_inverted_index
     58         let l:cmd += ['-I']
     59     endif
     60     let l:cmd = gutentags#make_args(l:cmd)
     61 
     62     call gutentags#trace("Running: " . string(l:cmd))
     63     call gutentags#trace("In:      " . getcwd())
     64     if !g:gutentags_fake
     65 		let l:job_opts = gutentags#build_default_job_options('cscope')
     66         let l:job = gutentags#start_job(l:cmd, l:job_opts)
     67         call gutentags#add_job('cscope', a:tags_file, l:job)
     68     else
     69         call gutentags#trace("(fake... not actually running)")
     70     endif
     71 endfunction
     72 
     73 function! gutentags#cscope#on_job_exit(job, exit_val) abort
     74     let l:job_idx = gutentags#find_job_index_by_data('cscope', a:job)
     75     let l:dbfile_path = gutentags#get_job_tags_file('cscope', l:job_idx)
     76     call gutentags#remove_job('cscope', l:job_idx)
     77 
     78     if a:exit_val == 0
     79         if index(s:added_dbs, l:dbfile_path) < 0
     80             call add(s:added_dbs, l:dbfile_path)
     81             silent! execute 'cs add ' . fnameescape(l:dbfile_path)
     82         else
     83             silent! execute 'cs reset'
     84         endif
     85     elseif !g:__gutentags_vim_is_leaving
     86         call gutentags#warning(
     87                     \"cscope job failed, returned: ".
     88                     \string(a:exit_val))
     89     endif
     90     if has('win32') && g:__gutentags_vim_is_leaving
     91         " The process got interrupted because Vim is quitting.
     92         " Remove the db file on Windows because there's no `trap`
     93         " statement in the update script.
     94         try | call delete(l:dbfile_path) | endtry
     95     endif
     96 endfunction
     97 
     98 " }}}
     99