Saturday, October 5, 2013

Re: cscope best practices

On 2013-10-05, Ethan Hereth wrote:

> So, my question for everyone is: can you share with me the maps,
> habits, functions, etc. that you've developed over time to
> streamline your used of cscope within vim. I would love to see
> these. Really, I would love to get any advice you'd be willing to
> offer up about it.

The most useful feature of the mappings I use is the automatic
adding of the cscope database: it's added only when I request
information from it. Here's an example mapping and the command and
function it invokes. Typing ,s over a symbol finds all occurrences
of that symbol and puts them in the quickfix list because I have set
'cscopequickfix' to include "s-".

map <silent> ,s :Csfind s <C-R><C-W><CR>zv

command! -nargs=+ Csfind call Csfind("cscope", <f-args>)

function! Csfind(cmd, querytype, name)
try
execute a:cmd "find" a:querytype a:name
return
catch /E567/ " 'no cscope connections'
" Continue after endtry.
catch /.*/ " Any other error.
call s:EchoException()
return
endtry
try
if exists("g:cscope_prepend_path")
execute "cs add" g:cscope_database g:cscope_prepend_path
else
execute "cs add" g:cscope_database
endif
catch /.*/
" Note: The perror() message
" cs_read_prompt EOF: Error 0
" currently (2004-02-20) hides the more-informative message
" E609: Cscope error: cscope: cannot read file version from file cscope.out
"
call s:EchoException()
return
endtry
try
execute a:cmd "find" a:querytype a:name
catch /.*/ " Any error.
call s:EchoException()
endtry
endfunction

function! s:EchoException()
if &errorbells
normal \<Esc> " Generate a bell
endif
echohl ErrorMsg
echo matchstr(v:exception, ':\zs.*')
echohl None
endfunction

Regards,
Gary

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: