Friday, February 11, 2011

Re: Autoloading Cscope

Hi Jan, thanks for pointing this out.

So now (assuming there's no ctags-like one-liner trick for cscope) it comes down to the following:

------------------
function! LoadCscope()
    let db = findfile("cscope.out", ".;")
    if (!empty(db))
        let path = strpart(db, 0, match(db, "/cscope.out$"))
        set nocsverb " suppress 'duplicate connection' error
        exe "cs add " . db . " " . path
        set csverb   " switch back to verbose mode
    endif
endfunction
au BufEnter /* call LoadCscope()
------------------

I created a tip with the same code: http://vim.wikia.com/wiki/Autoloading_Cscope_Database, hope it'll be helpful for someone.

On Fri, Feb 11, 2011 at 2:00 AM, Jan Larres <lists@majutsushi.net> wrote:
Hi Sergey,

Sergey Doroshenko <dorserg@gmail.com>:
> 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:
>
> 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.

you can do the same thing with the findfile() function, see

 :h findfile()

Cheers,
       Jan

--
-[ OpenPGP key ID: 00A0FD5F ]-
Never offend people with style when you can offend them with substance.
               -- Sam Brown, "The Washington Post", January 26, 1977

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



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

No comments: