diff options
Diffstat (limited to '.vim/plugin')
-rw-r--r-- | .vim/plugin/buftabs.vim | 309 | ||||
-rw-r--r-- | .vim/plugin/c.vim | 3550 | ||||
-rwxr-xr-x | .vim/plugin/crefvim.vim | 356 | ||||
-rw-r--r-- | .vim/plugin/cscope_maps.vim | 165 | ||||
-rw-r--r-- | .vim/plugin/vtreeexplorer.vim | 872 |
5 files changed, 5252 insertions, 0 deletions
diff --git a/.vim/plugin/buftabs.vim b/.vim/plugin/buftabs.vim new file mode 100644 index 0000000..30edea9 --- /dev/null +++ b/.vim/plugin/buftabs.vim @@ -0,0 +1,309 @@ +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" buftabs (C) 2006 Ico Doornekamp +" +" This program is free software; you can redistribute it and/or modify it +" under the terms of the GNU General Public License as published by the Free +" Software Foundation; either version 2 of the License, or (at your option) +" any later version. +" +" This program is distributed in the hope that it will be useful, but WITHOUT +" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +" more details. +" +" Introduction +" ------------ +" +" This is a simple script that shows a tabs-like list of buffers in the bottom +" of the window. The biggest advantage of this script over various others is +" that it does not take any lines away from your terminal, leaving more space +" for the document you're editing. The tabs are only visible when you need +" them - when you are switchin between buffers. +" +" Usage +" ----- +" +" This script draws buffer tabs on vim startup, when a new buffer is created +" and when switching between buffers. +" +" It might be handy to create a few maps for easy switching of buffers in your +" .vimrc file. For example, using F1 and F2 keys: +" +" noremap <f1> :bprev<CR> +" noremap <f2> :bnext<CR> +" +" or using control-left and control-right keys: +" +" :noremap <C-left> :bprev<CR> +" :noremap <C-right> :bnext<CR> +" +" +" The following extra configuration variables are availabe: +" +" * g:buftabs_only_basename +" +" Define this variable to make buftabs only print the filename of each buffer, +" omitting the preceding directory name. Add to your .vimrc: +" +" :let g:buftabs_only_basename=1 +" +" +" * g:buftabs_in_statusline +" +" Define this variable to make the plugin show the buftabs in the statusline +" instead of the command line. It is a good idea to configure vim to show +" the statusline as well when only one window is open. Add to your .vimrc: +" +" set laststatus=2 +" :let g:buftabs_in_statusline=1 +" +" +" * g:buftabs_active_highlight_group +" * g:buftabs_inactive_highlight_group +" +" The name of a highlight group (:help highligh-groups) which is used to +" show the name of the current active buffer and of all other inactive +" buffers. If these variables are not defined, no highlighting is used. +" (Highlighting is only functional when g:buftabs_in_statusline is enabled) +" +" :let g:buftabs_active_highlight_group="Visual" +" +" +" * g:buftabs_marker_start [ +" * g:buftabs_marker_end ] +" * g:buftabs_separator - +" +" These strings are drawn around each tab as separators. +" +" :let g:buftabs_separator = "." +" :let g:buftabs_marker_start = "(" +" :let g:buftabs_marker_end = ")" +" +" +" Changelog +" --------- +" +" 0.1 2006-09-22 Initial version +" +" 0.2 2006-09-22 Better handling when the list of buffers is longer then the +" window width. +" +" 0.3 2006-09-27 Some cleanups, set 'hidden' mode by default +" +" 0.4 2007-02-26 Don't draw buftabs until VimEnter event to avoid clutter at +" startup in some circumstances +" +" 0.5 2007-02-26 Added option for showing only filenames without directories +" in tabs +" +" 0.6 2007-03-04 'only_basename' changed to a global variable. Removed +" functions and add event handlers instead. 'hidden' mode +" broke some things, so is disabled now. Fixed documentation +" +" 0.7 2007-03-07 Added configuration option to show tabs in statusline +" instead of cmdline +" +" 0.8 2007-04-02 Update buftabs when leaving insertmode +" +" 0.9 2007-08-22 Now compatible with older Vim versions < 7.0 +" +" 0.10 2008-01-26 Added GPL license +" +" 0.11 2008-02-29 Added optional syntax highlighting to active buffer name +" +" 0.12 2009-03-18 Fixed support for split windows +" +" 0.13 2009-05-07 Store and reuse right-aligned part of original statusline +" +" 0.14 2010-01-28 Fixed bug that caused buftabs in command line being +" overwritten when 'hidden' mode is enabled. +" +" 0.15 2010-02-16 Fixed window width handling bug which caused strange +" behaviour in combination with the bufferlist plugin. +" Fixed wrong buffer display when deleting last window. +" Added extra options for tabs style and highlighting. +" +" 0.16 2010-02-28 Fixed bug causing errors when using buftabs in vim +" diff mode. +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +let w:buftabs_enabled = 0 +let w:original_statusline = matchstr(&statusline, "%=.*") + +" +" Don't bother when in diff mode +" + +if &diff + finish +endif + + +" +" Called on VimEnter event +" + +function! Buftabs_enable() + let w:buftabs_enabled = 1 +endfunction + + +" +" Persistent echo to avoid overwriting of status line when 'hidden' is enabled +" + +function! Pecho(msg) + let s:hold_ut=&ut|let &ut=1 + let s:Pecho=a:msg + aug Pecho + au CursorHold * ec s:Pecho + \|let &ut=s:hold_ut + \|aug Pecho|exe 'au!'|aug END|aug! Pecho + aug END +endf + + +" +" Draw the buftabs +" + +function! Buftabs_show(deleted_buf) + + let l:i = 1 + let l:list = '' + let l:start = 0 + let l:end = 0 + if ! exists("w:from") + let w:from = 0 + endif + + if ! exists("w:buftabs_enabled") + return + endif + + " Walk the list of buffers + + while(l:i <= bufnr('$')) + + " Only show buffers in the list, and omit help screens + + if buflisted(l:i) && getbufvar(l:i, "&modifiable") && a:deleted_buf != l:i + + " Get the name of the current buffer, and escape characters that might + " mess up the statusline + + if exists("g:buftabs_only_basename") + let l:name = fnamemodify(bufname(l:i), ":t") + else + let l:name = bufname(l:i) + endif + let l:name = substitute(l:name, "%", "%%", "g") + + " Append the current buffer number and name to the list. If the buffer + " is the active buffer, enclose it in some magick characters which will + " be replaced by markers later. If it is modified, it is appended with + " an exclaimation mark + + if winbufnr(winnr()) == l:i + let l:start = strlen(l:list) + let l:list = l:list . "\x01" + else + let l:list = l:list . ' ' + endif + + let l:buftabs_separator = "-" + if exists("g:buftabs_separator") + let l:buftabs_separator = g:buftabs_separator + endif + + let l:list = l:list . l:i . l:buftabs_separator + let l:list = l:list . l:name + + if getbufvar(l:i, "&modified") == 1 + let l:list = l:list . "!" + endif + + if winbufnr(winnr()) == l:i + let l:list = l:list . "\x02" + let l:end = strlen(l:list) + else + let l:list = l:list . ' ' + endif + end + + let l:i = l:i + 1 + endwhile + + " If the resulting list is too long to fit on the screen, chop + " out the appropriate part + + let l:width = winwidth(0) - 12 + + if(l:start < w:from) + let w:from = l:start - 1 + endif + if l:end > w:from + l:width + let w:from = l:end - l:width + endif + + let l:list = strpart(l:list, w:from, l:width) + + " Replace the magic characters by visible markers for highlighting the + " current buffer. The markers can be simple characters like square brackets, + " but can also be special codes with highlight groups + + let l:buftabs_marker_start = "[" + if exists("g:buftabs_marker_start") + let l:buftabs_marker_start = g:buftabs_marker_start + endif + + let l:buftabs_marker_end = "]" + if exists("g:buftabs_marker_end") + let l:buftabs_marker_end = g:buftabs_marker_end + endif + + if exists("g:buftabs_active_highlight_group") + if exists("g:buftabs_in_statusline") + let l:buftabs_marker_start = "%#" . g:buftabs_active_highlight_group . "#" . l:buftabs_marker_start + let l:buftabs_marker_end = l:buftabs_marker_end . "%##" + end + end + + if exists("g:buftabs_inactive_highlight_group") + if exists("g:buftabs_in_statusline") + let l:list = '%#' . g:buftabs_inactive_highlight_group . '#' . l:list + let l:list .= '%##' + let l:buftabs_marker_end = l:buftabs_marker_end . '%#' . g:buftabs_inactive_highlight_group . '#' + end + end + + let l:list = substitute(l:list, "\x01", l:buftabs_marker_start, 'g') + let l:list = substitute(l:list, "\x02", l:buftabs_marker_end, 'g') + + " Show the list. The buftabs_in_statusline variable determines of the list + " is displayed in the command line (volatile) or in the statusline + " (persistent) + + if exists("g:buftabs_in_statusline") + let &l:statusline = l:list . w:original_statusline + else + redraw + call Pecho(l:list) + end + +endfunction + + +" Hook to events to show buftabs at startup, when creating and when switching +" buffers + +autocmd VimEnter * call Buftabs_enable() +autocmd VimEnter,BufNew,BufEnter,BufWritePost * call Buftabs_show(-1) +autocmd BufDelete * call Buftabs_show(expand('<abuf>')) +if version >= 700 + autocmd InsertLeave,VimResized * call Buftabs_show(-1) +end + +" vi: ts=2 sw=2 + diff --git a/.vim/plugin/c.vim b/.vim/plugin/c.vim new file mode 100644 index 0000000..741764b --- /dev/null +++ b/.vim/plugin/c.vim @@ -0,0 +1,3550 @@ +"################################################################################# +" +" Filename: c.vim +" +" Description: C/C++-IDE. Write programs by inserting complete statements, +" comments, idioms, code snippets, templates and comments. +" Compile, link and run one-file-programs without a makefile. +" See also help file csupport.txt . +" +" GVIM Version: 7.0+ +" +" Configuration: There are some personal details which should be configured +" (see the files README.csupport and csupport.txt). +" +" Author: Dr.-Ing. Fritz Mehner, FH Südwestfalen, 58644 Iserlohn, Germany +" Email: mehner@fh-swf.de +" +" Version: see variable g:C_Version below +" Created: 04.11.2000 +" License: Copyright (c) 2000-2010, Fritz Mehner +" This program is free software; you can redistribute it and/or +" modify it under the terms of the GNU General Public License as +" published by the Free Software Foundation, version 2 of the +" License. +" This program is distributed in the hope that it will be +" useful, but WITHOUT ANY WARRANTY; without even the implied +" warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +" PURPOSE. +" See the GNU General Public License version 2 for more details. +" Revision: $Id: c.vim,v 1.106 2010/02/02 13:24:41 mehner Exp $ +" +"------------------------------------------------------------------------------ +" +if v:version < 700 + echohl WarningMsg | echo 'The plugin c-support.vim needs Vim version >= 7 .'| echohl None + finish +endif +" +" Prevent duplicate loading: +" +if exists("g:C_Version") || &cp + finish +endif +let g:C_Version= "5.10" " version number of this script; do not change +" +"################################################################################# +" +" Global variables (with default values) which can be overridden. +" +" Platform specific items: {{{1 +" - root directory +" - characters that must be escaped for filenames +" +let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") +" +if s:MSWIN + " + let s:escfilename = '' + let s:plugin_dir = $VIM.'\vimfiles\' + let s:C_CodeSnippets = s:plugin_dir.'c-support/codesnippets/' + let s:C_IndentErrorLog = $HOME.'.indent.errorlog' + let s:installation = 'system' + " + let s:C_Display = '' + " +else + " + let s:escfilename = ' \%#[]' + let s:installation = 'local' + " + " user / system wide installation (Linux/Unix) + " + if match( expand("<sfile>"), $VIM ) >= 0 + " system wide installation + let s:plugin_dir = $VIM.'/vimfiles/' + let s:installation = 'system' + else + " user installation assumed + let s:plugin_dir = $HOME.'/.vim/' + endif + " + let s:C_CodeSnippets = $HOME.'/.vim/c-support/codesnippets/' + let s:C_IndentErrorLog = $HOME.'/.indent.errorlog' + " + let s:C_Display = system("echo -n $DISPLAY") + " +endif +" Use of dictionaries {{{1 +" Key word completion is enabled by the filetype plugin 'c.vim' +" g:C_Dictionary_File must be global +" +if !exists("g:C_Dictionary_File") + let g:C_Dictionary_File = s:plugin_dir.'c-support/wordlists/c-c++-keywords.list,'. + \ s:plugin_dir.'c-support/wordlists/k+r.list,'. + \ s:plugin_dir.'c-support/wordlists/stl_index.list' +endif +" +" Modul global variables (with default values) which can be overridden. {{{1 +" +if s:MSWIN + let s:C_CCompiler = 'gcc.exe' " the C compiler + let s:C_CplusCompiler = 'g++.exe' " the C++ compiler + let s:C_ExeExtension = '.exe' " file extension for executables (leading point required) + let s:C_ObjExtension = '.obj' " file extension for objects (leading point required) + let s:C_Man = 'man.exe' " the manual program +else + let s:C_CCompiler = 'gcc' " the C compiler + let s:C_CplusCompiler = 'g++' " the C++ compiler + let s:C_ExeExtension = '' " file extension for executables (leading point required) + let s:C_ObjExtension = '.o' " file extension for objects (leading point required) + let s:C_Man = 'man' " the manual program +endif +" +let s:C_CExtension = 'c' " C file extension; everything else is C++ +let s:C_CFlags = '-Wall -g -O0 -c' " compiler flags: compile, don't optimize +let s:C_CodeCheckExeName = 'check' +let s:C_CodeCheckOptions = '-K13' +let s:C_LFlags = '-Wall -g -O0' " compiler flags: link , don't optimize +let s:C_Libs = '-lm' " libraries to use +let s:C_LineEndCommColDefault = 49 +let s:C_LoadMenus = 'yes' +let s:C_MenuHeader = 'yes' +let s:C_OutputGvim = 'vim' +let s:C_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} Page %N" +let s:C_Root = '&C\/C\+\+.' " the name of the root menu of this plugin +let s:C_TypeOfH = 'cpp' +let s:C_Wrapper = s:plugin_dir.'c-support/scripts/wrapper.sh' +let s:C_XtermDefaults = '-fa courier -fs 12 -geometry 80x24' +let s:C_GuiSnippetBrowser = 'gui' " gui / commandline +let s:C_GuiTemplateBrowser = 'gui' " gui / explorer / commandline +" +let s:C_GlobalTemplateFile = s:plugin_dir.'c-support/templates/Templates' +let s:C_GlobalTemplateDir = fnamemodify( s:C_GlobalTemplateFile, ":p:h" ).'/' +let s:C_LocalTemplateFile = $HOME.'/.vim/c-support/templates/Templates' +let s:C_LocalTemplateDir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' +let s:C_TemplateOverwrittenMsg= 'yes' +let s:C_Ctrl_j = 'on' +" +let s:C_FormatDate = '%x' +let s:C_FormatTime = '%X' +let s:C_FormatYear = '%Y' +let s:C_SourceCodeExtensions = 'c cc cp cxx cpp CPP c++ C i ii' +" +"------------------------------------------------------------------------------ +" +" Look for global variables (if any), to override the defaults. +" +function! C_CheckGlobal ( name ) + if exists('g:'.a:name) + exe 'let s:'.a:name.' = g:'.a:name + endif +endfunction " ---------- end of function C_CheckGlobal ---------- +" +call C_CheckGlobal('C_CCompiler ') +call C_CheckGlobal('C_CExtension ') +call C_CheckGlobal('C_CFlags ') +call C_CheckGlobal('C_CodeCheckExeName ') +call C_CheckGlobal('C_CodeCheckOptions ') +call C_CheckGlobal('C_CodeSnippets ') +call C_CheckGlobal('C_CplusCompiler ') +call C_CheckGlobal('C_Ctrl_j ') +call C_CheckGlobal('C_ExeExtension ') +call C_CheckGlobal('C_FormatDate ') +call C_CheckGlobal('C_FormatTime ') +call C_CheckGlobal('C_FormatYear ') +call C_CheckGlobal('C_GlobalTemplateFile ') +call C_CheckGlobal('C_GuiSnippetBrowser ') +call C_CheckGlobal('C_GuiTemplateBrowser ') +call C_CheckGlobal('C_IndentErrorLog ') +call C_CheckGlobal('C_LFlags ') +call C_CheckGlobal('C_Libs ') +call C_CheckGlobal('C_LineEndCommColDefault ') +call C_CheckGlobal('C_LoadMenus ') +call C_CheckGlobal('C_LocalTemplateFile ') +call C_CheckGlobal('C_Man ') +call C_CheckGlobal('C_MenuHeader ') +call C_CheckGlobal('C_ObjExtension ') +call C_CheckGlobal('C_OutputGvim ') +call C_CheckGlobal('C_Printheader ') +call C_CheckGlobal('C_Root ') +call C_CheckGlobal('C_SourceCodeExtensions ') +call C_CheckGlobal('C_TemplateOverwrittenMsg ') +call C_CheckGlobal('C_TypeOfH ') +call C_CheckGlobal('C_XtermDefaults ') +" +"----- some variables for internal use only ----------------------------------- +" +" +" set default geometry if not specified +" +if match( s:C_XtermDefaults, "-geometry\\s\\+\\d\\+x\\d\\+" ) < 0 + let s:C_XtermDefaults = s:C_XtermDefaults." -geometry 80x24" +endif +" +" escape the printheader +" +let s:C_Printheader = escape( s:C_Printheader, ' %' ) +" +let s:C_HlMessage = "" +" +" characters that must be escaped for filenames +" +let s:C_If0_Counter = 0 +let s:C_If0_Txt = "If0Label_" +" +let s:C_SplintIsExecutable = 0 +if executable( "splint" ) + let s:C_SplintIsExecutable = 1 +endif +" +let s:C_CodeCheckIsExecutable = 0 +if executable( s:C_CodeCheckExeName ) + let s:C_CodeCheckIsExecutable = 1 +endif +" +"------------------------------------------------------------------------------ +" Control variables (not user configurable) +"------------------------------------------------------------------------------ +let s:Attribute = { 'below':'', 'above':'', 'start':'', 'append':'', 'insert':'' } +let s:C_Attribute = {} +let s:C_ExpansionLimit = 10 +let s:C_FileVisited = [] +" +let s:C_MacroNameRegex = '\([a-zA-Z][a-zA-Z0-9_]*\)' +let s:C_MacroLineRegex = '^\s*|'.s:C_MacroNameRegex.'|\s*=\s*\(.*\)' +let s:C_MacroCommentRegex = '^\$' +let s:C_ExpansionRegex = '|?'.s:C_MacroNameRegex.'\(:\a\)\?|' +let s:C_NonExpansionRegex = '|'.s:C_MacroNameRegex.'\(:\a\)\?|' +" +let s:C_TemplateNameDelimiter = '-+_,\. ' +let s:C_TemplateLineRegex = '^==\s*\([a-zA-Z][0-9a-zA-Z'.s:C_TemplateNameDelimiter +let s:C_TemplateLineRegex .= ']\+\)\s*==\s*\([a-z]\+\s*==\)\?' +let s:C_TemplateIf = '^==\s*IF\s\+|STYLE|\s\+IS\s\+'.s:C_MacroNameRegex.'\s*==' +let s:C_TemplateEndif = '^==\s*ENDIF\s*==' +" +let s:C_ExpansionCounter = {} +let s:C_TJT = '[ 0-9a-zA-Z_]*' +let s:C_TemplateJumpTarget1 = '<+'.s:C_TJT.'+>\|{+'.s:C_TJT.'+}' +let s:C_TemplateJumpTarget2 = '<-'.s:C_TJT.'->\|{-'.s:C_TJT.'-}' +let s:C_Macro = {'|AUTHOR|' : 'first name surname', + \ '|AUTHORREF|' : '', + \ '|EMAIL|' : '', + \ '|COMPANY|' : '', + \ '|PROJECT|' : '', + \ '|COPYRIGHTHOLDER|': '', + \ '|STYLE|' : '' + \ } +let s:C_MacroFlag = { ':l' : 'lowercase' , + \ ':u' : 'uppercase' , + \ ':c' : 'capitalize' , + \ ':L' : 'legalize name' , + \ } +let s:C_ActualStyle = 'default' +let s:C_ActualStyleLast = s:C_ActualStyle +let s:C_Template = { 'default' : {} } + +let s:C_ForTypes = [ + \ 'char ' , + \ 'int ' , + \ 'long int ' , + \ 'long ' , + \ 'short int ' , + \ 'short ' , + \ 'size_t ' , + \ 'unsigned char ' , + \ 'unsigned int ' , + \ 'unsigned long int ' , + \ 'unsigned long ' , + \ 'unsigned short int ', + \ 'unsigned short ' , + \ 'unsigned ' , + \ ] + +let s:MsgInsNotAvail = "insertion not available for a fold" + +"------------------------------------------------------------------------------ + +let s:C_SourceCodeExtensionsList = split( s:C_SourceCodeExtensions, '\s\+' ) + +"------------------------------------------------------------------------------ + +"------------------------------------------------------------------------------ +" C : C_InitMenus {{{1 +" Initialization of C support menus +"------------------------------------------------------------------------------ +" +" the menu names +" +let s:Comments = s:C_Root.'&Comments' +let s:Statements = s:C_Root.'&Statements' +let s:Idioms = s:C_Root.'&Idioms' +let s:Preprocessor = s:C_Root.'&Preprocessor' +let s:Snippets = s:C_Root.'S&nippets' +let s:Cpp = s:C_Root.'C&++' +let s:Run = s:C_Root.'&Run' +" +function! C_InitMenus () + " + "=============================================================================================== + "----- Menu : C main menu entry ------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_Root != "" + if s:C_MenuHeader == 'yes' + exe "amenu ".s:C_Root.'C\/C\+\+ <Nop>' + exe "amenu ".s:C_Root.'-Sep00- <Nop>' + endif + endif + " + "=============================================================================================== + "----- Menu : C-Comments -------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:C_Root.'&Comments.&Comments<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:C_Root.'&Comments.-Sep00- <Nop>' + endif + exe "amenu <silent> ".s:Comments.'.end-of-&line\ comment<Tab>\\cl :call C_LineEndComment( )<CR>' + exe "vmenu <silent> ".s:Comments.'.end-of-&line\ comment<Tab>\\cl <Esc>:call C_MultiLineEndComments( )<CR>a' + + exe "amenu <silent> ".s:Comments.'.ad&just\ end-of-line\ com\.<Tab>\\cj :call C_AdjustLineEndComm("a")<CR>' + exe "vmenu <silent> ".s:Comments.'.ad&just\ end-of-line\ com\.<Tab>\\cj :call C_AdjustLineEndComm("v")<CR>' + + exe "amenu <silent> ".s:Comments.'.&set\ end-of-line\ com\.\ col\.<Tab>\\cs :call C_GetLineEndCommCol()<CR>' + + exe "amenu ".s:Comments.'.-SEP10- :' + exe "amenu <silent> ".s:Comments.'.code\ ->\ comment\ \/&*\ *\/<Tab>\\c* :call C_CodeComment("a","yes")<CR>:nohlsearch<CR>j' + exe "vmenu <silent> ".s:Comments.'.code\ ->\ comment\ \/&*\ *\/<Tab>\\c* <Esc>:call C_CodeComment("v","yes")<CR>:nohlsearch<CR>j' + exe "amenu <silent> ".s:Comments.'.code\ ->\ comment\ &\/\/<Tab>\\cc :call C_CodeComment("a","no")<CR>:nohlsearch<CR>j' + exe "vmenu <silent> ".s:Comments.'.code\ ->\ comment\ &\/\/<Tab>\\cc <Esc>:call C_CodeComment("v","no")<CR>:nohlsearch<CR>j' + exe "amenu <silent> ".s:Comments.'.c&omment\ ->\ code<Tab>\\co :call C_CommentCode("a")<CR>:nohlsearch<CR>' + exe "vmenu <silent> ".s:Comments.'.c&omment\ ->\ code<Tab>\\co :call C_CommentCode("v")<CR>:nohlsearch<CR>' + + exe "amenu ".s:Comments.'.-SEP0- :' + exe "amenu <silent> ".s:Comments.'.&frame\ comment<Tab>\\cfr :call C_InsertTemplate("comment.frame")<CR>' + exe "amenu <silent> ".s:Comments.'.f&unction\ description<Tab>\\cfu :call C_InsertTemplate("comment.function")<CR>' + exe "amenu ".s:Comments.'.-SEP1- :' + exe "amenu <silent> ".s:Comments.'.&method\ description<Tab>\\cme :call C_InsertTemplate("comment.method")<CR>' + exe "amenu <silent> ".s:Comments.'.cl&ass\ description<Tab>\\ccl :call C_InsertTemplate("comment.class")<CR>' + exe "amenu ".s:Comments.'.-SEP2- :' + exe "amenu <silent> ".s:Comments.'.file\ description\ \(impl\.\)<Tab>\\cfdi :call C_InsertTemplate("comment.file-description")<CR>' + exe "amenu <silent> ".s:Comments.'.file\ description\ \(header\)<Tab>\\cfdh :call C_InsertTemplate("comment.file-description-header")<CR>' + exe "amenu ".s:Comments.'.-SEP3- :' + " + "----- Submenu : C-Comments : file sections ------------------------------------------------------------- + " + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.file\ sections<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.-Sep0- <Nop>' + " + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.&Header\ File\ Includes :call C_InsertTemplate("comment.file-section-cpp-header-includes")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.Local\ &Macros :call C_InsertTemplate("comment.file-section-cpp-macros")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.Local\ &Type\ Def\. :call C_InsertTemplate("comment.file-section-cpp-typedefs")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.Local\ &Data\ Types :call C_InsertTemplate("comment.file-section-cpp-data-types")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.Local\ &Variables :call C_InsertTemplate("comment.file-section-cpp-local-variables")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.Local\ &Prototypes :call C_InsertTemplate("comment.file-section-cpp-prototypes")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.&Exp\.\ Function\ Def\. :call C_InsertTemplate("comment.file-section-cpp-function-defs-exported")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.&Local\ Function\ Def\. :call C_InsertTemplate("comment.file-section-cpp-function-defs-local")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.-SEP6- :' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.Local\ &Class\ Def\. :call C_InsertTemplate("comment.file-section-cpp-class-defs")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.E&xp\.\ Class\ Impl\. :call C_InsertTemplate("comment.file-section-cpp-class-implementations-exported")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.L&ocal\ Class\ Impl\. :call C_InsertTemplate("comment.file-section-cpp-class-implementations-local")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.-SEP7- :' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.&All\ sections,\ C :call C_Comment_C_SectionAll("c")<CR>' + exe "amenu ".s:Comments.'.&C\/C\+\+-file\ sections<Tab>\\ccs.All\ §ions,\ C++ :call C_Comment_C_SectionAll("cpp")<CR>' + " + "----- Submenu : H-Comments : file sections ------------------------------------------------------------- + " + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.H-file\ sections<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.-Sep0- <Nop>' + "' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.&Header\ File\ Includes :call C_InsertTemplate("comment.file-section-hpp-header-includes")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.Exported\ &Macros :call C_InsertTemplate("comment.file-section-hpp-macros")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.Exported\ &Type\ Def\. :call C_InsertTemplate("comment.file-section-hpp-exported-typedefs")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.Exported\ &Data\ Types :call C_InsertTemplate("comment.file-section-hpp-exported-data-types")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.Exported\ &Variables :call C_InsertTemplate("comment.file-section-hpp-exported-variables")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.Exported\ &Funct\.\ Decl\. :call C_InsertTemplate("comment.file-section-hpp-exported-function-declarations")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.-SEP4- :' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.E&xported\ Class\ Def\. :call C_InsertTemplate("comment.file-section-hpp-exported-class-defs")<CR>' + + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.-SEP5- :' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.&All\ sections,\ C :call C_Comment_H_SectionAll("c")<CR>' + exe "amenu ".s:Comments.'.&H-file\ sections<Tab>\\chs.All\ §ions,\ C++ :call C_Comment_H_SectionAll("cpp")<CR>' + " + exe "amenu ".s:Comments.'.-SEP8- :' + " + "----- Submenu : C-Comments : keyword comments ---------------------------------------------------------- + " + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.keyw\.+comm\.<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.-Sep0- <Nop>' +" + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&BUG\: $:call C_InsertTemplate("comment.keyword-bug")<CR>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&COMPILER\: $:call C_InsertTemplate("comment.keyword-compiler")<CR>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&TODO\: $:call C_InsertTemplate("comment.keyword-todo")<CR>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:T&RICKY\: $:call C_InsertTemplate("comment.keyword-tricky")<CR>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&WARNING\: $:call C_InsertTemplate("comment.keyword-warning")<CR>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:W&ORKAROUND\: $:call C_InsertTemplate("comment.keyword-workaround")<CR>' + exe "amenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&new\ keyword\: $:call C_InsertTemplate("comment.keyword-keyword")<CR>' +" + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&BUG\: <Esc>$:call C_InsertTemplate("comment.keyword-bug")<CR>' + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&COMPILER\: <Esc>$:call C_InsertTemplate("comment.keyword-compiler")<CR>' + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&TODO\: <Esc>$:call C_InsertTemplate("comment.keyword-todo")<CR>' + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:T&RICKY\: <Esc>$:call C_InsertTemplate("comment.keyword-tricky")<CR>' + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&WARNING\: <Esc>$:call C_InsertTemplate("comment.keyword-warning")<CR>' + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:W&ORKAROUND\: <Esc>$:call C_InsertTemplate("comment.keyword-workaround")<CR>' + exe "imenu ".s:Comments.'.&keyword\ comm\.<Tab>\\ckc.\:&new\ keyword\: <Esc>$:call C_InsertTemplate("comment.keyword-keyword")<CR>' + " + "----- Submenu : C-Comments : special comments ---------------------------------------------------------- + " + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.special\ comm\.<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.-Sep0- <Nop>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&EMPTY $:call C_InsertTemplate("comment.special-empty")<CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&FALL\ THROUGH $:call C_InsertTemplate("comment.special-fall-through") <CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&IMPL\.\ TYPE\ CONV $:call C_InsertTemplate("comment.special-implicit-type-conversion") <CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&NO\ RETURN $:call C_InsertTemplate("comment.special-no-return") <CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.NOT\ &REACHED $:call C_InsertTemplate("comment.special-not-reached") <CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&TO\ BE\ IMPL\. $:call C_InsertTemplate("comment.special-remains-to-be-implemented")<CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.-SEP81- :' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.constant\ type\ is\ &long\ (L) $:call C_InsertTemplate("comment.special-constant-type-is-long")<CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.constant\ type\ is\ &unsigned\ (U) $:call C_InsertTemplate("comment.special-constant-type-is-unsigned")<CR>' + exe "amenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.constant\ type\ is\ unsigned\ l&ong\ (UL) $:call C_InsertTemplate("comment.special-constant-type-is-unsigned-long")<CR>' + " + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&EMPTY <Esc>$:call C_InsertTemplate("comment.special-empty")<CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&FALL\ THROUGH <Esc>$:call C_InsertTemplate("comment.special-fall-through") <CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&IMPL\.\ TYPE\ CONV <Esc>$:call C_InsertTemplate("comment.special-implicit-type-conversion") <CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&NO\ RETURN <Esc>$:call C_InsertTemplate("comment.special-no-return") <CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.NOT\ &REACHED <Esc>$:call C_InsertTemplate("comment.special-not-reached") <CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.&TO\ BE\ IMPL\. <Esc>$:call C_InsertTemplate("comment.special-remains-to-be-implemented")<CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.-SEP81- :' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.constant\ type\ is\ &long\ (L) <Esc>$:call C_InsertTemplate("comment.special-constant-type-is-long")<CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.constant\ type\ is\ &unsigned\ (U) <Esc>$:call C_InsertTemplate("comment.special-constant-type-is-unsigned")<CR>' + exe "imenu ".s:Comments.'.&special\ comm\.<Tab>\\ckc.constant\ type\ is\ unsigned\ l&ong\ (UL) <Esc>$:call C_InsertTemplate("comment.special-constant-type-is-unsigned-long")<CR>' + " + "----- Submenu : C-Comments : Tags ---------------------------------------------------------- + " + exe "amenu ".s:Comments.'.ta&gs\ (plugin).tags\ (plugin)<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Comments.'.ta&gs\ (plugin).-Sep0- <Nop>' + " + exe "anoremenu ".s:Comments.'.ta&gs\ (plugin).&AUTHOR :call C_InsertMacroValue("AUTHOR")<CR>' + exe "anoremenu ".s:Comments.'.ta&gs\ (plugin).AUTHOR&REF :call C_InsertMacroValue("AUTHORREF")<CR>' + exe "anoremenu ".s:Comments.'.ta&gs\ (plugin).&COMPANY :call C_InsertMacroValue("COMPANY")<CR>' + exe "anoremenu ".s:Comments.'.ta&gs\ (plugin).C&OPYRIGHTHOLDER :call C_InsertMacroValue("COPYRIGHTHOLDER")<CR>' + exe "anoremenu ".s:Comments.'.ta&gs\ (plugin).&EMAIL :call C_InsertMacroValue("EMAIL")<CR>' + exe "anoremenu ".s:Comments.'.ta&gs\ (plugin).&PROJECT :call C_InsertMacroValue("PROJECT")<CR>' + " + exe "inoremenu ".s:Comments.'.ta&gs\ (plugin).&AUTHOR <Esc>:call C_InsertMacroValue("AUTHOR")<CR>a' + exe "inoremenu ".s:Comments.'.ta&gs\ (plugin).AUTHOR&REF <Esc>:call C_InsertMacroValue("AUTHORREF")<CR>a' + exe "inoremenu ".s:Comments.'.ta&gs\ (plugin).&COMPANY <Esc>:call C_InsertMacroValue("COMPANY")<CR>a' + exe "inoremenu ".s:Comments.'.ta&gs\ (plugin).C&OPYRIGHTHOLDER <Esc>:call C_InsertMacroValue("COPYRIGHTHOLDER")<CR>a' + exe "inoremenu ".s:Comments.'.ta&gs\ (plugin).&EMAIL <Esc>:call C_InsertMacroValue("EMAIL")<CR>a' + exe "inoremenu ".s:Comments.'.ta&gs\ (plugin).&PROJECT <Esc>:call C_InsertMacroValue("PROJECT")<CR>a' + " + exe "vnoremenu ".s:Comments.'.ta&gs\ (plugin).&AUTHOR s<Esc>:call C_InsertMacroValue("AUTHOR")<CR>a' + exe "vnoremenu ".s:Comments.'.ta&gs\ (plugin).AUTHOR&REF s<Esc>:call C_InsertMacroValue("AUTHORREF")<CR>a' + exe "vnoremenu ".s:Comments.'.ta&gs\ (plugin).&COMPANY s<Esc>:call C_InsertMacroValue("COMPANY")<CR>a' + exe "vnoremenu ".s:Comments.'.ta&gs\ (plugin).C&OPYRIGHTHOLDER s<Esc>:call C_InsertMacroValue("COPYRIGHTHOLDER")<CR>a' + exe "vnoremenu ".s:Comments.'.ta&gs\ (plugin).&EMAIL s<Esc>:call C_InsertMacroValue("EMAIL")<CR>a' + exe "vnoremenu ".s:Comments.'.ta&gs\ (plugin).&PROJECT s<Esc>:call C_InsertMacroValue("PROJECT")<CR>a' + " + " + exe "amenu ".s:Comments.'.-SEP9- :' + " + exe " menu ".s:Comments.'.&date<Tab>\\cd <Esc>:call C_InsertDateAndTime("d")<CR>' + exe "imenu ".s:Comments.'.&date<Tab>\\cd <Esc>:call C_InsertDateAndTime("d")<CR>a' + exe "vmenu ".s:Comments.'.&date<Tab>\\cd s<Esc>:call C_InsertDateAndTime("d")<CR>a' + exe " menu ".s:Comments.'.date\ &time<Tab>\\ct <Esc>:call C_InsertDateAndTime("dt")<CR>' + exe "imenu ".s:Comments.'.date\ &time<Tab>\\ct <Esc>:call C_InsertDateAndTime("dt")<CR>a' + exe "vmenu ".s:Comments.'.date\ &time<Tab>\\ct s<Esc>:call C_InsertDateAndTime("dt")<CR>a' + + exe "amenu ".s:Comments.'.-SEP12- :' + exe "amenu <silent> ".s:Comments.'.\/\/\ xxx\ \ \ \ \ &->\ \ \/*\ xxx\ *\/ :call C_CommentCppToC()<CR>' + exe "vmenu <silent> ".s:Comments.'.\/\/\ xxx\ \ \ \ \ &->\ \ \/*\ xxx\ *\/ <Esc>:'."'<,'>".'call C_CommentCppToC()<CR>' + exe "amenu <silent> ".s:Comments.'.\/*\ xxx\ *\/\ \ -&>\ \ \/\/\ xxx :call C_CommentCToCpp()<CR>' + exe "vmenu <silent> ".s:Comments.'.\/*\ xxx\ *\/\ \ -&>\ \ \/\/\ xxx <Esc>:'."'<,'>".'call C_CommentCToCpp()<CR>' + " + "=============================================================================================== + "----- Menu : C-Statements------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:Statements.'.&Statements<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Statements.'.-Sep00- <Nop>' + endif + " + exe "amenu <silent>".s:Statements.'.&do\ \{\ \}\ while<Tab>\\sd :call C_InsertTemplate("statements.do-while")<CR>' + exe "vmenu <silent>".s:Statements.'.&do\ \{\ \}\ while<Tab>\\sd <Esc>:call C_InsertTemplate("statements.do-while", "v")<CR>' + exe "imenu <silent>".s:Statements.'.&do\ \{\ \}\ while<Tab>\\sd <Esc>:call C_InsertTemplate("statements.do-while")<CR>' + " + exe "amenu <silent>".s:Statements.'.f&or<Tab>\\sf :call C_InsertTemplate("statements.for")<CR>' + exe "imenu <silent>".s:Statements.'.f&or<Tab>\\sf <Esc>:call C_InsertTemplate("statements.for")<CR>' + " + exe "amenu <silent>".s:Statements.'.fo&r\ \{\ \}<Tab>\\sfo :call C_InsertTemplate("statements.for-block")<CR>' + exe "vmenu <silent>".s:Statements.'.fo&r\ \{\ \}<Tab>\\sfo <Esc>:call C_InsertTemplate("statements.for-block", "v")<CR>' + exe "imenu <silent>".s:Statements.'.fo&r\ \{\ \}<Tab>\\sfo <Esc>:call C_InsertTemplate("statements.for-block")<CR>' + " + exe "amenu <silent>".s:Statements.'.&if<Tab>\\si :call C_InsertTemplate("statements.if")<CR>' + exe "imenu <silent>".s:Statements.'.&if<Tab>\\si <Esc>:call C_InsertTemplate("statements.if")<CR>' + " + exe "amenu <silent>".s:Statements.'.i&f\ \{\ \}<Tab>\\sif :call C_InsertTemplate("statements.if-block")<CR>' + exe "vmenu <silent>".s:Statements.'.i&f\ \{\ \}<Tab>\\sif <Esc>:call C_InsertTemplate("statements.if-block", "v")<CR>' + exe "imenu <silent>".s:Statements.'.i&f\ \{\ \}<Tab>\\sif <Esc>:call C_InsertTemplate("statements.if-block")<CR>' + + exe "amenu <silent>".s:Statements.'.if\ &else<Tab>\\sie :call C_InsertTemplate("statements.if-else")<CR>' + exe "vmenu <silent>".s:Statements.'.if\ &else<Tab>\\sie <Esc>:call C_InsertTemplate("statements.if-else", "v")<CR>' + exe "imenu <silent>".s:Statements.'.if\ &else<Tab>\\sie <Esc>:call C_InsertTemplate("statements.if-else")<CR>' + " + exe "amenu <silent>".s:Statements.'.if\ \{\ \}\ e&lse\ \{\ \}<Tab>\\sife :call C_InsertTemplate("statements.if-block-else")<CR>' + exe "vmenu <silent>".s:Statements.'.if\ \{\ \}\ e&lse\ \{\ \}<Tab>\\sife <Esc>:call C_InsertTemplate("statements.if-block-else", "v")<CR>' + exe "imenu <silent>".s:Statements.'.if\ \{\ \}\ e&lse\ \{\ \}<Tab>\\sife <Esc>:call C_InsertTemplate("statements.if-block-else")<CR>' + " + exe "amenu <silent>".s:Statements.'.&else\ \{\ \}<Tab>\\se :call C_InsertTemplate("statements.else-block")<CR>' + exe "vmenu <silent>".s:Statements.'.&else\ \{\ \}<Tab>\\se <Esc>:call C_InsertTemplate("statements.else-block", "v")<CR>' + exe "imenu <silent>".s:Statements.'.&else\ \{\ \}<Tab>\\se <Esc>:call C_InsertTemplate("statements.else-block")<CR>' + " + exe "amenu <silent>".s:Statements.'.&while<Tab>\\sw :call C_InsertTemplate("statements.while")<CR>' + exe "imenu <silent>".s:Statements.'.&while<Tab>\\sw <Esc>:call C_InsertTemplate("statements.while")<CR>' + " + exe "amenu <silent>".s:Statements.'.w&hile\ \{\ \}<Tab>\\swh :call C_InsertTemplate("statements.while-block")<CR>' + exe "vmenu <silent>".s:Statements.'.w&hile\ \{\ \}<Tab>\\swh <Esc>:call C_InsertTemplate("statements.while-block", "v")<CR>' + exe "imenu <silent>".s:Statements.'.w&hile\ \{\ \}<Tab>\\swh <Esc>:call C_InsertTemplate("statements.while-block")<CR>' + " + exe "amenu <silent>".s:Statements.'.&switch\ \{\ \}<Tab>\\ss :call C_InsertTemplate("statements.switch")<CR>' + exe "vmenu <silent>".s:Statements.'.&switch\ \{\ \}<Tab>\\ss <Esc>:call C_InsertTemplate("statements.switch", "v")<CR>' + exe "imenu <silent>".s:Statements.'.&switch\ \{\ \}<Tab>\\ss <Esc>:call C_InsertTemplate("statements.switch")<CR>' + " + exe "amenu ".s:Statements.'.&case\ \.\.\.\ break<Tab>\\sc :call C_InsertTemplate("statements.case")<CR>' + exe "imenu ".s:Statements.'.&case\ \.\.\.\ break<Tab>\\sc <Esc>:call C_InsertTemplate("statements.case")<CR>' + " + " + exe "amenu <silent>".s:Statements.'.&\{\ \}<Tab>\\sb :call C_InsertTemplate("statements.block")<CR>' + exe "vmenu <silent>".s:Statements.'.&\{\ \}<Tab>\\sb <Esc>:call C_InsertTemplate("statements.block", "v")<CR>' + exe "imenu <silent>".s:Statements.'.&\{\ \}<Tab>\\sb <Esc>:call C_InsertTemplate("statements.block")<CR>' + " + " + "=============================================================================================== + "----- Menu : C-Idioms ---------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:Idioms.'.&Idioms<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Idioms.'.-Sep00- <Nop>' + endif + exe "amenu <silent> ".s:Idioms.'.&function<Tab>\\if :call C_InsertTemplate("idioms.function")<CR>' + exe "vmenu <silent> ".s:Idioms.'.&function<Tab>\\if <Esc>:call C_InsertTemplate("idioms.function", "v")<CR>' + exe "imenu <silent> ".s:Idioms.'.&function<Tab>\\if <Esc>:call C_InsertTemplate("idioms.function")<CR>' + exe "amenu <silent> ".s:Idioms.'.s&tatic\ function<Tab>\\isf :call C_InsertTemplate("idioms.function-static")<CR>' + exe "vmenu <silent> ".s:Idioms.'.s&tatic\ function<Tab>\\isf <Esc>:call C_InsertTemplate("idioms.function-static", "v")<CR>' + exe "imenu <silent> ".s:Idioms.'.s&tatic\ function<Tab>\\isf <Esc>:call C_InsertTemplate("idioms.function-static")<CR>' + exe "amenu <silent> ".s:Idioms.'.&main<Tab>\\im :call C_InsertTemplate("idioms.main")<CR>' + exe "vmenu <silent> ".s:Idioms.'.&main<Tab>\\im <Esc>:call C_InsertTemplate("idioms.main", "v")<CR>' + exe "imenu <silent> ".s:Idioms.'.&main<Tab>\\im <Esc>:call C_InsertTemplate("idioms.main")<CR>' + + exe "amenu ".s:Idioms.'.-SEP1- :' + exe "amenu ".s:Idioms.'.for(x=&0;\ x<n;\ x\+=1)<Tab>\\i0 :call C_CodeFor("up" , "a")<CR>' + exe "vmenu ".s:Idioms.'.for(x=&0;\ x<n;\ x\+=1)<Tab>\\i0 <Esc>:call C_CodeFor("up" , "v")<CR>' + exe "imenu ".s:Idioms.'.for(x=&0;\ x<n;\ x\+=1)<Tab>\\i0 <Esc>:call C_CodeFor("up" , "a")<CR>i' + exe "amenu ".s:Idioms.'.for(x=&n-1;\ x>=0;\ x\-=1)<Tab>\\in :call C_CodeFor("down", "a")<CR>' + exe "vmenu ".s:Idioms.'.for(x=&n-1;\ x>=0;\ x\-=1)<Tab>\\in <Esc>:call C_CodeFor("down", "v")<CR>' + exe "imenu ".s:Idioms.'.for(x=&n-1;\ x>=0;\ x\-=1)<Tab>\\in <Esc>:call C_CodeFor("down", "a")<CR>i' + + exe "amenu ".s:Idioms.'.-SEP2- :' + exe "amenu <silent> ".s:Idioms.'.&enum<Tab>\\ie :call C_InsertTemplate("idioms.enum")<CR>' + exe "vmenu <silent> ".s:Idioms.'.&enum<Tab>\\ie <Esc>:call C_InsertTemplate("idioms.enum" , "v")<CR>' + exe "imenu <silent> ".s:Idioms.'.&enum<Tab>\\ie <Esc>:call C_InsertTemplate("idioms.enum" )<CR>' + exe "amenu <silent> ".s:Idioms.'.&struct<Tab>\\is :call C_InsertTemplate("idioms.struct")<CR>' + exe "vmenu <silent> ".s:Idioms.'.&struct<Tab>\\is <Esc>:call C_InsertTemplate("idioms.struct", "v")<CR>' + exe "imenu <silent> ".s:Idioms.'.&struct<Tab>\\is <Esc>:call C_InsertTemplate("idioms.struct")<CR>' + exe "amenu <silent> ".s:Idioms.'.&union<Tab>\\iu :call C_InsertTemplate("idioms.union")<CR>' + exe "vmenu <silent> ".s:Idioms.'.&union<Tab>\\iu <Esc>:call C_InsertTemplate("idioms.union" , "v")<CR>' + exe "imenu <silent> ".s:Idioms.'.&union<Tab>\\iu <Esc>:call C_InsertTemplate("idioms.union" )<CR>' + exe "amenu ".s:Idioms.'.-SEP3- :' + " + exe "amenu <silent> ".s:Idioms.'.scanf<Tab>\\isc :call C_InsertTemplate("idioms.scanf")<CR>' + exe "imenu <silent> ".s:Idioms.'.scanf<Tab>\\isc <Esc>:call C_InsertTemplate("idioms.scanf")<CR>' + exe "amenu <silent> ".s:Idioms.'.printf<Tab>\\ip :call C_InsertTemplate("idioms.printf")<CR>' + exe "imenu <silent> ".s:Idioms.'.printf<Tab>\\ip <Esc>:call C_InsertTemplate("idioms.printf")<CR>' + " + exe "amenu ".s:Idioms.'.-SEP4- :' + exe "amenu <silent> ".s:Idioms.'.p=ca&lloc\(n,sizeof(type)\)<Tab>\\ica :call C_InsertTemplate("idioms.calloc")<CR>' + exe "imenu <silent> ".s:Idioms.'.p=ca&lloc\(n,sizeof(type)\)<Tab>\\ica <Esc>:call C_InsertTemplate("idioms.calloc")<CR>' + exe "amenu <silent> ".s:Idioms.'.p=m&alloc\(sizeof(type)\)<Tab>\\ima :call C_InsertTemplate("idioms.malloc")<CR>' + exe "imenu <silent> ".s:Idioms.'.p=m&alloc\(sizeof(type)\)<Tab>\\ima <Esc>:call C_InsertTemplate("idioms.malloc")<CR>' + " + exe "anoremenu <silent> ".s:Idioms.'.si&zeof(\ \)<Tab>\\isi :call C_InsertTemplate("idioms.sizeof")<CR>' + exe "inoremenu <silent> ".s:Idioms.'.si&zeof(\ \)<Tab>\\isi <Esc>:call C_InsertTemplate("idioms.sizeof")<CR>' + exe "vnoremenu <silent> ".s:Idioms.'.si&zeof(\ \)<Tab>\\isi <Esc>:call C_InsertTemplate("idioms.sizeof", "v")<CR>' + " + exe "anoremenu <silent> ".s:Idioms.'.asse&rt(\ \)<Tab>\\ias :call C_InsertTemplate("idioms.assert")<CR>' + exe "inoremenu <silent> ".s:Idioms.'.asse&rt(\ \)<Tab>\\ias <Esc>:call C_InsertTemplate("idioms.assert")<CR>' + exe "vnoremenu <silent> ".s:Idioms.'.asse&rt(\ \)<Tab>\\ias <Esc>:call C_InsertTemplate("idioms.assert", "v")<CR>' + + exe "amenu ".s:Idioms.'.-SEP5- :' + exe "amenu <silent> ".s:Idioms.'.open\ &input\ file<Tab>\\ii :call C_InsertTemplate("idioms.open-input-file")<CR>' + exe "imenu <silent> ".s:Idioms.'.open\ &input\ file<Tab>\\ii <Esc>:call C_InsertTemplate("idioms.open-input-file")<CR>' + exe "vmenu <silent> ".s:Idioms.'.open\ &input\ file<Tab>\\ii <Esc>:call C_InsertTemplate("idioms.open-input-file", "v")<CR>' + exe "amenu <silent> ".s:Idioms.'.open\ &output\ file<Tab>\\io :call C_InsertTemplate("idioms.open-output-file")<CR>' + exe "imenu <silent> ".s:Idioms.'.open\ &output\ file<Tab>\\io <Esc>:call C_InsertTemplate("idioms.open-output-file")<CR>' + exe "vmenu <silent> ".s:Idioms.'.open\ &output\ file<Tab>\\io <Esc>:call C_InsertTemplate("idioms.open-output-file", "v")<CR>' + " + exe "amenu <silent> ".s:Idioms.'.fscanf :call C_InsertTemplate("idioms.fscanf")<CR>' + exe "imenu <silent> ".s:Idioms.'.fscanf <Esc>:call C_InsertTemplate("idioms.fscanf")<CR>' + exe "amenu <silent> ".s:Idioms.'.fprintf :call C_InsertTemplate("idioms.fprintf")<CR>' + exe "imenu <silent> ".s:Idioms.'.fprintf <Esc>:call C_InsertTemplate("idioms.fprintf")<CR>' + " + "=============================================================================================== + "----- Menu : C-Preprocessor ---------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:Preprocessor.'.&Preprocessor<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Preprocessor.'.-Sep00- <Nop>' + endif + " + "----- Submenu : C-Idioms: standard library ------------------------------------------------------- + "' + exe "amenu ".s:Preprocessor.'.#include\ &Std\.Lib\.<Tab>\\ps.Std\.Lib\.<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Preprocessor.'.#include\ &Std\.Lib\.<Tab>\\ps.-Sep0- <Nop>' + call C_CIncludeMenus ( s:Preprocessor.'.#include\ &Std\.Lib\.<Tab>\\ps', s:C_StandardLibs ) + " + exe "anoremenu ".s:Preprocessor.'.#include\ C&99<Tab>\\pc.C99<Tab>C\/C\+\+ <Nop>' + exe "anoremenu ".s:Preprocessor.'.#include\ C&99<Tab>\\pc.-Sep0- <Nop>' + call C_CIncludeMenus ( s:Preprocessor.'.#include\ C&99<Tab>\\pc', s:C_C99Libs ) + " + exe "amenu ".s:Preprocessor.'.-SEP2- :' + exe "anoremenu ".s:Preprocessor.'.#include\ &\<\.\.\.\><Tab>\\p< :call C_InsertTemplate("preprocessor.include-global")<CR>' + exe "inoremenu ".s:Preprocessor.'.#include\ &\<\.\.\.\><Tab>\\p< <Esc>:call C_InsertTemplate("preprocessor.include-global")<CR>' + exe "anoremenu ".s:Preprocessor.'.#include\ &\"\.\.\.\"<Tab>\\p" :call C_InsertTemplate("preprocessor.include-local")<CR>' + exe "inoremenu ".s:Preprocessor.'.#include\ &\"\.\.\.\"<Tab>\\p" <Esc>:call C_InsertTemplate("preprocessor.include-local")<CR>' + exe "amenu ".s:Preprocessor.'.#&define<Tab>\\pd :call C_InsertTemplate("preprocessor.define")<CR>' + exe "imenu ".s:Preprocessor.'.#&define<Tab>\\pd <Esc>:call C_InsertTemplate("preprocessor.define")<CR>' + exe "amenu ".s:Preprocessor.'.&#undef<Tab>\\pu :call C_InsertTemplate("preprocessor.undefine")<CR>' + exe "imenu ".s:Preprocessor.'.&#undef<Tab>\\pu <Esc>:call C_InsertTemplate("preprocessor.undefine")<CR>' + " + exe "amenu ".s:Preprocessor.'.#&if\ #else\ #endif<Tab>\\pie :call C_InsertTemplate("preprocessor.if-else-endif")<CR>' + exe "imenu ".s:Preprocessor.'.#&if\ #else\ #endif<Tab>\\pie <Esc>:call C_InsertTemplate("preprocessor.if-else-endif")<CR>' + exe "vmenu ".s:Preprocessor.'.#&if\ #else\ #endif<Tab>\\pie <Esc>:call C_InsertTemplate("preprocessor.if-else-endif", "v")<CR>' + exe "amenu ".s:Preprocessor.'.#i&fdef\ #else\ #endif<Tab>\\pid :call C_InsertTemplate("preprocessor.ifdef-else-endif")<CR>' + exe "imenu ".s:Preprocessor.'.#i&fdef\ #else\ #endif<Tab>\\pid <Esc>:call C_InsertTemplate("preprocessor.ifdef-else-endif")<CR>' + exe "vmenu ".s:Preprocessor.'.#i&fdef\ #else\ #endif<Tab>\\pid <Esc>:call C_InsertTemplate("preprocessor.ifdef-else-endif", "v")<CR>' + exe "amenu ".s:Preprocessor.'.#if&ndef\ #else\ #endif<Tab>\\pin :call C_InsertTemplate("preprocessor.ifndef-else-endif")<CR>' + exe "imenu ".s:Preprocessor.'.#if&ndef\ #else\ #endif<Tab>\\pin <Esc>:call C_InsertTemplate("preprocessor.ifndef-else-endif")<CR>' + exe "vmenu ".s:Preprocessor.'.#if&ndef\ #else\ #endif<Tab>\\pin <Esc>:call C_InsertTemplate("preprocessor.ifndef-else-endif", "v")<CR>' + exe "amenu ".s:Preprocessor.'.#ifnd&ef\ #def\ #endif<Tab>\\pind :call C_InsertTemplate("preprocessor.ifndef-def-endif")<CR>' + exe "imenu ".s:Preprocessor.'.#ifnd&ef\ #def\ #endif<Tab>\\pind <Esc>:call C_InsertTemplate("preprocessor.ifndef-def-endif")<CR>' + exe "vmenu ".s:Preprocessor.'.#ifnd&ef\ #def\ #endif<Tab>\\pind <Esc>:call C_InsertTemplate("preprocessor.ifndef-def-endif", "v")<CR>' + + exe "amenu ".s:Preprocessor.'.#if\ &0\ #endif<Tab>\\pi0 :call C_PPIf0("a")<CR>2ji' + exe "imenu ".s:Preprocessor.'.#if\ &0\ #endif<Tab>\\pi0 <Esc>:call C_PPIf0("a")<CR>2ji' + exe "vmenu ".s:Preprocessor.'.#if\ &0\ #endif<Tab>\\pi0 <Esc>:call C_PPIf0("v")<CR>' + " + exe "amenu <silent> ".s:Preprocessor.'.&remove\ #if\ 0\ #endif<Tab>\\pr0 :call C_PPIf0Remove()<CR>' + exe "imenu <silent> ".s:Preprocessor.'.&remove\ #if\ 0\ #endif<Tab>\\pr0 <Esc>:call C_PPIf0Remove()<CR>' + " + exe "amenu ".s:Preprocessor.'.#err&or<Tab>\\pe :call C_InsertTemplate("preprocessor.error")<CR>' + exe "imenu ".s:Preprocessor.'.#err&or<Tab>\\pe <C-C>:call C_InsertTemplate("preprocessor.error")<CR>' + exe "amenu ".s:Preprocessor.'.#&line<Tab>\\pl :call C_InsertTemplate("preprocessor.line")<CR>' + exe "imenu ".s:Preprocessor.'.#&line<Tab>\\pl <C-C>:call C_InsertTemplate("preprocessor.line")<CR>' + exe "amenu ".s:Preprocessor.'.#&pragma<Tab>\\pp :call C_InsertTemplate("preprocessor.pragma")<CR>' + exe "imenu ".s:Preprocessor.'.#&pragma<Tab>\\pp <C-C>:call C_InsertTemplate("preprocessor.pragma")<CR>' + " + "=============================================================================================== + "----- Menu : Snippets ---------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:Snippets.'.S&nippets<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Snippets.'.-Sep00- <Nop>' + endif + if s:C_CodeSnippets != "" + exe "amenu <silent> ".s:Snippets.'.&read\ code\ snippet<Tab>\\nr :call C_CodeSnippet("r")<CR>' + exe "imenu <silent> ".s:Snippets.'.&read\ code\ snippet<Tab>\\nr <C-C>:call C_CodeSnippet("r")<CR>' + exe "amenu <silent> ".s:Snippets.'.&write\ code\ snippet<Tab>\\nw :call C_CodeSnippet("w")<CR>' + exe "imenu <silent> ".s:Snippets.'.&write\ code\ snippet<Tab>\\nw <C-C>:call C_CodeSnippet("w")<CR>' + exe "vmenu <silent> ".s:Snippets.'.&write\ code\ snippet<Tab>\\nw <C-C>:call C_CodeSnippet("wv")<CR>' + exe "amenu <silent> ".s:Snippets.'.&edit\ code\ snippet<Tab>\\ne :call C_CodeSnippet("e")<CR>' + exe "imenu <silent> ".s:Snippets.'.&edit\ code\ snippet<Tab>\\ne <C-C>:call C_CodeSnippet("e")<CR>' + exe " menu <silent> ".s:Snippets.'.-SEP1- :' + endif + exe " menu <silent> ".s:Snippets.'.&pick\ up\ prototype<Tab>\\np :call C_ProtoPick("n")<CR>' + exe "imenu <silent> ".s:Snippets.'.&pick\ up\ prototype<Tab>\\np <C-C>:call C_ProtoPick("n")<CR>' + exe "vmenu <silent> ".s:Snippets.'.&pick\ up\ prototype<Tab>\\np <C-C>:call C_ProtoPick("v")<CR>' + exe " menu <silent> ".s:Snippets.'.&insert\ prototype(s)<Tab>\\ni :call C_ProtoInsert()<CR>' + exe "imenu <silent> ".s:Snippets.'.&insert\ prototype(s)<Tab>\\ni <C-C>:call C_ProtoInsert()<CR>' + exe " menu <silent> ".s:Snippets.'.&clear\ prototype(s)<Tab>\\nc :call C_ProtoClear()<CR>' + exe "imenu <silent> ".s:Snippets.'.&clear\ prototype(s)<Tab>\\nc <C-C>:call C_ProtoClear()<CR>' + exe " menu <silent> ".s:Snippets.'.&show\ prototype(s)<Tab>\\ns :call C_ProtoShow()<CR>' + exe "imenu <silent> ".s:Snippets.'.&show\ prototype(s)<Tab>\\ns <C-C>:call C_ProtoShow()<CR>' + + exe " menu <silent> ".s:Snippets.'.-SEP2- :' + exe "amenu <silent> ".s:Snippets.'.edit\ &local\ templates<Tab>\\ntl :call C_EditTemplates("local")<CR>' + exe "imenu <silent> ".s:Snippets.'.edit\ &local\ templates<Tab>\\ntl <C-C>:call C_EditTemplates("local")<CR>' + exe "amenu <silent> ".s:Snippets.'.edit\ &global\ templates<Tab>\\ntg :call C_EditTemplates("global")<CR>' + exe "imenu <silent> ".s:Snippets.'.edit\ &global\ templates<Tab>\\ntg <C-C>:call C_EditTemplates("global")<CR>' + exe "amenu <silent> ".s:Snippets.'.reread\ &templates<Tab>\\ntr :call C_RereadTemplates()<CR>' + exe "imenu <silent> ".s:Snippets.'.reread\ &templates<Tab>\\ntr <C-C>:call C_RereadTemplates()<CR>' + exe "amenu ".s:Snippets.'.switch\ template\ st&yle<Tab>\\nts :CStyle<Space>' + exe "imenu ".s:Snippets.'.switch\ template\ st&yle<Tab>\\nts <C-C>:CStyle<Space>' + " + "=============================================================================================== + "----- Menu : C++ --------------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:Cpp.'.C&\+\+<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.-Sep00- <Nop>' + endif + exe "anoremenu ".s:Cpp.'.c&in :call C_InsertTemplate("cpp.cin")<CR>' + exe "inoremenu ".s:Cpp.'.c&in <Esc>:call C_InsertTemplate("cpp.cin")<CR>' + exe "anoremenu ".s:Cpp.'.c&out<Tab>\\+co :call C_InsertTemplate("cpp.cout")<CR>' + exe "inoremenu ".s:Cpp.'.c&out<Tab>\\+co <Esc>:call C_InsertTemplate("cpp.cout")<CR>' + exe "anoremenu ".s:Cpp.'.<<\ &\"\" :call C_InsertTemplate("cpp.cout-operator")<CR>' + exe "inoremenu ".s:Cpp.'.<<\ &\"\" <Esc>:call C_InsertTemplate("cpp.cout-operator")<CR>' + " + "----- Submenu : C++ : output manipulators ------------------------------------------------------- + " + exe "amenu ".s:Cpp.'.&output\ manipulators.output\ manip\.<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.&output\ manipulators.-Sep0- <Nop>' + " + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &boolalpha :call C_InsertTemplate("cpp.output-manipulator-boolalpha")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &dec :call C_InsertTemplate("cpp.output-manipulator-dec")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &endl :call C_InsertTemplate("cpp.output-manipulator-endl")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &fixed :call C_InsertTemplate("cpp.output-manipulator-fixed")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ fl&ush :call C_InsertTemplate("cpp.output-manipulator-flush")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &hex :call C_InsertTemplate("cpp.output-manipulator-hex")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &internal :call C_InsertTemplate("cpp.output-manipulator-internal")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &left :call C_InsertTemplate("cpp.output-manipulator-left")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &oct :call C_InsertTemplate("cpp.output-manipulator-oct")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &right :call C_InsertTemplate("cpp.output-manipulator-right")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ s&cientific :call C_InsertTemplate("cpp.output-manipulator-scientific")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &setbase\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setbase")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ se&tfill\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setfill")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ setiosfla&g\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setiosflags")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ set&precision\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setprecision")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ set&w\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setw")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ showb&ase :call C_InsertTemplate("cpp.output-manipulator-showbase")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ showpoi&nt :call C_InsertTemplate("cpp.output-manipulator-showpoint")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ showpos\ \(&1\) :call C_InsertTemplate("cpp.output-manipulator-showpos")<CR>' + exe "anoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ uppercase\ \(&2\) :call C_InsertTemplate("cpp.output-manipulator-uppercase")<CR>' + " + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &boolalpha <Esc>:call C_InsertTemplate("cpp.output-manipulator-boolalpha")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &dec <Esc>:call C_InsertTemplate("cpp.output-manipulator-dec")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &endl <Esc>:call C_InsertTemplate("cpp.output-manipulator-endl")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &fixed <Esc>:call C_InsertTemplate("cpp.output-manipulator-fixed")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ fl&ush <Esc>:call C_InsertTemplate("cpp.output-manipulator-flush")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &hex <Esc>:call C_InsertTemplate("cpp.output-manipulator-hex")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &internal <Esc>:call C_InsertTemplate("cpp.output-manipulator-internal")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &left <Esc>:call C_InsertTemplate("cpp.output-manipulator-left")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &oct <Esc>:call C_InsertTemplate("cpp.output-manipulator-oct")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &right <Esc>:call C_InsertTemplate("cpp.output-manipulator-right")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ s&cientific <Esc>:call C_InsertTemplate("cpp.output-manipulator-scientific")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ &setbase\(\ \) <Esc>:call C_InsertTemplate("cpp.output-manipulator-setbase")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ se&tfill\(\ \) <Esc>:call C_InsertTemplate("cpp.output-manipulator-setfill")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ setiosfla&g\(\ \) <Esc>:call C_InsertTemplate("cpp.output-manipulator-setiosflags")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ set&precision\(\ \) <Esc>:call C_InsertTemplate("cpp.output-manipulator-setprecision")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ set&w\(\ \) <Esc>:call C_InsertTemplate("cpp.output-manipulator-setw")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ showb&ase <Esc>:call C_InsertTemplate("cpp.output-manipulator-showbase")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ showpoi&nt <Esc>:call C_InsertTemplate("cpp.output-manipulator-showpoint")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ showpos\ \(&1\) <Esc>:call C_InsertTemplate("cpp.output-manipulator-showpos")<CR>' + exe "inoremenu ".s:Cpp.'.&output\ manipulators.\<\<\ uppercase\ \(&2\) <Esc>:call C_InsertTemplate("cpp.output-manipulator-uppercase")<CR>' + " + "----- Submenu : C++ : ios flag bits ------------------------------------------------------------- + " + exe "amenu ".s:Cpp.'.ios\ flag&bits.ios\ flags<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.ios\ flag&bits.-Sep0- <Nop>' + " + call C_CIosFlagMenus ( s:Cpp.'.ios\ flag&bits', s:Cpp_IosFlagBits ) + " + "----- Submenu : C++ library (algorithm - locale) ---------------------------------------------- + " + exe "amenu ".s:Cpp.'.&#include\ <alg\.\.vec><Tab>\\+ps.alg\.\.vec<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.&#include\ <alg\.\.vec><Tab>\\+ps.-Sep0- <Nop>' + call C_CIncludeMenus ( s:Cpp.'.&#include\ <alg\.\.vec><Tab>\\+ps', s:Cpp_StandardLibs ) + " + "----- Submenu : C library (cassert - ctime) ------------------------------------------------- + " + exe "amenu ".s:Cpp.'.&#include\ <cX><Tab>\\+pc.cX<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.&#include\ <cX><Tab>\\+pc.-Sep0- <Nop>' + call C_CIncludeMenus ( s:Cpp.'.&#include\ <cX><Tab>\\+pc', s:Cpp_CStandardLibs ) + " + "----- End Submenu : C library (cassert - ctime) --------------------------------------------- + " + exe "amenu <silent> ".s:Cpp.'.-SEP2- :' + + exe "amenu <silent> ".s:Cpp.'.&class<Tab>\\+c :call C_InsertTemplate("cpp.class-definition")<CR>' + exe "imenu <silent> ".s:Cpp.'.&class<Tab>\\+c <Esc>:call C_InsertTemplate("cpp.class-definition")<CR>' + exe "amenu <silent> ".s:Cpp.'.class\ (w\.\ &new)<Tab>\\+cn :call C_InsertTemplate("cpp.class-using-new-definition")<CR>' + exe "imenu <silent> ".s:Cpp.'.class\ (w\.\ &new)<Tab>\\+cn <Esc>:call C_InsertTemplate("cpp.class-using-new-definition")<CR>' + exe "amenu <silent> ".s:Cpp.'.&templ\.\ class<Tab>\\+tc :call C_InsertTemplate("cpp.template-class-definition")<CR>' + exe "imenu <silent> ".s:Cpp.'.&templ\.\ class<Tab>\\+tc <Esc>:call C_InsertTemplate("cpp.template-class-definition")<CR>' + exe "amenu <silent> ".s:Cpp.'.templ\.\ class\ (w\.\ ne&w)<Tab>\\+tcn :call C_InsertTemplate("cpp.template-class-using-new-definition")<CR>' + exe "imenu <silent> ".s:Cpp.'.templ\.\ class\ (w\.\ ne&w)<Tab>\\+tcn <Esc>:call C_InsertTemplate("cpp.template-class-using-new-definition")<CR>' + + " + "----- Submenu : C++ : IMPLEMENTATION ------------------------------------------------------- + " + exe "amenu ".s:Cpp.'.IM&PLEMENTATION.IMPLEMENT\.<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.IM&PLEMENTATION.-Sep0- <Nop>' + " + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&class<Tab>\\+ci :call C_InsertTemplate("cpp.class-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&class<Tab>\\+ci <Esc>:call C_InsertTemplate("cpp.class-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.class\ (w\.\ &new)<Tab>\\+cni :call C_InsertTemplate("cpp.class-using-new-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.class\ (w\.\ &new)<Tab>\\+cni <Esc>:call C_InsertTemplate("cpp.class-using-new-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&method<Tab>\\+mi :call C_InsertTemplate("cpp.method-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&method<Tab>\\+mi <Esc>:call C_InsertTemplate("cpp.method-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&accessor<Tab>\\+ai :call C_InsertTemplate("cpp.accessor-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&accessor<Tab>\\+ai <Esc>:call C_InsertTemplate("cpp.accessor-implementation")<CR>' + " + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.-SEP21- :' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&templ\.\ class<Tab>\\+tci <Esc>:call C_InsertTemplate("cpp.template-class-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.&templ\.\ class<Tab>\\+tci :call C_InsertTemplate("cpp.template-class-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.templ\.\ class\ (w\.\ ne&w)<Tab>\\+tcni <Esc>:call C_InsertTemplate("cpp.template-class-using-new-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.templ\.\ class\ (w\.\ ne&w)<Tab>\\+tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.templ\.\ mðod<Tab>\\+tmi :call C_InsertTemplate("cpp.template-method-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.templ\.\ mðod<Tab>\\+tmi <Esc>:call C_InsertTemplate("cpp.template-method-implementation")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.templ\.\ a&ccessor<Tab>\\+tai :call C_InsertTemplate("cpp.template-accessor-implementation")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.templ\.\ a&ccessor<Tab>\\+tai <Esc>:call C_InsertTemplate("cpp.template-accessor-implementation")<CR>' + " + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.-SEP22- :' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.operator\ &<< :call C_InsertTemplate("cpp.operator-in")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.operator\ &<< <Esc>:call C_InsertTemplate("cpp.operator-in")<CR>' + exe "amenu <silent> ".s:Cpp.'.IM&PLEMENTATION.operator\ &>> :call C_InsertTemplate("cpp.operator-out")<CR>' + exe "imenu <silent> ".s:Cpp.'.IM&PLEMENTATION.operator\ &>> <Esc>:call C_InsertTemplate("cpp.operator-out")<CR>' + " + "----- End Submenu : C++ : IMPLEMENTATION ------------------------------------------------------- + " + exe "amenu <silent> ".s:Cpp.'.-SEP31- :' + exe "amenu <silent> ".s:Cpp.'.templ\.\ &function<Tab>\\+tf :call C_InsertTemplate("cpp.template-function")<CR>' + exe "imenu <silent> ".s:Cpp.'.templ\.\ &function<Tab>\\+tf <Esc>:call C_InsertTemplate("cpp.template-function")<CR>' + exe "amenu <silent> ".s:Cpp.'.&error\ class<Tab>\\+ec :call C_InsertTemplate("cpp.error-class")<CR>' + exe "imenu <silent> ".s:Cpp.'.&error\ class<Tab>\\+ec <Esc>:call C_InsertTemplate("cpp.error-class")<CR>' + + exe "amenu <silent> ".s:Cpp.'.-SEP5- :' + exe "amenu <silent> ".s:Cpp.'.tr&y\ \.\.\ catch<Tab>\\+tr :call C_InsertTemplate("cpp.try-catch")<CR>' + exe "imenu <silent> ".s:Cpp.'.tr&y\ \.\.\ catch<Tab>\\+tr <Esc>:call C_InsertTemplate("cpp.try-catch")<CR>' + exe "vmenu <silent> ".s:Cpp.'.tr&y\ \.\.\ catch<Tab>\\+tr <Esc>:call C_InsertTemplate("cpp.try-catch", "v")<CR>' + exe "amenu <silent> ".s:Cpp.'.catc&h<Tab>\\+ca :call C_InsertTemplate("cpp.catch")<CR>' + exe "imenu <silent> ".s:Cpp.'.catc&h<Tab>\\+ca <Esc>:call C_InsertTemplate("cpp.catch")<CR>' + exe "vmenu <silent> ".s:Cpp.'.catc&h<Tab>\\+ca <Esc>:call C_InsertTemplate("cpp.catch", "v")<CR>' + + exe "amenu <silent> ".s:Cpp.'.catch\(&\.\.\.\)<Tab>\\+c\. :call C_InsertTemplate("cpp.catch-points")<CR>' + exe "imenu <silent> ".s:Cpp.'.catch\(&\.\.\.\)<Tab>\\+c\. <Esc>:call C_InsertTemplate("cpp.catch-points")<CR>' + exe "vmenu <silent> ".s:Cpp.'.catch\(&\.\.\.\)<Tab>\\+c\. <Esc>:call C_InsertTemplate("cpp.catch-points", "v")<CR>' + + exe "amenu <silent> ".s:Cpp.'.-SEP6- :' + exe "amenu <silent> ".s:Cpp.'.open\ input\ file\ \ \(&4\) :call C_InsertTemplate("cpp.open-input-file")<CR>' + exe "imenu <silent> ".s:Cpp.'.open\ input\ file\ \ \(&4\) <Esc>:call C_InsertTemplate("cpp.open-input-file")<CR>' + exe "vmenu <silent> ".s:Cpp.'.open\ input\ file\ \ \(&4\) <Esc>:call C_InsertTemplate("cpp.open-input-file", "v")<CR>' + exe "amenu <silent> ".s:Cpp.'.open\ output\ file\ \(&5\) :call C_InsertTemplate("cpp.open-output-file")<CR>' + exe "imenu <silent> ".s:Cpp.'.open\ output\ file\ \(&5\) <Esc>:call C_InsertTemplate("cpp.open-output-file")<CR>' + exe "vmenu <silent> ".s:Cpp.'.open\ output\ file\ \(&5\) <Esc>:call C_InsertTemplate("cpp.open-output-file", "v")<CR>' + exe "amenu <silent> ".s:Cpp.'.-SEP7- :' + + exe "amenu <silent> ".s:Cpp.'.&using\ namespace\ std; :call C_InsertTemplate("cpp.namespace-std")<CR>' + exe "imenu <silent> ".s:Cpp.'.&using\ namespace\ std; <Esc>:call C_InsertTemplate("cpp.namespace-std")<CR>' + exe "amenu <silent> ".s:Cpp.'.u&sing\ namespace\ ???; :call C_InsertTemplate("cpp.namespace")<CR>' + exe "imenu <silent> ".s:Cpp.'.u&sing\ namespace\ ???; <Esc>:call C_InsertTemplate("cpp.namespace")<CR>' + + exe "amenu <silent> ".s:Cpp.'.names&pace\ ???\ \{\ \} :call C_InsertTemplate("cpp.namespace-block")<CR>' + exe "imenu <silent> ".s:Cpp.'.names&pace\ ???\ \{\ \} <Esc>:call C_InsertTemplate("cpp.namespace-block")<CR>' + exe "vmenu <silent> ".s:Cpp.'.names&pace\ ???\ \{\ \} <Esc>:call C_InsertTemplate("cpp.namespace-block", "v")<CR>' + exe "amenu <silent> ".s:Cpp.'.namespace\ &alias\ =\ ??? :call C_InsertTemplate("cpp.namespace-alias")<CR>' + exe "imenu <silent> ".s:Cpp.'.namespace\ &alias\ =\ ??? <Esc>:call C_InsertTemplate("cpp.namespace-alias")<CR>' + + exe "amenu <silent> ".s:Cpp.'.-SEP8- :' + " + "----- Submenu : RTTI ---------------------------------------------------------------------------- + " + exe "amenu ".s:Cpp.'.&RTTI.RTTI<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Cpp.'.&RTTI.-Sep0- <Nop>' + " + exe "anoremenu ".s:Cpp.'.&RTTI.&typeid :call C_InsertTemplate("cpp.rtti-typeid")<CR>' + exe "anoremenu ".s:Cpp.'.&RTTI.&static_cast :call C_InsertTemplate("cpp.rtti-static-cast")<CR>' + exe "anoremenu ".s:Cpp.'.&RTTI.&const_cast :call C_InsertTemplate("cpp.rtti-const-cast")<CR>' + exe "anoremenu ".s:Cpp.'.&RTTI.&reinterpret_cast :call C_InsertTemplate("cpp.rtti-reinterpret-cast")<CR>' + exe "anoremenu ".s:Cpp.'.&RTTI.&dynamic_cast :call C_InsertTemplate("cpp.rtti-dynamic-cast")<CR>' + " + exe "inoremenu ".s:Cpp.'.&RTTI.&typeid <Esc>:call C_InsertTemplate("cpp.rtti-typeid")<CR>' + exe "inoremenu ".s:Cpp.'.&RTTI.&static_cast <Esc>:call C_InsertTemplate("cpp.rtti-static-cast")<CR>' + exe "inoremenu ".s:Cpp.'.&RTTI.&const_cast <Esc>:call C_InsertTemplate("cpp.rtti-const-cast")<CR>' + exe "inoremenu ".s:Cpp.'.&RTTI.&reinterpret_cast <Esc>:call C_InsertTemplate("cpp.rtti-reinterpret-cast")<CR>' + exe "inoremenu ".s:Cpp.'.&RTTI.&dynamic_cast <Esc>:call C_InsertTemplate("cpp.rtti-dynamic-cast")<CR>' + " + exe "vnoremenu ".s:Cpp.'.&RTTI.&typeid <Esc>:call C_InsertTemplate("cpp.rtti-typeid", "v")<CR>' + exe "vnoremenu ".s:Cpp.'.&RTTI.&static_cast <Esc>:call C_InsertTemplate("cpp.rtti-static-cast", "v")<CR>' + exe "vnoremenu ".s:Cpp.'.&RTTI.&const_cast <Esc>:call C_InsertTemplate("cpp.rtti-const-cast", "v")<CR>' + exe "vnoremenu ".s:Cpp.'.&RTTI.&reinterpret_cast <Esc>:call C_InsertTemplate("cpp.rtti-reinterpret-cast", "v")<CR>' + exe "vnoremenu ".s:Cpp.'.&RTTI.&dynamic_cast <Esc>:call C_InsertTemplate("cpp.rtti-dynamic-cast", "v")<CR>' + " + "----- End Submenu : RTTI ------------------------------------------------------------------------ + " + exe "amenu <silent>".s:Cpp.'.e&xtern\ \"C\"\ \{\ \} :call C_InsertTemplate("cpp.extern")<CR>' + exe "imenu <silent>".s:Cpp.'.e&xtern\ \"C\"\ \{\ \} <Esc>:call C_InsertTemplate("cpp.extern")<CR>' + exe "vmenu <silent>".s:Cpp.'.e&xtern\ \"C\"\ \{\ \} <Esc>:call C_InsertTemplate("cpp.extern", "v")<CR>' + " + "=============================================================================================== + "----- Menu : run ----- -------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_MenuHeader == 'yes' + exe "amenu ".s:Run.'.&Run<Tab>C\/C\+\+ <Nop>' + exe "amenu ".s:Run.'.-Sep00- <Nop>' + endif + " + exe "amenu <silent> ".s:Run.'.save\ and\ &compile<Tab>\\rc\ \ \<A-F9\> :call C_Compile()<CR>:call C_HlMessage()<CR>' + exe "imenu <silent> ".s:Run.'.save\ and\ &compile<Tab>\\rc\ \ \<A-F9\> <C-C>:call C_Compile()<CR>:call C_HlMessage()<CR>' + exe "amenu <silent> ".s:Run.'.&link<Tab>\\rl\ \ \ \ \<F9\> :call C_Link()<CR>:call C_HlMessage()<CR>' + exe "imenu <silent> ".s:Run.'.&link<Tab>\\rl\ \ \ \ \<F9\> <C-C>:call C_Link()<CR>:call C_HlMessage()<CR>' + exe "amenu <silent> ".s:Run.'.&run<Tab>\\rr\ \ \<C-F9\> :call C_Run()<CR>' + exe "imenu <silent> ".s:Run.'.&run<Tab>\\rr\ \ \<C-F9\> <C-C>:call C_Run()<CR>' + exe "amenu <silent> ".s:Run.'.cmd\.\ line\ &arg\.<Tab>\\ra\ \ \<S-F9\> :call C_Arguments()<CR>' + exe "imenu <silent> ".s:Run.'.cmd\.\ line\ &arg\.<Tab>\\ra\ \ \<S-F9\> <C-C>:call C_Arguments()<CR>' + " + exe "amenu <silent> ".s:Run.'.-SEP0- :' + exe "amenu <silent> ".s:Run.'.&make<Tab>\\rm :call C_Make()<CR>' + exe "imenu <silent> ".s:Run.'.&make<Tab>\\rm <C-C>:call C_Make()<CR>' + exe "amenu <silent> ".s:Run.'.cmd\.\ line\ ar&g\.\ for\ make<Tab>\\rg :call C_MakeArguments()<CR>' + exe "imenu <silent> ".s:Run.'.cmd\.\ line\ ar&g\.\ for\ make<Tab>\\rg <C-C>:call C_MakeArguments()<CR>' + " + exe "amenu <silent> ".s:Run.'.-SEP1- :' + " + if s:C_SplintIsExecutable==1 + exe "amenu <silent> ".s:Run.'.s&plint<Tab>\\rp :call C_SplintCheck()<CR>:call C_HlMessage()<CR>' + exe "imenu <silent> ".s:Run.'.s&plint<Tab>\\rp <C-C>:call C_SplintCheck()<CR>:call C_HlMessage()<CR>' + exe "amenu <silent> ".s:Run.'.cmd\.\ line\ arg\.\ for\ spl&int<Tab>\\ri :call C_SplintArguments()<CR>' + exe "imenu <silent> ".s:Run.'.cmd\.\ line\ arg\.\ for\ spl&int<Tab>\\ri <C-C>:call C_SplintArguments()<CR>' + exe "amenu <silent> ".s:Run.'.-SEP2- :' + endif + " + if s:C_CodeCheckIsExecutable==1 + exe "amenu <silent> ".s:Run.'.CodeChec&k<Tab>\\rk :call C_CodeCheck()<CR>:call C_HlMessage()<CR>' + exe "imenu <silent> ".s:Run.'.CodeChec&k<Tab>\\rk <C-C>:call C_CodeCheck()<CR>:call C_HlMessage()<CR>' + exe "amenu <silent> ".s:Run.'.cmd\.\ line\ arg\.\ for\ Cod&eCheck<Tab>\\re :call C_CodeCheckArguments()<CR>' + exe "imenu <silent> ".s:Run.'.cmd\.\ line\ arg\.\ for\ Cod&eCheck<Tab>\\re <C-C>:call C_CodeCheckArguments()<CR>' + exe "amenu <silent> ".s:Run.'.-SEP3- :' + endif + " + exe "amenu <silent> ".s:Run.'.in&dent<Tab>\\rd :call C_Indent()<CR>' + exe "imenu <silent> ".s:Run.'.in&dent<Tab>\\rd <C-C>:call C_Indent()<CR>' + if s:MSWIN + exe "amenu <silent> ".s:Run.'.&hardcopy\ to\ printer<Tab>\\rh :call C_Hardcopy("n")<CR>' + exe "imenu <silent> ".s:Run.'.&hardcopy\ to\ printer<Tab>\\rh <C-C>:call C_Hardcopy("n")<CR>' + exe "vmenu <silent> ".s:Run.'.&hardcopy\ to\ printer<Tab>\\rh <C-C>:call C_Hardcopy("v")<CR>' + else + exe "amenu <silent> ".s:Run.'.&hardcopy\ to\ FILENAME\.ps<Tab>\\rh :call C_Hardcopy("n")<CR>' + exe "imenu <silent> ".s:Run.'.&hardcopy\ to\ FILENAME\.ps<Tab>\\rh <C-C>:call C_Hardcopy("n")<CR>' + exe "vmenu <silent> ".s:Run.'.&hardcopy\ to\ FILENAME\.ps<Tab>\\rh <C-C>:call C_Hardcopy("v")<CR>' + endif + exe "imenu <silent> ".s:Run.'.-SEP4- :' + + exe "amenu <silent> ".s:Run.'.&settings<Tab>\\rs :call C_Settings()<CR>' + exe "imenu <silent> ".s:Run.'.&settings<Tab>\\rs <C-C>:call C_Settings()<CR>' + exe "imenu <silent> ".s:Run.'.-SEP5- :' + + if !s:MSWIN + exe "amenu <silent> ".s:Run.'.&xterm\ size<Tab>\\rx :call C_XtermSize()<CR>' + exe "imenu <silent> ".s:Run.'.&xterm\ size<Tab>\\rx <C-C>:call C_XtermSize()<CR>' + endif + if s:C_OutputGvim == "vim" + exe "amenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm<Tab>\\ro :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm<Tab>\\ro <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + else + if s:C_OutputGvim == "buffer" + exe "amenu <silent> ".s:Run.'.&output:\ BUFFER->xterm->vim<Tab>\\ro :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ BUFFER->xterm->vim<Tab>\\ro <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + else + exe "amenu <silent> ".s:Run.'.&output:\ XTERM->vim->buffer<Tab>\\ro :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ XTERM->vim->buffer<Tab>\\ro <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + endif + endif + " + "=============================================================================================== + "----- Menu : help ------------------------------------------------------- {{{2 + "=============================================================================================== + " + if s:C_Root != "" + exe " menu <silent> ".s:C_Root.'&help\ (C-Support)<Tab>\\hp :call C_HelpCsupport()<CR>' + exe "imenu <silent> ".s:C_Root.'&help\ (C-Support)<Tab>\\hp <C-C>:call C_HelpCsupport()<CR>' + exe " menu <silent> ".s:C_Root.'show\ &manual<Tab>\\hm :call C_Help("m")<CR>' + exe "imenu <silent> ".s:C_Root.'show\ &manual<Tab>\\hm <C-C>:call C_Help("m")<CR>' + endif + +endfunction " ---------- end of function C_InitMenus ---------- +" +"=============================================================================================== +"----- Menu Functions -------------------------------------------------------------------------- +"=============================================================================================== +" +let s:C_StandardLibs = [ + \ '&assert\.h' , '&ctype\.h' , '&errno\.h' , + \ '&float\.h' , '&limits\.h' , 'l&ocale\.h' , + \ '&math\.h' , 'set&jmp\.h' , 's&ignal\.h' , + \ 'stdar&g\.h' , 'st&ddef\.h' , '&stdio\.h' , + \ 'stdli&b\.h' , 'st&ring\.h' , '&time\.h' , + \ ] +" +let s:C_C99Libs = [ + \ '&complex\.h', '&fenv\.h', '&inttypes\.h', + \ 'is&o646\.h', '&stdbool\.h', 's&tdint\.h', + \ 'tg&math\.h', '&wchar\.h', 'wct&ype\.h', + \ ] +" +let s:Cpp_StandardLibs = [ + \ '&algorithm', '&bitset', '&complex', '&deque', + \ '&exception', '&fstream', 'f&unctional', 'iomani&p', + \ '&ios', 'iosf&wd', 'io&stream', 'istrea&m', + \ 'iterato&r', '&limits', 'lis&t', 'l&ocale', + \ '&map', 'memor&y', '&new', 'numeri&c', + \ '&ostream', '&queue', '&set', 'sst&ream', + \ 'st&ack', 'stde&xcept', 'stream&buf', 'str&ing', + \ '&typeinfo', '&utility', '&valarray', 'v&ector', + \ ] +" +let s:Cpp_CStandardLibs = [ + \ 'c&assert', 'c&ctype', 'c&errno', 'c&float', + \ 'c&limits', 'cl&ocale', 'c&math', 'cset&jmp', + \ 'cs&ignal', 'cstdar&g', 'cst&ddef', 'c&stdio', + \ 'cstdli&b', 'cst&ring', 'c&time', + \ ] + +let s:Cpp_IosFlagBits = [ + \ 'ios::&adjustfield', 'ios::bas&efield', 'ios::&boolalpha', + \ 'ios::&dec', 'ios::&fixed', 'ios::floa&tfield', + \ 'ios::&hex', 'ios::&internal', 'ios::&left', + \ 'ios::&oct', 'ios::&right', 'ios::s&cientific', + \ 'ios::sho&wbase', 'ios::showpoint\ \(&1\)', 'ios::show&pos', + \ 'ios::&skipws', 'ios::u&nitbuf', 'ios::&uppercase', + \ ] + +"------------------------------------------------------------------------------ +" C_CIncludeMenus: generate the C/C++-standard library menu entries {{{1 +"------------------------------------------------------------------------------ +function! C_CIncludeMenus ( menupath, liblist ) + for item in a:liblist + let replacement = substitute( item, '[&\\]*', '','g' ) + exe "anoremenu ".a:menupath.'.'.item.' o#include<Tab><'.replacement.'>' + exe "inoremenu ".a:menupath.'.'.item.' <Esc>o#include<Tab><'.replacement.'>' + endfor + return +endfunction " ---------- end of function C_CIncludeMenus ---------- + +"------------------------------------------------------------------------------ +" C_CIosFlagMenus: generate the C++ ios flags menu entries {{{1 +"------------------------------------------------------------------------------ +function! C_CIosFlagMenus ( menupath, flaglist ) + for item in a:flaglist + let replacement = substitute( item, '[^[:alpha:]:]', '','g' ) + exe " noremenu ".a:menupath.'.'.item.' i'.replacement + exe "inoremenu ".a:menupath.'.'.item.' '.replacement + endfor + return +endfunction " ---------- end of function C_CIosFlagMenus ---------- +" +"------------------------------------------------------------------------------ +" C_Input: Input after a highlighted prompt {{{1 +"------------------------------------------------------------------------------ +function! C_Input ( promp, text, ... ) + echohl Search " highlight prompt + call inputsave() " preserve typeahead + if a:0 == 0 || a:1 == '' + let retval =input( a:promp, a:text ) + else + let retval =input( a:promp, a:text, a:1 ) + endif + call inputrestore() " restore typeahead + echohl None " reset highlighting + let retval = substitute( retval, '^\s\+', "", "" ) " remove leading whitespaces + let retval = substitute( retval, '\s\+$', "", "" ) " remove trailing whitespaces + return retval +endfunction " ---------- end of function C_Input ---------- +" +"------------------------------------------------------------------------------ +" C_AdjustLineEndComm: adjust line-end comments {{{1 +"------------------------------------------------------------------------------ +" +" C comment or C++ comment: +let s:c_cppcomment= '\(\/\*.\{-}\*\/\|\/\/.*$\)' + +function! C_AdjustLineEndComm ( mode ) range + " + if !exists("b:C_LineEndCommentColumn") + let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault + endif + + let save_cursor = getpos(".") + + let save_expandtab = &expandtab + exe ":set expandtab" + + if a:mode == 'v' + let pos0 = line("'<") + let pos1 = line("'>") + else + let pos0 = line(".") + let pos1 = pos0 + endif + + let linenumber = pos0 + exe ":".pos0 + + while linenumber <= pos1 + let line= getline(".") + + " line is not a pure comment but contains one + " + if match( line, '^\s*'.s:c_cppcomment ) < 0 && match( line, s:c_cppcomment ) > 0 + " + " disregard comments starting in a string + " + let idx1 = -1 + let idx2 = -1 + let commentstart= -2 + let commentend = 0 + while commentstart < idx2 && idx2 < commentend + let start = commentend + let idx2 = match( line, s:c_cppcomment, start ) + let commentstart= match ( line, '"[^"]\+"', start ) + let commentend = matchend( line, '"[^"]\+"', start ) + endwhile + " + " try to adjust the comment + " + let idx1 = 1 + match( line, '\s*'.s:c_cppcomment, start ) + let idx2 = 1 + idx2 + call setpos(".", [ 0, linenumber, idx1, 0 ] ) + let vpos1 = virtcol(".") + call setpos(".", [ 0, linenumber, idx2, 0 ] ) + let vpos2 = virtcol(".") + + if ! ( vpos2 == b:C_LineEndCommentColumn + \ || vpos1 > b:C_LineEndCommentColumn + \ || idx2 == 0 ) + + exe ":.,.retab" + " insert some spaces + if vpos2 < b:C_LineEndCommentColumn + let diff = b:C_LineEndCommentColumn-vpos2 + call setpos(".", [ 0, linenumber, vpos2, 0 ] ) + let @" = ' ' + exe "normal ".diff."P" + endif + + " remove some spaces + if vpos1 < b:C_LineEndCommentColumn && vpos2 > b:C_LineEndCommentColumn + let diff = vpos2 - b:C_LineEndCommentColumn + call setpos(".", [ 0, linenumber, b:C_LineEndCommentColumn, 0 ] ) + exe "normal ".diff."x" + endif + + endif + endif + let linenumber=linenumber+1 + normal j + endwhile + " + " restore tab expansion settings and cursor position + let &expandtab = save_expandtab + call setpos('.', save_cursor) + +endfunction " ---------- end of function C_AdjustLineEndComm ---------- +" +"------------------------------------------------------------------------------ +" C_GetLineEndCommCol: get line-end comment position {{{1 +"------------------------------------------------------------------------------ +function! C_GetLineEndCommCol () + let actcol = virtcol(".") + if actcol+1 == virtcol("$") + let b:C_LineEndCommentColumn = '' + while match( b:C_LineEndCommentColumn, '^\s*\d\+\s*$' ) < 0 + let b:C_LineEndCommentColumn = C_Input( 'start line-end comment at virtual column : ', actcol, '' ) + endwhile + else + let b:C_LineEndCommentColumn = virtcol(".") + endif + echomsg "line end comments will start at column ".b:C_LineEndCommentColumn +endfunction " ---------- end of function C_GetLineEndCommCol ---------- +" +"------------------------------------------------------------------------------ +" C_LineEndComment: single line-end comment {{{1 +"------------------------------------------------------------------------------ +function! C_LineEndComment ( ) + if !exists("b:C_LineEndCommentColumn") + let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault + endif + " ----- trim whitespaces ----- + exe 's/\s*$//' + let linelength= virtcol("$") - 1 + if linelength < b:C_LineEndCommentColumn + let diff = b:C_LineEndCommentColumn -1 -linelength + exe "normal ".diff."A " + endif + " append at least one blank + if linelength >= b:C_LineEndCommentColumn + exe "normal A " + endif + call C_InsertTemplate('comment.end-of-line-comment') +endfunction " ---------- end of function C_LineEndComment ---------- +" +"------------------------------------------------------------------------------ +" C_MultiLineEndComments: multi line-end comments {{{1 +"------------------------------------------------------------------------------ +function! C_MultiLineEndComments ( ) + " + if !exists("b:C_LineEndCommentColumn") + let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault + endif + " + let pos0 = line("'<") + let pos1 = line("'>") + " + " ----- trim whitespaces ----- + exe pos0.','.pos1.'s/\s*$//' + " + " ----- find the longest line ----- + let maxlength = 0 + normal '< + for linenumber in range( pos0, pos1 ) + if getline(linenumber) !~ '^\s*$' && maxlength<virtcol("$") + let maxlength= virtcol("$") + endif + endfor + " + if maxlength < b:C_LineEndCommentColumn + let maxlength = b:C_LineEndCommentColumn + else + let maxlength = maxlength+1 " at least 1 blank + endif + " + " ----- fill lines with blanks ----- + for linenumber in range( pos0, pos1 ) + exe ":".linenumber + if getline(linenumber) !~ '^\s*$' + let diff = maxlength - virtcol("$") + exe "normal ".diff."A " + call C_InsertTemplate('comment.end-of-line-comment') + endif + endfor + " + " ----- back to the begin of the marked block ----- + stopinsert + normal '<$ + if match( getline("."), '\/\/\s*$' ) < 0 + if search( '\/\*', 'bcW', line(".") ) > 1 + normal l + endif + let save_cursor = getpos(".") + if getline(".")[save_cursor[2]+1] == ' ' + normal l + endif + else + normal $ + endif +endfunction " ---------- end of function C_MultiLineEndComments ---------- +" +"------------------------------------------------------------------------------ +" C_Comment_C_SectionAll: Section Comments {{{1 +"------------------------------------------------------------------------------ +" +function! C_Comment_C_SectionAll ( type ) + + call C_InsertTemplate("comment.file-section-cpp-header-includes") + call C_InsertTemplate("comment.file-section-cpp-macros") + call C_InsertTemplate("comment.file-section-cpp-typedefs") + call C_InsertTemplate("comment.file-section-cpp-data-types") + if a:type=="cpp" + call C_InsertTemplate("comment.file-section-cpp-class-defs") + endif + call C_InsertTemplate("comment.file-section-cpp-local-variables") + call C_InsertTemplate("comment.file-section-cpp-prototypes") + call C_InsertTemplate("comment.file-section-cpp-function-defs-exported") + call C_InsertTemplate("comment.file-section-cpp-function-defs-local") + if a:type=="cpp" + call C_InsertTemplate("comment.file-section-cpp-class-implementations-exported") + call C_InsertTemplate("comment.file-section-cpp-class-implementations-local") + endif + +endfunction " ---------- end of function C_Comment_C_SectionAll ---------- +" +function! C_Comment_H_SectionAll ( type ) + + call C_InsertTemplate("comment.file-section-hpp-header-includes") + call C_InsertTemplate("comment.file-section-hpp-macros") + call C_InsertTemplate("comment.file-section-hpp-exported-typedefs") + call C_InsertTemplate("comment.file-section-hpp-exported-data-types") + if a:type=="cpp" + call C_InsertTemplate("comment.file-section-hpp-exported-class-defs") + endif + call C_InsertTemplate("comment.file-section-hpp-exported-variables") + call C_InsertTemplate("comment.file-section-hpp-exported-function-declarations") + +endfunction " ---------- end of function C_Comment_H_SectionAll ---------- +" +"---------------------------------------------------------------------- +" C_CodeComment : Code -> Comment {{{1 +"---------------------------------------------------------------------- +function! C_CodeComment( mode, style ) + + if a:mode=="a" + if a:style == 'yes' + silent exe ":s#^#/\* #" + silent put = ' */' + else + silent exe ":s#^#//#" + endif + endif + + if a:mode=="v" + if a:style == 'yes' + silent exe ":'<,'>s/^/ \* /" + silent exe ":'< s'^ '\/'" + silent exe ":'>" + silent put = ' */' + else + silent exe ":'<,'>s#^#//#" + endif + endif + +endfunction " ---------- end of function C_CodeComment ---------- +" +"---------------------------------------------------------------------- +" C_StartMultilineComment : Comment -> Code {{{1 +"---------------------------------------------------------------------- +let s:C_StartMultilineComment = '^\s*\/\*[\*! ]\=' + +function! C_RemoveCComment( start, end ) + + if a:end-a:start<1 + return 0 " lines removed + endif + " + " Is the C-comment complete ? Get length. + " + let check = getline( a:start ) =~ s:C_StartMultilineComment + let linenumber = a:start+1 + while linenumber < a:end && getline( linenumber ) !~ '^\s*\*\/' + let check = check && getline( linenumber ) =~ '^\s*\*[ ]\=' + let linenumber = linenumber+1 + endwhile + let check = check && getline( linenumber ) =~ '^\s*\*\/' + " + " remove a complete comment + " + if check + exe "silent :".a:start.' s/'.s:C_StartMultilineComment.'//' + let linenumber1 = a:start+1 + while linenumber1 < linenumber + exe "silent :".linenumber1.' s/^\s*\*[ ]\=//' + let linenumber1 = linenumber1+1 + endwhile + exe "silent :".linenumber1.' s/^\s*\*\///' + endif + + return linenumber-a:start+1 " lines removed +endfunction " ---------- end of function C_RemoveCComment ---------- +" +"---------------------------------------------------------------------- +" C_CommentCode : Comment -> Code {{{1 +"---------------------------------------------------------------------- +function! C_CommentCode(mode) + if a:mode=="a" + let pos1 = line(".") + let pos2 = pos1 + endif + if a:mode=="v" + let pos1 = line("'<") + let pos2 = line("'>") + endif + + let removed = 0 + " + let linenumber=pos1 + while linenumber <= pos2 + " Do we have a C++ comment ? + if getline( linenumber ) =~ '^\s*//' + exe "silent :".linenumber.' s#^\s*//##' + let removed = 1 + endif + " Do we have a C comment ? + if removed == 0 && getline( linenumber ) =~ s:C_StartMultilineComment + let removed = C_RemoveCComment(linenumber,pos2) + endif + + if removed!=0 + let linenumber = linenumber+removed + let removed = 0 + else + let linenumber = linenumber+1 + endif + endwhile +endfunction " ---------- end of function C_CommentCode ---------- +" +"---------------------------------------------------------------------- +" C_CommentCppToC : C++ Comment -> C Comment {{{1 +" Removes trailing whitespaces. +"---------------------------------------------------------------------- +function! C_CommentCppToC() + silent! exe ':s#\/\/\s*\(.*\)\s*$#/* \1 */#' +endfunction " ---------- end of function C_CommentCppToC ---------- +" +"---------------------------------------------------------------------- +" C_CommentCToCpp : C Comment -> C++ Comment {{{1 +" Changes the first comment in case of multiple comments: +" xxxx; /* */ /* */ +" xxxx; // /* */ +" Removes trailing whitespaces. +"---------------------------------------------------------------------- +function! C_CommentCToCpp() + silent! exe ':s!\/\*\s*\(.\{-}\)\*\/!\/\/ \1!' + silent! exe ':s!\s*$!!' +endfunction " ---------- end of function C_CommentCToCpp ---------- +" +"===================================================================================== +"----- Menu : Statements ----------------------------------------------------------- +"===================================================================================== +" +"------------------------------------------------------------------------------ +" C_PPIf0 : #if 0 .. #endif {{{1 +"------------------------------------------------------------------------------ +function! C_PPIf0 (mode) + " + let s:C_If0_Counter = 0 + let save_line = line(".") + let actual_line = 0 + " + " search for the maximum option number (if any) + " + normal gg + while actual_line < search( s:C_If0_Txt."\\d\\+" ) + let actual_line = line(".") + let actual_opt = matchstr( getline(actual_line), s:C_If0_Txt."\\d\\+" ) + let actual_opt = strpart( actual_opt, strlen(s:C_If0_Txt),strlen(actual_opt)-strlen(s:C_If0_Txt)) + if s:C_If0_Counter < actual_opt + let s:C_If0_Counter = actual_opt + endif + endwhile + let s:C_If0_Counter = s:C_If0_Counter+1 + silent exe ":".save_line + " + if a:mode=='a' + let zz= "\n#if 0 ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n" + let zz= zz."\n#endif ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n\n" + put =zz + normal 4k + endif + + if a:mode=='v' + let pos1 = line("'<") + let pos2 = line("'>") + let zz= "#endif ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n\n" + exe ":".pos2."put =zz" + let zz= "\n#if 0 ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n" + exe ":".pos1."put! =zz" + " + if &foldenable && foldclosed(".") + normal zv + endif + endif + +endfunction " ---------- end of function C_PPIf0 ---------- +" +"------------------------------------------------------------------------------ +" C_PPIf0Remove : remove #if 0 .. #endif {{{1 +"------------------------------------------------------------------------------ +function! C_PPIf0Remove () + " + " cursor on fold: open fold first + if &foldenable && foldclosed(".") + normal zv + endif + " + let frstline = searchpair( '^\s*#if\s\+0', '', '^\s*#endif\>.\+\<If0Label_', 'bn' ) + if frstline<=0 + echohl WarningMsg | echo 'no #if 0 ... #endif found or cursor not inside such a directive'| echohl None + return + endif + let lastline = searchpair( '^\s*#if\s\+0', '', '^\s*#endif\>.\+\<If0Label_', 'n' ) + if lastline<=0 + echohl WarningMsg | echo 'no #if 0 ... #endif found or cursor not inside such a directive'| echohl None + return + endif + let actualnumber1 = matchstr( getline(frstline), s:C_If0_Txt."\\d\\+" ) + let actualnumber2 = matchstr( getline(lastline), s:C_If0_Txt."\\d\\+" ) + if actualnumber1 != actualnumber2 + echohl WarningMsg | echo 'lines '.frstline.', '.lastline.': comment tags do not match'| echohl None + return + endif + + silent exe ':'.lastline.','.lastline.'d' + silent exe ':'.frstline.','.frstline.'d' + +endfunction " ---------- end of function C_PPIf0Remove ---------- +" +"------------------------------------------------------------------------------- +" C_LegalizeName : replace non-word characters by underscores +" - multiple whitespaces +" - multiple non-word characters +" - multiple underscores +"------------------------------------------------------------------------------- +function! C_LegalizeName ( name ) + let identifier = substitute( a:name, '\s\+', '_', 'g' ) + let identifier = substitute( identifier, '\W\+', '_', 'g' ) + let identifier = substitute( identifier, '_\+', '_', 'g' ) + return identifier +endfunction " ---------- end of function C_LegalizeName ---------- + +"------------------------------------------------------------------------------ +" C_CodeSnippet : read / edit code snippet {{{1 +"------------------------------------------------------------------------------ +function! C_CodeSnippet(mode) + + if isdirectory(s:C_CodeSnippets) + " + " read snippet file, put content below current line and indent + " + if a:mode == "r" + if has("browse") && s:C_GuiSnippetBrowser == 'gui' + let l:snippetfile=browse(0,"read a code snippet",s:C_CodeSnippets,"") + else + let l:snippetfile=input("read snippet ", s:C_CodeSnippets, "file" ) + endif + if filereadable(l:snippetfile) + let linesread= line("$") + let l:old_cpoptions = &cpoptions " Prevent the alternate buffer from being set to this files + setlocal cpoptions-=a + :execute "read ".l:snippetfile + let &cpoptions = l:old_cpoptions " restore previous options + let linesread= line("$")-linesread-1 + if linesread>=0 && match( l:snippetfile, '\.\(ni\|noindent\)$' ) < 0 + endif + endif + if line(".")==2 && getline(1)=~"^$" + silent exe ":1,1d" + endif + endif + " + " update current buffer / split window / edit snippet file + " + if a:mode == "e" + if has("browse") && s:C_GuiSnippetBrowser == 'gui' + let l:snippetfile = browse(0,"edit a code snippet",s:C_CodeSnippets,"") + else + let l:snippetfile=input("edit snippet ", s:C_CodeSnippets, "file" ) + endif + if l:snippetfile != "" + :execute "update! | split | edit ".l:snippetfile + endif + endif + " + " write whole buffer into snippet file + " + if a:mode == "w" || a:mode == "wv" + if has("browse") && s:C_GuiSnippetBrowser == 'gui' + let l:snippetfile = browse(0,"write a code snippet",s:C_CodeSnippets,"") + else + let l:snippetfile=input("write snippet ", s:C_CodeSnippets, "file" ) + endif + if l:snippetfile != "" + if filereadable(l:snippetfile) + if confirm("File ".l:snippetfile." exists ! Overwrite ? ", "&Cancel\n&No\n&Yes") != 3 + return + endif + endif + if a:mode == "w" + :execute ":write! ".l:snippetfile + else + :execute ":*write! ".l:snippetfile + endif + endif + endif + + else + echo "code snippet directory ".s:C_CodeSnippets." does not exist (please create it)" + endif +endfunction " ---------- end of function C_CodeSnippets ---------- +" +"------------------------------------------------------------------------------ +" C_help : builtin completion {{{1 +"------------------------------------------------------------------------------ +function! C_ForTypeComplete ( ArgLead, CmdLine, CursorPos ) + " + " show all types + if a:ArgLead == '' + return s:C_ForTypes + endif + " + " show types beginning with a:ArgLead + let expansions = [] + for item in s:C_ForTypes + if match( item, '\<'.a:ArgLead.'\w*' ) == 0 + call add( expansions, item ) + endif + endfor + return expansions +endfunction " ---------- end of function C_ForTypeComplete ---------- +" +"------------------------------------------------------------------------------ +" C_CodeFor : for (idiom) {{{1 +"------------------------------------------------------------------------------ +function! C_CodeFor( direction, mode ) + " + if a:direction == 'up' + let string = 'INCR.' + else + let string = 'DECR.' + endif + let string = C_Input( '[TYPE (expand)] VARIABLE [START [END ['.string.']]] : ', '', 'customlist,C_ForTypeComplete' ) + if string == '' + return + endif + " + let part = [''] + let nextindex = -1 + for item in s:C_ForTypes + let nextindex = matchend( string, '^'.item ) + if nextindex >= 0 + let part[0] = item + let string = strpart( string, nextindex-1 ) + endif + endfor + let part = part + split( string ) + + if len( part ) > 5 + echohl WarningMsg | echomsg "for loop construction : to many arguments " | echohl None + return + endif + + let missing = 0 + while len(part) < 5 + let part = part + [''] + let missing = missing+1 + endwhile + + let [ loopvar_type, loopvar, startval, endval, incval ] = part + + if incval=='' + let incval = '1' + endif + + if a:direction == 'up' + if endval == '' + let endval = 'n' + endif + if startval == '' + let startval = '0' + endif + let zz= 'for ( '.loopvar_type.loopvar.' = '.startval.'; '.loopvar.' < '.endval.'; '.loopvar.' += '.incval." )" + else + if endval == '' + let endval = '0' + endif + if startval == '' + let startval = 'n-1' + endif + let zz= 'for ( '.loopvar_type.loopvar.' = '.startval.'; '.loopvar.' >= '.endval.'; '.loopvar.' -= '.incval." )" + endif + " + " use internal formatting to avoid conficts when using == below + let equalprg_save = &equalprg + set equalprg= + + " ----- normal mode ---------------- + if a:mode=='a' + let zz = zz." {\n}" + put =zz + normal k + normal 2== + endif + " ----- visual mode ---------------- + if a:mode=='v' + let pos1 = line("'<") + let pos2 = line("'>") + let zz = zz.' {' + let zz2= '}' + exe ":".pos2."put =zz2" + exe ":".pos1."put! =zz" + :exe 'normal ='.(pos2-pos1+2).'+' + endif + " + " restore formatter programm + let &equalprg = equalprg_save + " + " position the cursor + " + normal ^ + if missing == 1 + let match = search( '\<'.incval.'\>', 'W', line(".") ) + else + if missing == 2 + let match = search( '\<'.endval.'\>', 'W', line(".") ) + else + if missing == 3 + let match = search( '\<'.startval.'\>', 'W', line(".") ) + endif + endif + endif + " +endfunction " ---------- end of function C_CodeFor ---------- +" +"------------------------------------------------------------------------------ +" Handle prototypes {{{1 +"------------------------------------------------------------------------------ +" +let s:C_Prototype = [] +let s:C_PrototypeShow = [] +let s:C_PrototypeCounter = 0 +let s:C_CComment = '\/\*.\{-}\*\/\s*' " C comment with trailing whitespaces + " '.\{-}' any character, non-greedy +let s:C_CppComment = '\/\/.*$' " C++ comment +" +"------------------------------------------------------------------------------ +" C_ProtoPick : pick up (normal/visual) {{{1 +"------------------------------------------------------------------------------ +function! C_ProtoPick (mode) + if a:mode=="n" + " --- normal mode ------------------- + let pos1 = line(".") + let pos2 = pos1 + else + " --- visual mode ------------------- + let pos1 = line("'<") + let pos2 = line("'>") + endif + " + " remove C/C++-comments, leading and trailing whitespaces, squeeze whitespaces + " + let prototyp = '' + for linenumber in range( pos1, pos2 ) + let newline = getline(linenumber) + let newline = substitute( newline, s:C_CppComment, "", "" ) " remove C++ comment + let prototyp = prototyp." ".newline + endfor + " + let prototyp = substitute( prototyp, '^\s\+', "", "" ) " remove leading whitespaces + let prototyp = substitute( prototyp, s:C_CComment, "", "g" ) " remove (multiline) C comments + let prototyp = substitute( prototyp, '\s\+', " ", "g" ) " squeeze whitespaces + let prototyp = substitute( prototyp, '\s\+$', "", "" ) " remove trailing whitespaces + " + " remove template keyword + " + let prototyp = substitute( prototyp, '^template\s*<\s*class \w\+\s*>\s*', "", "" ) + " + let parlist = stridx( prototyp, '(' ) " start of the parameter list + let part1 = strpart( prototyp, 0, parlist ) + let part2 = strpart( prototyp, parlist ) + " + " remove the scope res. operator + " + let part1 = substitute( part1, '<\s*\w\+\s*>', "", "g" ) + let part1 = substitute( part1, '\<std\s*::', 'std##', 'g' ) " remove the scope res. operator + let part1 = substitute( part1, '\<\h\w*\s*::', '', 'g' ) " remove the scope res. operator + let part1 = substitute( part1, '\<std##', 'std::', 'g' ) " remove the scope res. operator + let prototyp = part1.part2 + " + " remove trailing parts of the function body; add semicolon + " + let prototyp = substitute( prototyp, '\s*{.*$', "", "" ) + let prototyp = prototyp.";\n" + " + " bookkeeping + " + let s:C_PrototypeCounter += 1 + let s:C_Prototype += [prototyp] + let s:C_PrototypeShow += ["(".s:C_PrototypeCounter.") ".bufname("%")." # ".prototyp] + " + echon s:C_PrototypeCounter.' prototype' + if s:C_PrototypeCounter > 1 + echon 's' + endif + " +endfunction " --------- end of function C_ProtoPick ---------- +" +"------------------------------------------------------------------------------ +" C_ProtoInsert : insert {{{1 +"------------------------------------------------------------------------------ +function! C_ProtoInsert () + " + " use internal formatting to avoid conficts when using == below + let equalprg_save = &equalprg + set equalprg= + " + if s:C_PrototypeCounter > 0 + for protytype in s:C_Prototype + put =protytype + endfor + let lines = s:C_PrototypeCounter - 1 + silent exe "normal =".lines."-" + call C_ProtoClear() + else + echo "currently no prototypes available" + endif + " + " restore formatter programm + let &equalprg = equalprg_save + " +endfunction " --------- end of function C_ProtoInsert ---------- +" +"------------------------------------------------------------------------------ +" C_ProtoClear : clear {{{1 +"------------------------------------------------------------------------------ +function! C_ProtoClear () + if s:C_PrototypeCounter > 0 + let s:C_Prototype = [] + let s:C_PrototypeShow = [] + if s:C_PrototypeCounter == 1 + echo s:C_PrototypeCounter.' prototype deleted' + else + echo s:C_PrototypeCounter.' prototypes deleted' + endif + let s:C_PrototypeCounter = 0 + else + echo "currently no prototypes available" + endif +endfunction " --------- end of function C_ProtoClear ---------- +" +"------------------------------------------------------------------------------ +" C_ProtoShow : show {{{1 +"------------------------------------------------------------------------------ +function! C_ProtoShow () + if s:C_PrototypeCounter > 0 + for protytype in s:C_PrototypeShow + echo protytype + endfor + else + echo "currently no prototypes available" + endif +endfunction " --------- end of function C_ProtoShow ---------- +" +"------------------------------------------------------------------------------ +" C_EscapeBlanks : C_EscapeBlanks {{{1 +"------------------------------------------------------------------------------ +function! C_EscapeBlanks (arg) + return substitute( a:arg, " ", "\\ ", "g" ) +endfunction " --------- end of function C_EscapeBlanks ---------- +" +"------------------------------------------------------------------------------ +" C_Compile : C_Compile {{{1 +"------------------------------------------------------------------------------ +" The standard make program 'make' called by vim is set to the C or C++ compiler +" and reset after the compilation (setlocal makeprg=... ). +" The errorfile created by the compiler will now be read by gvim and +" the commands cl, cp, cn, ... can be used. +"------------------------------------------------------------------------------ +let s:LastShellReturnCode = 0 " for compile / link / run only + +function! C_Compile () + + let s:C_HlMessage = "" + exe ":cclose" + let Sou = expand("%:p") " name of the file in the current buffer + let Obj = expand("%:p:r").s:C_ObjExtension " name of the object + let SouEsc= escape( Sou, s:escfilename ) + let ObjEsc= escape( Obj, s:escfilename ) + + " update : write source file if necessary + exe ":update" + + " compilation if object does not exist or object exists and is older then the source + if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou))) + " &makeprg can be a string containing blanks + let makeprg_saved = '"'.&makeprg.'"' + if expand("%:e") == s:C_CExtension + exe "setlocal makeprg=".s:C_CCompiler + else + exe "setlocal makeprg=".s:C_CplusCompiler + endif + " + " COMPILATION + " + let v:statusmsg = '' + let s:LastShellReturnCode = 0 + if s:MSWIN + exe "make ".s:C_CFlags." \"".SouEsc."\" -o \"".ObjEsc."\"" + else + exe "make ".s:C_CFlags." ".SouEsc." -o ".ObjEsc + endif + exe "setlocal makeprg=".makeprg_saved + if v:statusmsg == '' + let s:C_HlMessage = "'".Obj."' : compilation successful" + endif + if v:shell_error != 0 + let s:LastShellReturnCode = v:shell_error + endif + " + " open error window if necessary + :redraw! + exe ":botright cwindow" + else + let s:C_HlMessage = " '".Obj."' is up to date " + endif + +endfunction " ---------- end of function C_Compile ---------- +" +"------------------------------------------------------------------------------ +" C_Link : C_Link {{{1 +"------------------------------------------------------------------------------ +" The standard make program which is used by gvim is set to the compiler +" (for linking) and reset after linking. +" +" calls: C_Compile +"------------------------------------------------------------------------------ +function! C_Link () + + call C_Compile() + :redraw! + if s:LastShellReturnCode != 0 + let s:LastShellReturnCode = 0 + return + endif + + let s:C_HlMessage = "" + let Sou = expand("%:p") " name of the file (full path) + let Obj = expand("%:p:r").s:C_ObjExtension " name of the object file + let Exe = expand("%:p:r").s:C_ExeExtension " name of the executable + let ObjEsc= escape( Obj, s:escfilename ) + let ExeEsc= escape( Exe, s:escfilename ) + + " no linkage if: + " executable exists + " object exists + " source exists + " executable newer then object + " object newer then source + + if filereadable(Exe) && + \ filereadable(Obj) && + \ filereadable(Sou) && + \ (getftime(Exe) >= getftime(Obj)) && + \ (getftime(Obj) >= getftime(Sou)) + let s:C_HlMessage = " '".Exe."' is up to date " + return + endif + + " linkage if: + " object exists + " source exists + " object newer then source + + if filereadable(Obj) && (getftime(Obj) >= getftime(Sou)) + let makeprg_saved='"'.&makeprg.'"' + if expand("%:e") == s:C_CExtension + exe "setlocal makeprg=".s:C_CCompiler + else + exe "setlocal makeprg=".s:C_CplusCompiler + endif + let s:LastShellReturnCode = 0 + let v:statusmsg = '' + if s:MSWIN + silent exe "make ".s:C_LFlags." ".s:C_Libs." -o \"".ExeEsc."\" \"".ObjEsc."\"" + else + silent exe "make ".s:C_LFlags." ".s:C_Libs." -o ".ExeEsc." ".ObjEsc + endif + if v:statusmsg == '' + let s:C_HlMessage = "'".Exe."' : linking successful" + else + let s:C_HlMessage = "'".Exe."' : linking NOT successful" + endif + if v:shell_error != 0 + let s:LastShellReturnCode = v:shell_error + endif + exe "setlocal makeprg=".makeprg_saved + endif +endfunction " ---------- end of function C_Link ---------- +" +"------------------------------------------------------------------------------ +" C_Run : C_Run {{{1 +" calls: C_Link +"------------------------------------------------------------------------------ +" +let s:C_OutputBufferName = "C-Output" +let s:C_OutputBufferNumber = -1 +let s:C_RunMsg1 ="' does not exist or is not executable or object/source older then executable" +" +function! C_Run () +" + let s:C_HlMessage = "" + let Sou = expand("%:p") " name of the source file + let Obj = expand("%:p:r").s:C_ObjExtension " name of the object file + let Exe = expand("%:p:r").s:C_ExeExtension " name of the executable + let ExeEsc = escape( Exe, s:escfilename ) " name of the executable, escaped + " + let l:arguments = exists("b:C_CmdLineArgs") ? b:C_CmdLineArgs : '' + " + let l:currentbuffer = bufname("%") + " + "============================================================================== + " run : run from the vim command line + "============================================================================== + if s:C_OutputGvim == "vim" + " + silent call C_Link() + if s:LastShellReturnCode == 0 + " clear the last linking message if any" + let s:C_HlMessage = "" + call C_HlMessage() + endif + " + if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) + if s:MSWIN + exe "!\"".ExeEsc."\" ".l:arguments + else + exe "!".ExeEsc." ".l:arguments + endif + else + echomsg "file '".Exe.s:C_RunMsg1 + endif + + endif + " + "============================================================================== + " run : redirect output to an output buffer + "============================================================================== + if s:C_OutputGvim == "buffer" + let l:currentbuffernr = bufnr("%") + " + silent call C_Link() + " + if l:currentbuffer == bufname("%") + " + " + if bufloaded(s:C_OutputBufferName) != 0 && bufwinnr(s:C_OutputBufferNumber)!=-1 + exe bufwinnr(s:C_OutputBufferNumber) . "wincmd w" + " buffer number may have changed, e.g. after a 'save as' + if bufnr("%") != s:C_OutputBufferNumber + let s:C_OutputBufferNumber = bufnr(s:C_OutputBufferName) + exe ":bn ".s:C_OutputBufferNumber + endif + else + silent exe ":new ".s:C_OutputBufferName + let s:C_OutputBufferNumber=bufnr("%") + setlocal buftype=nofile + setlocal noswapfile + setlocal syntax=none + setlocal bufhidden=delete + setlocal tabstop=8 + endif + " + " run programm + " + setlocal modifiable + if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) + if s:MSWIN + exe "%!\"".ExeEsc."\" ".l:arguments + else + exe "%!".ExeEsc." ".l:arguments + endif + setlocal nomodifiable + " + if winheight(winnr()) >= line("$") + exe bufwinnr(l:currentbuffernr) . "wincmd w" + endif + else + setlocal nomodifiable + :close + echomsg "file '".Exe.s:C_RunMsg1 + endif + " + endif + endif + " + "============================================================================== + " run : run in a detached xterm (not available for MS Windows) + "============================================================================== + if s:C_OutputGvim == "xterm" + " + silent call C_Link() + " + if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) + if s:MSWIN + exe "!\"".ExeEsc."\" ".l:arguments + else + silent exe '!xterm -title '.ExeEsc.' '.s:C_XtermDefaults.' -e '.s:C_Wrapper.' '.ExeEsc.' '.l:arguments.' &' + :redraw! + endif + else + echomsg "file '".Exe.s:C_RunMsg1 + endif + endif + + if v:statusmsg == '' + let s:C_HlMessage = "" + endif +endfunction " ---------- end of function C_Run ---------- +" +"------------------------------------------------------------------------------ +" C_Arguments : Arguments for the executable {{{1 +"------------------------------------------------------------------------------ +function! C_Arguments () + let Exe = expand("%:r").s:C_ExeExtension + if Exe == "" + redraw + echohl WarningMsg | echo "no file name " | echohl None + return + endif + let prompt = 'command line arguments for "'.Exe.'" : ' + if exists("b:C_CmdLineArgs") + let b:C_CmdLineArgs= C_Input( prompt, b:C_CmdLineArgs, 'file' ) + else + let b:C_CmdLineArgs= C_Input( prompt , "", 'file' ) + endif +endfunction " ---------- end of function C_Arguments ---------- +" +"---------------------------------------------------------------------- +" C_Toggle_Gvim_Xterm : change output destination {{{1 +"---------------------------------------------------------------------- +function! C_Toggle_Gvim_Xterm () + + if s:C_OutputGvim == "vim" + if has("gui_running") + exe "aunmenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm' + exe "amenu <silent> ".s:Run.'.&output:\ BUFFER->xterm->vim :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ BUFFER->xterm->vim <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + endif + let s:C_OutputGvim = "buffer" + else + if s:C_OutputGvim == "buffer" + if has("gui_running") + exe "aunmenu <silent> ".s:Run.'.&output:\ BUFFER->xterm->vim' + if (!s:MSWIN) + exe "amenu <silent> ".s:Run.'.&output:\ XTERM->vim->buffer :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ XTERM->vim->buffer <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + else + exe "amenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + endif + endif + if (!s:MSWIN) && (s:C_Display != '') + let s:C_OutputGvim = "xterm" + else + let s:C_OutputGvim = "vim" + endif + else + " ---------- output : xterm -> gvim + if has("gui_running") + exe "aunmenu <silent> ".s:Run.'.&output:\ XTERM->vim->buffer' + exe "amenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm :call C_Toggle_Gvim_Xterm()<CR><CR>' + exe "imenu <silent> ".s:Run.'.&output:\ VIM->buffer->xterm <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>' + endif + let s:C_OutputGvim = "vim" + endif + endif + echomsg "output destination is '".s:C_OutputGvim."'" + +endfunction " ---------- end of function C_Toggle_Gvim_Xterm ---------- +" +"------------------------------------------------------------------------------ +" C_XtermSize : xterm geometry {{{1 +"------------------------------------------------------------------------------ +function! C_XtermSize () + let regex = '-geometry\s\+\d\+x\d\+' + let geom = matchstr( s:C_XtermDefaults, regex ) + let geom = matchstr( geom, '\d\+x\d\+' ) + let geom = substitute( geom, 'x', ' ', "" ) + let answer= C_Input(" xterm size (COLUMNS LINES) : ", geom ) + while match(answer, '^\s*\d\+\s\+\d\+\s*$' ) < 0 + let answer= C_Input(" + xterm size (COLUMNS LINES) : ", geom ) + endwhile + let answer = substitute( answer, '\s\+', "x", "" ) " replace inner whitespaces + let s:C_XtermDefaults = substitute( s:C_XtermDefaults, regex, "-geometry ".answer , "" ) +endfunction " ---------- end of function C_XtermSize ---------- +" +"------------------------------------------------------------------------------ +" C_MakeArguments : run make(1) {{{1 +"------------------------------------------------------------------------------ + +let s:C_MakeCmdLineArgs = "" " command line arguments for Run-make; initially empty + +function! C_MakeArguments () + let s:C_MakeCmdLineArgs= C_Input("make command line arguments : ",s:C_MakeCmdLineArgs ) +endfunction " ---------- end of function C_MakeArguments ---------- +" +function! C_Make() + " update : write source file if necessary + exe ":update" + " run make + exe ":!make ".s:C_MakeCmdLineArgs +endfunction " ---------- end of function C_Make ---------- +" +"------------------------------------------------------------------------------ +" C_SplintArguments : splint command line arguments {{{1 +"------------------------------------------------------------------------------ +function! C_SplintArguments () + if s:C_SplintIsExecutable==0 + let s:C_HlMessage = ' Splint is not executable or not installed! ' + else + let prompt = 'Splint command line arguments for "'.expand("%").'" : ' + if exists("b:C_SplintCmdLineArgs") + let b:C_SplintCmdLineArgs= C_Input( prompt, b:C_SplintCmdLineArgs ) + else + let b:C_SplintCmdLineArgs= C_Input( prompt , "" ) + endif + endif +endfunction " ---------- end of function C_SplintArguments ---------- +" +"------------------------------------------------------------------------------ +" C_SplintCheck : run splint(1) {{{1 +"------------------------------------------------------------------------------ +function! C_SplintCheck () + if s:C_SplintIsExecutable==0 + let s:C_HlMessage = ' Splint is not executable or not installed! ' + return + endif + let l:currentbuffer=bufname("%") + if &filetype != "c" && &filetype != "cpp" + let s:C_HlMessage = ' "'.l:currentbuffer.'" seems not to be a C/C++ file ' + return + endif + let s:C_HlMessage = "" + exe ":cclose" + silent exe ":update" + let makeprg_saved='"'.&makeprg.'"' + " Windows seems to need this: + if s:MSWIN + :compiler splint + endif + :setlocal makeprg=splint + " + let l:arguments = exists("b:C_SplintCmdLineArgs") ? b:C_SplintCmdLineArgs : ' ' + silent exe "make ".l:arguments." ".escape(l:currentbuffer,s:escfilename) + exe "setlocal makeprg=".makeprg_saved + exe ":botright cwindow" + " + " message in case of success + " + if l:currentbuffer == bufname("%") + let s:C_HlMessage = " Splint --- no warnings for : ".l:currentbuffer + endif +endfunction " ---------- end of function C_SplintCheck ---------- +" +"------------------------------------------------------------------------------ +" C_CodeCheckArguments : CodeCheck command line arguments {{{1 +"------------------------------------------------------------------------------ +function! C_CodeCheckArguments () + if s:C_CodeCheckIsExecutable==0 + let s:C_HlMessage = ' CodeCheck is not executable or not installed! ' + else + let prompt = 'CodeCheck command line arguments for "'.expand("%").'" : ' + if exists("b:C_CodeCheckCmdLineArgs") + let b:C_CodeCheckCmdLineArgs= C_Input( prompt, b:C_CodeCheckCmdLineArgs ) + else + let b:C_CodeCheckCmdLineArgs= C_Input( prompt , s:C_CodeCheckOptions ) + endif + endif +endfunction " ---------- end of function C_CodeCheckArguments ---------- +" +"------------------------------------------------------------------------------ +" C_CodeCheck : run CodeCheck {{{1 +"------------------------------------------------------------------------------ +function! C_CodeCheck () + if s:C_CodeCheckIsExecutable==0 + let s:C_HlMessage = ' CodeCheck is not executable or not installed! ' + return + endif + let l:currentbuffer=bufname("%") + if &filetype != "c" && &filetype != "cpp" + let s:C_HlMessage = ' "'.l:currentbuffer.'" seems not to be a C/C++ file ' + return + endif + let s:C_HlMessage = "" + exe ":cclose" + silent exe ":update" + let makeprg_saved='"'.&makeprg.'"' + exe "setlocal makeprg=".s:C_CodeCheckExeName + " + " match the splint error messages (quickfix commands) + " ignore any lines that didn't match one of the patterns + " + :setlocal errorformat=%f(%l)%m + " + let l:arguments = exists("b:C_CodeCheckCmdLineArgs") ? b:C_CodeCheckCmdLineArgs : "" + if l:arguments == "" + let l:arguments = s:C_CodeCheckOptions + endif + exe ":make ".l:arguments." ".escape( l:currentbuffer, s:escfilename ) + exe ':setlocal errorformat=' + exe ":setlocal makeprg=".makeprg_saved + exe ":botright cwindow" + " + " message in case of success + " + if l:currentbuffer == bufname("%") + let s:C_HlMessage = " CodeCheck --- no warnings for : ".l:currentbuffer + endif +endfunction " ---------- end of function C_CodeCheck ---------- +" +"------------------------------------------------------------------------------ +" C_Indent : run indent(1) {{{1 +"------------------------------------------------------------------------------ +" +function! C_Indent ( ) + if !executable("indent") + echomsg 'indent is not executable or not installed!' + return + endif + let l:currentbuffer=expand("%:p") + if &filetype != "c" && &filetype != "cpp" + echomsg '"'.l:currentbuffer.'" seems not to be a C/C++ file ' + return + endif + if C_Input("indent whole file [y/n/Esc] : ", "y" ) != "y" + return + endif + :update + + exe ":cclose" + if s:MSWIN + silent exe ":%!indent " + else + silent exe ":%!indent 2> ".s:C_IndentErrorLog + redraw! + if getfsize( s:C_IndentErrorLog ) > 0 + exe ':edit! '.s:C_IndentErrorLog + let errorlogbuffer = bufnr("%") + exe ':%s/^indent: Standard input/indent: '.escape( l:currentbuffer, '/' ).'/' + setlocal errorformat=indent:\ %f:%l:%m + :cbuffer + exe ':bdelete! '.errorlogbuffer + exe ':botright cwindow' + else + echomsg 'File "'.l:currentbuffer.'" reformatted.' + endif + setlocal errorformat= + endif + +endfunction " ---------- end of function C_Indent ---------- +" +"------------------------------------------------------------------------------ +" C_HlMessage : indent message {{{1 +"------------------------------------------------------------------------------ +function! C_HlMessage () + redraw! + echohl Search + echo s:C_HlMessage + echohl None +endfunction " ---------- end of function C_HlMessage ---------- +" +"------------------------------------------------------------------------------ +" C_Settings : settings {{{1 +"------------------------------------------------------------------------------ +function! C_Settings () + let txt = " C/C++-Support settings\n\n" + let txt = txt.' author : "'.s:C_Macro['|AUTHOR|']."\"\n" + let txt = txt.' initials : "'.s:C_Macro['|AUTHORREF|']."\"\n" + let txt = txt.' email : "'.s:C_Macro['|EMAIL|']."\"\n" + let txt = txt.' company : "'.s:C_Macro['|COMPANY|']."\"\n" + let txt = txt.' project : "'.s:C_Macro['|PROJECT|']."\"\n" + let txt = txt.' copyright holder : "'.s:C_Macro['|COPYRIGHTHOLDER|']."\"\n" + let txt = txt.' C / C++ compiler : '.s:C_CCompiler.' / '.s:C_CplusCompiler."\n" + let txt = txt.' C file extension : "'.s:C_CExtension.'" (everything else is C++)'."\n" + let txt = txt.' extension for objects : "'.s:C_ObjExtension."\"\n" + let txt = txt.'extension for executables : "'.s:C_ExeExtension."\"\n" + let txt = txt.' compiler flags : "'.s:C_CFlags."\"\n" + let txt = txt.' linker flags : "'.s:C_LFlags."\"\n" + let txt = txt.' libraries : "'.s:C_Libs."\"\n" + let txt = txt.' code snippet directory : "'.s:C_CodeSnippets."\"\n" + " ----- template files ------------------------ + let txt = txt.' template style : "'.s:C_ActualStyle."\"\n" + if s:installation == 'system' + let txt = txt.'global template directory : '.s:C_GlobalTemplateDir."\n" + if filereadable( s:C_LocalTemplateFile ) + let txt = txt.' local template directory : '.s:C_LocalTemplateDir."\n" + endif + else + let txt = txt.' local template directory : '.s:C_GlobalTemplateDir."\n" + endif + if !s:MSWIN + let txt = txt.' xterm defaults : '.s:C_XtermDefaults."\n" + endif + " ----- dictionaries ------------------------ + if g:C_Dictionary_File != "" + let ausgabe= &dictionary + let ausgabe= substitute( ausgabe, ",", ",\n + ", "g" ) + let txt = txt." dictionary file(s) : ".ausgabe."\n" + endif + let txt = txt.' current output dest. : '.s:C_OutputGvim."\n" + " ----- splint ------------------------------ + if s:C_SplintIsExecutable==1 + if exists("b:C_SplintCmdLineArgs") + let ausgabe = b:C_SplintCmdLineArgs + else + let ausgabe = "" + endif + let txt = txt." splint options(s) : ".ausgabe."\n" + endif + " ----- code check -------------------------- + if s:C_CodeCheckIsExecutable==1 + if exists("b:C_CodeCheckCmdLineArgs") + let ausgabe = b:C_CodeCheckCmdLineArgs + else + let ausgabe = s:C_CodeCheckOptions + endif + let txt = txt."CodeCheck (TM) options(s) : ".ausgabe."\n" + endif + let txt = txt."\n" + let txt = txt."__________________________________________________________________________\n" + let txt = txt." C/C++-Support, Version ".g:C_Version." / Dr.-Ing. Fritz Mehner / mehner@fh-swf.de\n\n" + echo txt +endfunction " ---------- end of function C_Settings ---------- +" +"------------------------------------------------------------------------------ +" C_Hardcopy : hardcopy {{{1 +" MSWIN : a printer dialog is displayed +" other : print PostScript to file +"------------------------------------------------------------------------------ +function! C_Hardcopy (mode) + let outfile = expand("%") + if outfile == "" + let s:C_HlMessage = 'Buffer has no name.' + call C_HlMessage() + endif + let outdir = getcwd() + if filewritable(outdir) != 2 + let outdir = $HOME + endif + if !s:MSWIN + let outdir = outdir.'/' + endif + let old_printheader=&printheader + exe ':set printheader='.s:C_Printheader + " ----- normal mode ---------------- + if a:mode=="n" + silent exe 'hardcopy > '.outdir.outfile.'.ps' + if !s:MSWIN + echo 'file "'.outfile.'" printed to "'.outdir.outfile.'.ps"' + endif + endif + " ----- visual mode ---------------- + if a:mode=="v" + silent exe "*hardcopy > ".outdir.outfile.".ps" + if !s:MSWIN + echo 'file "'.outfile.'" (lines '.line("'<").'-'.line("'>").') printed to "'.outdir.outfile.'.ps"' + endif + endif + exe ':set printheader='.escape( old_printheader, ' %' ) +endfunction " ---------- end of function C_Hardcopy ---------- +" +"------------------------------------------------------------------------------ +" C_HelpCsupport : help csupport {{{1 +"------------------------------------------------------------------------------ +function! C_HelpCsupport () + try + :help csupport + catch + exe ':helptags '.s:plugin_dir.'doc' + :help csupport + endtry +endfunction " ---------- end of function C_HelpCsupport ---------- +" +"------------------------------------------------------------------------------ +" C_Help : lookup word under the cursor or ask {{{1 +"------------------------------------------------------------------------------ +" +let s:C_DocBufferName = "C_HELP" +let s:C_DocHelpBufferNumber = -1 +" +function! C_Help( type ) + + let cuc = getline(".")[col(".") - 1] " character under the cursor + let item = expand("<cword>") " word under the cursor + if cuc == '' || item == "" || match( item, cuc ) == -1 + let item=C_Input('name of the manual page : ', '' ) + endif + + if item == "" + return + endif + "------------------------------------------------------------------------------ + " replace buffer content with bash help text + "------------------------------------------------------------------------------ + " + " jump to an already open bash help window or create one + " + if bufloaded(s:C_DocBufferName) != 0 && bufwinnr(s:C_DocHelpBufferNumber) != -1 + exe bufwinnr(s:C_DocHelpBufferNumber) . "wincmd w" + " buffer number may have changed, e.g. after a 'save as' + if bufnr("%") != s:C_DocHelpBufferNumber + let s:C_DocHelpBufferNumber=bufnr(s:C_OutputBufferName) + exe ":bn ".s:C_DocHelpBufferNumber + endif + else + exe ":new ".s:C_DocBufferName + let s:C_DocHelpBufferNumber=bufnr("%") + setlocal buftype=nofile + setlocal noswapfile + setlocal bufhidden=delete + setlocal filetype=sh " allows repeated use of <S-F1> + setlocal syntax=OFF + endif + setlocal modifiable + " + if a:type == 'm' + " + " Is there more than one manual ? + " + let manpages = system( s:C_Man.' -k '.item ) + if v:shell_error + echomsg "Shell command '".s:C_Man." -k ".item."' failed." + :close + return + endif + let catalogs = split( manpages, '\n', ) + let manual = {} + " + " Select manuals where the name exactly matches + " + for line in catalogs + if line =~ '^'.item.'\s\+(' + let itempart = split( line, '\s\+' ) + let catalog = itempart[1][1:-2] + if match( catalog, '.p$' ) == -1 + let manual[catalog] = catalog + endif + endif + endfor + " + " Build a selection list if there are more than one manual + " + let catalog = "" + if len(keys(manual)) > 1 + for key in keys(manual) + echo ' '.item.' '.key + endfor + let defaultcatalog = '' + if has_key( manual, '3' ) + let defaultcatalog = '3' + else + if has_key( manual, '2' ) + let defaultcatalog = '2' + endif + endif + let catalog = input( 'select manual section (<Enter> cancels) : ', defaultcatalog ) + if ! has_key( manual, catalog ) + :close + :redraw + echomsg "no appropriate manual section '".catalog."'" + return + endif + endif + + set filetype=man + silent exe ":%!".s:C_Man." ".catalog." ".item + + endif + + setlocal nomodifiable +endfunction " ---------- end of function C_Help ---------- + +"------------------------------------------------------------------------------ +" C_CreateGuiMenus {{{1 +"------------------------------------------------------------------------------ +let s:C_MenuVisible = 0 " state variable controlling the C-menus +" +function! C_CreateGuiMenus () + if s:C_MenuVisible != 1 + aunmenu <silent> &Tools.Load\ C\ Support + amenu <silent> 40.1000 &Tools.-SEP100- : + amenu <silent> 40.1030 &Tools.Unload\ C\ Support <C-C>:call C_RemoveGuiMenus()<CR> + call C_InitMenus() + let s:C_MenuVisible = 1 + endif +endfunction " ---------- end of function C_CreateGuiMenus ---------- + +"------------------------------------------------------------------------------ +" C_ToolMenu {{{1 +"------------------------------------------------------------------------------ +function! C_ToolMenu () + amenu <silent> 40.1000 &Tools.-SEP100- : + amenu <silent> 40.1030 &Tools.Load\ C\ Support :call C_CreateGuiMenus()<CR> + imenu <silent> 40.1030 &Tools.Load\ C\ Support <C-C>:call C_CreateGuiMenus()<CR> +endfunction " ---------- end of function C_ToolMenu ---------- + +"------------------------------------------------------------------------------ +" C_RemoveGuiMenus {{{1 +"------------------------------------------------------------------------------ +function! C_RemoveGuiMenus () + if s:C_MenuVisible == 1 + if s:C_Root == "" + aunmenu <silent> Comments + aunmenu <silent> Statements + aunmenu <silent> Preprocessor + aunmenu <silent> Idioms + aunmenu <silent> Snippets + aunmenu <silent> C++ + aunmenu <silent> Run + else + exe "aunmenu <silent> ".s:C_Root + endif + " + aunmenu <silent> &Tools.Unload\ C\ Support + call C_ToolMenu() + " + let s:C_MenuVisible = 0 + endif +endfunction " ---------- end of function C_RemoveGuiMenus ---------- + +"------------------------------------------------------------------------------ +" C_RereadTemplates {{{1 +" rebuild commands and the menu from the (changed) template file +"------------------------------------------------------------------------------ +function! C_RereadTemplates () + let s:style = 'default' + let s:C_Template = { 'default' : {} } + let s:C_FileVisited = [] + call C_ReadTemplates(s:C_GlobalTemplateFile) + echomsg "templates rebuilt from '".s:C_GlobalTemplateFile."'" + " + if s:installation == 'system' && filereadable( s:C_LocalTemplateFile ) + call C_ReadTemplates( s:C_LocalTemplateFile ) + echomsg " and from '".s:C_LocalTemplateFile."'" + endif +endfunction " ---------- end of function C_RereadTemplates ---------- + +"------------------------------------------------------------------------------ +" C_BrowseTemplateFiles {{{1 +"------------------------------------------------------------------------------ +function! C_BrowseTemplateFiles ( type ) + if filereadable( eval( 's:C_'.a:type.'TemplateFile' ) ) + if has("browse") && s:C_GuiTemplateBrowser == 'gui' + let l:templatefile = browse(0,"edit a template file", eval('s:C_'.a:type.'TemplateDir'), "" ) + else + let l:templatefile = '' + if s:C_GuiTemplateBrowser == 'explorer' + exe ':Explore '.eval('s:C_'.a:type.'TemplateDir') + endif + if s:C_GuiTemplateBrowser == 'commandline' + let l:templatefile = input("edit a template file", eval('s:C_'.a:type.'TemplateDir'), "file" ) + endif + endif + if l:templatefile != "" + :execute "update! | split | edit ".l:templatefile + endif + else + echomsg a:type." template file not readable." + endif +endfunction " ---------- end of function C_BrowseTemplateFiles ---------- + +"------------------------------------------------------------------------------ +" C_EditTemplates {{{1 +"------------------------------------------------------------------------------ +function! C_EditTemplates ( type ) + " + if a:type == 'global' + if s:installation == 'system' + call C_BrowseTemplateFiles('Global') + else + echomsg "C/C++-Support is user installed: no global template file" + endif + endif + " + if a:type == 'local' + if s:installation == 'system' + call C_BrowseTemplateFiles('Local') + else + call C_BrowseTemplateFiles('Global') + endif + endif + " +endfunction " ---------- end of function C_EditTemplates ---------- +" +"------------------------------------------------------------------------------ +" C_ReadTemplates {{{1 +" read the template file(s), build the macro and the template dictionary +" +"------------------------------------------------------------------------------ +let s:style = 'default' +function! C_ReadTemplates ( templatefile ) + + if !filereadable( a:templatefile ) + echohl WarningMsg + echomsg "C/C++ template file '".a:templatefile."' does not exist or is not readable" + echohl None + return + endif + + let skipmacros = 0 + let s:C_FileVisited += [a:templatefile] + + "------------------------------------------------------------------------------ + " read template file, start with an empty template dictionary + "------------------------------------------------------------------------------ + + let item = '' + let skipline = 0 + for line in readfile( a:templatefile ) + " if not a comment : + if line !~ s:C_MacroCommentRegex + " + "------------------------------------------------------------------------------- + " IF |STYLE| IS ... + "------------------------------------------------------------------------------- + " + let string = matchlist( line, s:C_TemplateIf ) + if !empty(string) + if !has_key( s:C_Template, string[1] ) + " new s:style + let s:style = string[1] + let s:C_Template[s:style] = {} + continue + endif + endif + " + "------------------------------------------------------------------------------- + " ENDIF + "------------------------------------------------------------------------------- + " + let string = matchlist( line, s:C_TemplateEndif ) + if !empty(string) + let s:style = 'default' + continue + endif + " + " macros and file includes + " + let string = matchlist( line, s:C_MacroLineRegex ) + if !empty(string) && skipmacros == 0 + let key = '|'.string[1].'|' + let val = string[2] + let val = substitute( val, '\s\+$', '', '' ) + let val = substitute( val, "[\"\']$", '', '' ) + let val = substitute( val, "^[\"\']", '', '' ) + " + if key == '|includefile|' && count( s:C_FileVisited, val ) == 0 + let path = fnamemodify( a:templatefile, ":p:h" ) + call C_ReadTemplates( path.'/'.val ) " recursive call + else + let s:C_Macro[key] = escape( val, '&' ) + endif + continue " next line + endif + " + " template header + " + let name = matchstr( line, s:C_TemplateLineRegex ) + " + if name != '' + let part = split( name, '\s*==\s*') + let item = part[0] + if has_key( s:C_Template[s:style], item ) && s:C_TemplateOverwrittenMsg == 'yes' + echomsg "existing C/C++ template '".item."' overwritten" + endif + let s:C_Template[s:style][item] = '' + let skipmacros = 1 + " + let s:C_Attribute[item] = 'below' + if has_key( s:Attribute, get( part, 1, 'NONE' ) ) + let s:C_Attribute[item] = part[1] + endif + else + if item != '' + let s:C_Template[s:style][item] .= line."\n" + endif + endif + endif + " + endfor " --------- read line --------- + + let s:C_ActualStyle = 'default' + if s:C_Macro['|STYLE|'] != '' + let s:C_ActualStyle = s:C_Macro['|STYLE|'] + endif + let s:C_ActualStyleLast = s:C_ActualStyle + + call C_SetSmallCommentStyle() +endfunction " ---------- end of function C_ReadTemplates ---------- + +"------------------------------------------------------------------------------ +" C_Style{{{1 +" ex-command CStyle : callback function +"------------------------------------------------------------------------------ +function! C_Style ( style ) + let lstyle = substitute( a:style, '^\s\+', "", "" ) " remove leading whitespaces + let lstyle = substitute( lstyle, '\s\+$', "", "" ) " remove trailing whitespaces + if has_key( s:C_Template, lstyle ) + if len( s:C_Template[lstyle] ) == 0 + echomsg "style '".lstyle."' : no templates defined" + return + endif + let s:C_ActualStyleLast = s:C_ActualStyle + let s:C_ActualStyle = lstyle + if len( s:C_ActualStyle ) > 1 && s:C_ActualStyle != s:C_ActualStyleLast + echomsg "template style is '".lstyle."'" + endif + else + echomsg "style '".lstyle."' does not exist" + endif +endfunction " ---------- end of function C_Style ---------- + +"------------------------------------------------------------------------------ +" C_StyleList {{{1 +" ex-command CStyle +"------------------------------------------------------------------------------ +function! C_StyleList ( ArgLead, CmdLine, CursorPos ) + " show all types / types beginning with a:ArgLead + return filter( copy(keys( s:C_Template) ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) +endfunction " ---------- end of function C_StyleList ---------- + +"------------------------------------------------------------------------------ +" C_OpenFold {{{1 +" Open fold and go to the first or last line of this fold. +"------------------------------------------------------------------------------ +function! C_OpenFold ( mode ) + if foldclosed(".") >= 0 + " we are on a closed fold: get end position, open fold, jump to the + " last line of the previously closed fold + let foldstart = foldclosed(".") + let foldend = foldclosedend(".") + normal zv + if a:mode == 'below' + exe ":".foldend + endif + if a:mode == 'start' + exe ":".foldstart + endif + endif +endfunction " ---------- end of function C_OpenFold ---------- + +"------------------------------------------------------------------------------ +" C_InsertTemplate {{{1 +" insert a template from the template dictionary +" do macro expansion +"------------------------------------------------------------------------------ +function! C_InsertTemplate ( key, ... ) + + if !has_key( s:C_Template[s:C_ActualStyle], a:key ) && + \ !has_key( s:C_Template['default'], a:key ) + echomsg "style '".a:key."' / template '".a:key + \ ."' not found. Please check your template file in '".s:C_GlobalTemplateDir."'" + return + endif + + if &foldenable + let foldmethod_save = &foldmethod + set foldmethod=manual + endif + "------------------------------------------------------------------------------ + " insert the user macros + "------------------------------------------------------------------------------ + + " use internal formatting to avoid conficts when using == below + " + let equalprg_save = &equalprg + set equalprg= + + let mode = s:C_Attribute[a:key] + + " remove <SPLIT> and insert the complete macro + " + if a:0 == 0 + let val = C_ExpandUserMacros (a:key) + if val == "" + return + endif + let val = C_ExpandSingleMacro( val, '<SPLIT>', '' ) + + if mode == 'below' + call C_OpenFold('below') + let pos1 = line(".")+1 + put =val + let pos2 = line(".") + " proper indenting + exe ":".pos1 + let ins = pos2-pos1+1 + exe "normal ".ins."==" + " + elseif mode == 'above' + let pos1 = line(".") + put! =val + let pos2 = line(".") + " proper indenting + exe ":".pos1 + let ins = pos2-pos1+1 + exe "normal ".ins."==" + " + elseif mode == 'start' + normal gg + call C_OpenFold('start') + let pos1 = 1 + put! =val + let pos2 = line(".") + " proper indenting + exe ":".pos1 + let ins = pos2-pos1+1 + exe "normal ".ins."==" + " + elseif mode == 'append' + if &foldenable && foldclosed(".") >= 0 + echohl WarningMsg | echomsg s:MsgInsNotAvail | echohl None + exe "set foldmethod=".foldmethod_save + return + else + let pos1 = line(".") + put =val + let pos2 = line(".")-1 + exe ":".pos1 + :join! + endif + " + elseif mode == 'insert' + if &foldenable && foldclosed(".") >= 0 + echohl WarningMsg | echomsg s:MsgInsNotAvail | echohl None + exe "set foldmethod=".foldmethod_save + return + else + let val = substitute( val, '\n$', '', '' ) + let currentline = getline( "." ) + let pos1 = line(".") + let pos2 = pos1 + count( split(val,'\zs'), "\n" ) + " assign to the unnamed register "" : + let @"=val + normal p + " reformat only multiline inserts and previously empty lines + if pos2-pos1 > 0 || currentline =~ '' + exe ":".pos1 + let ins = pos2-pos1+1 + exe "normal ".ins."==" + endif + endif + " + endif + " + else + " + " ===== visual mode =============================== + " + if a:1 == 'v' + let val = C_ExpandUserMacros (a:key) + let val = C_ExpandSingleMacro( val, s:C_TemplateJumpTarget2, '' ) + if val == "" + return + endif + + if match( val, '<SPLIT>\s*\n' ) >= 0 + let part = split( val, '<SPLIT>\s*\n' ) + else + let part = split( val, '<SPLIT>' ) + endif + + if len(part) < 2 + let part = [ "" ] + part + echomsg 'SPLIT missing in template '.a:key + endif + " + " 'visual' and mode 'insert': + " <part0><marked area><part1> + " part0 and part1 can consist of several lines + " + if mode == 'insert' + let pos1 = line(".") + let pos2 = pos1 + let string= @* + let replacement = part[0].string.part[1] + " remove trailing '\n' + let replacement = substitute( replacement, '\n$', '', '' ) + exe ':s/'.string.'/'.replacement.'/' + endif + " + " 'visual' and mode 'below': + " <part0> + " <marked area> + " <part1> + " part0 and part1 can consist of several lines + " + if mode == 'below' + + :'<put! =part[0] + :'>put =part[1] + + let pos1 = line("'<") - len(split(part[0], '\n' )) + let pos2 = line("'>") + len(split(part[1], '\n' )) + "" echo part[0] part[1] pos1 pos2 + " " proper indenting + exe ":".pos1 + let ins = pos2-pos1+1 + exe "normal ".ins."==" + endif + " + endif " ---------- end visual mode + endif + + " restore formatter programm + let &equalprg = equalprg_save + + "------------------------------------------------------------------------------ + " position the cursor + "------------------------------------------------------------------------------ + exe ":".pos1 + let mtch = search( '<CURSOR>', 'c', pos2 ) + if mtch != 0 + let line = getline(mtch) + if line =~ '<CURSOR>$' + call setline( mtch, substitute( line, '<CURSOR>', '', '' ) ) + if a:0 != 0 && a:1 == 'v' && getline(".") =~ '^\s*$' + normal J + else + :startinsert! + endif + else + call setline( mtch, substitute( line, '<CURSOR>', '', '' ) ) + :startinsert + endif + else + " to the end of the block; needed for repeated inserts + if mode == 'below' + exe ":".pos2 + endif + endif + + "------------------------------------------------------------------------------ + " marked words + "------------------------------------------------------------------------------ + " define a pattern to highlight + call C_HighlightJumpTargets () + + if &foldenable + " restore folding method + exe "set foldmethod=".foldmethod_save + normal zv + endif + +endfunction " ---------- end of function C_InsertTemplate ---------- + +"------------------------------------------------------------------------------ +" C_HighlightJumpTargets +"------------------------------------------------------------------------------ +function! C_HighlightJumpTargets () + if s:C_Ctrl_j == 'on' + exe 'match Search /'.s:C_TemplateJumpTarget1.'\|'.s:C_TemplateJumpTarget2.'/' + endif +endfunction " ---------- end of function C_HighlightJumpTargets ---------- + +"------------------------------------------------------------------------------ +" C_JumpCtrlJ {{{1 +"------------------------------------------------------------------------------ +function! C_JumpCtrlJ () + let match = search( s:C_TemplateJumpTarget1.'\|'.s:C_TemplateJumpTarget2, 'c' ) + if match > 0 + " remove the target + call setline( match, substitute( getline('.'), s:C_TemplateJumpTarget1.'\|'.s:C_TemplateJumpTarget2, '', '' ) ) + else + " try to jump behind parenthesis or strings in the current line + if match( getline(".")[col(".") - 1], "[\]})\"'`]" ) != 0 + call search( "[\]})\"'`]", '', line(".") ) + endif + normal l + endif + return '' +endfunction " ---------- end of function C_JumpCtrlJ ---------- + +"------------------------------------------------------------------------------ +" C_ExpandUserMacros {{{1 +"------------------------------------------------------------------------------ +function! C_ExpandUserMacros ( key ) + + if has_key( s:C_Template[s:C_ActualStyle], a:key ) + let template = s:C_Template[s:C_ActualStyle][ a:key ] + else + let template = s:C_Template['default'][ a:key ] + endif + let s:C_ExpansionCounter = {} " reset the expansion counter + + "------------------------------------------------------------------------------ + " renew the predefined macros and expand them + " can be replaced, with e.g. |?DATE| + "------------------------------------------------------------------------------ + let s:C_Macro['|BASENAME|'] = toupper(expand("%:t:r")) + let s:C_Macro['|DATE|'] = C_DateAndTime('d') + let s:C_Macro['|FILENAME|'] = expand("%:t") + let s:C_Macro['|PATH|'] = expand("%:p:h") + let s:C_Macro['|SUFFIX|'] = expand("%:e") + let s:C_Macro['|TIME|'] = C_DateAndTime('t') + let s:C_Macro['|YEAR|'] = C_DateAndTime('y') + + "------------------------------------------------------------------------------ + " delete jump targets if mapping for C-j is off + "------------------------------------------------------------------------------ + if s:C_Ctrl_j == 'off' + let template = substitute( template, s:C_TemplateJumpTarget1.'\|'.s:C_TemplateJumpTarget2, '', 'g' ) + endif + + "------------------------------------------------------------------------------ + " look for replacements + "------------------------------------------------------------------------------ + while match( template, s:C_ExpansionRegex ) != -1 + let macro = matchstr( template, s:C_ExpansionRegex ) + let replacement = substitute( macro, '?', '', '' ) + let template = substitute( template, macro, replacement, "g" ) + + let match = matchlist( macro, s:C_ExpansionRegex ) + + if match[1] != '' + let macroname = '|'.match[1].'|' + " + " notify flag action, if any + let flagaction = '' + if has_key( s:C_MacroFlag, match[2] ) + let flagaction = ' (-> '.s:C_MacroFlag[ match[2] ].')' + endif + " + " ask for a replacement + if has_key( s:C_Macro, macroname ) + let name = C_Input( match[1].flagaction.' : ', C_ApplyFlag( s:C_Macro[macroname], match[2] ) ) + else + let name = C_Input( match[1].flagaction.' : ', '' ) + endif + if name == "" + return "" + endif + " + " keep the modified name + let s:C_Macro[macroname] = C_ApplyFlag( name, match[2] ) + endif + endwhile + + "------------------------------------------------------------------------------ + " do the actual macro expansion + " loop over the macros found in the template + "------------------------------------------------------------------------------ + while match( template, s:C_NonExpansionRegex ) != -1 + + let macro = matchstr( template, s:C_NonExpansionRegex ) + let match = matchlist( macro, s:C_NonExpansionRegex ) + + if match[1] != '' + let macroname = '|'.match[1].'|' + + if has_key( s:C_Macro, macroname ) + "------------------------------------------------------------------------------- + " check for recursion + "------------------------------------------------------------------------------- + if has_key( s:C_ExpansionCounter, macroname ) + let s:C_ExpansionCounter[macroname] += 1 + else + let s:C_ExpansionCounter[macroname] = 0 + endif + if s:C_ExpansionCounter[macroname] >= s:C_ExpansionLimit + echomsg " recursion terminated for recursive macro ".macroname + return template + endif + "------------------------------------------------------------------------------- + " replace + "------------------------------------------------------------------------------- + let replacement = C_ApplyFlag( s:C_Macro[macroname], match[2] ) + let template = substitute( template, macro, replacement, "g" ) + else + " + " macro not yet defined + let s:C_Macro['|'.match[1].'|'] = '' + endif + endif + + endwhile + + return template +endfunction " ---------- end of function C_ExpandUserMacros ---------- + +"------------------------------------------------------------------------------ +" C_ApplyFlag {{{1 +"------------------------------------------------------------------------------ +function! C_ApplyFlag ( val, flag ) + " + " l : lowercase + if a:flag == ':l' + return tolower(a:val) + endif + " + " u : uppercase + if a:flag == ':u' + return toupper(a:val) + endif + " + " c : capitalize + if a:flag == ':c' + return toupper(a:val[0]).a:val[1:] + endif + " + " L : legalized name + if a:flag == ':L' + return C_LegalizeName(a:val) + endif + " + " flag not valid + return a:val +endfunction " ---------- end of function C_ApplyFlag ---------- +" +"------------------------------------------------------------------------------ +" C_ExpandSingleMacro {{{1 +"------------------------------------------------------------------------------ +function! C_ExpandSingleMacro ( val, macroname, replacement ) + return substitute( a:val, escape(a:macroname, '$' ), a:replacement, "g" ) +endfunction " ---------- end of function C_ExpandSingleMacro ---------- + +"------------------------------------------------------------------------------ +" C_SetSmallCommentStyle {{{1 +"------------------------------------------------------------------------------ +function! C_SetSmallCommentStyle () + if has_key( s:C_Template, 'comment.end-of-line-comment' ) + if match( s:C_Template['comment.end-of-line-comment'], '^\s*/\*' ) != -1 + let s:C_Com1 = '/*' " C-style : comment start + let s:C_Com2 = '*/' " C-style : comment end + else + let s:C_Com1 = '//' " C++style : comment start + let s:C_Com2 = '' " C++style : comment end + endif + endif +endfunction " ---------- end of function C_SetSmallCommentStyle ---------- + +"------------------------------------------------------------------------------ +" C_InsertMacroValue {{{1 +"------------------------------------------------------------------------------ +function! C_InsertMacroValue ( key ) + if s:C_Macro['|'.a:key.'|'] == '' + echomsg 'the tag |'.a:key.'| is empty' + return + endif + " + if &foldenable && foldclosed(".") >= 0 + echohl WarningMsg | echomsg s:MsgInsNotAvail | echohl None + return + endif + if col(".") > 1 + exe 'normal a'.s:C_Macro['|'.a:key.'|'] + else + exe 'normal i'.s:C_Macro['|'.a:key.'|'] + endif +endfunction " ---------- end of function C_InsertMacroValue ---------- + +"------------------------------------------------------------------------------ +" insert date and time {{{1 +"------------------------------------------------------------------------------ +function! C_InsertDateAndTime ( format ) + if &foldenable && foldclosed(".") >= 0 + echohl WarningMsg | echomsg s:MsgInsNotAvail | echohl None + return "" + endif + if col(".") > 1 + exe 'normal a'.C_DateAndTime(a:format) + else + exe 'normal i'.C_DateAndTime(a:format) + endif +endfunction " ---------- end of function C_InsertDateAndTime ---------- + +"------------------------------------------------------------------------------ +" generate date and time {{{1 +"------------------------------------------------------------------------------ +function! C_DateAndTime ( format ) + if a:format == 'd' + return strftime( s:C_FormatDate ) + elseif a:format == 't' + return strftime( s:C_FormatTime ) + elseif a:format == 'dt' + return strftime( s:C_FormatDate ).' '.strftime( s:C_FormatTime ) + elseif a:format == 'y' + return strftime( s:C_FormatYear ) + endif +endfunction " ---------- end of function C_DateAndTime ---------- + +"------------------------------------------------------------------------------ +" check for header or implementation file {{{1 +"------------------------------------------------------------------------------ +function! C_InsertTemplateWrapper () + if index( s:C_SourceCodeExtensionsList, expand('%:e') ) >= 0 + call C_InsertTemplate("comment.file-description") + else + call C_InsertTemplate("comment.file-description-header") + endif +endfunction " ---------- end of function C_InsertTemplateWrapper ---------- + +" +"------------------------------------------------------------------------------- +" Comment : C/C++ File Sections {{{1 +"------------------------------------------------------------------------------- +let s:CFileSection = { + \ "Header\ File\ Includes" : "file-section-cpp-header-includes" , + \ "Local\ Macros" : "file-section-cpp-macros" , + \ "Local\ Type\ Def\." : "file-section-cpp-typedefs" , + \ "Local\ Data\ Types" : "file-section-cpp-data-types" , + \ "Local\ Variables" : "file-section-cpp-local-variables" , + \ "Local\ Prototypes" : "file-section-cpp-prototypes" , + \ "Exp\.\ Function\ Def\." : "file-section-cpp-function-defs-exported" , + \ "Local\ Function\ Def\." : "file-section-cpp-function-defs-local" , + \ "Local\ Class\ Def\." : "file-section-cpp-class-defs" , + \ "Exp\.\ Class\ Impl\." : "file-section-cpp-class-implementations-exported", + \ "Local\ Class\ Impl\." : "file-section-cpp-class-implementations-local" , + \ "All\ sections,\ C" : "c", + \ "All\ sections,\ C++" : "cpp", + \ } + +function! C_CFileSectionList ( ArgLead, CmdLine, CursorPos ) + return filter( copy( sort(keys( s:CFileSection)) ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) +endfunction " ---------- end of function C_CFileSectionList ---------- + +function! C_CFileSectionListInsert ( arg ) + if has_key( s:CFileSection, a:arg ) + if s:CFileSection[a:arg] == 'c' || s:CFileSection[a:arg] == 'cpp' + call C_Comment_C_SectionAll( 'comment.'.s:CFileSection[a:arg] ) + return + endif + call C_InsertTemplate( 'comment.'.s:CFileSection[a:arg] ) + else + echomsg "entry ".a:arg." does not exist" + endif +endfunction " ---------- end of function C_CFileSectionListInsert ---------- +" +"------------------------------------------------------------------------------- +" Comment : H File Sections {{{1 +"------------------------------------------------------------------------------- +let s:HFileSection = { + \ "Header\ File\ Includes" : "file-section-hpp-header-includes" , + \ "Exported\ Macros" : "file-section-hpp-macros" , + \ "Exported\ Type\ Def\." : "file-section-hpp-exported-typedefs" , + \ "Exported\ Data\ Types" : "file-section-hpp-exported-data-types" , + \ "Exported\ Variables" : "file-section-hpp-exported-variables" , + \ "Exported\ Funct\.\ Decl\." : "file-section-hpp-exported-function-declarations", + \ "Exported\ Class\ Def\." : "file-section-hpp-exported-class-defs" , + \ "All\ sections,\ C" : "c" , + \ "All\ sections,\ C++" : "cpp" , + \ } + +function! C_HFileSectionList ( ArgLead, CmdLine, CursorPos ) + return filter( copy( sort(keys( s:HFileSection)) ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) +endfunction " ---------- end of function C_HFileSectionList ---------- + +function! C_HFileSectionListInsert ( arg ) + if has_key( s:HFileSection, a:arg ) + if s:HFileSection[a:arg] == 'c' || s:HFileSection[a:arg] == 'cpp' + call C_Comment_C_SectionAll( 'comment.'.s:HFileSection[a:arg] ) + return + endif + call C_InsertTemplate( 'comment.'.s:HFileSection[a:arg] ) + else + echomsg "entry ".a:arg." does not exist" + endif +endfunction " ---------- end of function C_HFileSectionListInsert ---------- +" +"------------------------------------------------------------------------------- +" Comment : Keyword Comments {{{1 +"------------------------------------------------------------------------------- +let s:KeywordComment = { + \ 'BUG' : 'keyword-bug', + \ 'COMPILER' : 'keyword-compiler', + \ 'TODO' : 'keyword-todo', + \ 'TRICKY' : 'keyword-tricky', + \ 'WARNING' : 'keyword-warning', + \ 'WORKAROUND' : 'keyword-workaround', + \ 'new\ keyword' : 'keyword-keyword', + \ } + +function! C_KeywordCommentList ( ArgLead, CmdLine, CursorPos ) + return filter( copy( sort(keys( s:KeywordComment)) ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) +endfunction " ---------- end of function C_KeywordCommentList ---------- + +function! C_KeywordCommentListInsert ( arg ) + if has_key( s:KeywordComment, a:arg ) + if s:KeywordComment[a:arg] == 'c' || s:KeywordComment[a:arg] == 'cpp' + call C_Comment_C_SectionAll( 'comment.'.s:KeywordComment[a:arg] ) + return + endif + call C_InsertTemplate( 'comment.'.s:KeywordComment[a:arg] ) + else + echomsg "entry ".a:arg." does not exist" + endif +endfunction " ---------- end of function C_KeywordCommentListInsert ---------- +" +"------------------------------------------------------------------------------- +" Comment : Special Comments {{{1 +"------------------------------------------------------------------------------- +let s:SpecialComment = { + \ 'EMPTY' : 'special-empty' , + \ 'FALL\ THROUGH' : 'special-fall-through' , + \ 'IMPL\.\ TYPE\ CONV' : 'special-implicit-type-conversion")' , + \ 'NO\ RETURN' : 'special-no-return' , + \ 'NOT\ REACHED' : 'special-not-reached' , + \ 'TO\ BE\ IMPL\.' : 'special-remains-to-be-implemented' , + \ 'constant\ type\ is\ long\ (L)' : 'special-constant-type-is-long' , + \ 'constant\ type\ is\ unsigned\ (U)' : 'special-constant-type-is-unsigned' , + \ 'constant\ type\ is\ unsigned\ long\ (UL)' : 'special-constant-type-is-unsigned-long' , + \ } + +function! C_SpecialCommentList ( ArgLead, CmdLine, CursorPos ) + return filter( copy( sort(keys( s:SpecialComment)) ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) +endfunction " ---------- end of function C_SpecialCommentList ---------- + +function! C_SpecialCommentListInsert ( arg ) + if has_key( s:SpecialComment, a:arg ) + if s:SpecialComment[a:arg] == 'c' || s:SpecialComment[a:arg] == 'cpp' + call C_Comment_C_SectionAll( 'comment.'.s:SpecialComment[a:arg] ) + return + endif + call C_InsertTemplate( 'comment.'.s:SpecialComment[a:arg] ) + else + echomsg "entry ".a:arg." does not exist" + endif +endfunction " ---------- end of function C_SpecialCommentListInsert ---------- + +"------------------------------------------------------------------------------- +" Standard Library Includes +"------------------------------------------------------------------------------- +function! C_CleanDirNameList ( list ) + let result = copy( a:list ) + let index = 0 + while index < len( result ) + let result[index] = substitute( result[index], '[&\\]', '', 'g' ) + let index = index + 1 + endwhile + return result +endfunction " ---------- end of function C_CleanDirNameList ---------- + +let s:C_StandardLibsClean = C_CleanDirNameList( s:C_StandardLibs ) +let s:C_C99LibsClean = C_CleanDirNameList( s:C_C99Libs ) +let s:Cpp_StandardLibsClean = C_CleanDirNameList( s:Cpp_StandardLibs ) +let s:Cpp_CStandardLibsClean = C_CleanDirNameList( s:Cpp_CStandardLibs ) + +"------------------------------------------------------------------------------- +" callback functions used in the filetype plugin ftplugin/c.vim +" callback functions +"------------------------------------------------------------------------------- + +function! C_IncludesInsert ( arg, List ) + if index( a:List, a:arg ) >= 0 + let zz = "#include\t<".a:arg.'>' + put =zz + else + echomsg "entry ".a:arg." does not exist" + endif +endfunction " ---------- end of function C_IncludesInsert +" +function! C_StdLibraryIncludesInsert ( arg ) + call C_IncludesInsert ( a:arg, s:C_StandardLibsClean ) +endfunction " ---------- end of function C_StdLibraryIncludesInsert + +function! C_C99LibraryIncludesInsert ( arg ) + call C_IncludesInsert ( a:arg, s:C_C99LibsClean ) +endfunction " ---------- end of function C_C99LibraryIncludesInsert + +function! C_CppLibraryIncludesInsert ( arg ) + call C_IncludesInsert ( a:arg, s:Cpp_StandardLibsClean ) +endfunction " ---------- end of function C_CppLibraryIncludesInsert + +function! C_CppCLibraryIncludesInsert ( arg ) + call C_IncludesInsert ( a:arg, s:Cpp_CStandardLibsClean ) +endfunction " ---------- end of function C_CppCLibraryIncludesInsert + +"------------------------------------------------------------------------------- +" callback functions used in the filetype plugin ftplugin/c.vim +" custom completion +"------------------------------------------------------------------------------- + +function! C_IncludesList ( ArgLead, CmdLine, CursorPos, List ) + " show all libs + if a:ArgLead == '' + return a:List + endif + " show libs beginning with a:ArgLead + let expansions = [] + for item in a:List + if match( item, '\<'.a:ArgLead.'\w*' ) == 0 + call add( expansions, item ) + endif + endfor + return expansions +endfunction " ---------- end of function C_IncludesList ---------- +" +function! C_StdLibraryIncludesList ( ArgLead, CmdLine, CursorPos ) + return C_IncludesList ( a:ArgLead, a:CmdLine, a:CursorPos, s:C_StandardLibsClean ) +endfunction " ---------- end of function C_StdLibraryIncludesList ---------- + +function! C_C99LibraryIncludesList ( ArgLead, CmdLine, CursorPos ) + return C_IncludesList ( a:ArgLead, a:CmdLine, a:CursorPos, s:C_C99LibsClean ) +endfunction " ---------- end of function C_C99LibraryIncludesList ---------- + +function! C_CppLibraryIncludesList ( ArgLead, CmdLine, CursorPos ) + return C_IncludesList ( a:ArgLead, a:CmdLine, a:CursorPos, s:Cpp_StandardLibsClean ) +endfunction " ---------- end of function C_CppLibraryIncludesList ---------- + +function! C_CppCLibraryIncludesList ( ArgLead, CmdLine, CursorPos ) + return C_IncludesList ( a:ArgLead, a:CmdLine, a:CursorPos, s:Cpp_CStandardLibsClean ) +endfunction " ---------- end of function C_CppCLibraryIncludesList ---------- + +"------------------------------------------------------------------------------ +" show / hide the c-support menus +" define key mappings (gVim only) +"------------------------------------------------------------------------------ +" +if has("gui_running") + " + call C_ToolMenu() + " + if s:C_LoadMenus == 'yes' + call C_CreateGuiMenus() + endif + " + nmap <unique> <silent> <Leader>lcs :call C_CreateGuiMenus()<CR> + nmap <unique> <silent> <Leader>ucs :call C_RemoveGuiMenus()<CR> + " +endif + +"------------------------------------------------------------------------------ +" Automated header insertion +" Local settings for the quickfix window +"------------------------------------------------------------------------------ + +if has("autocmd") + " + " Automated header insertion (suffixes from the gcc manual) + " + if !exists( 'g:C_Styles' ) + "------------------------------------------------------------------------------- + " template styles are the default settings + "------------------------------------------------------------------------------- + autocmd BufNewFile * if (&filetype=='cpp' || &filetype=='c') | + \ call C_InsertTemplateWrapper() | endif + " + " *.h has filetype 'cpp' by default; this can be changed to 'c' : + " + if s:C_TypeOfH=='c' + autocmd BufNewFile,BufEnter *.h :set filetype=c + endif + " + " C/C++ source code files which should not be preprocessed. + " + autocmd BufNewFile,BufRead *.i :set filetype=c + autocmd BufNewFile,BufRead *.ii :set filetype=cpp + " + else + "------------------------------------------------------------------------------- + " template styles are related to file extensions + "------------------------------------------------------------------------------- + for [ pattern, stl ] in items( g:C_Styles ) + exe "autocmd BufNewFile,BufRead,BufEnter ".pattern." call C_Style( '".stl."' )" + exe "autocmd BufNewFile ".pattern." call C_InsertTemplateWrapper() | :w!" + endfor + " + endif + " + " Wrap error descriptions in the quickfix window. + " + autocmd BufReadPost quickfix setlocal wrap | setlocal linebreak + " + exe 'autocmd BufRead *.'.join( s:C_SourceCodeExtensionsList, '\|*.' ) + \ .' call C_HighlightJumpTargets()' + " +endif " has("autocmd") +" +"------------------------------------------------------------------------------ +" READ THE TEMPLATE FILES +"------------------------------------------------------------------------------ +call C_ReadTemplates(s:C_GlobalTemplateFile) +if s:installation == 'system' && filereadable( s:C_LocalTemplateFile ) + call C_ReadTemplates( s:C_LocalTemplateFile ) +endif +" +"===================================================================================== +" vim: tabstop=2 shiftwidth=2 foldmethod=marker diff --git a/.vim/plugin/crefvim.vim b/.vim/plugin/crefvim.vim new file mode 100755 index 0000000..db0c757 --- /dev/null +++ b/.vim/plugin/crefvim.vim @@ -0,0 +1,356 @@ +"***************************************************************************** +"** Name: crefvim.vim - a C-Reference for Vim ** +"** ** +"** Type: global VIM plugin ** +"** ** +"** Author: Christian Habermann ** +"** christian(at)habermann-net(point)de ** +"** ** +"** Copyright: (c) 2002, 2003 by Christian Habermann ** +"** ** +"** License: GNU General Public License 2 (GPL 2) or later ** +"** ** +"** This program is free software; you can redistribute it ** +"** and/or modify it under the terms of the GNU General Public ** +"** License as published by the Free Software Foundation; either ** +"** version 2 of the License, or (at your option) any later ** +"** version. ** +"** ** +"** This program is distributed in the hope that it will be ** +"** useful, but WITHOUT ANY WARRANTY; without even the implied ** +"** warrenty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ** +"** PURPOSE. ** +"** See the GNU General Public License for more details. ** +"** ** +"** Version: 1.0.0 ** +"** tested under Linux (vim, gvim 6.1) and Win32 (gvim 6.1) ** +"** ** +"** History: 0.1.0 12. Dec. 2002 - 23. Feb. 2003 ** +"** initial version, not released ** +"** 1.0.0 6. Apr. 2003 ** +"** no changes, first release ** +"** ** +"** ** +"***************************************************************************** +"** Description: ** +"** This script's intention is to provide a C-reference manual that can ** +"** be accessed from within Vim. ** +"** ** +"** For futher information see crefvim.txt or do :help crefvim ** +"** ** +"** ** +"** Happy viming... ** +"***************************************************************************** + +" allow user to avoid loading this plugin and prevent loading twice +if exists ("loaded_crefvim") + finish +endif + +let loaded_crefvim = 1 + + + + +"***************************************************************************** +"************************** C O N F I G U R A T I O N ************************ +"***************************************************************************** + +" the mappings: +if !hasmapto('<Plug>CRV_CRefVimVisual') + vmap <silent> <unique> <Leader>cr <Plug>CRV_CRefVimVisual +endif +if !hasmapto('<Plug>CRV_CRefVimNormal') + nmap <silent> <unique> <Leader>cr <Plug>CRV_CRefVimNormal +endif +if !hasmapto('<Plug>CRV_CRefVimAsk') + map <silent> <unique> <Leader>cw <Plug>CRV_CRefVimAsk +endif +if !hasmapto('<Plug>CRV_CRefVimInvoke') + map <silent> <unique> <Leader>cc <Plug>CRV_CRefVimInvoke +endif + +vmap <silent> <unique> <script> <Plug>CRV_CRefVimVisual y:call <SID>CRV_CRefVimWord('<c-r>"')<CR> +nmap <silent> <unique> <script> <Plug>CRV_CRefVimNormal :call <SID>CRV_CRefVimWord(expand("<cword>"))<CR> +map <silent> <unique> <script> <Plug>CRV_CRefVimAsk :call <SID>CRV_CRefVimAskForWord()<CR> +map <silent> <unique> <script> <Plug>CRV_CRefVimInvoke :call <SID>CRV_CRefVimShowContents()<CR> + + + + +"***************************************************************************** +"************************* I N I T I A L I S A T I O N *********************** +"***************************************************************************** + + +"***************************************************************************** +"****************** I N T E R F A C E T O C O R E ************************** +"***************************************************************************** + +"***************************************************************************** +"** this function separates plugin-core-function from user ** +"***************************************************************************** +function <SID>CRV_CRefVimWord(str) + call s:CRefVim(a:str) +endfunction + + +"***************************************************************************** +"** this function separates plugin-core-function from user ** +"***************************************************************************** +function <SID>CRV_CRefVimAskForWord() + call s:CRefVimAskForWord() +endfunction + + +"***************************************************************************** +"** this function separates plugin-core-function from user ** +"***************************************************************************** +function <SID>CRV_CRefVimShowContents() + " show contents of C-reference manual + call s:LookUp("") +endfunction + + + + + +"***************************************************************************** +"************************ C O R E F U N C T I O N S ************************* +"***************************************************************************** + +"***************************************************************************** +"** ask for a word/phrase and lookup ** +"***************************************************************************** +function s:CRefVimAskForWord() + let l:strng = input("What to lookup: ") + call s:LookUp(l:strng) +endfunction + + + +"***************************************************************************** +"** input: "str" ** +"** output: empty string: "str" is not an operator ** +"** else: name of tag to go to ** +"** ** +"***************************************************************************** +"** remarks: ** +"** This function tests whether or not "str" is an operator. ** +"** If so, the tag to go to is returned. ** +"** ** +"***************************************************************************** +function s:IsItAnOperator(str) + + " get first character + let l:firstChr = strpart(a:str, 0, 1) + + " is the first character of the help-string an operator? + if stridx("!&+-*/%,.:<=>?^|~(){}[]", l:firstChr) >= 0 + return "crv-operators" + else + return "" + endif + +endfunction + + + +"***************************************************************************** +"** input: "str" ** +"** output: empty string: "str" is not an escape-sequence ** +"** else: name of tag to go to ** +"** ** +"***************************************************************************** +"** remarks: ** +"** This function tests whether or not "str" is an escape-sequence. ** +"** If so, the tag to go to is returned. ** +"** Note: currently \' does not work (="\\\'") ** +"** ** +"***************************************************************************** +function s:IsItAnEscSequence(str) + + if (a:str == "\\") || (a:str == "\\\\") || (a:str == "\\0") || (a:str == "\\x") || + \(a:str == "\\a") || (a:str == "\\b") || (a:str == "\\f") || (a:str == "\\n") || + \(a:str == "\\r") || (a:str == "\\t") || (a:str == "\\v") || (a:str == "\\?") || + \(a:str == "\\\'") || (a:str == "\\\"") + return "crv-lngEscSeq" + else + return "" + endif + +endfunction + + + + +"***************************************************************************** +"** input: "str" ** +"** output: empty string: "str" is not a comment ** +"** else: name of tag to go to ** +"** ** +"***************************************************************************** +"** remarks: ** +"** This function tests whether or not "str" is a comment. ** +"** If so, the tag to go to is returned. ** +"** ** +"***************************************************************************** +function s:IsItAComment(str) + + if (a:str == "//") || (a:str == "/*") || (a:str == "*/") + return "crv-lngComment" + else + return "" + endif + +endfunction + + + + +"***************************************************************************** +"** input: "str" ** +"** output: empty string: "str" is not a preprocessor ** +"** else: name of tag to go to ** +"** ** +"***************************************************************************** +"** remarks: ** +"** This function tests whether or not "str" is a preprocessor command ** +"** or a preprocessor operator. ** +"** If so, the tag to go to is returned. ** +"** ** +"** Nothing is done if the help-string is equal to "if" or "else" ** +"** because these are statements too. For "if" and "else" it's assumed ** +"** that the statements are meant. But "#if" and "#else" are treated ** +"** as preprocessor commands. ** +"** ** +"***************************************************************************** +function s:IsItAPreprocessor(str) + + " get first character + let l:firstChr = strpart(a:str, 0, 1) + + " if first character of the help-string is a #, we have the command/operator + " string in an appropriate form, so append this help-string to "crv-" + if l:firstChr == "#" + return "crv-" . a:str + else + " no # in front of the help string, so evaluate which command/operator + " is meant + if (a:str == "defined") + return "crv-defined" + else + if (a:str == "define") || + \(a:str == "undef") || + \(a:str == "ifdef") || + \(a:str == "ifndef") || + \(a:str == "elif") || + \(a:str == "endif") || + \(a:str == "include") || + \(a:str == "line") || + \(a:str == "error") || + \(a:str == "pragma") + return "\#" . a:str + endif + endif + endif + +endfunction + + + + +"***************************************************************************** +"** input: "str" to lookup in C-reference manual ** +"** output: none ** +"***************************************************************************** +"** remarks: ** +"** Lookup string "str". ** +"** Generally this function calls :help crv-"str" where "str" is the ** +"** word for which the user wants some help. ** +"** ** +"** But before activating VIM's help-system some tests and/or ** +"** modifications are done on "str": ** +"** - if help-string is a comment (//, /* or */), go to section ** +"** describing comments ** +"** - if help-string is an escape-sequence, go to section describing ** +"** escape-sequences ** +"** - if help-string is an operator, go to section dealing with operators ** +"** - if help-string is a preprocessor command/operator, go to section ** +"** that describes that command/operator ** +"** - else call :help crv-"str" ** +"** ** +"** If the help-string is empty, go to contents of C-reference manual. ** +"** ** +"***************************************************************************** +function s:LookUp(str) + + if a:str != "" + + let l:helpTag = s:IsItAComment(a:str) + + if l:helpTag == "" + let l:helpTag = s:IsItAnEscSequence(a:str) + + if l:helpTag == "" + let l:helpTag = s:IsItAnOperator(a:str) + + if l:helpTag == "" + let l:helpTag = s:IsItAPreprocessor(a:str) + + if l:helpTag == "" + let l:helpTag = "crv-" . a:str + endif + + endif + + endif + + endif + + + " reset error message + let v:errmsg = "" + + " activate help-system looking for the appropriate topic + " suppress error messages + silent! execute ":help " . l:helpTag + + " if there was an error, print message + if v:errmsg != "" + echo " No help found for \"" .a:str . "\"" + endif + else + " help string is empty, so show contents of manual + execute ":help crefvim" + endif + + +endfunction + + + +"***************************************************************************** +"** input: "str" to lookup in C-reference manual ** +"** output: none ** +"***************************************************************************** +"** remarks: ** +"** lookup string "str". ** +"** If there is no string, ask for word/phrase. ** +"** ** +"***************************************************************************** +function s:CRefVim(str) + + let s:strng = a:str + + if s:strng == "" " is there a string to search for? + call s:CRefVimAskForWord() + else + call s:LookUp(s:strng) + endif + +endfunction + + + +"*** EOF *** diff --git a/.vim/plugin/cscope_maps.vim b/.vim/plugin/cscope_maps.vim new file mode 100644 index 0000000..c577b45 --- /dev/null +++ b/.vim/plugin/cscope_maps.vim @@ -0,0 +1,165 @@ +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" 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 cscopetag + + " 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-@ 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-@>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR> + + nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR> + nmap <C-@>g :scs find g <C-R>=expand("<cword>")<CR><CR> + nmap <C-@>c :scs find c <C-R>=expand("<cword>")<CR><CR> + nmap <C-@>t :scs find t <C-R>=expand("<cword>")<CR><CR> + nmap <C-@>e :scs find e <C-R>=expand("<cword>")<CR><CR> + nmap <C-@>f :scs find f <C-R>=expand("<cfile>")<CR><CR> + nmap <C-@>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR> + nmap <C-@>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 + " if you prefer the new window on the right instead of the left + + nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR> + nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR> + nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR> + nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR> + nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR> + nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR> + nmap <C-@><C-@>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR> + nmap <C-@><C-@>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 + +endif + + diff --git a/.vim/plugin/vtreeexplorer.vim b/.vim/plugin/vtreeexplorer.vim new file mode 100644 index 0000000..2458abc --- /dev/null +++ b/.vim/plugin/vtreeexplorer.vim @@ -0,0 +1,872 @@ +"" File: vtreeexplorer.vim +"" Description: tree-like file system explorer for vim +"" Version: $Revision: 1.24 $ $Date: 2005/11/17 16:24:33 $ +"" Author: TS Urban (thomas.scott.urban@HORMELgmail.com) +"" (remove the source of SPAM from my email first) +"" +"" Instructions: +"" 1 - source this file or put in your plugin directory +"" 2 - :VTreeExlorer or :VSTreeExplore +"" 3 - help at top of screen +"" 4 - this script comes with a help text that integrates with the vim help +"" system, put vtreeexplorer.txt in your ~/.vim/doc dir, then do +"" :helptags ~/.vim/doc +"" +"" Global Configuration Variables: +"" treeExplVertical : split vertically when starting with VSTreeExplore +"" treeExplWinSize : window size (width or height) when doing VSTreeExplore +"" treeExplHidden : set to have explorer start with hidden files shown +"" treeExplHidePattern : set have matching files not shown +"" treeExplDirSort : start explorer with desired directory sorting: +"" 0 : no directory sorting +"" 1 : directories sorting first +"" -1 : directories sorting last +"" treeExplIndent : width of tree indentation in spaces (min 3, max 8) +"" treeExplNoList : don't list the explorer in the buffer list +"" +"" Todo: +"" - global option for path separator +"" - merge in patches for winmanager +"" - +/- keymappings, etc +"" - recursively collapse binding/function + +"" prevent multiple loading unless developing with g:treeExplDebug +if exists("vloaded_tree_explorer") && !exists("g:treeExplDebug") + finish +endif +let vloaded_tree_explorer=1 + +let s:cpo_save = &cpo +set cpo&vim + +"" create commands +command! -n=? -complete=dir VTreeExplore :call s:TreeExplorer(0, '<args>') +command! -n=? -complete=dir VSTreeExplore :call s:TreeExplorer(1, '<args>') + +"" support sessions +autocmd BufNewFile TreeExplorer VTreeExplore + +"" create a string of chr cnt long - emulate vim7 repeat function +function! s:MyRepeat(chr, cnt) " <<< + let sret = "" + let lcnt = a:cnt + while lcnt > 0 + let sret = sret . a:chr + let lcnt = lcnt - 1 + endwhile + return sret +endf " >>> + +function! s:InitWindowVars() " <<< + if exists("w:tree_vars_defined") + return + endif + + let w:tree_vars_defined = 1 + + let w:escape_chars = " `|\"~'#" + + " win specific vars from globals if they exist + let w:hidden_files = (exists("g:treeExplHidden")) ? 1 : 0 + let w:dirsort = (exists("g:treeExplDirSort")) ? g:treeExplDirSort : 0 + if w:dirsort < -1 || w:dirsort > 1 + let w:dirsort = 0 + let w:escape_chars = w:escape_chars . '+' + endif + + " tree visual widget configuration, width limited to range [3,16] + let w:tree_wid_ind = (exists("g:treeExplIndent")) ? g:treeExplIndent : 3 + let w:tree_wid_ind = (w:tree_wid_ind < 3) ? 3 : w:tree_wid_ind + let w:tree_wid_ind = (w:tree_wid_ind > 8) ? 16 : w:tree_wid_ind + + let bar_char = '|' + let dsh_char = '-' + let grv_char = '`' + let spc_char = ' ' + + let w:tree_par_wid = bar_char . s:MyRepeat (spc_char, w:tree_wid_ind - 2) . spc_char + let w:tree_dir_wid = bar_char . s:MyRepeat (dsh_char, w:tree_wid_ind - 2) . spc_char + let w:tree_end_wid = grv_char . s:MyRepeat (dsh_char, w:tree_wid_ind - 2) . spc_char + let w:tree_spc_wid = s:MyRepeat (spc_char, w:tree_wid_ind) + + " init help to short version + let w:helplines = 1 + +endfunction " >>> + +"" TreeExplorer() - set up explorer window +function! s:TreeExplorer(split, start) " <<< + + " dir to start in from arg, buff dir, or pwd + let fname = (a:start != "") ? a:start : expand ("%:p:h") + let fname = (fname != "") ? fname : getcwd () + + " construct command to open window + if a:split || &modified + " if starting with split, get split parameters from globals + let splitMode = (exists("g:treeExplVertical")) ? "vertical " : "" + let splitSize = (exists("g:treeExplWinSize")) ? g:treeExplWinSize : 20 + let cmd = splitMode . splitSize . "new TreeExplorer" + else + let cmd = "e TreeExplorer" + endif + silent execute cmd + + call s:InitWindowVars() + + "" chars to escape in file/dir names - TODO '+' ? + " throwaway buffer options + setlocal noswapfile + setlocal buftype=nowrite + setlocal bufhidden=delete " d + setlocal nowrap + setlocal foldcolumn=0 + + if exists("g:treeExplNoList") + setlocal nobuflisted + endif + if has('spell') + setlocal nospell + endif + iabc <buffer> + + " setup folding for markers that will be inserted + setlocal foldmethod=marker + setlocal foldtext=substitute(getline(v:foldstart),'.{{{.*','','') + setlocal foldlevel=1 + + " syntax highlighting + if has("syntax") && exists("g:syntax_on") && !has("syntax_items") + syn match treeHlp #^" .*# + syn match treeDir "^\.\. (up a directory)$" + + syn match treeFld "{{{" + syn match treeFld "}}}" + + execute "syn match treePrt #" . w:tree_par_wid . "#" + execute "syn match treePrt #" . w:tree_dir_wid . "#" + execute "syn match treePrt #" . w:tree_end_wid . "#" + + syn match treeLnk #[^-| `].* -> # contains=treeFld + syn match treeDir #[^-| `].*/\([ {}]\{4\}\)*$# contains=treeFld,treeLnk + syn match treeCWD #^/.*$# contains=treeFld + + hi def link treePrt Normal + hi def link treeFld Ignore + hi def link treeHlp Special + hi def link treeDir Directory + hi def link treeCWD Statement + hi def link treeLnk Title + endif + + " for line continuation + let cpo_save1 = &cpo + set cpo&vim + + " set up mappings and commands for this buffer + nnoremap <buffer> <cr> :call <SID>Activate("win")<cr> + nnoremap <buffer> o :call <SID>Activate("win")<cr> + nnoremap <buffer> O :call <SID>Activate("cur")<cr> + nnoremap <buffer> t :call <SID>Activate("tab")<cr> + nnoremap <buffer> X :call <SID>RecursiveExpand()<cr> + nnoremap <buffer> E :call <SID>OpenExplorer()<cr> + nnoremap <buffer> C :call <SID>ChangeTop()<cr> + nnoremap <buffer> H :call <SID>InitWithDir($HOME)<cr> + nnoremap <buffer> u :call <SID>ChdirUp()<cr> + nnoremap <buffer> p :call <SID>MoveParent()<cr> + nnoremap <buffer> r :call <SID>RefreshDir()<cr> + nnoremap <buffer> R :call <SID>InitWithDir("")<cr> + nnoremap <buffer> S :call <SID>StartShell()<cr> + nnoremap <buffer> D :call <SID>ToggleDirSort()<cr> + nnoremap <buffer> a :call <SID>ToggleHiddenFiles()<cr> + nnoremap <buffer> ? :call <SID>ToggleHelp()<cr> + nnoremap <buffer> <2-leftmouse> :call <SID>Activate("win")<cr> + + command! -buffer -complete=dir -nargs=1 CD :call s:TreeCD('<args>') + command! -buffer -range -nargs=0 Yank :<line1>,<line2>y | + \ let @" = substitute (@", ' [{}]\{3\}', "", "g") + + let &cpo = cpo_save1 " restore + + call s:InitWithDir(fname) " load fname dir +endfunction " >>> + +"" TreeCD() - change to dir from cmdline arg +function! s:TreeCD(dir) " <<< + if isdirectory (a:dir) + call s:InitWithDir (a:dir) + else + echo "can not change to directory: " . a:dir + endif +endfunction " >>> + +"" InitWithDir() - reload tree with dir +function! s:InitWithDir(dir) " <<< + call s:InitWindowVars() + + if a:dir != "" + try + execute "lcd " . escape (a:dir, w:escape_chars) + catch + echo "ERROR: changing to directory: " . a:dir + return + endtry + endif + let cwd = getcwd () + + if has("unix") == 0 + let cwd = substitute (cwd, '\\', '/', "g") + let is_root = (cwd =~ '^[A-Z]:/$') ? 1 : 0 + else + let is_root = (cwd == "/") ? 1 : 0 + endif + + let cwd = substitute (cwd, '/*$', '/', "") + + let save_f = @f + let save_y = @" + + " clear buffer + setlocal modifiable | silent! normal ggdG + setlocal nomodifiable + + "insert header + call s:AddHeader() + normal G + + "insert parent link unless we're at / for unix or X:\ for dos + if is_root == 0 + let @f=".. (up a directory)" + endif + let @f=@f . "\n" . cwd . "\n\n" + + setlocal modifiable | silent put f | setlocal nomodifiable + + normal Gk + + call s:ReadDir (line("."), cwd) " read dir + + let @f = save_f + let @" = save_y +endfunction " >>> + +"" ReadDir() - read dir after current line with tree pieces and foldmarkers +function! s:ReadDir(lpn,dir) " <<< + let olddir = getcwd () + + let lps = getline (a:lpn) + + if a:dir == "" + let dir = GetAbsPath2 (lpn, 0) + if w:firstdirline ! = lpn + echo "ERROR" + return + endif + else + let dir = a:dir + endif + + " TODO - error when dir no longer exists + try + execute "lcd " . escape (dir, w:escape_chars) + catch + echo "ERROR: changing to directory: " . dir + return + endtry + + """ THIS BLOCK DOESN' DO ANYTHING + " change dos path to look like unix path + "if has("unix") == 0 " TODO - so many dos/win variants, this seemed easier - maybe not correct (e.g. OS2, mac, etc) + " let dir = substitute (dir, '\\', '/', "g") + "endif + "let dir = substitute (dir, '/\?$', '/', "") + """ THIS BLOCK DOESN' DO ANYTHING + + " get dir contents + if w:hidden_files == 1 + let dirlines = glob ('.*') . "\n" . glob ('*') + else + let dirlines = glob ('*') + endif + + " if empty, don't change line + if dirlines == "" + return + endif + + let treeprt = substitute (lps, '[^-| `].*', "", "") + let pdirprt = substitute (lps, '^[-| `]*', "", "") + let pdirprt = substitute (pdirprt, '[{} ]*$', "", "") + let foldprt = substitute (lps, '.*' . pdirprt, "", "") + + " save states of registers for restoring + " @l is used for first line, last line, and if dir sorting is off + " @f and @d are used for file and dirs with dir sorting + let save_l = @l | let @l = "" + let save_d = @d | let @d = "" + let save_f = @f | let @f = "" + let save_y = @" + + let @l = treeprt . pdirprt . ' {{{' + + let treeprt = substitute (treeprt, w:tree_end_wid, w:tree_spc_wid, "") + let treeprt = substitute (treeprt, w:tree_dir_wid, w:tree_par_wid, "") + + " parse dir contents by '/' + let dirlines = substitute (dirlines, "\n", '/', "g") + + if exists("g:treeExplHidePattern") + let do_hide_re = 1 + else + let do_hide_re = 0 + endif + + while strlen (dirlines) > 0 + let curdir = substitute (dirlines, '/.*', "", "") + let dirlines = substitute (dirlines, '[^/]*/\?', "", "") + + if w:hidden_files == 1 && curdir =~ '^\.\.\?$' + continue + endif + + if w:hidden_files == 0 && do_hide_re == 1 && curdir =~ g:treeExplHidePattern + continue + endif + + let linkedto = resolve (curdir) + if linkedto != curdir + let curdir = curdir . ' -> ' . linkedto + endif + if isdirectory (linkedto) + let isdir = 1 + let curdir = curdir . '/' + else + let isdir = 0 + endif + + " escape leading characters confused with tree parts + if curdir =~ '^[-| `]' + let curdir = '\' . curdir + endif + + if w:dirsort != 0 + if isdir == 1 + let @d = @d . "\n" . treeprt . w:tree_dir_wid . curdir + else + let @f = @f . "\n" . treeprt . w:tree_dir_wid . curdir + endif + else + let @l = @l . "\n" . treeprt . w:tree_dir_wid . curdir + endif + endwhile + + if w:dirsort == 1 + let @l = @l . @d . @f . "\n" + elseif w:dirsort == -1 + let @l = @l . @f . @d . "\n" + else + let @l = @l . "\n" + endif + + exec (":" . a:lpn) + + " TODO handle fold open v fold closed + setlocal modifiable + silent normal ddk + silent put l + setlocal nomodifiable + + " make sure fold is open so we don't delete the whole thing + "if foldclosed (line (".")) != -1 + if foldclosed (a:lpn) != -1 + foldopen + endif + + normal! `] + + " change last tree part to the final leaf marking, add final fold mark + let @l = getline(".") + let @l = substitute (@l, w:tree_dir_wid, w:tree_end_wid, "") + let @l = @l . foldprt . " }}}\n" + + setlocal modifiable | silent normal dd + silent put! l | setlocal nomodifiable + + " restore registers + let @l = save_l + let @d = save_d + let @f = save_f + let @" = save_y + + exec (":" . a:lpn) + + execute "lcd " . escape (olddir, w:escape_chars) +endfunction " >>> + +"" ChdirUp() - cd up (if possible) +function! s:ChdirUp() " <<< + let cwd = getcwd() + if cwd == "/" || cwd =~ '^[^/]..$' + echo "already at top dir" + else + call s:InitWithDir("..") + endif +endfunction " >>> + +"" MoveParent() - move cursor to parent dir +function! s:MoveParent() " <<< + call s:InitWindowVars() + + let ln = line(".") + call s:GetAbsPath2 (ln, 1) + if w:firstdirline != 0 + exec (":" . w:firstdirline) + else + exec (":" . w:helplines) + endif +endfunction " >>> + +"" ChangeTop() - change top dir to cursor dir +function! s:ChangeTop() " <<< + call s:InitWindowVars() + + let ln = line(".") + let l = getline(ln) + + " on current top or non-tree line? + if l !~ '^[| `]' + return + endif + + " parent dir + if l =~ '^\.\. ' + call s:ChdirUp() + return + endif + + let curfile = s:GetAbsPath2(ln, 0) + if curfile !~ '/$' + let curfile = substitute (curfile, '[^/]*$', "", "") + endif + call s:InitWithDir (curfile) +endfunction " >>> + +"" RecursiveExpand() - expand cursor dir recursively +function! s:RecursiveExpand() " <<< + call s:InitWindowVars() + + echo "recursively expanding, this might take a while (CTRL-C to stop)" + + let curfile = s:GetAbsPath2(line("."), 0) + + if w:firstdirline == 0 + let init_ln = w:helplines + let curfile = substitute (getline (init_ln), '[ {]*', "", "") + else + let init_ln = w:firstdirline + endif + + let init_ind = match (getline (init_ln), '[^-| `]') / w:tree_wid_ind + + let curfile = substitute (curfile, '[^/]*$', "", "") + + let l = getline (init_ln) + + if l =~ ' {{{$' + if foldclosed (init_ln) != -1 + foldopen + endif + endif + + if l !~ ' {{{$' " dir not open + call s:ReadDir (init_ln, curfile) + + if getline (init_ln) !~ ' {{{$' " dir still not open (empty) + echo "expansion done" + return + endif + endif + + let ln = init_ln + 1 + + let l = getline (ln) + + let match_str = '[^-| `]' + while init_ind < (match (l, '[^-| `]') / w:tree_wid_ind) + let tl = l + let tln = ln + let ln = ln + 1 + let l = getline (ln) + + if tl =~ ' {{{$' + if foldclosed (tln) != -1 + foldopen + endif + continue + endif + + " link or non dir + if tl =~ ' -> ' || tl !~ '/[ }]*$' + continue + endif + + let curfile = s:GetAbsPath2(tln, 0) + + call s:ReadDir (tln, curfile) + + let l = getline (ln) + endwhile + + exec (":" . init_ln) + echo "expansion done" +endfunction " >>> + +"" OpenExplorer() - open file explorer on cursor dir +function! s:OpenExplorer() " <<< + call s:InitWindowVars() + + let curfile = s:GetAbsPath2 (line ("."), 0) + + if w:firstdirline == 0 + let curfile = getcwd () + else + " remove file name, if any + let curfile = substitute (curfile, '[^/]*$', "", "") + endif + + let curfile = escape (curfile, w:escape_chars) + + let oldwin = winnr() + wincmd p + if oldwin == winnr() || &modified + wincmd p + exec ("new " . curfile) + else + exec ("edit " . curfile) + endif + +endfunction " >>> + +"" Activate() - (un)fold read dirs, read unread dirs, open files, cd .. on .. +function! s:Activate(how) " <<< + call s:InitWindowVars() + + let ln = line(".") + let l = getline(ln) + + " parent dir, change to it + if l =~ '^\.\. (up a directory)$' + call s:ChdirUp() + return + endif + + " directory loaded, toggle folded state + if l =~ ' {{{$' + if foldclosed(ln) == -1 + foldclose + else + foldopen + endif + return + endif + + " on top, no folds, or not on tree + if l !~ '^[-| `]' + return + endif + + " get path of line + let curfile = s:GetAbsPath2 (ln, 0) + + if curfile =~ '/$' " dir + call s:ReadDir (ln, curfile) + return + else " file + let f = escape (curfile, w:escape_chars) + let oldwin = winnr() + wincmd p + if a:how == "tab" + exec ("tabedit " . f) + elseif a:how == "cur" + exec ("tabedit " . f) + elseif oldwin == winnr() || (&modified && s:BufInWindows(winbufnr(winnr())) < 2) + wincmd p + exec ("new " . f) + else + exec ("edit " . f) + endif + endif +endfunction " >>> + +"" RefreshDir() - refresh current dir +function! s:RefreshDir() " <<< + call s:InitWindowVars() + + let curfile = s:GetAbsPath2(line("."), 0) + + let init_ln = w:firstdirline + + " not in tree, or on path line or parent is top + if curfile == "" || init_ln == 0 + call s:InitWithDir("") + return + endif + + let save_l = @l + + " remove file name, if any + let curfile = substitute (curfile, '[^/]*$', "", "") + + let @l = getline (init_ln) + + " if there is no fold, just do normal ReadDir, and return + if @l !~ ' {{{$' + call s:ReadDir (init_ln, curfile) + let @l = save_l + return + endif + + " TODO factor + + if foldclosed(init_ln) == -1 + foldclose + endif + + " remove one foldlevel from line + let @l = substitute (@l, ' {{{$', "", "") + + exec (":" . init_ln) + + setlocal modifiable + silent normal ddk + silent put l + setlocal nomodifiable + + call s:ReadDir (init_ln, curfile) + + let @l = save_l +endfunction " >>> + +"" ToggleHiddenFiles() - toggle hidden files +function! s:ToggleHiddenFiles() " <<< + call s:InitWindowVars() + + let w:hidden_files = w:hidden_files ? 0 : 1 + let msg = w:hidden_files ? "on" : "off" + let hre = exists("g:treeExplHidePattern") ? g:treeExplHidePattern : '' + let msg = "hidden (dotfiles and regex = '" . hre . "') files now = " . msg + echo msg + call s:UpdateHeader () + call s:RefreshDir() +endfunction " >>> + +"" ToggleDirSort() - toggle dir sorting +function! s:ToggleDirSort() " <<< + call s:InitWindowVars() + + if w:dirsort == 0 + let w:dirsort = 1 + let msg = "dirs first" + elseif w:dirsort > 0 + let w:dirsort = -1 + let msg = "dirs last" + else + let w:dirsort = 0 + let msg = "off" + endif + let msg = "dirs sorting now = " . msg + echo msg + call s:UpdateHeader () + call s:RefreshDir() +endfunction " >>> + +"" StartShell() - start shell in cursor dir +function! s:StartShell() " <<< + call s:InitWindowVars() + + let ln = line(".") + + let curfile = s:GetAbsPath2 (ln, 1) + let prevdir = getcwd() + + if w:firstdirline == 0 + let dir = prevdir + else + let dir = substitute (curfile, '[^/]*$', "", "") + endif + + try + execute "lcd " . escape (dir, w:escape_chars) + shell + catch + echo "ERROR: changing to directory: " . dir + return + endtry + execute "lcd " . escape (prevdir, w:escape_chars) +endfunction " >>> + +"" GetAbsPath2() - get absolute path at line ln, set w:firstdirline, +"" - if ignore_current is 1, don't set line to current line when on a dir +function! s:GetAbsPath2(ln,ignore_current) " <<< + let lnum = a:ln + let l = getline(lnum) + + let w:firstdirline = 0 + + " in case called from outside the tree + if l =~ '^[/".]' || l =~ '^$' + return "" + endif + + let wasdir = 0 + + " strip file + let curfile = substitute (l,'^[-| `]*',"","") " remove tree parts + let curfile = substitute (curfile,'[ {}]*$',"",'') " remove fold marks + "let curfile = substitute (curfile,'[*=@|]$',"","") " remove file class + + " remove leading escape + let curfile = substitute (curfile,'^\\', "", "") + + if curfile =~ '/$' && a:ignore_current == 0 + let wasdir = 1 + let w:firstdirline = lnum + endif + + let curfile = substitute (curfile,' -> .*',"","") " remove link to + if wasdir == 1 + let curfile = substitute (curfile, '/\?$', '/', "") + endif + + let indent = match(l,'[^-| `]') / w:tree_wid_ind + + let dir = "" + while lnum > 0 + let lnum = lnum - 1 + let lp = getline(lnum) + if lp =~ '^/' + let sd = substitute (lp, '[ {]*$', "", "") + let dir = sd . dir + break + endif + if lp =~ ' {{{$' + let lpindent = match(lp,'[^-| `]') / w:tree_wid_ind + if lpindent < indent + if w:firstdirline == 0 + let w:firstdirline = lnum + endif + let indent = indent - 1 + let sd = substitute (lp, '^[-| `]*',"","") " rm tree parts + let sd = substitute (sd, '[ {}]*$', "", "") " rm foldmarks + let sd = substitute (sd, ' -> .*','/',"") " replace link to with / + + " remove leading escape + let sd = substitute (sd,'^\\', "", "") + + let dir = sd . dir + continue + endif + endif + endwhile + let curfile = dir . curfile + return curfile +endfunction " >>> + +"" ToggleHelp() - toggle between long and short help +function! s:ToggleHelp() " <<< + call s:InitWindowVars() + + let w:helplines = (w:helplines <= 4) ? 6 : 0 + call s:UpdateHeader () +endfunction " >>> + +"" Determine the number of windows open to this buffer number. +"" Care of Yegappan Lakshman. Thanks! +fun! s:BufInWindows(bnum) " <<< + let cnt = 0 + let winnum = 1 + while 1 + let bufnum = winbufnr(winnum) + if bufnum < 0 + break + endif + if bufnum == a:bnum + let cnt = cnt + 1 + endif + let winnum = winnum + 1 + endwhile + + return cnt +endfunction " >>> + +"" UpdateHeader() - update the header +function! s:UpdateHeader() " <<< + let oldRep=&report + set report=10000 + normal! mt + + " Remove old header + 0 + setlocal modifiable | silent! 1,/^" ?/ d _ | setlocal nomodifiable + + call s:AddHeader() + + " return to previous mark + 0 + if line("'t") != 0 + normal! `t + endif + + let &report=oldRep +endfunction " >>> + +"" - AddHeader() - add the header with help information +function! s:AddHeader() " <<< + if w:dirsort == 0 + let dt = "off)\n" + elseif w:dirsort == 1 + let dt = "dirs first)\n" + else + let dt = "dirs last)\n" + endif + + let hre = exists("g:treeExplHidePattern") ? g:treeExplHidePattern : "" + + let save_f=@f + 1 + let ln = 3 + if w:helplines > 4 + let ln=ln+1 | let @f= "\" o = (file) open in another window\n" + let ln=ln+1 | let @f=@f."\" o = (dir) toggle dir fold or load dir\n" + let ln=ln+1 | let @f=@f."\" <ret> = same as 'o'\n" + let ln=ln+1 | let @f=@f."\" O = same as 'o' but use replace explorer\n" + let ln=ln+1 | let @f=@f."\" t = same as 'o' but use new tab\n" + let ln=ln+1 | let @f=@f."\" X = recursive expand cursor dir\n" + let ln=ln+1 | let @f=@f."\" E = open Explorer on cursor dir\n" + let ln=ln+1 | let @f=@f."\" C = chdir top of tree to cursor dir\n" + let ln=ln+1 | let @f=@f."\" H = chdir top of tree to home dir\n" + let ln=ln+1 | let @f=@f."\" u = chdir top of tree to parent dir\n" + let ln=ln+1 | let @f=@f."\" :CD d = chdir top of tree to dir <d>\n" + let ln=ln+1 | let @f=@f."\" p = move cursor to parent dir\n" + let ln=ln+1 | let @f=@f."\" r = refresh cursor dir\n" + let ln=ln+1 | let @f=@f."\" R = refresh top dir\n" + let ln=ln+1 | let @f=@f."\" S = start a shell in cursor dir\n" + let ln=ln+1 | let @f=@f."\" :Yank = yank <range> lines withoug fold marks\n" + let ln=ln+1 | let @f=@f."\" D = toggle dir sort (now = " . dt + let ln=ln+1 | let @f=@f."\" a = toggle hidden (dotfiles and regex = '" + \ . hre . "') files (now = " + \ . ((w:hidden_files) ? "on)\n" : "off)\n") + let ln=ln+1 | let @f=@f."\" ? = toggle long help\n" + else + let ln=ln+1 | let @f="\" ? : toggle long help\n" + endif + let w:helplines = ln + + setlocal modifiable | silent put! f | setlocal nomodifiable + + let @f=save_f +endfunction " >>> + +let &cpo = s:cpo_save + +" vim: set ts=2 sw=2 foldmethod=marker foldmarker=<<<,>>> foldlevel=2 : |