Skip to content

Commit

Permalink
Support multiple cscope database names
Browse files Browse the repository at this point in the history
  • Loading branch information
ktchen14 committed Apr 7, 2018
1 parent 2943e28 commit 64eb60c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ cscope database for the current buffer. If your cscope databases aren't named
let g:cscope_auto_database_name = '.cscope'
```

Or if you have cscope databases with different names then do:

```vim
let g:cscope_auto_database_name = ['.cscope', 'cscope.out']
```

In addition cscope-auto automatically reestablishes the existing cscope
connection when you change `&ignorecase` or when the cscope database has been
updated.
Expand Down
18 changes: 11 additions & 7 deletions autoload/cscope_auto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ let s:dirsep = fnamemodify(getcwd(), ':p')[-1:]
" Return the nearest cscope database to the path by walking up the directory
" tree and looking for a file named according to cscope_auto_database_name. If
" there is no matching cscope database then return an empty string.
"
" Consider just using findfile() if we can find a way to easily work around
" &suffixesadd.
function! cscope_auto#locate_database(path)
let path = fnamemodify(a:path, ':p:h')

let database_name = get(g:, 'cscope_auto_database_name', 'cscope.out')
if type(database_name) != type([])
let database_name = [database_name]
endif

while !exists('last') || path !=# last
let file = substitute(path, s:dirsep . '\?$', s:dirsep . database_name, '')
if filereadable(file)
return file
endif
for name in database_name
let file = substitute(path, s:dirsep . '\?$', s:dirsep . name, '')
if filereadable(file)
return file
endif
endfor
let last = path
let path = fnamemodify(path, ':h')
endwhile

return ''
endfunction

Expand Down

0 comments on commit 64eb60c

Please sign in to comment.