From 692afd7a97d5c6bbca22581e094b10db6481f30d Mon Sep 17 00:00:00 2001 From: Peter Rincker Date: Mon, 23 Oct 2017 09:43:27 -0700 Subject: [PATCH 1/4] Use findfile() --- autoload/cscope_auto.vim | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/autoload/cscope_auto.vim b/autoload/cscope_auto.vim index 97c1f45..834323b 100644 --- a/autoload/cscope_auto.vim +++ b/autoload/cscope_auto.vim @@ -1,7 +1,5 @@ " Maintainer: Kaiting Chen -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. @@ -9,17 +7,13 @@ let s:dirsep = fnamemodify(getcwd(), ':p')[-1:] " 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 From 37b7f1d8b47f989ed86068739dbee2687ee28a97 Mon Sep 17 00:00:00 2001 From: Peter Rincker Date: Mon, 23 Oct 2017 10:12:58 -0700 Subject: [PATCH 2/4] Add initial documentation --- doc/cscope_auto.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 doc/cscope_auto.txt diff --git a/doc/cscope_auto.txt b/doc/cscope_auto.txt new file mode 100644 index 0000000..ee49a62 --- /dev/null +++ b/doc/cscope_auto.txt @@ -0,0 +1,42 @@ +*cscope_auto.txt* Automatically connect to cscope + +Author: Kaiting Chen *cscope-auto-author* +License: See |cscope-auto-license| + +============================================================================== + *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: From a8e75563b930cec2db117de2c1d8122799f93d0a Mon Sep 17 00:00:00 2001 From: Peter Rincker Date: Mon, 23 Oct 2017 10:16:40 -0700 Subject: [PATCH 3/4] Require +cscope support --- doc/cscope_auto.txt | 1 + plugin/cscope_auto.vim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/cscope_auto.txt b/doc/cscope_auto.txt index ee49a62..0511db1 100644 --- a/doc/cscope_auto.txt +++ b/doc/cscope_auto.txt @@ -3,6 +3,7 @@ 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* diff --git a/plugin/cscope_auto.vim b/plugin/cscope_auto.vim index e891967..9170af1 100644 --- a/plugin/cscope_auto.vim +++ b/plugin/cscope_auto.vim @@ -1,6 +1,6 @@ " Maintainer: Kaiting Chen -if exists('g:loaded_cscope_auto') +if exists('g:loaded_cscope_auto') || !has('cscope') finish endif let g:loaded_cscope_auto = 1 From 42ec889dfed5ccf8c71a55b005c072b31b2776a6 Mon Sep 17 00:00:00 2001 From: Peter Rincker Date: Mon, 23 Oct 2017 10:17:37 -0700 Subject: [PATCH 4/4] Add cscope help tag --- doc/cscope_auto.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/cscope_auto.txt b/doc/cscope_auto.txt index 0511db1..a357e9c 100644 --- a/doc/cscope_auto.txt +++ b/doc/cscope_auto.txt @@ -7,7 +7,7 @@ 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-auto ensures that a single |cscope| connection is available to the best cscope database for the current buffer. *g:cscope_auto_database_name*