On 2007-03-29, "A.J.Mechelynck" <[EMAIL PROTECTED]> wrote:
> Sergey Khorev wrote:
> > You need to run a script, e.g.
> >     if filereadable("cscope.out")
> >         cs add cscope.out
> >     endif
> >
> >     if filereadable("../cscope.out")
> >         cs add ../cscope.out
> >     endif
> >
> > etc :)
> 
> function GetCscopeFileName()
>     let curdir = fnamemodify(getcwd(), ':p')
>     while 1
>         let f = curdir . (curdir =~ '[\\/]$' ? '' : '/') . 'cscope.out'
>         if filereadable(f)
>             " found
>             return f
>         endif
>         " try one level up
>         let d = fnamemodify(curdir, ':h')
>         if d == curdir
>             " trying to go past top level: not found
>             return ''
>         endif
>         let curdir = d
>     endwhile
> endfunction
> 
> let csfn = GetCscopeFileName()
> if csfn != ''
>       exe 'cs add' csfn
> endif

How about using findfile()?

    command -nargs=1 CsAdd call CsAdd("<args>")

    function CsAdd(file)
        let path = findfile(a:file, ".;")
        if path != ''
            exe 'cs add' path
        else
            echo a:file "not found"
        endif
    endfunction

Usage:
    :CsAdd cscope.out

Regards,
Gary

-- 
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Mobile Broadband Division
                             | Spokane, Washington, USA

Reply via email to