By default, cscope script (the one at
http://cscope.sourceforge.net/cscope_maps.vim) adds cscope.out from vim's
current directory and from $CSCOPE_DB.
But if I'm starting Vim from say ~/proj/src/a/b/c/, while cscope.out is at
~/proj/src/, that cscope.out won't be loaded automatically.

For ctags, there's a nice trick: you do "set tags=tags;/" and Vim will look
for tags file everywhere starting from the current dir up to the root.
I haven't found the same thing for cscope, so I came up with my own
function:

----------------
function! LoadCscope()
    " get current buffer's path
    let path = getcwd()
    if (winbufnr(0) != -1)
        let path = fnamemodify(bufname(winbufnr(0)), ":p:h")
    endif
    " walk up the directory structure
    while (strlen(path) > 0)
        let db = path . "/cscope.out"
        if (filereadable(db))
            " echo "w00t " . db
            set nocsverb " suppress 'duplicate connection' error
            exe "cs add " . db . " " . path
            set csverb   " switch bach to verbose mode
            break
        endif
        let slash = match(path, "/[^/]*$")
        if (slash == -1)
            break
        endif
        let path = strpart(path, 0, slash)
    endwhile
endfunction

au BufEnter /* call LoadCscope()
----------------

What this basically does is it gets currently active buffer's path and walks
up to the root trying to find cscope.out.

So my question is, haven't I reinvented the wheel -- maybe I missed some
obvious cscope setting that would do the same? Google et al. doesn't seem to
have a good answer on this.
If there's no such thing, I could add my function to Vim Tips Wiki.


P.S. Is it conceptually correct to use "au BufEnter /* <do something>" in
order to <do something> upon entering any buffer, i.e. for any filetype?


-- 
Best regards,
Sergey Doroshenko: http://dorserg.com

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to