Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions autoload/cscope_auto.vim
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
" Maintainer: Kaiting Chen <ktchen14@gmail.com>

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')

while !exists('last') || path !=# last
let file = substitute(path, s:dirsep . '\?$', s:dirsep . database_name, '')
if filereadable(file)
return file
endif
let last = path
let path = fnamemodify(path, ':h')
endwhile
let suffixesadd = &suffixesadd
let &suffixesadd = ''
let file = fnamemodify(findfile(get(b:, 'cscope_auto_database_name', get(g:, 'cscope_auto_database_name', 'cscope.out')), './;'), ':p')
let &suffixesadd = suffixesadd
if filereadable(file)
return file
endif
return ''
endfunction

Expand Down
43 changes: 43 additions & 0 deletions doc/cscope_auto.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
*cscope_auto.txt* Automatically connect to cscope

Author: Kaiting Chen *cscope-auto-author*
License: See |cscope-auto-license|

This plugin is only available if Vim is compiled with |+cscope| support.
==============================================================================
*cscope-auto*

cscope-auto ensures that a single |cscope| connection is available to the best
cscope database for the current buffer.

*g:cscope_auto_database_name*
>
let g:cscope_auto_database_name = 'cscope.out'
<
Change the cscope database name via |g:cscope_auto_database_name| variable.
Defaults to 'cscope.out'. Use b:cscope_auto_database_name for buffer local
database name.


==============================================================================
LICENSE *cscope-license*

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

vim:tw=78:ts=8:ft=help:norl:
2 changes: 1 addition & 1 deletion plugin/cscope_auto.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" Maintainer: Kaiting Chen <ktchen14@gmail.com>

if exists('g:loaded_cscope_auto')
if exists('g:loaded_cscope_auto') || !has('cscope')
finish
endif
let g:loaded_cscope_auto = 1
Expand Down