(1) cscope & gvim; (2) ctags & C++/STL

From: Fred Ma (fma_at_doe.carleton.ca)
Date: 01/29/04


Date: 29 Jan 2004 22:34:02 GMT


===========================================================================
   Question (1): cscope choosese wrong match from list
===========================================================================

I'm using gvim 6.2 on solaris 8. I've posted question
(1) to the vim group comp.editors, as well as the vim
mailing list vim@vim.org. I haven't gotten much
response yet. I'm using cscope 15.5 with the cscope
plugin file attached at the very end of this posting.
I'm pretty new to cscope, but am very pleased with what
it can do. Especially for C++/STL, where you have
things defined all over the place.

My problem is that when I do a cscope query for symbols
and get multiple matching results, I get warped to the
wrong occurance of that symbol. That is, if I choose
the 7th occurance, I end up at the 5th occurance. The
offset is usually (but not always) 2 positions up in
the match list; sometimes, it's 2 positions down,
depending on the symbol queried. The matching list
isn't particularly long (less than 10 items), though
the offset doesn't occur if the list contains only 2
matches. The offset only seems to happen with symbols,
not if I search for functions that call the function
under the cursor (the "c" option for a query).

I tried killing the connection to cscope.out and adding
it again, but the behaviour was the same. I also tried
killing the connection, rebuilding cscope.out using
"cscope -b *.?pp" and adding it again (same result).
This build command builds a cscope database from files
client.cpp, Routines.hpp, and Routines.cpp in the
current directory.

I never tried ":cs reset" because I can't find enough
documentation what it exactly does (not in the cscope
man page either). If anyone knows about this command,
I'd appreciate a pointer to a better explanation.

The offset occurs regardless of whether I use hot keys
or full command line commands.

I tried to see if the offset happens when I call cscope
outside of gvim, but it doesn't.

The behaviour is not changed by the cst and csto
options.

Has anyone experienced this problem or have any comment
on it?

===========================================================================
   Question (2): C++ object declarations being missed
===========================================================================

I recently installed Ctags 5.5.2 on solaris 8. After
posting about how to get it to tag local variables, I
was told to use "ctags --c-types=+l", which seemed to
work. The problem I'm seeing now is that only some
local variables are tagged. And it isn't just a
problem with local variables. Only some global
variables are tagged too. I've posted to the
ctags-users mailing list about this. It seems that
this problem with potentially untagged variables only
afflicts types which I've defined as classes. I am
using C++/STL. For example, the following local
variables are tagged:

        Any native type (int, double, bool, etc.)
        typedef vecstatvec<double> vsvd; //vecstatvec is a template
        vector<int> IdxGenes2swap;

The following local variables are not tagged:

        vsvd m3_ChromCost (nc_m3,LimlessStart);
        string KidRankLabl[]= { "Max", "Mean", "Min", "MeanMax", "MeanMin" };

Of the following two global declarations:

        myrand RndGenr( myrand::ZERO_SEED );
        RandInt RandIntGenr;

only the 2nd one is tagged. They are both nontemplate
structs, and the 2nd one is much simpler. However, the
2nd one is derived from a template:

        struct RandInt: public unary_function<int,int> {...};

while the first one is not:

        struct myrand { public: ... };

Since I'm using C++/STL, is this to be expected? If so,
why would the above "struct myrand" be ignroed? I know
there are more C++ specific code analysis tools like
source navigator, but I really need a tool that I can
use with gvim. Thanks for any feedback.

Fred

-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
===========================================================================
   cscope plugin file for vim (for question#1)
===========================================================================
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CSCOPE settings for vim           
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" This file contains some boilerplate settings for vim's cscope interface,
" plus some keyboard mappings that I've found useful.
"
" USAGE: 
" -- vim 6:     Stick this file in your ~/.vim/plugin directory (or in a
"               'plugin' directory in some other directory that is in your
"               'runtimepath'.
"
" -- vim 5:     Stick this file somewhere and 'source cscope.vim' it from
"               your ~/.vimrc file (or cut and paste it into your .vimrc).
"
" NOTE: 
" These key maps use multiple keystrokes (2 or 3 keys).  If you find that vim
" keeps timing you out before you can complete them, try changing your timeout
" settings, as explained below.
"
" Happy cscoping,
"
" Jason Duell       jduell@alumni.princeton.edu     2002/3/7
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This tests to see if vim was configured with the '--enable-cscope' option
" when it was compiled.  If it wasn't, time to recompile vim... 
if has("cscope")
    """"""""""""" Standard cscope/vim boilerplate
    " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
    set nocscopetag
    " check cscope for definition of a symbol before checking ctags: set to 1
    " if you want the reverse search order.
    set csto=0
    " add any cscope database in current directory
    if filereadable("cscope.out")
        cs add cscope.out  
    " else add the database pointed to by environment variable 
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    " show msg when any other cscope db added
    set cscopeverbose  
    """"""""""""" My cscope/vim key mappings
    "
    " The following maps all invoke one of the following cscope search types:
    "
    "   's'   symbol: find all references to the token under cursor
    "   'g'   global: find global definition(s) of the token under cursor
    "   'c'   calls:  find all calls to the function name under cursor
    "   't'   text:   find all instances of the text under cursor
    "   'e'   egrep:  egrep search for the word under cursor
    "   'f'   file:   open the filename under cursor
    "   'i'   includes: find files that include the filename under cursor
    "   'd'   called: find functions that function under cursor calls
    "
    " Below are three sets of the maps: one set that just jumps to your
    " search result, one that splits the existing vim window horizontally and
    " diplays your search result in the new window, and one that does the same
    " thing, but does a vertical split instead (vim 6 only).
    "
    " I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
    " unlikely that you need their default mappings (CTRL-\'s default use is
    " as part of CTRL-\ CTRL-N typemap, which basically just does the same
    " thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
    " If you don't like using 'CTRL-@' or CTRL-\, , you can change some or all
    " of these maps to use other keys.  One likely candidate is 'CTRL-_'
    " (which also maps to CTRL-/, which is easier to type).  By default it is
    " used to switch between Hebrew and English keyboard mode.
    "
    " All of the maps involving the <cfile> macro use '^<cfile>$': this is so
    " that searches over '#include <time.h>" return only references to
    " 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
    " files that contain 'time.h' as part of their name).
    " To do the first type of search, hit 'CTRL-\', followed by one of the
    " cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
    " search will be displayed in the current window.  You can use CTRL-T to
    " go back to where you were before the search.  
    "
    nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>	
    nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>	
    " Using 'CTRL-spacebar' (intepreted as CTRL-Space by vim) then a search type
    " makes the vim window split horizontally, with search result displayed in
    " the new window.
    "
    " (Note: earlier versions of vim may not have the :scs command, but it
    " can be simulated roughly via:
    "    nmap <C-Space>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-Space>s :scs find s <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-Space>g :scs find g <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-Space>c :scs find c <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-Space>t :scs find t <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-Space>e :scs find e <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-Space>f :scs find f <C-R>=expand("<cfile>")<CR><CR>	
    nmap <C-Space>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>	
    nmap <C-Space>d :scs find d <C-R>=expand("<cword>")<CR><CR>	
    " Hitting CTRL-space *twice* before the search type does a vertical 
    " split instead of a horizontal one (vim 6 and up only)
    "
    " (Note: you may wish to put a 'set splitright' in your .vimrc
    " Oif you prefer the new window on the right instead of the left
    nmap <C-Space><C-Space>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>	
    nmap <C-Space><C-Space>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>	
    nmap <C-Space><C-Space>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>
    """"""""""""" key map timeouts
    "
    " By default Vim will only wait 1 second for each keystroke in a mapping.
    " You may find that too short with the above typemaps.  If so, you should
    " either turn off mapping timeouts via 'notimeout'.
    "
    "set notimeout 
    "
    " Or, you can keep timeouts, by uncommenting the timeoutlen line below,
    " with your own personal favorite value (in milliseconds):
    "
    "set timeoutlen=4000
    "
    " Either way, since mapping timeout settings by default also set the
    " timeouts for multicharacter 'keys codes' (like <F1>), you should also
    " set ttimeout and ttimeoutlen: otherwise, you will experience strange
    " delays as vim waits for a keystroke after you hit ESC (it will be
    " waiting to see if the ESC is actually part of a key code like <F1>).
    "
    "set ttimeout 
    "
    " personally, I find a tenth of a second to work well for key code
    " timeouts. If you experience problems and have a slow terminal or network
    " connection, set it higher.  If you don't set ttimeoutlen, the value for
    " timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
    "
    "set ttimeoutlen=100
   map <F11>  :sp tags<CR>:%s/^\([^	:]*:\)\=\([^	]*\).*/syntax keyword Tag \2/<CR>:wq! tags.vim<CR>/^<CR><F12>
   map <F12>  :so tags.vim<CR>
endif


Relevant Pages

  • Re: Linux user interested in *BSD
    ... vim is a very good example. ... On another newsgroup people ignored the mere existence of cscope. ... >> Hence hardwiring a dependence on cscope in vim is not necessary. ... >> support, ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Linux user interested in *BSD
    ... >> This is a typical example of the bloatware that the ports maintainers ... In this case vim is an ... >> editor which is used by programmers and other people, while cscope is a ... > and it won't install cscope by default from port. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: should I use cscope or ctags?
    ... I am using cscope and ctags in Vim. ... You can chase declaration of a function in *.h by [i ...
    (comp.editors)
  • Re: Read the VI source code?
    ... Vim to examine the sources. ... like ctags, ... , or cscope ... I personally prefer the Lucent cscope (it is what we used in the ...
    (comp.editors)
  • cscope 15.5 on unix returns blank lines egrepping dos files
    ... When using vim, it is easy to not realize that some files ... When you run cscope from the unix prompt, ... be the interface with egrep rather than cscope itself. ... be the ones that show in the cscope hit list for egrep searches. ...
    (comp.unix.programmer)