" Introduction: Call GenerateTags and press F8/F9 for completions, F5 shows " the class in a preview window. Only tested in GTK but there does Alt+l pops up " a menu with the possible completions. If you are running gvim will you also see a " new menu in the menu bar. " " A try to write some documentation: " Vim global plugin for completion of classes, structs and unions in C/C++ " This plugin helps you complete things like: " variableName.abc " variableName->abc " typeName::abc " from the members of the struct/class/union that starts with abc. " " The script has a number of variables that can be set from the menu in the " GUI version. I should probably write something about them but " so you will have to try them and see what happens. They are at the top of the script if " you want to change them more permanent. " " The popup menu with the last results can be reached by pressing " Alt+j or the right mouse button, selecting any item will paste the text. " " The plugin is depending on that exuberant ctags has generated some tags with " the same options as in the following example: " ctags -n -f cppcomplete.tags --fields=+ai --C++-types=+p * " The script has a command called GenerateTags that executes the above ctags " command. The tag file cppcomplete.tags is 'local' to the script so you can " use other tag files without affecting cppcomplete. I know that another script also has " a function called GenerateTags so make sure that the correct one is called. " " BUGS/Features " This plugin does not understand any C/C++ code so it will just use gd/gD and try to " get the class name. It works surprisingly well but can of course give a surprising " result. :) " If the mouse leaves and then reenters the popup menu is the text cursor affected. " Does not work under Windows. (grep, limited command line length, popup menu) " The popup is displayed at the mouse position and not the text cursor position. " For internal use is register c used. " Requires exuberant ctags and gnu grep. " + probably a lot of other issues " Here is the variables that can be changed " " Search for typedefs? let s:searchTDefs=1 " search for macros? " this is not well supported let s:searchMacros=0 " I have not tested to have anything else than 25 menu lines let s:maxNMenuLines=25 " ctags sometimes miss to set the access so the check is disabled by default let s:accessCheck=0 " if you only use local variables is it recommended that you set onlyGD to 0 " but this does not work for global variables so the default is on let s:onlyGD=1 " I like the preview window but the default is not to display let s:showPreview=0 " Commands command! -nargs=0 GenerateTags call s:GenerateTags() command! -nargs=0 PreviewClass call s:PreCl() if has("gui_running") command! -nargs=0 BuildMenu call s:BuildMenu() command! -nargs=0 DoMenu call s:DoMenu() command! -nargs=0 RestorePopup call s:SetStandardPopup() command! -nargs=0 RefreshMenu call s:RefreshMenu() command! -nargs=0 ClearFromTags call s:ClearFromTags() command! -nargs=0 InsertToTags call s:InsertToTags() command! -nargs=0 ToggleTDefs call s:ToggleTDefs() command! -nargs=0 ToggleMacros call s:ToggleMacros() command! -nargs=0 BrowseNFiles call s:BrowseNFiles() command! -nargs=1 PreviewEntry call s:PreviewEntry() command! -nargs=0 ToggleAccess call s:ToggleAccess() command! -nargs=0 ToggleGD call s:ToggleGD() command! -nargs=0 TogglePreview call s:TogglePreview() endif command! -nargs=0 InsPrevHit call s:InsPrevHit() command! -nargs=0 InsNextHit call s:InsNextHit() " Mappings imap :PreviewClassa if has("gui_running") imap :BuildMenua imap a endif " I wanted to have the following mappings but could only set it in GUI mode " imap :InsPrevHita " imap :InsNextHita " " so I picked two function keys instead imap :InsNextHita imap :InsPrevHita " some variables for internal use let s:listAge=0 let s:lastHit=0 let s:hitList="" " build the gui menu if has("gui_running") set mousemodel=popup silent! aunmenu CppComplete amenu .100 &CppComplete.&Preview.Scan\ for\ new\ &items:RefreshMenu :RefreshMenu amenu .200 &CppComplete.&Preview.&Classes.*****\ \ \ Nothing\ yet\ \ \ ***** amenu .300 &CppComplete.&Preview.&Structures.*****\ \ \ Nothing\ yet\ \ \ ****** amenu .400 &CppComplete.&Preview.&Unions.*****\ \ \ Nothing\ yet\ \ \ ***** amenu &CppComplete.&Use\ generated\ tag\ file\ in\ tags.&No:ClearFromTags :ClearFromTags amenu &CppComplete.&Use\ generated\ tag\ file\ in\ tags.&Yes:InsertToTags :InsertToTags amenu &CppComplete.&Toggle.&Typedefs:ToggleTDefs :ToggleTDefs amenu &CppComplete.&Toggle.&Macros:ToggleMacros :ToggleMacros amenu &CppComplete.&Toggle.&Access\ check:ToggleAccess :ToggleAccess amenu &CppComplete.&Toggle.&gd:ToggleGD :ToggleGD amenu &CppComplete.&Toggle.&Preview:TogglePreview :TogglePreview amenu &CppComplete.Re&build\ tags:GenerateTags :GenerateTags amenu &CppComplete.&Append\ file\ to\ tags:BrowseNFiles :BrowseNFiles amenu &CppComplete.&RestorePopUp:RestorePopup :RestorePopup endif function! s:PreCl() if &previewwindow return endif if ! s:CheckForTagFile() return endif call s:GetPieces() if (s:gotCType) call s:PreviewEntry(s:clType) endif endfunction function! s:PreviewEntry(entry) if &previewwindow return endif if ! s:CheckForTagFile() return endif if (a:entry!="") let tagsSav=&tags let &tags="cppcomplete.tags" execute "ptag " . a:entry silent! wincmd P if &previewwindow normal! zt silent! wincmd p endif let &tags=tagsSav endif endfunction function! s:TogglePreview() let s:showPreview=!s:showPreview endfunction function! s:ToggleGD() let s:onlyGD=!s:onlyGD if s:onlyGD let cText="Cppcomplete will only use gD" else let cText="Cppcomplete will first try gd before gD" endif call confirm(cText,"&Ok",1,"Info") endfunction function! s:ToggleAccess() let s:accessCheck=!s:accessCheck if s:accessCheck let cText="Access check enabled" else let cText="Access check disabled" endif call confirm(cText, "&Ok",1,"Info") endfunction function! s:ToggleTDefs() let s:searchTDefs=!s:searchTDefs if (s:searchTDefs) let cText="Typedefs is now included in the search" else let cText="Further searches will not look for typedefs" endif call confirm(cText,"&Ok",1,"Info") endfunction function! s:ToggleMacros() let s:searchMacros=!s:searchMacros if (s:searchMacros) let cText="Macros is now included in the search" else let cText="Further searches will not look for macros" endif call confirm(cText,"&Ok",1,"Info") endfunction function! s:InsertToTags() if (match(&tags, "cppcomplete.tags,",0)>=0) call confirm("cppcomplete.tags is already in tags","&Ok",1,"Info") else let &tags="cppcomplete.tags, " . &tags endif endfunction function! s:ClearFromTags() if (match(&tags,"cppcomplete.tags")<0) call confirm("tags did not include cppcomplete.tags","&Ok",1,"Info") else let &tags=substitute(&tags,"cppcomplete.tags.","","g") endif endfunction function! s:RefreshMenu() if ! s:CheckForTagFile() return endif silent! aunmenu CppComplete.Preview.Classes silent! aunmenu CppComplete.Preview.Structures silent! aunmenu CppComplete.Preview.Unions let cf=0 let sf=0 let uf=0 let spaceAfter="[^![:space:]]\\+[[:space:]]" let items=system("grep '^" . spaceAfter . spaceAfter . spaceAfter . "\\(c\\|s\\|u\\)' cppcomplete.tags") let nextM=0 let nclines=0 let nslines=0 let nulines=0 let cMore="" let sMore="" let uMore="" while match(items,"\t",nextM)>0 let oldM=nextM let @c=strpart(items,nextM,match(items,"\t",nextM)-nextM) let nextM=matchend(items,"\n",nextM) if nextM<0 let nextM=strlen(items) endif let mc=match(items,"^[^\t]*\t[^\t]*\t[^\t]*\tc",oldM) let ms=match(items,"^[^\t]*\t[^\t]*\t[^\t]*\ts.*",oldM) if (mc>=0) && (mc" let nclines=nclines+1 if (nclines%s:maxNMenuLines)==0 let cMore=cMore . "More." endif elseif (ms>=0) && (ms" let nslines=nslines+1 if (nslines%s:maxNMenuLines)==0 let sMore=sMore . "More." endif else let uf=1 execute "amenu .400 &CppComplete.&Preview.&Unions." . uMore . @c . " :PreviewEntry " . @c ."" let nulines=nulines+1 if (nulines%s:maxNMenuLines)==0 let uMore=uMore . "More." endif endif endwhile if cf==0 amenu &CppComplete.&Preview.&Classes.*****\ \ \ no\ classes\ found\ \ \ ***** endif if sf==0 amenu &CppComplete.&Preview.&Structures.*****\ \ \ no\ structures\ found\ \ \ ***** endif if uf==0 amenu &CppComplete.&Preview.&Unions.*****\ \ \ no\ unions\ found\ \ \ ***** endif endfunction function! s:SetStandardPopup() aunmenu PopUp " The popup menu an 1.10 PopUp.&Undo u an 1.15 PopUp.-SEP1- vnoremenu 1.20 PopUp.Cu&t "+x vnoremenu 1.30 PopUp.&Copy "+y cnoremenu 1.30 PopUp.&Copy nnoremenu 1.40 PopUp.&Paste "+gP cnoremenu 1.40 PopUp.&Paste + if has("virtualedit") vnoremenu