diff --git a/README b/README deleted file mode 100644 index b35ee6e..0000000 --- a/README +++ /dev/null @@ -1,54 +0,0 @@ -This is a mirror of http://www.vim.org/scripts/script.php?script_id=213 - -** Statement oriented editing of C / C++ programs -** Speed up writing new code considerably. -** Write code und comments with a professional appearance from the beginning. -** Use code snippets - - - insertion of various types of comments (file prologue, function descriptions, file section headers - keyword comments, date, time, ... ) -- insertion of empty control statements (if-else, while, do-while, switch, ... ) -- insertion of various preprocessor directives -- insertion of C-idioms (enum+typedef, loops, complete main, empty function, file open dialogs, ... ) -- insertion of C++ -idioms ( frames for simple classes and template classes, try-catch blocks, - file open dialogs, output manipulators, ios flags, ... ) -- use and organize your own collection of code snippets -- compile / link / run support for one-file projects (without a makefile) -- run buffer through splint -- personalization of comments (name, email, ... ) -- menus can be switched on and off (Tools menu) - -Here are some screen shots : http://lug.fh-swf.de/vim/vim-c/screenshots-en.html - -The help file online : http://lug.fh-swf.de/vim/vim-doc/csupport.html - -The key mappings of this plugin (PDF) : http://lug.fh-swf.de/vim/vim-c/c-hotkeys.pdf - -See also the http://www.thegeekstuff.com tutorial -"Make Vim as Your C/C++ IDE Using c.vim Plugin" -(http://www.thegeekstuff.com/2009/01/tutorial-make-vim-as-your-cc-ide-using-cvim-plugin/) - -DOCUMENTATION --------------------------------------------------------- -This plugin comes with a help file (csupport.txt). Read it with - -:h csupport - - ** PLEASE READ THE DOCUMENTATION ** - -Editing actions differ for different modes! -There are a lot of features which can be configured or customized -to match your needs. - - -MAILING LIST --------------------------------------------------------- -You can subscribe to the vim-plugins-list mailing list to post your questions or -suggestions for improvement or to report bugs. The list will also be used to -announce new releases ( c.vim / bash-support / perl-support / doxygen-support ). -Visit the following page for subscribing to the mailing list: - - http://lug.fh-swf.de/cgi-bin/mailman/listinfo/vim-plugins-list - -The vim-plugins-list list is very low on traffic. - diff --git a/README.md b/README.md new file mode 100644 index 0000000..b5de1fc --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Announcement +-------------------------------------------------------------------------------- + +I am going to discontinue this fork, since [vim-scripts](https://github.com/vim-scripts) seems to have stopped updating their repositories. + +Please use my own repository [C-Support](https://github.com/WolfgangMehner/c-support). + diff --git a/autoload/mmtemplates/core.vim b/autoload/mmtemplates/core.vim new file mode 100644 index 0000000..249228a --- /dev/null +++ b/autoload/mmtemplates/core.vim @@ -0,0 +1,3883 @@ +"=============================================================================== +" +" File: mmtemplates#core.vim +" +" Description: Template engine: Core. +" +" Maps & Menus - Template Engine +" +" VIM Version: 7.0+ +" Author: Wolfgang Mehner, wolfgang-mehner@web.de +" Organization: +" Version: see variable g:Templates_Version below +" Created: 30.08.2011 +" Revision: 28.03.2014 +" License: Copyright (c) 2012-2013, Wolfgang 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. +"=============================================================================== +" +"------------------------------------------------------------------------------- +" === Basic Checks === {{{1 +"------------------------------------------------------------------------------- +" +" need at least 7.0 +if v:version < 700 + echohl WarningMsg + echo 'The plugin templates.vim needs Vim version >= 7.' + echohl None + finish +endif +" +" prevent duplicate loading +" need compatible +if &cp || ( exists('g:Templates_Version') && g:Templates_Version != 'searching' && ! exists('g:Templates_DevelopmentOverwrite') ) + finish +endif +" +let s:Templates_Version = '0.9.3' " version number of this script; do not change +" +"---------------------------------------------------------------------- +" --- Find Newest Version --- {{{2 +"---------------------------------------------------------------------- +" +if exists('g:Templates_DevelopmentOverwrite') + " skip ahead +elseif exists('g:Templates_VersionUse') + " + " not the newest one: abort + if s:Templates_Version != g:Templates_VersionUse + finish + endif + " + " otherwise: skip ahead + " +elseif exists('g:Templates_VersionSearch') + " + " add own version number to the list + call add ( g:Templates_VersionSearch, s:Templates_Version ) + " + finish + " +else + " + "------------------------------------------------------------------------------- + " s:VersionComp : Compare two version numbers. {{{3 + " + " Parameters: + " op1 - first version number (string) + " op2 - second version number (string) + " Returns: + " result - -1, 0 or 1, to the specifications of sort() (integer) + "------------------------------------------------------------------------------- + function! s:VersionComp ( op1, op2 ) + " + let l1 = split ( a:op1, '[.-]' ) + let l2 = split ( a:op2, '[.-]' ) + " + for i in range( 0, max( [ len( l1 ), len( l2 ) ] ) - 1 ) + " until now, all fields where equal + if len ( l2 ) <= i + return -1 " op1 has more fields -> sorts first + elseif len( l1 ) <= i + return 1 " op2 has more fields -> sorts first + elseif str2nr ( l1[i] ) > str2nr ( l2[i] ) + return -1 " op1 is larger here -> sorts first + elseif str2nr ( l2[i] ) > str2nr ( l1[i] ) + return 1 " op2 is larger here -> sorts first + endif + endfor + " + return 0 " same amount of fields, all equal + endfunction " ---------- end of function s:VersionComp ---------- + " }}}3 + "------------------------------------------------------------------------------- + " + try + " + " collect all available version + let g:Templates_Version = 'searching' + let g:Templates_VersionSearch = [] + " + runtime! autoload/mmtemplates/core.vim + " + " select the newest one + call sort ( g:Templates_VersionSearch, 's:VersionComp' ) + " + let g:Templates_VersionUse = g:Templates_VersionSearch[ 0 ] + " + " run all scripts again, the newest one will be used + runtime! autoload/mmtemplates/core.vim + " + unlet g:Templates_VersionSearch + unlet g:Templates_VersionUse + " + finish + " + catch /.*/ + " + " an error occurred, skip ahead + echohl WarningMsg + echomsg 'Search for the newest version number failed.' + echomsg 'Using this version ('.s:Templates_Version.').' + echohl None + endtry + " +endif +" }}}2 +"------------------------------------------------------------------------------- +" +let g:Templates_Version = s:Templates_Version " version number of this script; do not change +" +"---------------------------------------------------------------------- +" === Modul Setup === {{{1 +"---------------------------------------------------------------------- +" +let s:DebugGlobalOverwrite = 0 +let s:DebugLevel = s:DebugGlobalOverwrite +" +if ! exists ( 'g:Templates_MapInUseWarn' ) + let g:Templates_MapInUseWarn = 1 +endif +" +let s:StateStackStyleTop = -2 +let s:StateStackFile = -1 +" +let s:StateStackLength = 2 +" +let s:Flagactions = { + \ ':i' : '', + \ ':l' : ' (-> lowercase)', + \ ':u' : ' (-> uppercase)', + \ ':c' : ' (-> capitalize)', + \ ':L' : ' (-> legalize name)', + \ } +" +let s:StandardPriority = 500 +" +let g:CheckedFiletypes = {} +" +"---------------------------------------------------------------------- +" s:StandardMacros : The standard macros. {{{2 +"---------------------------------------------------------------------- +" +let s:StandardMacros = { + \ 'BASENAME' : '', + \ 'DATE' : '%x', + \ 'FILENAME' : '', + \ 'PATH' : '', + \ 'SUFFIX' : '', + \ 'TIME' : '%X', + \ 'YEAR' : '%Y', + \ } +" +"---------------------------------------------------------------------- +" s:StandardProperties : The standard properties. {{{2 +"---------------------------------------------------------------------- +" +let s:StandardProperties = { + \ 'Templates::EditTemplates::Map' : 're', + \ 'Templates::RereadTemplates::Map' : 'rr', + \ 'Templates::ChooseStyle::Map' : 'rs', + \ + \ 'Templates::EditTemplates::Shortcut' : 'e', + \ 'Templates::RereadTemplates::Shortcut' : 'r', + \ 'Templates::ChooseStyle::Shortcut' : 's', + \ + \ 'Templates::Mapleader' : '\', + \ } +" +"---------------------------------------------------------------------- +" s:TypeNames : Name of types as characters. {{{2 +"---------------------------------------------------------------------- +" +let s:TypeNames = [ ' ', ' ', ' ', ' ', ' ', ' ' ] +" +let s:TypeNames[ type(0) ] = 'i' " integer +let s:TypeNames[ type("") ] = 's' " string +let s:TypeNames[ type([]) ] = 'l' " list +let s:TypeNames[ type({}) ] = 'd' " dict +"let s:TypeNames[ type(0.0) ] = 'n' " number +" TODO: why does float not work in some cases? +" not important right now. +" +"---------------------------------------------------------------------- +" === Syntax: Regular Expressions === {{{1 +"---------------------------------------------------------------------- +" +let s:RegexSettings = { + \ 'MacroName' : '[a-zA-Z_][a-zA-Z0-9_]*', + \ 'MacroList' : '\%([a-zA-Z_]\|[a-zA-Z_][a-zA-Z0-9_ \t,]*[a-zA-Z0-9_]\)', + \ 'TemplateName' : '[a-zA-Z_][a-zA-Z0-9_+\-\., ]*[a-zA-Z0-9_+\-\.,]', + \ 'TextOpt' : '[a-zA-Z_][a-zA-Z0-9_+\-: \t,]*[a-zA-Z0-9_+\-]', + \ 'Mapping' : '[a-zA-Z0-9+\-]\+', + \ + \ 'CommentStart' : '\$', + \ 'BlockDelimiter' : '==', + \ + \ 'CommentHint' : '$', + \ 'CommandHint' : '[A-Z]', + \ 'DelimHint' : '=', + \ 'MacroHint' : '|', + \ + \ 'MacroStart' : '|', + \ 'MacroEnd' : '|', + \ 'EditTagStart' : '<', + \ 'EditTagEnd' : '>', + \ 'JumpTag1Start' : '{', + \ 'JumpTag1End' : '}', + \ 'JumpTag2Start' : '<', + \ 'JumpTag2End' : '>', + \ } +" +"---------------------------------------------------------------------- +" s:UpdateFileReadRegex : Update the regular expressions. {{{2 +"---------------------------------------------------------------------- +" +function! s:UpdateFileReadRegex ( regex, settings ) + " + let quote = '\(["'']\?\)' + " + " Basics + let a:regex.MacroName = a:settings.MacroName + let a:regex.MacroNameC = '\('.a:settings.MacroName.'\)' + let a:regex.TemplateNameC = '\('.a:settings.TemplateName.'\)' + let a:regex.Mapping = a:settings.Mapping + let a:regex.AbsolutePath = '^[\~/]' " TODO: Is that right and/or complete? + " + " Syntax Categories + let a:regex.EmptyLine = '^\s*$' + let a:regex.CommentLine = '^'.a:settings.CommentStart + let a:regex.FunctionCall = '^\s*'.a:regex.MacroNameC.'\s*(\(.*\))\s*$' + let a:regex.MacroAssign = '^\s*'.a:settings.MacroStart.a:regex.MacroNameC.a:settings.MacroEnd + \ .'\s*=\s*'.quote.'\(.\{-}\)'.'\2'.'\s*$' " deprecated + " + " Blocks + let delim = a:settings.BlockDelimiter + let a:regex.Styles1Start = '^'.delim.'\s*IF\s\+|STYLE|\s\+IS\s\+'.a:regex.MacroNameC.'\s*'.delim + let a:regex.Styles1End = '^'.delim.'\s*ENDIF\s*'.delim + + let a:regex.Styles2Start = '^'.delim.'\s*USE\s\+STYLES\s*:' + \ .'\s*\('.a:settings.MacroList.'\)'.'\s*'.delim + let a:regex.Styles2End = '^'.delim.'\s*ENDSTYLES\s*'.delim + " + " Texts + let a:regex.TemplateStart = '^'.delim.'\s*\%(TEMPLATE:\)\?\s*'.a:regex.TemplateNameC.'\s*'.delim + \ .'\s*\%(\('.a:settings.TextOpt.'\)\s*'.delim.'\)\?' + let a:regex.TemplateEnd = '^'.delim.'\s*ENDTEMPLATE\s*'.delim + " + let a:regex.HelpStart = '^'.delim.'\s*HELP:\s*'.a:regex.TemplateNameC.'\s*'.delim + \ .'\s*\%(\('.a:settings.TextOpt.'\)\s*'.delim.'\)\?' + "let a:regex.HelpEnd = '^'.delim.'\s*ENDHELP\s*'.delim + " + let a:regex.MenuSep = '^'.delim.'\s*SEP:\s*'.a:regex.TemplateNameC.'\s*'.delim + " + let a:regex.ListStart = '^'.delim.'\s*LIST:\s*'.a:regex.MacroNameC.'\s*'.delim + \ .'\s*\%(\('.a:settings.TextOpt.'\)\s*'.delim.'\)\?' + let a:regex.ListEnd = '^'.delim.'\s*ENDLIST\s*'.delim + " + " Special Hints + let a:regex.CommentHint = a:settings.CommentHint + let a:regex.CommandHint = a:settings.CommandHint + let a:regex.DelimHint = a:settings.DelimHint + let a:regex.MacroHint = a:settings.MacroHint + " +endfunction " ---------- end of function s:UpdateFileReadRegex ---------- +" +"---------------------------------------------------------------------- +" s:UpdateTemplateRegex : Update the regular expressions. {{{2 +"---------------------------------------------------------------------- +" +function! s:UpdateTemplateRegex ( regex, settings ) + " + let quote = '["'']' + " + " Function Arguments + let a:regex.RemoveQuote = '^\s*'.quote.'\zs.*\ze'.quote.'\s*$' + " + " Basics + let a:regex.MacroStart = a:settings.MacroStart + let a:regex.MacroEnd = a:settings.MacroEnd + let a:regex.MacroName = a:settings.MacroName + let a:regex.MacroNameC = '\('.a:settings.MacroName.'\)' + let a:regex.MacroMatch = '^'.a:settings.MacroStart.a:settings.MacroName.a:settings.MacroEnd.'$' + " + " Syntax Categories + let a:regex.FunctionLine = '^'.a:settings.MacroStart.'\('.a:regex.MacroNameC.'(\(.*\))\)'.a:settings.MacroEnd.'\s*\n' + let a:regex.FunctionChecked = '^'.a:regex.MacroNameC.'(\(.*\))$' + let a:regex.FunctionList = '^LIST(\(.\{-}\))$' + let a:regex.FunctionComment = a:settings.MacroStart.'\(C\|Comment\)'.'(\(.\{-}\))'.a:settings.MacroEnd + let a:regex.FunctionInsert = a:settings.MacroStart.'\(Insert\|InsertLine\)'.'(\(.\{-}\))'.a:settings.MacroEnd + let a:regex.MacroRequest = a:settings.MacroStart.'?'.a:regex.MacroNameC.'\%(:\(\a\)\)\?'.a:settings.MacroEnd + let a:regex.MacroInsert = a:settings.MacroStart.''.a:regex.MacroNameC.'\%(:\(\a\)\)\?'.a:settings.MacroEnd + let a:regex.MacroNoCapture = a:settings.MacroStart.a:settings.MacroName.'\%(:\a\)\?'.a:settings.MacroEnd + let a:regex.ListItem = a:settings.MacroStart.''.a:regex.MacroNameC.':ENTRY_*'.a:settings.MacroEnd + " + let a:regex.TextBlockFunctions = '^\%(C\|Comment\|Insert\|InsertLine\)$' + " + " Jump Tags + let a:regex.JumpTagBoth = '<-\w*->\|{-\w*-}\|<+\w*+>\|{+\w*+}' + let a:regex.JumpTagType2 = '<-\w*->\|{-\w*-}' + " +endfunction " ---------- end of function s:UpdateTemplateRegex ---------- +" }}}2 +" +"---------------------------------------------------------------------- +" === Script: Auxiliary Functions === {{{1 +"---------------------------------------------------------------------- +" +"---------------------------------------------------------------------- +" s:ParameterTypes : Get the types of the arguments. {{{2 +" +" Returns a string with one character per argument, denoting the type. +" Uses the codebook 's:TypeNames'. +" +" Examples: +" - s:ParameterTypes ( 1, "string", [] ) -> "isl" +" - s:ParameterTypes ( 1, 'string', {} ) -> "isd" +" - s:ParameterTypes ( 1, 1.0 ) -> "in" +"---------------------------------------------------------------------- +" +function! s:ParameterTypes ( ... ) + return join( map( copy( a:000 ), 's:TypeNames[ type ( v:val ) ]' ), '' ) +endfunction " ---------- end of function s:ParameterTypes ---------- +" +"---------------------------------------------------------------------- +" s:FunctionCheck : Check the syntax, name and parameter types. {{{2 +" +" Throw a 'Template:Check:*' exception whenever: +" - The syntax of the call "name( params )" is wrong. +" - The function name 'name' is not a key in 'namespace'. +" - The parameter string (as produced by s:ParameterTypes) does not match +" the regular expression found in "namespace[name]". +"---------------------------------------------------------------------- +" +function! s:FunctionCheck ( name, param, namespace ) + " + " check the syntax and get the parameter string + try + exe 'let param_s = s:ParameterTypes( '.a:param.' )' + catch /^Vim(let):E\d\+:/ + throw 'Template:Check:function call "'.a:name.'('.a:param.')": '.matchstr ( v:exception, '^Vim(let):E\d\+:\zs.*' ) + endtry + " + " check the function and the parameters + if ! has_key ( a:namespace, a:name ) + throw 'Template:Check:unknown function: "'.a:name.'"' + elseif param_s !~ '^'.a:namespace[ a:name ].'$' + throw 'Template:Check:wrong parameter types: "'.a:name.'"' + endif + " +endfunction " ---------- end of function s:FunctionCheck ---------- +" +"---------------------------------------------------------------------- +" s:LiteralReplacement : Substitute without using regular expressions. {{{2 +"---------------------------------------------------------------------- +" +function! s:LiteralReplacement ( text, remove, insert, flag ) + return substitute( a:text, + \ '\V'.escape( a:remove, '\' ), + \ escape( a:insert, '\&~' ), a:flag ) +" \ '\='.string( a:insert ), a:flag ) +endfunction " ---------- end of function s:LiteralReplacement ---------- +" +"---------------------------------------------------------------------- +" s:ConcatNormalizedFilename : Concatenate and normalize a filename. {{{2 +"---------------------------------------------------------------------- +" +function! s:ConcatNormalizedFilename ( ... ) + if a:0 == 1 + let filename = ( a:1 ) + elseif a:0 == 2 + let filename = ( a:1 ).'/'.( a:2 ) + endif + return fnamemodify( filename, ':p' ) +endfunction " ---------- end of function s:ConcatNormalizedFilename ---------- +" +"---------------------------------------------------------------------- +" s:GetNormalizedPath : Split and normalize a path. {{{2 +"---------------------------------------------------------------------- +" +function! s:GetNormalizedPath ( filename ) + return fnamemodify( a:filename, ':p:h' ) +endfunction " ---------- end of function s:GetNormalizedPath ---------- +" +""---------------------------------------------------------------------- +" s:UserInput : Input after a highlighted prompt. {{{2 +" +" 3. argument : optional completion +" 4. argument : optional list, if the 3. argument is 'customlist' +" +" Throws an exception 'Template:UserInputAborted' if the obtained input is empty, +" so use it like this: +" try +" let style = s:UserInput( 'prompt', '', ... ) +" catch /Template:UserInputAborted/ +" return +" endtry +"---------------------------------------------------------------------- +" +function! s:UserInput ( prompt, text, ... ) + " + echohl Search " highlight prompt + call inputsave() " preserve typeahead + if a:0 == 0 || a:1 == '' + let retval = input( a:prompt, a:text ) + elseif a:1 == 'customlist' + let s:UserInputList = a:2 + let retval = input( a:prompt, a:text, 'customlist,mmtemplates#core#UserInputEx' ) + let s:UserInputList = [] + else + let retval = input( a:prompt, a:text, a:1 ) + endif + call inputrestore() " restore typeahead + echohl None " reset highlighting + " + if empty( retval ) + throw 'Template:UserInputAborted' + endif + " + let retval = substitute( retval, '^\s\+', "", "" ) " remove leading whitespaces + let retval = substitute( retval, '\s\+$', "", "" ) " remove trailing whitespaces + " + return retval + " +endfunction " ---------- end of function s:UserInput ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#UserInputEx : ex-command for s:UserInput. {{{3 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#UserInputEx ( ArgLead, CmdLine, CursorPos ) + if empty( a:ArgLead ) + return copy( s:UserInputList ) + endif + return filter( copy( s:UserInputList ), 'v:val =~ ''\V\<'.escape(a:ArgLead,'\').'\w\*''' ) +endfunction " ---------- end of function mmtemplates#core#UserInputEx ---------- +" }}}3 +" +let s:UserInputList = [] +" +"---------------------------------------------------------------------- +" s:ErrorMsg : Print an error message. {{{2 +"---------------------------------------------------------------------- +" +function! s:ErrorMsg ( ... ) + echohl WarningMsg + for line in a:000 + echomsg line + endfor + echohl None +endfunction " ---------- end of function s:ErrorMsg ---------- +" +"---------------------------------------------------------------------- +" s:DebugMsg : Print debug information. {{{2 +"---------------------------------------------------------------------- +" +function! s:DebugMsg ( msg, ... ) + if s:DebugLevel + if a:0 == 0 || ( a:1 <= s:DebugLevel ) + echo a:msg + endif + endif +endfunction " ---------- end of function s:DebugMsg ---------- +" +"---------------------------------------------------------------------- +" s:OpenFold : Open fold and go to the first or last line of this fold. {{{2 +"---------------------------------------------------------------------- +" +function! s:OpenFold ( mode ) + if foldclosed(".") < 0 + return + endif + " 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 + elseif a:mode == 'start' + exe ":".foldstart + endif +endfunction " ---------- end of function s:OpenFold ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#NewLibrary : Create a new template library. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#NewLibrary ( ... ) + " + " ================================================== + " options + " ================================================== + " + let i = 1 + while i <= a:0 + " + if a:[i] == 'debug' && i+1 <= a:0 && ! s:DebugGlobalOverwrite + let s:DebugLevel = a:[i+1] + let i += 2 + else + if type ( a:[i] ) == type ( '' ) | call s:ErrorMsg ( 'Unknown option: "'.a:[i].'"' ) + else | call s:ErrorMsg ( 'Unknown option at position '.i.'.' ) | endif + let i += 1 + endif + " + endwhile + " + " ================================================== + " data + " ================================================== + " + " library + let library = { + \ 'macros' : {}, + \ 'properties' : {}, + \ 'resources' : {}, + \ 'templates' : {}, + \ + \ 'menu_order' : [], + \ + \ 'styles' : [ 'default' ], + \ 'current_style' : 'default', + \ + \ 'menu_shortcuts' : {}, + \ 'menu_existing' : { 'base' : 0 }, + \ + \ 'regex_settings' : ( copy ( s:RegexSettings ) ), + \ 'regex_file' : {}, + \ 'regex_template' : {}, + \ + \ 'library_files' : [], + \ } + " entry used by maps: 'map_commands' + " + call extend ( library.macros, s:StandardMacros, 'keep' ) + call extend ( library.properties, s:StandardProperties, 'keep' ) + " + call s:UpdateFileReadRegex ( library.regex_file, library.regex_settings ) + call s:UpdateTemplateRegex ( library.regex_template, library.regex_settings ) + " + " ================================================== + " wrap up + " ================================================== + " + let s:DebugLevel = s:DebugGlobalOverwrite " reset debug + " + return library " return the new library + " +endfunction " ---------- end of function mmtemplates#core#NewLibrary ---------- +" +"---------------------------------------------------------------------- +" === Read Templates: Auxiliary Functions === {{{1 +"---------------------------------------------------------------------- +" +"---------------------------------------------------------------------- +" s:TemplateTypeNames : Readable type names for templates. {{{2 +"---------------------------------------------------------------------- +" +let s:TemplateTypeNames = { + \ 'help' : 'help', + \ 'sep' : 'separator', + \ 't' : 'template', + \ } +" +"---------------------------------------------------------------------- +" s:AddText : Add a text. {{{2 +"---------------------------------------------------------------------- +" +function! s:AddText ( type, name, settings, lines ) + " + if a:type == 'help' + call s:AddTemplate ( 'help', a:name, a:settings, a:lines ) + elseif a:type == 'list' + call s:AddList ( 'list', a:name, a:settings, a:lines ) + elseif a:type == 'template' + call s:AddTemplate ( 't', a:name, a:settings, a:lines ) + endif + " +endfunction " ---------- end of function s:AddText ---------- +" +"---------------------------------------------------------------------- +" s:AddList : Add a list. {{{2 +"---------------------------------------------------------------------- +" +function! s:AddList ( type, name, settings, lines ) + " + " ================================================== + " checks + " ================================================== + " + " Error: empty name + if empty ( a:name ) + call s:ErrorMsg ( 'List name can not be empty.' ) + return + endif + " + " Warning: empty list + if empty ( a:lines ) + call s:ErrorMsg ( 'Warning: Empty list: "'.a:name.'"' ) + endif + " + " Warning: already existing + if s:t_runtime.overwrite_warning && has_key ( s:library.resources, 'list!'.a:name ) + call s:ErrorMsg ( 'Warning: Overwriting list "'.a:name.'"' ) + endif + " + " ================================================== + " settings + " ================================================== + " + let type = 'list' + let bare = 0 + " + for s in a:settings + " + if s == 'list' + let type = 'list' + elseif s == 'hash' || s == 'dict' || s == 'dictionary' + let type = 'dict' + elseif s == 'bare' + let bare = 1 + else + call s:ErrorMsg ( 'Warning: Unknown setting in list "'.a:name.'": "'.s.'"' ) + endif + " + endfor + " + if type == 'list' + if bare + let lines = escape( a:lines, '"' ) + let lines = substitute( lines, '^\s*', '"', '' ) + let lines = substitute( lines, '\s*\n$', '"', '' ) + let lines = substitute( lines, '\s*\n\s*', '", "', 'g' ) + exe 'let list = [ '.lines.' ]' + else + exe 'let list = [ '.substitute( a:lines, '\n', ' ', 'g' ).' ]' + end + call sort ( list ) + elseif type == 'dict' + if bare + s:ErrorMsg ( 'bare hash: to be implemented' ) + else + exe 'let list = { '.substitute( a:lines, '\n', ' ', 'g' ).' }' + end + endif + " + let s:library.resources[ 'list!'.a:name ] = list + " +endfunction " ---------- end of function s:AddList ---------- +" +"---------------------------------------------------------------------- +" s:AddTemplate : Add a template. {{{2 +"---------------------------------------------------------------------- +" +function! s:AddTemplate ( type, name, settings, lines ) + " + let name = a:name + " + " ================================================== + " checks + " ================================================== + " + " Error: empty name + if empty ( name ) + call s:ErrorMsg ( 'Template name can not be empty.' ) + return + endif + " + " Warning: empty template + if empty ( a:lines ) + call s:ErrorMsg ( 'Warning: Empty template: "'.name.'"' ) + endif + " + " ================================================== + " new template + " ================================================== + " + if has_key ( s:library.templates, name.'!!type' ) + let my_type = a:type + let other_type = split ( s:library.templates[ name.'!!type' ], ',' )[0] + " + if my_type != other_type + if my_type == 't' + call s:ErrorMsg ( 'Template "'.name.'" can not overwrite an object of the same name of type "'.s:TemplateTypeNames[other_type].'".' ) + elseif my_type == 'help' + call s:ErrorMsg ( 'Help template "'.name.'" can not overwrite an object of the same name of type "'.s:TemplateTypeNames[other_type].'".' ) + endif + return + endif + else + " + " -------------------------------------------------- + " new template + " -------------------------------------------------- + let type = a:type + let placement = 'below' + let indentation = '1' + " + let visual = -1 != stridx ( a:lines, '' ) + let mp = '' + let entry = 1 + let sc = '' + " + " -------------------------------------------------- + " settings + " -------------------------------------------------- + for s in a:settings + " + if s == 'start' || s == 'above' || s == 'below' || s == 'append' || s == 'insert' + let placement = s + + " indentation + elseif s == 'indent' + let indentation = '1' + elseif s == 'noindent' + let indentation = '0' + + " special insertion in visual mode: + elseif s == 'visual' + let visual = 1 + elseif s == 'novisual' + let visual = 0 + + " map: + elseif s =~ '^map\s*:' + let mp = matchstr ( s, '^map\s*:\s*\zs'.s:library.regex_file.Mapping ) + + " entry and shortcut: + elseif s == 'nomenu' + let entry = 0 + elseif s == 'expandmenu' + let entry = 2 + elseif s =~ '^sc\s*:' || s =~ '^shortcut\s*:' + let sc = matchstr ( s, '^\w\+\s*:\s*\zs'.s:library.regex_file.Mapping ) + + else + call s:ErrorMsg ( 'Warning: Unknown setting in template "'.name.'": "'.s.'"' ) + endif + " + endfor + " + " TODO: review this + if a:type == 'help' + let placement = 'help' + endif + " + " -------------------------------------------------- + " new template + " -------------------------------------------------- + let s:library.templates[ name.'!!type' ] = type.','.placement.','.indentation + let s:library.templates[ name.'!!menu' ] = visual.",".string(mp).",".entry.",'',".string(sc) + " + call add ( s:library.menu_order, name ) + " + endif + " + " ================================================== + " text + " ================================================== + " + " the styles + if a:type == 'help' + " Warning: overwriting a style + if s:t_runtime.overwrite_warning && has_key ( s:library.templates, name.'!default' ) + call s:ErrorMsg ( 'Warning: Overwriting a help template: "'.name.'"' ) + endif + let s:library.templates[ name.'!default' ] = a:lines + return + elseif empty ( s:t_runtime.use_styles ) + let styles = [ 'default' ] + else + let styles = s:t_runtime.use_styles + endif + " + " save the lines + for s in styles + " + " Warning: overwriting a style + if s:t_runtime.overwrite_warning && has_key ( s:library.templates, name.'!'.s ) + call s:ErrorMsg ( 'Warning: Overwriting style in template "'.name.'": "'.s.'"' ) + endif + " + let s:library.templates[ name.'!'.s ] = a:lines + " + endfor + " +endfunction " ---------- end of function s:AddTemplate ---------- +" +"---------------------------------------------------------------------- +" s:AddSeparator : Add a menu separator. {{{2 +"---------------------------------------------------------------------- +" +function! s:AddSeparator ( type, name, settings ) + " + let name = a:name + " + " ================================================== + " checks + " ================================================== + " + " Error: empty name + if empty ( name ) + call s:ErrorMsg ( 'Separator name can not be empty.' ) + return + endif + " + " ================================================== + " new separator + " ================================================== + " + if has_key ( s:library.templates, name.'!!type' ) + " + let my_type = a:type + let other_type = split ( s:library.templates[ name.'!!type' ], ',' )[0] + " + if my_type != other_type + call s:ErrorMsg ( 'Separator "'.name.'" can not overwrite an object of the same name of type "'.s:TemplateTypeNames[other_type].'".' ) + return + endif + else + " + let s:library.templates[ name.'!!type' ] = 'sep,,0' + let s:library.templates[ name.'!!menu' ] = "0,'',11,'',''" + " + call add ( s:library.menu_order, name ) + " + endif + " +endfunction " ---------- end of function s:AddSeparator ---------- +" +"---------------------------------------------------------------------- +" s:AddStyles : Add styles to the list. {{{2 +"---------------------------------------------------------------------- +" +function! s:AddStyles ( styles ) + " + " TODO: check for valid name + " add the styles to the list + for s in a:styles + if -1 == index ( s:library.styles, s ) + call add ( s:library.styles, s ) + endif + endfor + " +endfunction " ---------- end of function s:AddStyles ---------- +" +"---------------------------------------------------------------------- +" s:UseStyles : Set the styles. {{{2 +"---------------------------------------------------------------------- +" +function! s:UseStyles ( styles ) + " + " 'use_styles' empty? -> we may have new styles + " otherwise -> must be a subset, so no new styles + if empty ( s:t_runtime.use_styles ) + " add the styles to the list + call s:AddStyles ( a:styles ) + else + " are the styles a sub-set of the currently used styles? + for s in a:styles + if -1 == index ( s:t_runtime.use_styles, s ) + call s:ErrorMsg ( 'Style "'.s.'" currently not in use.' ) + return + endif + endfor + endif + " + " push the new style and use it as the current style + call add ( s:t_runtime.styles_stack, a:styles ) + let s:t_runtime.use_styles = a:styles + " +endfunction " ---------- end of function s:UseStyles ---------- +" +"---------------------------------------------------------------------- +" s:RevertStyles : Revert the styles. {{{2 +"---------------------------------------------------------------------- +" +function! s:RevertStyles ( times ) + " + " get the current top, and check whether any more styles can be removed + let state_lim = s:t_runtime.state_stack[ s:StateStackStyleTop ] + let state_top = len( s:t_runtime.styles_stack ) + " + if state_lim > ( state_top - a:times ) + call s:ErrorMsg ( 'Can not close any more style sections.' ) + return + endif + " + " remove the top + call remove ( s:t_runtime.styles_stack, -1 * a:times, -1 ) + " + " reset the current style + if state_top > a:times + let s:t_runtime.use_styles = s:t_runtime.styles_stack[ -1 ] + else + let s:t_runtime.use_styles = [] + endif + " +endfunction " ---------- end of function s:RevertStyles ---------- +" +"---------------------------------------------------------------------- +" === Read Templates: Template File Namespace === {{{1 +"---------------------------------------------------------------------- +" +"---------------------------------------------------------------------- +" s:FileReadNameSpace : The set of functions a template file can call. {{{2 +"---------------------------------------------------------------------- +" +let s:FileReadNameSpace = { + \ 'IncludeFile' : 'ss\?', + \ 'SetFormat' : 'ss', + \ 'SetMacro' : 'ss', + \ 'SetPath' : 'ss', + \ 'SetProperty' : 'ss', + \ 'SetStyle' : 's', + \ + \ 'MenuShortcut' : 'ss', + \ } +" \ 'SetMap' : 'ss', +" \ 'SetShortcut' : 'ss', +" +"---------------------------------------------------------------------- +" s:SetFormat : Set the format of |DATE|, ... (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:SetFormat ( name, replacement ) + " + " check for valid name + if a:name !~ 'TIME\|DATE\|YEAR' + call s:ErrorMsg ( 'Can not set the format of: '.a:name ) + return + endif + " + let s:library.macros[ a:name ] = a:replacement + " +endfunction " ---------- end of function s:SetFormat ---------- +" +"---------------------------------------------------------------------- +" s:SetMacro : Set a replacement (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:SetMacro ( name, replacement ) + " + " check for valid name + if a:name !~ s:library.regex_file.MacroName + call s:ErrorMsg ( 'Macro name must be a valid identifier: '.a:name ) + return + elseif has_key ( s:StandardMacros, a:name ) + call s:ErrorMsg ( 'The special macro "'.a:name.'" can not be replaced via SetMacro.' ) + return + endif + " + let s:library.macros[ a:name ] = a:replacement + " +endfunction " ---------- end of function s:SetMacro ---------- +" +"---------------------------------------------------------------------- +" s:SetStyle : Set the current style (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:SetStyle ( name ) + " + " check for valid name + if a:name !~ s:library.regex_file.MacroName + call s:ErrorMsg ( 'Style name must be a valid identifier: '.a:name ) + return + endif + " + let s:library.current_style = a:name + " +endfunction " ---------- end of function s:SetStyle ---------- +" +"---------------------------------------------------------------------- +" s:SetPath : Set a path-resource (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:SetPath ( name, value ) + " + " check for valid name + if a:name !~ s:library.regex_file.MacroName + call s:ErrorMsg ( 'Path name must be a valid identifier: '.a:name ) + return + endif + " + let s:library.resources[ 'path!'.a:name ] = a:value + " +endfunction " ---------- end of function s:SetPath ---------- +" +"---------------------------------------------------------------------- +" s:MenuShortcut : Set a shortcut for a sub-menu (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:MenuShortcut ( name, shortcut ) + " + " check for valid shortcut + if len ( a:shortcut ) > 1 + call s:ErrorMsg ( 'The shortcut for "'.a:name.'" must be a single character.' ) + return + endif + " + let name = substitute( a:name, '\.$', '', '' ) + " + let s:library.menu_shortcuts[ name ] = a:shortcut + " +endfunction " ---------- end of function s:MenuShortcut ---------- +" +"---------------------------------------------------------------------- +" s:SetMap : TODO (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:SetMap ( name, map ) + " + echo 'SetMap: TO BE IMPLEMENTED' + " +endfunction " ---------- end of function s:SetMap ---------- +" +"---------------------------------------------------------------------- +" s:SetProperty : Set an existing property. {{{2 +"---------------------------------------------------------------------- +" +function! s:SetProperty ( name, value ) + " + let [ _, err ] = mmtemplates#core#Resource ( s:library, 'set', 'property', a:name , a:value ) + " + if err != '' + return s:ErrorMsg ( 'Can not set the property "'.a:name.'".' ) + endif + " +endfunction " ---------- end of function s:SetProperty ---------- +" +"---------------------------------------------------------------------- +" s:SetShortcut : TODO (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:SetShortcut ( name, shortcut ) + " + " check for valid shortcut + if len ( a:shortcut ) > 1 + call s:ErrorMsg ( 'The shortcut for "'.a:name.'" must be a single character.' ) + return + endif + " + echo 'SetShortcut: TO BE IMPLEMENTED' + " +endfunction " ---------- end of function s:SetShortcut ---------- +" +"---------------------------------------------------------------------- +" s:IncludeFile : Read a template file (template function). {{{2 +"---------------------------------------------------------------------- +" +function! s:IncludeFile ( templatefile, ... ) + " + let regex = s:library.regex_file + " + let read_abs = 0 + if a:0 >= 1 && a:1 == 'abs' + let read_abs = 1 + endif + " + " ================================================== + " checks + " ================================================== + " + " Expand ~, $HOME, ... and check for absolute path + let templatefile = expand( a:templatefile ) + " +" if templatefile =~ regex.AbsolutePath +" let templatefile = s:ConcatNormalizedFilename ( templatefile ) +" else +" let templatefile = s:ConcatNormalizedFilename ( s:t_runtime.state_stack[ s:StateStackFile ], templatefile ) +" endif + if read_abs + let templatefile = s:ConcatNormalizedFilename ( templatefile ) + else + let templatefile = s:ConcatNormalizedFilename ( s:t_runtime.state_stack[ s:StateStackFile ], templatefile ) + endif + " + " file does not exists or was already visited? + if !filereadable( templatefile ) + throw 'Template:Check:file "'.templatefile.'" does not exist or is not readable' + elseif has_key ( s:t_runtime.files_visited, templatefile ) + throw 'Template:Check:file "'.templatefile.'" already read' + endif + " + " ================================================== + " setup + " ================================================== + " + " add to the state stack + call add ( s:t_runtime.state_stack, len( s:t_runtime.styles_stack ) ) " length of styles_stack + call add ( s:t_runtime.state_stack, s:GetNormalizedPath ( templatefile ) ) " current path + " + " mark file as read + let s:t_runtime.files_visited[templatefile] = 1 + " + " debug: + call s:DebugMsg ( 'Reading '.templatefile.' ...', 2 ) + " + let state = 'command' + let t_start = 0 + let last_styles = '' + " + " ================================================== + " go trough the file + " ================================================== + " + let filelines = readfile( templatefile ) + " + for line in filelines + " + let firstchar = line[0] + " + " which state + if state == 'command' + " ================================================== + " state: command + " ================================================== + " + " empty line? + if empty ( line ) + continue + endif + " + " comment? + if firstchar == regex.CommentHint + if line =~ regex.CommentLine + continue + endif + endif + " + " macro line? --- |MACRO| = something + if firstchar == regex.MacroHint + " + let mlist = matchlist ( line, regex.MacroAssign ) + if ! empty ( mlist ) + " STYLE, includefile or general macro + if mlist[1] == 'STYLE' + call s:SetStyle ( mlist[3] ) + elseif mlist[1] == 'includefile' + try + call s:IncludeFile ( mlist[3], 'old' ) + catch /Template:Check:.*/ + let msg = v:exception[ len( 'Template:Check:') : -1 ] + call s:ErrorMsg ( 'While loading "'.templatefile.'":', msg ) + endtry + else + call s:SetMacro ( mlist[1], mlist[3] ) + endif + continue + endif + " + endif + " + " function call? --- Function( param_list ) + if firstchar =~ regex.CommandHint + " + let mlist = matchlist ( line, regex.FunctionCall ) + if ! empty ( mlist ) + let [ name, param ] = mlist[ 1 : 2 ] + " + try + " check the call + call s:FunctionCheck ( name, param, s:FileReadNameSpace ) + " try to call + exe 'call s:'.name.' ( '.param.' ) ' + catch /Template:Check:.*/ + let msg = v:exception[ len( 'Template:Check:') : -1 ] + call s:ErrorMsg ( 'While loading "'.templatefile.'":', msg ) + catch // + call s:ErrorMsg ( 'While calling "'.name.'" in "'.templatefile.'":', v:exception ) + endtry + " + continue + endif + " + endif + " + " section or text? + if firstchar == regex.DelimHint + " + " switch styles? + let mlist = matchlist ( line, regex.Styles1Start ) + if ! empty ( mlist ) + call s:UseStyles ( [ mlist[1] ] ) + let last_styles = mlist[0] + continue + endif + " + " switch styles? + if line =~ regex.Styles1End + call s:RevertStyles ( 1 ) + continue + endif + " + " switch styles? + let mlist = matchlist ( line, regex.Styles2Start ) + if ! empty ( mlist ) + call s:UseStyles ( split( mlist[1], '\s*,\s*' ) ) + let last_styles = mlist[0] + continue + endif + " + " switch styles? + if line =~ regex.Styles2End + call s:RevertStyles ( 1 ) + continue + endif + " + " separator? + let mlist = matchlist ( line, regex.MenuSep ) + if ! empty ( mlist ) + call s:AddSeparator ( 'sep', mlist[1], '' ) + continue + endif + " + " start of text? + let mlist_template = matchlist ( line, regex.TemplateStart ) + let mlist_help = matchlist ( line, regex.HelpStart ) + let mlist_list = matchlist ( line, regex.ListStart ) + if ! empty ( mlist_template ) + let state = 'text' + let t_type = 'template' + let t_start = 1 + elseif ! empty ( mlist_help ) + let state = 'text' + let t_type = 'help' + let t_start = 1 + elseif ! empty ( mlist_list ) + let state = 'text' + let t_type = 'list' + let t_start = 1 + endif + " + endif + " + " empty line? + if line =~ regex.EmptyLine + continue + endif + " + elseif state == 'text' + " ================================================== + " state: text + " ================================================== + " + if firstchar == regex.CommentHint || firstchar == regex.DelimHint + " + " comment or end of template? + if line =~ regex.CommentLine + \ || line =~ regex.TemplateEnd + \ || line =~ regex.ListEnd + let state = 'command' + call s:AddText ( t_type, t_name, t_settings, t_lines ) + continue + endif + " + " start of new text? + let mlist_template = matchlist ( line, regex.TemplateStart ) + let mlist_help = matchlist ( line, regex.HelpStart ) + let mlist_list = matchlist ( line, regex.ListStart ) + if ! empty ( mlist_template ) + call s:AddText ( t_type, t_name, t_settings, t_lines ) + let t_type = 'template' + let t_start = 1 + elseif ! empty ( mlist_help ) + call s:AddText ( t_type, t_name, t_settings, t_lines ) + let t_type = 'help' + let t_start = 1 + elseif ! empty ( mlist_list ) + call s:AddText ( t_type, t_name, t_settings, t_lines ) + let t_type = 'list' + let t_start = 1 + else + let t_lines .= line."\n" " read the line + continue + endif + " + else + let t_lines .= line."\n" " read the line + continue + endif + " + endif + " + " start of template? + if t_start + if t_type == 'template' + let t_name = mlist_template[1] + let t_settings = split( mlist_template[2], '\s*,\s*' ) + elseif t_type == 'list' + let t_name = mlist_list[1] + let t_settings = split( mlist_list[2], '\s*,\s*' ) + elseif t_type == 'help' + let t_name = mlist_help[1] + let t_settings = split( mlist_help[2], '\s*,\s*' ) + endif + let t_lines = '' + let t_start = 0 + continue + endif + " + call s:ErrorMsg ( 'Failed to read line: '.line ) + " + endfor + " + " ================================================== + " wrap up + " ================================================== + " + if state == 'text' + call s:AddText ( t_type, t_name, t_settings, t_lines ) + endif + " + " all style sections closed? + let state_lim = s:t_runtime.state_stack[ s:StateStackStyleTop ] + let state_top = len( s:t_runtime.styles_stack ) + if state_lim < state_top + call s:RevertStyles ( state_top - state_lim ) + call s:ErrorMsg ( 'Styles section has not been closed: '.last_styles ) + endif + " + " debug: + call s:DebugMsg ( '... '.templatefile.' done.', 2 ) + " + " restore the previous state + call remove ( s:t_runtime.state_stack, -1 * s:StateStackLength, -1 ) + " +endfunction " ---------- end of function s:IncludeFile ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#ReadTemplates : Read a template file. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#ReadTemplates ( library, ... ) + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + return s:ErrorMsg ( 'Argument "library" must be given as a dict or string.' ) + endif + " + " ================================================== + " setup + " ================================================== + " + " library and runtime information + let s:library = t_lib + let s:t_runtime = { + \ 'state_stack' : [], + \ 'use_styles' : [], + \ 'styles_stack' : [], + \ 'files_visited' : {}, + \ + \ 'overwrite_warning' : 0, + \ } + " + let mode = '' + let file = '' + " + " ================================================== + " options + " ================================================== + " + let i = 1 + while i <= a:0 + " + if a:[i] == 'load' && i+1 <= a:0 + let mode = 'load' + let file = a:[i+1] + let i += 2 + elseif a:[i] == 'reload' && i+1 <= a:0 + let mode = 'reload' + let file = a:[i+1] + let i += 2 + elseif a:[i] == 'overwrite_warning' + let s:t_runtime.overwrite_warning = 1 + let i += 1 + elseif a:[i] == 'debug' && i+1 <= a:0 && ! s:DebugGlobalOverwrite + let s:DebugLevel = a:[i+1] + let i += 2 + else + if type ( a:[i] ) == type ( '' ) | call s:ErrorMsg ( 'Unknown option: "'.a:[i].'"' ) + else | call s:ErrorMsg ( 'Unknown option at position '.i.'.' ) | endif + let i += 1 + endif + " + endwhile + " + " ================================================== + " files + " ================================================== + " + let templatefiles = [] + " + if mode == 'load' + " + " check the type + if type( file ) != type( '' ) + return s:ErrorMsg ( 'Argument "filename" must be given as a string.' ) + endif + " + " expand ~, $HOME, ... and normalize + let file = expand ( file ) + call add ( templatefiles, s:ConcatNormalizedFilename ( file ) ) + " + " add to library + call add ( t_lib.library_files, s:ConcatNormalizedFilename ( file ) ) + " + elseif mode == 'reload' + " + if type( file ) == type( 0 ) + call add ( templatefiles, t_lib.library_files[ file ] ) + elseif type( file ) == type( '' ) + " load all or a specific file + if file == 'all' + call extend ( templatefiles, t_lib.library_files ) + else + " + " check and add the file + let file = expand ( file ) + let file = s:ConcatNormalizedFilename ( file ) + " + if ! filereadable ( file ) + return s:ErrorMsg ( 'The file "'.file.'" does not exist.' ) + elseif index ( t_lib.library_files, file ) == -1 + return s:ErrorMsg ( 'The file "'.file.'" is not part of the template library.' ) + endif + " + call add ( templatefiles, file ) + " + endif + else + return s:ErrorMsg ( 'Argument "fileid" must be given as an integer or string.' ) + endif + " + " remove old maps + if has_key ( t_lib, 'map_commands' ) + call remove ( t_lib, 'map_commands' ) + endif + " + endif + " + " ================================================== + " read the library + " ================================================== + " + " debug: + if s:DebugLevel > 0 + let time_start = reltime() + endif + " + for f in templatefiles + " + " file exists? + if !filereadable ( f ) + call s:ErrorMsg ( 'Template library "'.f.'" does not exist or is not readable.' ) + continue + endif + " + " runtime information: + " - set up the state stack: length of styles_stack + current path + " - reset the current styles + let s:t_runtime.state_stack = [ 0, s:GetNormalizedPath ( f ) ] + let s:t_runtime.use_styles = [] + let s:t_runtime.styles_stack = [] + " + " read the top-level file + call s:IncludeFile ( f, 'abs' ) + " + endfor + " + call sort ( s:library.styles ) " sort the styles + " + " debug: + if s:DebugLevel > 0 + echo 'Loading library: '.reltimestr( reltime( time_start ) ) + endif + " + if mode == 'reload' + echo 'Reloaded the template library.' + endif + " + " ================================================== + " wrap up + " ================================================== + " + unlet s:library " remove script variables + unlet s:t_runtime " ... + " + let s:DebugLevel = s:DebugGlobalOverwrite " reset debug + " +endfunction " ---------- end of function mmtemplates#core#ReadTemplates ---------- +" +"---------------------------------------------------------------------- +" === Templates === {{{1 +"---------------------------------------------------------------------- +" +"---------------------------------------------------------------------- +" s:ApplyFlag : Modify a text according to 'flag'. {{{2 +"---------------------------------------------------------------------- +" +function! s:ApplyFlag ( text, flag ) + " + if a:flag == '' || a:flag == 'i' " i : identity + return a:text + elseif a:flag == 'l' " l : lowercase + return tolower(a:text) + elseif a:flag == 'u' " u : uppercase + return toupper(a:text) + elseif a:flag == 'c' " c : capitalize + return toupper(a:text[0]).a:text[1:] + elseif a:flag == 'L' " L : legalized name + let text = substitute( a:text, '\s\+', '_', 'g' ) " multiple whitespaces + let text = substitute( text, '\W\+', '_', 'g' ) " multiple non-word characters + let text = substitute( text, '_\+', '_', 'g' ) " multiple underscores + return text + else " flag not valid + return a:text + endif + " +endfunction " ---------- end of function s:ApplyFlag ---------- +" +"---------------------------------------------------------------------- +" s:ReplaceMacros : Replace all the macros in a text. {{{2 +"---------------------------------------------------------------------- +" +function! s:ReplaceMacros ( text, m_local ) + " + let text1 = '' + let text2 = a:text + " + let regex = '\(\_.\{-}\)'.s:library.regex_template.MacroInsert.'\(\_.*\)' + " + while 1 + " + let mlist = matchlist ( text2, regex ) + " + " no more macros? + if empty ( mlist ) + break + endif + " + " check for recursion + if -1 != index ( s:t_runtime.macro_stack, mlist[2] ) + let m_text = '' + call add ( s:t_runtime.macro_stack, mlist[2] ) + throw 'Template:MacroRecursion' + elseif has_key ( a:m_local, mlist[2] ) + let m_text = get ( a:m_local, mlist[2] ) + else + let m_text = get ( s:library.macros, mlist[2], '' ) + end + " + if m_text =~ s:library.regex_template.MacroNoCapture + " + call add ( s:t_runtime.macro_stack, mlist[2] ) + " + let m_text = s:ReplaceMacros ( m_text, a:m_local ) + " + call remove ( s:t_runtime.macro_stack, -1 ) + " + endif + " + " apply flag? + if ! empty ( mlist[3] ) + let m_text = s:ApplyFlag ( m_text, mlist[3] ) + endif + " + let text1 .= mlist[1].m_text + let text2 = mlist[4] + " + endwhile + " + return text1.text2 + " +endfunction " ---------- end of function s:ReplaceMacros ---------- +" +"---------------------------------------------------------------------- +" s:CheckHelp : Check a template (help). {{{2 +"---------------------------------------------------------------------- +" +let s:NamespaceHelp = { + \ 'Word' : 's', + \ 'Pattern' : 's', 'Default' : 's', + \ 'Substitute' : 'sss', 'LiteralSub' : 'sss', + \ 'System' : 's', 'Vim' : 's', + \ } +" +function! s:CheckHelp ( cmds, text, calls ) + return [ a:cmds, a:text ] +endfunction " ---------- end of function s:CheckHelp ---------- +" +" "---------------------------------------------------------------------- +" s:CheckStdTempl : Check a template (standard). {{{2 +"---------------------------------------------------------------------- +" +let s:NamespaceStdTempl = { + \ 'DefaultMacro' : 's[sl]', + \ 'PickFile' : 'ss', + \ 'PickList' : 's[sld]', + \ 'Prompt' : 'ss', + \ 'SurroundWith' : 's[sl]*', + \ } +let s:NamespaceStdTemplInsert = { + \ 'Comment' : 's\?', + \ 'Insert' : 's[sl]*', + \ 'InsertLine' : 's[sl]*', + \ } +" +function! s:CheckStdTempl ( cmds, text, calls ) + " + let regex = s:library.regex_template + let ms = regex.MacroStart + let me = regex.MacroEnd + " + let cmds = a:cmds + let text = a:text + " + let prompted = {} + " + " -------------------------------------------------- + " replacements + " -------------------------------------------------- + while 1 + " + let mlist = matchlist ( text, regex.MacroRequest ) + " + " no more macros? + if empty ( mlist ) + break + endif + " + let m_name = mlist[1] + let m_flag = mlist[2] + " + " not a special macro and not already done? + if has_key ( s:StandardMacros, m_name ) + call s:ErrorMsg ( 'The special macro "'.m_name.'" can not be replaced via |?'.m_name.'|.' ) + elseif ! has_key ( prompted, m_name ) + let cmds .= "Prompt(".string(m_name).",".string(m_flag).")\n" + let prompted[ m_name ] = 1 + endif + " + if ! empty ( m_flag ) | let m_flag = ':'.m_flag | endif + " + " insert a normal macro + let text = s:LiteralReplacement ( text, + \ mlist[0], ms.m_name.m_flag.me, 'g' ) + " + endwhile + " + " -------------------------------------------------- + " lists + " -------------------------------------------------- + let list_items = [ 'EMPTY', 'SINGLE', 'FIRST', 'LAST' ] " + 'ENTRY' + " + while 1 + " + let mlist = matchlist ( text, regex.ListItem ) + " + " no more macros? + if empty ( mlist ) + break + endif + " + let l_name = mlist[1] + " + let mlist = matchlist ( text, + \ '\([^'."\n".']*\)'.ms.l_name.':ENTRY_*'.me.'\([^'."\n".']*\)\n' ) + " + let cmds .= "LIST(".string(l_name)."," + \ .string(mlist[1]).",".string(mlist[2]).")\n" + let text = s:LiteralReplacement ( text, + \ mlist[0], ms.l_name.':LIST'.me."\n", '' ) + " + for item in list_items + " + let mlist = matchlist ( text, + \ '\([^'."\n".']*\)'.ms.l_name.':'.item.'_*'.me.'\([^'."\n".']*\)\n' ) + " + if empty ( mlist ) + let cmds .= "\n" + continue + endif + " + let cmds .= "[".string(mlist[1]).",".string(mlist[2])."]\n" + let text = s:LiteralReplacement ( text, mlist[0], '', '' ) + endfor + " + endwhile + " + " -------------------------------------------------- + " comments + " -------------------------------------------------- + while 1 + " + let mlist = matchlist ( text, regex.FunctionComment ) + " + " no more comments? + if empty ( mlist ) + break + endif + " + let [ f_name, f_param ] = mlist[ 1 : 2 ] + " + " check the call + call s:FunctionCheck ( 'Comment', f_param, s:NamespaceStdTemplInsert ) + " + exe 'let flist = ['.f_param.']' + " + if empty ( flist ) | let flag = 'eol' + else | let flag = flist[0] | endif + " + let mlist = matchlist ( text, regex.FunctionComment.'\s*\([^'."\n".']*\)' ) + " + let text = s:LiteralReplacement ( text, mlist[0], + \ ms.'InsertLine("Comments.end-of-line","|CONTENT|",'.string( mlist[3] ).')'.me, '' ) + " + endwhile + " + return [ cmds, text ] + " +endfunction " ---------- end of function s:CheckStdTempl ---------- +" +"---------------------------------------------------------------------- +" s:CheckTemplate : Check a template. {{{2 +" +" Get the command and text block. +"---------------------------------------------------------------------- +" +function! s:CheckTemplate ( template, type ) + " + let regex = s:library.regex_template + " + let cmds = '' + let text = '' + let calls = [] + " + " the known functions + if a:type == 't' + let namespace = s:NamespaceStdTempl +" " TODO: remove this code: +" elseif a:type == 'pick-file' +" let namespace = s:NamespacePickFile +" elseif a:type == 'pick-list' +" let namespace = s:NamespacePickList + elseif a:type == 'help' + let namespace = s:NamespaceHelp + endif + " + " go trough the lines + let idx = 0 + while idx < len ( a:template ) + " + let idx_n = stridx ( a:template, "\n", idx ) + let mlist = matchlist ( a:template[ idx : idx_n ], regex.FunctionLine ) + " + " no match or 'Comment' or 'Insert' function? + if empty ( mlist ) || mlist[ 2 ] =~ regex.TextBlockFunctions + break + endif + " + let [ f_name, f_param ] = mlist[ 2 : 3 ] + " + " check the call + call s:FunctionCheck ( f_name, f_param, namespace ) + " + call add ( calls, [ f_name, f_param ] ) + " + let cmds .= mlist[1]."\n" + let idx += len ( mlist[0] ) + " + endwhile + " + let text = a:template[ idx : -1 ] + " + " checks depending on the type + if a:type == 't' + return s:CheckStdTempl( cmds, text, calls ) +" " TODO: remove this code: +" elseif a:type == 'pick-file' +" return s:CheckPickFile( cmds, text, calls ) +" elseif a:type == 'pick-list' +" return s:CheckPickList( cmds, text, calls ) + elseif a:type == 'help' + return s:CheckHelp( cmds, text, calls ) + endif + " +endfunction " ---------- end of function s:CheckTemplate ---------- +" +"---------------------------------------------------------------------- +" s:GetTemplate : Get a template. {{{2 +"---------------------------------------------------------------------- +" +function! s:GetTemplate ( name, style ) + " + let name = a:name + let style = a:style + " + " check the template + if has_key ( s:library.templates, name.'!!type' ) + let info = s:library.templates[ a:name.'!!type' ] + let [ type, placement, indentation ] = split ( info, ',' ) + else + throw 'Template:Prepare:template does not exist' + endif + " + if style == '!any' + for s in s:library.styles + if has_key ( s:library.templates, name.'!'.s ) + let template = get ( s:library.templates, name.'!'.s ) + let style = s + endif + endfor + else + " check the style + if has_key ( s:library.templates, name.'!'.style ) + let template = get ( s:library.templates, name.'!'.style ) + elseif has_key ( s:library.templates, name.'!default' ) + let template = get ( s:library.templates, name.'!default' ) + let style = 'default' + elseif style == 'default' + throw 'Template:Prepare:template does not have the default style' + else + throw 'Template:Prepare:template has neither the style "'.style.'" nor the default style' + endif + endif + " + " check the text + let head = template[ 0 : 5 ] + " + if head == "|P()|\n" " plain text + " TODO: special type for plain + let cmds = '' + let text = template[ 6 : -1 ] + elseif head == "|T()|\n" " only text (contains only macros without '?') + let cmds = '' + let text = template[ 6 : -1 ] + elseif head == "|C()|\n" " command and text block + let splt = stridx ( template, "|T()|\n" ) - 1 + let cmds = template[ 6 : splt ] + let text = template[ splt+7 : -1 ] + else + " + " do checks + let [ cmds, text ] = s:CheckTemplate ( template, type ) + " + " save the result + if empty ( cmds ) + let template = "|T()|\n".text + else + let template = "|C()|\n".cmds."|T()|\n".text + end + let s:library.templates[ a:name.'!'.style ] = template + " + end + " + return [ cmds, text, type, placement, indentation ] +endfunction " ---------- end of function s:GetTemplate ---------- +" +"---------------------------------------------------------------------- +" s:GetPickList : Get the list used in a template. {{{2 +"---------------------------------------------------------------------- +" +function! s:GetPickList ( name ) + " + let regex = s:library.regex_template + " + " get the template + let [ cmds, text, type, placement, indentation ] = s:GetTemplate ( a:name, '!any' ) + " + if type == 't' + " + for line in split( cmds, "\n" ) + " the line will match and it will be a valid function + let [ f_name, f_param ] = matchlist ( line, regex.FunctionChecked )[ 1 : 2 ] + " + if f_name == 'PickList' + " + exe 'let [ _, listarg ] = [ '.f_param.' ]' + " + let entry = '' + " + if type ( listarg ) == type ( '' ) + if ! has_key ( s:library.resources, 'list!'.listarg ) + call s:ErrorMsg ( 'List "'.listarg.'" does not exist.' ) + return [] + endif + let list = s:library.resources[ 'list!'.listarg ] + else + let list = listarg + endif + " + endif + endfor + " +" " TODO: remove this code: +" elseif type == 'pick-list' +" " +" for line in split( cmds, "\n" ) +" " the line will match and it will be a valid function +" let [ f_name, f_param ] = matchlist ( line, regex.FunctionChecked )[ 1 : 2 ] +" " +" if f_name == 'List' +" exe 'let list = '.f_param +" elseif f_name == 'GetList' +" " +" let listname = matchstr ( f_param, regex.RemoveQuote ) +" if ! has_key ( s:library.resources, 'list!'.listname ) +" call s:ErrorMsg ( 'List "'.listname.'" does not exist.' ) +" return [] +" endif +" let list = s:library.resources[ 'list!'.listname ] +" " +" endif +" endfor +" " + else + call s:ErrorMsg ( 'Template "'.a:name.'" is not a list picker.' ) + return [] + endif + " + if type ( list ) == type ( [] ) + return list + else + return sort ( keys ( list ) ) + endif + " +endfunction " ---------- end of function s:GetPickList ---------- +" +"---------------------------------------------------------------------- +" s:PrepareHelp : Prepare a template (help). {{{2 +"---------------------------------------------------------------------- +" +function! s:PrepareHelp ( cmds, text ) + " + let regex = s:library.regex_template + " + let pick = '' + let default = '' + let method = '' + let call = '' + " + let buf_line = getline('.') + let buf_pos = col('.') - 1 + " + " ================================================== + " command block + " ================================================== + " + for line in split( a:cmds, "\n" ) + " + " the line will match and it will be a valid function + let [ f_name, f_param ] = matchlist ( line, regex.FunctionChecked )[ 1 : 2 ] + " + if f_name == 'C' + " ignore + elseif f_name == 'Word' + exe 'let switch = '.f_param | " TODO: works differently than 'Pattern': picks up word behind the cursor, too + if switch == 'W' | let pick = expand('') + else | let pick = expand('') | endif + elseif f_name == 'Pattern' + exe 'let pattern = '.f_param + let cnt = 1 + while 1 + let m_end = matchend ( buf_line, pattern, 0, cnt ) - 1 + if m_end < 0 + let pick = '' + break + elseif m_end >= buf_pos + let m_start = match ( buf_line, pattern, 0, cnt ) + if m_start <= buf_pos | let pick = buf_line[ m_start : m_end ] + else | let pick = '' | endif + break + endif + let cnt += 1 + endwhile + elseif f_name == 'Default' + exe 'let default = '.f_param + elseif f_name == 'LiteralSub' + exe 'let [ p, r, f ] = ['.f_param.']' + let pick = s:LiteralReplacement ( pick, p, r, f ) + elseif f_name == 'Substitute' + exe 'let [ p, r, f ] = ['.f_param.']' + let pick = substitute ( pick, p, r, f ) + elseif f_name == 'System' || f_name == 'Vim' + let method = f_name + exe 'let call = '.f_param + endif + " + endfor + " + " ================================================== + " call for help + " ================================================== + " + if empty ( pick ) && empty ( default ) + \ || empty ( method ) + return '' + endif + " + let m_local = copy ( s:t_runtime.macros ) + " + if ! empty ( pick ) + let m_local.PICK = pick + let call = s:ReplaceMacros ( call, m_local ) + else + let call = s:ReplaceMacros ( default, m_local ) + endif + " + if method == 'System' + echo 'call system ( '.string ( call ).' )' | " debug + exe 'call system ( '.string ( call ).' )' + elseif method == 'Vim' + echo call | " debug + exe call + endif + " + return '' + " +endfunction " ---------- end of function s:PrepareHelp ---------- +" +" "---------------------------------------------------------------------- +" s:PrepareStdTempl : Prepare a template (standard). {{{2 +"---------------------------------------------------------------------- +" +function! s:PrepareStdTempl ( cmds, text ) + " + " TODO: revert must work like a stack, first set, last reverted + " TODO: revert in case of PickList and PickFile + " + let regex = s:library.regex_template + let ms = regex.MacroStart + let me = regex.MacroEnd + " + let m_local = s:t_runtime.macros + let m_global = s:library.macros + let prompted = s:t_runtime.prompted + " + let text = a:text + let surround = '' + let revert = '' + " + " + " ================================================== + " command block + " ================================================== + " + let cmds = split( a:cmds, "\n" ) + let i_cmds = 0 + let n_cmds = len( cmds ) + " + while i_cmds < n_cmds + " + " the line will match and it will be a valid function + let [ f_name, f_param ] = matchlist ( cmds[ i_cmds ], regex.FunctionChecked )[ 1 : 2 ] + " + if f_name == 'C' + " ignore + elseif f_name == 'SurroundWith' + let surround = f_param + elseif f_name == 'DefaultMacro' + " + let [ m_name, m_text ] = eval ( '[ '.f_param.' ]' ) + " + if ! has_key ( m_local, m_name ) + let revert = 'call remove ( m_local, "'.m_name.'" ) | '.revert + let m_local[ m_name ] = m_text + endif + " + elseif f_name == 'PickFile' + " + let [ p_prompt, p_path ] = eval ( '[ '.f_param.' ]' ) + " + if p_path =~ regex.MacroName + if ! has_key ( s:library.resources, 'path!'.p_path ) + throw 'Template:Prepare:the resources "'.p_path.'" does not exist' + endif + let p_path = s:library.resources[ 'path!'.p_path ] + endif + " + let p_path = expand ( p_path ) + let file = s:UserInput ( p_prompt.' : ', p_path, 'file' ) + " + let m_local.PICK_COMPL = file + let m_local.PATH_COMPL = fnamemodify ( file, ':h' ) + " + let file = substitute ( file, '\V\^'.p_path, '', '' ) + " + let m_local.PICK = file + let m_local.PATH = fnamemodify ( file, ':h' ) + let m_local.FILENAME = fnamemodify ( file, ':t' ) + let m_local.BASENAME = fnamemodify ( file, ':t:r' ) + let m_local.SUFFIX = fnamemodify ( file, ':e' ) + " + elseif f_name == 'PickEntry' + " + let [ p_which, p_entry ] = eval ( '[ '.f_param.' ]' ) + " + let l:pick_entry = p_entry + " + elseif f_name == 'PickList' + " + let [ p_prompt, p_list ] = eval ( '[ '.f_param.' ]' ) + " + if type ( p_list ) == type ( '' ) + if ! has_key ( s:library.resources, 'list!'.p_list ) + throw 'Template:Prepare:the resources "'.p_list.'" does not exist' + endif + let list = s:library.resources[ 'list!'.p_list ] + else + let list = p_list + end + " + if type ( list ) == type ( [] ) + let type = 'list' + let input_list = list + else + let type = 'dict' + let input_list = sort ( keys ( list ) ) + endif + " + if exists ( 'l:pick_entry' ) + let entry = l:pick_entry + else + let entry = s:UserInput ( p_prompt.' : ', '', 'customlist', input_list ) + endif + " + let m_local.KEY = entry + " + if type == 'dict' + if ! has_key ( list, entry ) + throw 'Template:Prepare:the entry "'.entry.'" does not exist' + endif + let entry = list[ entry ] + endif + " + let m_local.VALUE = entry + let m_local.PICK = entry + " + elseif f_name == 'Prompt' + " + let [ m_name, m_flag ] = eval ( '[ '.f_param.' ]' ) + " + " not already done and not a local macro? + if ! has_key ( prompted, m_name ) + \ && ! has_key ( m_local, m_name ) + let m_text = get ( m_global, m_name, '' ) + " + " prompt user for replacement + let flagaction = get ( s:Flagactions, m_flag, '' ) " notify flag action, if any + let m_text = s:UserInput ( m_name.flagaction.' : ', m_text ) + let m_text = s:ApplyFlag ( m_text, m_flag ) + " + " save the result + let m_global[ m_name ] = m_text + let prompted[ m_name ] = 1 + endif + else + break + endif + " + let i_cmds += 1 + endwhile + " + " -------------------------------------------------- + " lists + " -------------------------------------------------- + " + while i_cmds < n_cmds + " + let mlist = matchlist ( cmds[ i_cmds ], regex.FunctionList ) + " + if empty ( mlist ) + break + endif + " + exe 'let [ l_name, head_def, tail_def ] = ['.mlist[1].']' + let l_text = '' + if ! has_key ( m_local, l_name ) + let l_len = 0 + elseif type ( m_local[ l_name ] ) == type ( '' ) + let l_list = [ m_local[ l_name ] ] + let l_len = 1 + else + let l_list = m_local[ l_name ] + let l_len = len ( l_list ) + endif + " + if l_len == 0 + if ! empty ( cmds[ i_cmds+1 ] ) + exe 'let [ head, tail ] = '.cmds[ i_cmds+1 ] + let l_text = head.tail."\n" + endif + elseif l_len == 1 + if ! empty ( cmds[ i_cmds+2 ] ) + exe 'let [ head, tail ] = '.cmds[ i_cmds+2 ] + let l_text = head.l_list[0].tail."\n" + elseif ! empty ( cmds[ i_cmds+3 ] ) + exe 'let [ head, tail ] = '.cmds[ i_cmds+3 ] + let l_text = head.l_list[0].tail."\n" + else + let l_text = head_def.l_list[0].tail_def."\n" + end + else " l_len >= 2 + " + if ! empty ( cmds[ i_cmds+3 ] ) + exe 'let [ head, tail ] = '.cmds[ i_cmds+3 ] + let l_text .= head.l_list[0].tail."\n" + else + let l_text .= head_def.l_list[0].tail_def."\n" + endif + " + for idx in range ( 1, l_len-2 ) + let l_text .= head_def.l_list[idx].tail_def."\n" + endfor + " + if ! empty ( cmds[ i_cmds+4 ] ) + exe 'let [ head, tail ] = '.cmds[ i_cmds+4 ] + let l_text .= head.l_list[-1].tail."\n" + else + let l_text .= head_def.l_list[-1].tail_def."\n" + endif + endif + " + let text = s:LiteralReplacement ( text, ms.l_name.':LIST'.me."\n", l_text, '' ) + " + let i_cmds += 5 + endwhile + " + " ================================================== + " text block: macros and templates + " ================================================== + " + " insert other templates + while 1 + " + let mlist = matchlist ( text, regex.FunctionInsert ) + " + " no more inserts? + if empty ( mlist ) + break + endif + " + let [ f_name, f_param ] = mlist[ 1 : 2 ] + " + " check the call + call s:FunctionCheck ( f_name, f_param, s:NamespaceStdTemplInsert ) + " + if f_name == 'InsertLine' + " get the replacement + exe 'let m_text = s:PrepareTemplate ( '.f_param.' )[0]' + let m_text = m_text[ 0 : -2 ] + " check + if m_text =~ "\n" + throw 'Template:Prepare:inserts more than a single line: "'.mlist[0].'"' + endif + elseif f_name == 'Insert' + " get the replacement + exe 'let m_text = s:PrepareTemplate ( '.f_param.' )[0]' + let m_text = m_text[ 0 : -2 ] + " prepare + let mlist = matchlist ( text, '\([^'."\n".']*\)'.regex.FunctionInsert.'\([^'."\n".']*\)' ) + let head = mlist[1] + let tail = mlist[4] + let m_text = head.substitute( m_text, "\n", tail."\n".head, 'g' ).tail + else + throw 'Template:Check:the function "'.f_name.'" does not exist' + endif + " + " insert + let text = s:LiteralReplacement ( text, mlist[0], m_text, '' ) + " + endwhile + " + " insert the replacements + let text = s:ReplaceMacros ( text, m_local ) + " + " ================================================== + " surround the template + " ================================================== + " + if ! empty ( surround ) + " get the replacement + exe 'let [ s_text, s_place ] = s:PrepareTemplate ( '.surround.', "do_surround" )' + " + if s_place == 'CONTENT' + if -1 == match( s_text, '' ) + throw 'Template:Prepare:surround template: missing' + endif + " + let mcontext = matchlist ( s_text, '\([^'."\n".']*\)'.''.'\([^'."\n".']*\)' ) + let head = mcontext[1] + let tail = mcontext[2] + " insert + let text = text[ 0: -2 ] " remove trailing '\n' + let text = head.substitute( text, "\n", tail."\n".head, 'g' ).tail + let text = s:LiteralReplacement ( s_text, mcontext[0], text, '' ) + elseif s_place == 'SPLIT' + if -1 == match( s_text, '' ) + throw 'Template:Prepare:surround template: missing' + endif + " + if match( s_text, '\s*\n' ) >= 0 + let part = split ( s_text, '\s*\s*\n', 1 ) + else + let part = split ( s_text, '', 1 ) + endif + let text = part[0].text.part[1] + endif + endif + " + exe revert + " + return text + " +endfunction " ---------- end of function s:PrepareStdTempl ---------- +" +"---------------------------------------------------------------------- +" s:PrepareTemplate : Prepare a template for insertion. {{{2 +"---------------------------------------------------------------------- +" +function! s:PrepareTemplate ( name, ... ) + " + let regex = s:library.regex_template + " + " ================================================== + " setup and checks + " ================================================== + " + " check for recursion + if -1 != index ( s:t_runtime.obj_stack, a:name ) + call add ( s:t_runtime.obj_stack, a:name ) + throw 'Template:Recursion' + endif + " + call add ( s:t_runtime.obj_stack, a:name ) + " + " current style + let style = s:library.current_style + " + " get the template + let [ cmds, text, type, placement, indentation ] = s:GetTemplate ( a:name, style ) + " + " current macros + let m_local = s:t_runtime.macros + let prompted = s:t_runtime.prompted + " + let remove_cursor = 1 + let remove_split = 1 + let use_surround = 0 + let use_split = 0 + " + let revert = '' + " + " ================================================== + " parameters + " ================================================== + " + let i = 1 + while i <= a:0 + " + if a:[i] =~ regex.MacroMatch && i+1 <= a:0 + let m_name = matchlist ( a:[i], regex.MacroNameC )[1] + if has_key ( m_local, m_name ) + let revert = 'let m_local["'.m_name.'"] = '.string( m_local[ m_name ] ).' | '.revert + else + let revert = 'call remove ( m_local, "'.m_name.'" ) | '.revert + endif + let m_local[ m_name ] = a:[i+1] + let i += 2 + elseif a:[i] == '' + let remove_cursor = 0 + let i += 1 + elseif a:[i] == '' + let remove_split = 0 + let i += 1 + elseif a:[i] == 'do_surround' + let use_surround = 1 + let i += 1 + elseif a:[i] == 'use_split' + let use_split = 1 + let remove_split = 0 + let i += 1 + elseif a:[i] == 'pick' && i+1 <= a:0 + let cmds = "PickEntry( '', ".string(a:[i+1])." )\n".cmds + let i += 2 + else + if type ( a:[i] ) == type ( '' ) | call s:ErrorMsg ( 'Unknown option: "'.a:[i].'"' ) + else | call s:ErrorMsg ( 'Unknown option at position '.i.'.' ) | endif + let i += 1 + endif + " + endwhile + " + " ================================================== + " prepare + " ================================================== + " + if type == 't' + let text = s:PrepareStdTempl( cmds, text ) +" " TODO: remove this code: +" elseif type == 'pick-file' +" let text = s:PreparePickFile( cmds, text ) +" elseif type == 'pick-list' +" let text = s:PreparePickList( cmds, text ) + elseif type == 'help' + let text = s:PrepareHelp( cmds, text ) + endif + " + if remove_cursor + let text = s:LiteralReplacement( text, '', '', 'g' ) + endif + if remove_split + let text = s:LiteralReplacement( text, '', '', 'g' ) + endif + if ! use_surround || use_split + let text = s:LiteralReplacement( text, '', '', 'g' ) + endif + " + " ================================================== + " wrap up + " ================================================== + " + exe revert + " + call remove ( s:t_runtime.obj_stack, -1 ) + " + if use_split + return [ text, 'SPLIT' ] + elseif use_surround + return [ text, 'CONTENT' ] + else + return [ text, placement, indentation ] + endif + " +endfunction " ---------- end of function s:PrepareTemplate ---------- +" +"---------------------------------------------------------------------- +" === Insert Templates: Auxiliary Functions === {{{1 +"---------------------------------------------------------------------- +" +"---------------------------------------------------------------------- +" s:InsertIntoBuffer : Insert a text into the buffer. {{{2 +" (thanks to Fritz Mehner) +"---------------------------------------------------------------------- +" +function! s:InsertIntoBuffer ( text, placement, indentation, flag_mode ) + " + " TODO: syntax + let regex = s:library.regex_template + " + let placement = a:placement + let indentation = a:indentation == '1' + " + if a:flag_mode != 'v' + " -------------------------------------------------- + " command and insert mode + " -------------------------------------------------- + " + " remove the split point + let text = substitute( a:text, '\V'.'', '', 'g' ) + " + if placement == 'below' + " + exe ':'.s:t_runtime.range[1] + call s:OpenFold('below') + let pos1 = line(".")+1 + silent put = text + let pos2 = line(".") + " + elseif placement == 'above' + " + exe ':'.s:t_runtime.range[0] + let pos1 = line(".") + silent put! = text + let pos2 = line(".") + " + elseif placement == 'start' + " + exe ':1' + call s:OpenFold('start') + let pos1 = 1 + silent put! = text + let pos2 = line(".") + " + elseif placement == 'append' || placement == 'insert' + " + if &foldenable && foldclosed(".") >= 0 + throw 'Template:Insert:insertion not available for a closed fold' + elseif placement == 'append' + let pos1 = line(".") + silent put = text + let pos2 = line(".")-1 + exe ":".pos1 + :join! + let indentation = 0 + elseif placement == 'insert' + let text = text[ 0: -2 ] " remove trailing '\n' + let currentline = getline( "." ) + let pos1 = line(".") + let pos2 = pos1 + count( split(text,'\zs'), "\n" ) + if a:flag_mode == 'i' + exe 'normal! gi'.text + else + exe 'normal! a'.text + endif + " reformat only multi-line inserts and previously empty lines + if pos1 == pos2 && currentline != '' + let indentation = 0 + endif + endif + " + else + throw 'Template:Insert:unknown placement "'.placement.'"' + endif + " + elseif a:flag_mode == 'v' + " -------------------------------------------------- + " visual mode + " -------------------------------------------------- + " + " remove the jump targets (2nd type) + let text = substitute( a:text, regex.JumpTagType2, '', 'g' ) + " + " TODO: Is the behaviour well-defined? + " Suggestion: The line might include a cursor and a split and nothing else. + if match( text, '' ) >= 0 + if match( text, '\s*\n' ) >= 0 + let part = split ( text, '\s*\s*\n', 1 ) + else + let part = split ( text, '', 1 ) + endif + let part[1] = part[1][ 0: -2 ] " remove trailing '\n' + else + let part = [ "", text[ 0: -2 ] ] " remove trailing '\n' + echomsg 'tag missing in template.' + endif + " + " 'visual' and placement 'insert': + " + " part0 and part1 can consist of several lines + " + " 'visual' and placement 'below': + " + " + " + " part0 and part1 can consist of several lines + " + if placement == 'insert' + " windows: register @* does not work + " solution: recover area of the visual mode and yank, + " puts the selected area into the buffer @" + let pos1 = line("'<") + let pos2 = line("'>") + len(split( text, '\n' )) - 1 + normal! gvy + let repl = escape ( part[0].@".part[1], '\&~' ) + " substitute the selected area (using the '< and '> marks) + exe ':s/\%''<.*\%''>./'.repl.'/' + let indentation = 0 + elseif placement == 'below' + silent 'put = part[1] + let pos1 = line("'<") - len(split( part[0], '\n' )) + let pos2 = line("'>") + len(split( part[1], '\n' )) + elseif placement =~ '^\%(start\|above\|append\)$' + throw 'Template:Insert:usage in split mode not allowed for placement "'.placement.'"' + else + throw 'Template:Insert:unknown placement "'.placement.'"' + endif + " + endif + " + " proper indenting + if indentation + silent exe ":".pos1 + silent exe "normal! ".( pos2-pos1+1 )."==" + endif + " + return [ pos1, pos2 ] + " +endfunction " ---------- end of function s:InsertIntoBuffer ---------- +" +"---------------------------------------------------------------------- +" s:PositionCursor : Position the cursor. {{{2 +" (thanks to Fritz Mehner) +"---------------------------------------------------------------------- +" +function! s:PositionCursor ( placement, flag_mode, pos1, pos2 ) + " + " :TODO:12.08.2013 11:03:WM: changeable syntax? + " :TODO:12.08.2013 12:00:WM: change behavior? + " + call setpos ( '.', [ bufnr('%'), a:pos1, 1, 0 ] ) + let mtch = search( '\m\|{CURSOR}', 'c', a:pos2 ) + if mtch != 0 + " tag found (and cursor moved, we are now at the position of the match) + let line = getline(mtch) + if line =~ '$\|{CURSOR}$' + " the tag is at the end of the line + call setline( mtch, substitute( line, '\|{CURSOR}', '', '' ) ) + if a:flag_mode == 'v' && getline('.') =~ '^\s*$' + "if a:flag_mode == 'v' && getline('.') =~ '^\s*\%(\|{CURSOR}\)\s*$' + " the line contains nothing but the tag: remove and join without + " changing the second line + normal! J + "call setline( mtch, '' ) + "normal! gJ + else + " the line contains other characters: remove the tag and start appending + "call setline( mtch, substitute( line, '\|{CURSOR}', '', '' ) ) + startinsert! + endif + else + " the line contains other characters: remove the tag and start inserting + call setline( mtch, substitute( line, '\|{CURSOR}', '', '' ) ) + startinsert + endif + else + " no tag found (and cursor not moved) + if a:placement == 'below' + " to the end of the block, needed for repeated inserts + exe ":".a:pos2 + endif + endif + " +endfunction " ---------- end of function s:PositionCursor ---------- +" +"---------------------------------------------------------------------- +" s:HighlightJumpTargets : Highlight the jump targets. {{{2 +"---------------------------------------------------------------------- +" +function! s:HighlightJumpTargets ( regex ) + exe 'match Search /'.a:regex.'/' +endfunction " ---------- end of function s:HighlightJumpTargets ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#InsertTemplate : Insert a template. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#InsertTemplate ( library, t_name, ... ) range + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + return s:ErrorMsg ( 'Argument "library" must be given as a dict or string.' ) + endif + " + if type( a:t_name ) != type( '' ) + return s:ErrorMsg ( 'Argument "template_name" must be given as a string.' ) + endif + " + " ================================================== + " setup + " ================================================== + " + " library and runtime information + let s:library = t_lib + let s:t_runtime = { + \ 'obj_stack' : [], + \ 'macro_stack' : [], + \ 'macros' : {}, + \ 'prompted' : {}, + \ + \ 'placement' : '', + \ 'range' : [ a:firstline, a:lastline ], + \ } + let regex = s:library.regex_template + " + " renew the predefined macros + let s:t_runtime.macros[ 'BASENAME' ] = expand( '%:t:r' ) + let s:t_runtime.macros[ 'FILENAME' ] = expand( '%:t' ) + let s:t_runtime.macros[ 'PATH' ] = expand( '%:p:h' ) + let s:t_runtime.macros[ 'SUFFIX' ] = expand( '%:e' ) + " + let s:t_runtime.macros[ 'DATE' ] = strftime( s:library.macros[ 'DATE' ] ) + let s:t_runtime.macros[ 'TIME' ] = strftime( s:library.macros[ 'TIME' ] ) + let s:t_runtime.macros[ 'YEAR' ] = strftime( s:library.macros[ 'YEAR' ] ) + " + " handle folds internally (and save the state) + if &foldenable + let foldmethod_save = &foldmethod + set foldmethod=manual + endif + " use internal formatting to avoid conflicts when using == below + " (and save the state) + let equalprg_save = &equalprg + set equalprg= + " + let flag_mode = 'n' + let options = [] + " + " ================================================== + " options + " ================================================== + " + let i = 1 + while i <= a:0 + " + if a:[i] == 'i' || a:[i] == 'insert' + let flag_mode = 'i' + let i += 1 + elseif a:[i] == 'v' || a:[i] == 'visual' + let flag_mode = 'v' + let i += 1 + elseif a:[i] == 'placement' && i+1 <= a:0 + let s:t_runtime.placement = a:[i+1] + let i += 2 + elseif a:[i] == 'range' && i+2 <= a:0 + let s:t_runtime.range[0] = a:[i+1] + let s:t_runtime.range[1] = a:[i+2] + let i += 3 + elseif a:[i] =~ regex.MacroMatch && i+1 <= a:0 + let name = matchlist ( a:[i], regex.MacroNameC )[1] + let s:t_runtime.macros[ name ] = a:[i+1] + let i += 2 + elseif a:[i] == 'pick' && i+1 <= a:0 + call add ( options, 'pick' ) + call add ( options, a:[i+1] ) + let i += 2 + elseif a:[i] == 'debug' && i+1 <= a:0 && ! s:DebugGlobalOverwrite + let s:DebugLevel = a:[i+1] + let i += 2 + else + if type ( a:[i] ) == type ( '' ) | call s:ErrorMsg ( 'Unknown option: "'.a:[i].'"' ) + else | call s:ErrorMsg ( 'Unknown option at position '.i.'.' ) | endif + let i += 1 + endif + " + endwhile + " + " ================================================== + " do the job + " ================================================== + " + try + " + " prepare the template for insertion + if empty ( options ) + let [ text, placement, indentation ] = s:PrepareTemplate ( a:t_name, '', '' ) + else + let [ text, placement, indentation ] = call ( 's:PrepareTemplate', [ a:t_name, '', '' ] + options ) + endif + " + if placement == 'help' + " job already done, TODO: review this + else + " + if ! empty ( s:t_runtime.placement ) + let placement = s:t_runtime.placement + endif + " + " insert the text into the buffer + let [ pos1, pos2 ] = s:InsertIntoBuffer ( text, placement, indentation, flag_mode ) + " + " position the cursor + call s:PositionCursor ( placement, flag_mode, pos1, pos2 ) + " + " highlight jump targets + call s:HighlightJumpTargets ( regex.JumpTagBoth ) + endif + " + catch /Template:UserInputAborted/ + " noop + catch /Template:Check:.*/ + " + let templ = s:t_runtime.obj_stack[ -1 ] + let msg = v:exception[ len( 'Template:Check:') : -1 ] + call s:ErrorMsg ( 'Checking "'.templ.'":', msg ) + " + catch /Template:Prepare:.*/ + " + let templ = s:t_runtime.obj_stack[ -1 ] + let incld = len ( s:t_runtime.obj_stack ) == 1 ? '' : '(included by: "'.s:t_runtime.obj_stack[ -2 ].'")' + let msg = v:exception[ len( 'Template:Prepare:') : -1 ] + call s:ErrorMsg ( 'Preparing "'.templ.'":', incld, msg ) + " + catch /Template:Recursion/ + " + let templ = s:t_runtime.obj_stack[ -1 ] + let idx1 = index ( s:t_runtime.obj_stack, templ ) + let cont = idx1 == 0 ? [] : [ '...' ] + call call ( 's:ErrorMsg', [ 'Recursion detected while including the template/s:' ] + cont + + \ s:t_runtime.obj_stack[ idx1 : -1 ] ) + " + catch /Template:MacroRecursion/ + " + let macro = s:t_runtime.macro_stack[ -1 ] + let idx1 = index ( s:t_runtime.macro_stack, macro ) + let cont = idx1 == 0 ? [] : [ '...' ] + call call ( 's:ErrorMsg', [ 'Recursion detected while replacing the macro/s:' ] + cont + + \ s:t_runtime.macro_stack[ idx1 : -1 ] ) + " + catch /Template:Insert:.*/ + " + let msg = v:exception[ len( 'Template:Insert:') : -1 ] + call s:ErrorMsg ( 'Inserting "'.a:t_name.'":', msg ) + " + catch /Template:.*/ + " + let msg = v:exception[ len( 'Template:') : -1 ] + call s:ErrorMsg ( msg ) + " + finally + " + " ================================================== + " wrap up + " ================================================== + " + " restore the state: folding and formatter program + if &foldenable + exe "set foldmethod=".foldmethod_save + normal! zv + endif + let &equalprg = equalprg_save + " + unlet s:library " remove script variables + unlet s:t_runtime " ... + " + let s:DebugLevel = s:DebugGlobalOverwrite " reset debug + " + endtry + " +endfunction " ---------- end of function mmtemplates#core#InsertTemplate ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#CreateMaps : Create maps for a template library. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#CreateMaps ( library, localleader, ... ) + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + else + return s:ErrorMsg ( 'Argument "library" must be given as a string.' ) + endif + " + if type( a:localleader ) != type( '' ) + call s:ErrorMsg ( 'Argument "localleader" must be given as a string.' ) + return + elseif ! empty ( a:localleader ) + if exists ( 'g:maplocalleader' ) + let ll_save = g:maplocalleader + endif + let g:maplocalleader = a:localleader + endif + " + " ================================================== + " reuse previous commands + " ================================================== + " + if has_key ( t_lib, 'map_commands' ) + "let TimeStart = reltime() + exe t_lib.map_commands + if ! empty ( a:localleader ) + if exists ( 'll_save' ) + let g:maplocalleader = ll_save + else + unlet g:maplocalleader + endif + endif + "echo 'Executing maps: '.reltimestr( reltime( TimeStart ) ) + return + endif + " + " ================================================== + " setup + " ================================================== + " + " options + let options = ' ' + let leader = '' + let sep = "\n" + " + let do_jump_map = 0 + let do_special_maps = 0 + " + let cmd = '' + " + " ================================================== + " options + " ================================================== + " + let i = 1 + while i <= a:0 + " + if a:[i] == 'do_jump_map' + let do_jump_map = 1 + let i += 1 + elseif a:[i] == 'do_special_maps' + let do_special_maps = 1 + let i += 1 + else + if type ( a:[i] ) == type ( '' ) | call s:ErrorMsg ( 'Unknown option: "'.a:[i].'"' ) + else | call s:ErrorMsg ( 'Unknown option at position '.i.'.' ) | endif + let i += 1 + endif + " + endwhile + " + "let TimeStart = reltime() + " + " ================================================== + " generate new commands + " ================================================== + " + if has_key ( g:CheckedFiletypes, &filetype ) + let echo_warning = 0 + else + let g:CheckedFiletypes[ &filetype ] = 1 + let echo_warning = g:Templates_MapInUseWarn != 0 + endif + " + " go through all the templates + for t_name in t_lib.menu_order + " + exe 'let [ visual, mp ] = ['.t_lib.templates[ t_name.'!!menu' ].'][0:1]' + " + " no map? + " separators have an empty string "map", so they are skipped here + if empty ( mp ) + continue + endif + " + for mode in [ 'n', 'v', 'i' ] + " + " map already existing? + if ! empty ( maparg( leader.mp, mode ) ) + if echo_warning + call s:ErrorMsg ( 'Mapping already in use: "'.leader.mp.'", mode "'.mode.'"' ) + endif + continue + endif + " + " insert and visual mode: insert '' + if mode == 'n' | let esc = '' + else | let esc = '' | endif + " + " insert mode, flag 'i': + " change behavior of templates with placement 'insert' + " visual mode, flag 'v': + " template contains a split tag, or the mode is forced + if mode == 'i' | let flag = ',"i"' + elseif mode == 'v' && visual == 1 | let flag = ',"v"' + else | let flag = '' | endif + " + " assemble the command to create the maps + let cmd .= mode.'noremap '.options.' '.leader.mp.' '.esc.':call mmtemplates#core#InsertTemplate('.a:library.',"'.t_name.'"'.flag.')'.sep + endfor + " + endfor + " + " jump map + if do_jump_map + let jump_key = '' " TODO: configurable + if ! empty ( maparg( jump_key ) ) + if echo_warning + call s:ErrorMsg ( 'Mapping already in use: "'.jump_key.'"' ) + endif + else + let jump_regex = string ( escape ( t_lib.regex_template.JumpTagBoth, '|' ) ) + let cmd .= 'nnoremap '.options.' '.jump_key.' i=mmtemplates#core#JumpToTag('.jump_regex.')'.sep + let cmd .= 'inoremap '.options.' '.jump_key.' =mmtemplates#core#JumpToTag('.jump_regex.')'.sep + endif + endif + " + " special maps + " TODO: configuration of maps + " TODO: edit template + if do_special_maps + let special_maps = { + \ t_lib.properties[ 'Templates::EditTemplates::Map' ] : ':call mmtemplates#core#EditTemplateFiles('.a:library.',-1)', + \ t_lib.properties[ 'Templates::RereadTemplates::Map' ] : ':call mmtemplates#core#ReadTemplates('.a:library.',"reload","all")', + \ t_lib.properties[ 'Templates::ChooseStyle::Map' ] : ':call mmtemplates#core#ChooseStyle('.a:library.',"!pick")', + \ } + " + for [ mp, action ] in items ( special_maps ) + if ! empty ( maparg( leader.mp ) ) + if echo_warning + call s:ErrorMsg ( 'Mapping already in use: "'.leader.mp.'"' ) + endif + else + let cmd .= ' noremap '.options.' '.leader.mp.' '.action.sep + let cmd .= 'inoremap '.options.' '.leader.mp.' '.action.sep + endif + endfor + endif + " + let t_lib.map_commands = cmd + exe cmd + " + " ================================================== + " wrap up + " ================================================== + " + if ! empty ( a:localleader ) + if exists ( 'll_save' ) + let g:maplocalleader = ll_save + else + unlet g:maplocalleader + endif + endif + " + "echo 'Generating maps: '.reltimestr( reltime( TimeStart ) ) + " +endfunction " ---------- end of function mmtemplates#core#CreateMaps ---------- +" +"---------------------------------------------------------------------- +" === Create Menus: Auxiliary Functions === {{{1 +"---------------------------------------------------------------------- +" +"---------------------------------------------------------------------- +" s:InsertShortcut : Insert a shortcut into a menu entry. {{{2 +" +" Inserts the shortcut by prefixing the appropriate character with '&', +" or by appending " ()". If escaped is true, the appended string is +" correctly escaped. +"---------------------------------------------------------------------- +" +function! s:InsertShortcut ( entry, shortcut, escaped ) + if empty ( a:shortcut ) + return a:entry + else + let entry = a:entry + let sc = a:shortcut + if stridx ( tolower( entry ), tolower( sc ) ) == -1 + if a:escaped | return entry.'\ (&'.sc.')' + else | return entry.' (&'.sc.')' + endif + else + return substitute( entry, '\V\c'.sc, '\&&', '' ) + endif + endif +endfunction " ---------- end of function s:InsertShortcut ---------- +" +"---------------------------------------------------------------------- +" s:CreateSubmenu : Create sub-menus, given they do not already exists. {{{2 +" +" The menu 'menu' can contain '&' and a trailing '.'. Both are ignored. +"---------------------------------------------------------------------- +" +function! s:CreateSubmenu ( t_lib, root_menu, global_name, menu, priority ) + " + " split point: + " a point, preceded by an even number of backslashes + " in turn, the backslashes must be preceded by a different character, or the + " beginning of the string + let level = len( split( a:root_menu, '\%(\_^\|[^\\]\)\%(\\\\\)*\zs\.' ) ) + let parts = split( a:menu, '\%(\_^\|[^\\]\)\%(\\\\\)*\zs\.' ) + let n_parts = len( parts ) + let level += n_parts + " + let priority_str = '' + " + " go through the menu, clean up and check for new menus + let submenu = '' + for i in range( 1, len( parts ) ) + " + let part = parts[ i-1 ] + " + if i == n_parts + let priority_str = repeat( '.', level-1 ).a:priority.'. ' + endif + " + let clean = substitute( part, '&', '', 'g' ) + if ! has_key ( a:t_lib.menu_existing, submenu.clean ) + " a new menu! + let a:t_lib.menu_existing[ submenu.clean ] = 0 + " + " shortcut and menu entry + if has_key ( a:t_lib.menu_shortcuts, submenu.clean ) + let shortcut = a:t_lib.menu_shortcuts[ submenu.clean ] + if stridx ( tolower( clean ), tolower( shortcut ) ) == -1 + let assemble = submenu.clean.' (&'.shortcut.')' + else + let assemble = submenu.substitute( clean, '\c'.shortcut, '\&&', '' ) + endif + else + let assemble = submenu.part + endif + " + let assemble .= '.' + " + if -1 != stridx ( clean, '' ) + exe 'anoremenu '.priority_str.a:root_menu.escape( assemble.clean, ' ' ).' :echo "This is a menu header."' + else + exe 'anoremenu '.priority_str.a:root_menu.escape( assemble.clean, ' ' ).''.escape( a:global_name, ' .' ).' :echo "This is a menu header."' + endif + exe 'anoremenu '.a:root_menu.escape( assemble, ' ' ).'-TSep00- ' + endif + let submenu .= clean.'.' + endfor + " +endfunction " ---------- end of function s:CreateSubmenu ---------- +" +"---------------------------------------------------------------------- +" s:CreateTemplateMenus : Create menus for the templates. {{{2 +"---------------------------------------------------------------------- +" +function! s:CreateTemplateMenus ( t_lib, root_menu, global_name, t_lib_name ) + " + let map_ldr = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::Mapleader' ], 'right' ) + " + " go through all the templates + for t_name in a:t_lib.menu_order + " + exe 'let [ visual, mp, entry, _, shortcut ] = ['.a:t_lib.templates[ t_name.'!!menu' ].']' + " + " no menu entry? + if entry == 0 + continue + endif + " + " get the sub-menu and the entry + let [ t_menu, t_last ] = matchlist ( t_name, '^\(.*\.\)\?\([^\.]\+\)$' )[1:2] + " + " menu does not exist? + if ! empty ( t_menu ) && ! has_key ( a:t_lib.menu_existing, t_menu[ 0 : -2 ] ) + call s:CreateSubmenu ( a:t_lib, a:root_menu, a:global_name, t_menu[ 0 : -2 ], s:StandardPriority ) + endif + " + if entry == 11 + let m_key = t_menu[ 0 : -2 ] + if empty ( m_key ) + let m_key = '!base' + endif + " + let sep_nr = a:t_lib.menu_existing[ m_key ] + 1 + let a:t_lib.menu_existing[ m_key ] = sep_nr + " + exe 'anoremenu '.a:root_menu.escape( t_menu, ' ' ).'-TSep'.sep_nr.'- :' + " + continue + endif + " + " shortcut and menu entry + if ! empty ( shortcut ) + if stridx ( tolower( t_last ), tolower( shortcut ) ) == -1 + let t_last .= ' (&'.shortcut.')' + else + let t_last = substitute( t_last, '\c'.shortcut, '\&&', '' ) + endif + endif + " + " assemble the entry, including the map, TODO: escape the map + let compl_entry = escape( t_menu.t_last, ' ' ) + if empty ( mp ) + let map_entry = '' + else + let map_entry = ''.map_ldr.mp + end + " + if entry == 1 + " prevents problems in insert mode + exe 'anoremenu '.a:root_menu.compl_entry.map_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'")' + exe 'inoremenu '.a:root_menu.compl_entry.map_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","i")' + if visual == 1 + exe 'vnoremenu '.a:root_menu.compl_entry.map_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","v")' + endif + elseif entry == 2 + call s:CreateSubmenu ( a:t_lib, a:root_menu, a:global_name, t_menu.t_last.map_entry, s:StandardPriority ) + " + for item in s:GetPickList ( t_name ) + let item_entry = compl_entry.'.'.substitute ( substitute ( escape ( item, ' .' ), '&', '\&\&', 'g' ), '\w', '\&&', '' ) + exe 'anoremenu '.a:root_menu.item_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","pick",'.string(item).')' + exe 'inoremenu '.a:root_menu.item_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","i","pick",'.string(item).')' + if visual == 1 + exe 'vnoremenu '.a:root_menu.item_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","v","pick",'.string(item).')' + endif + endfor + " +" exe 'anoremenu '.a:root_menu.compl_entry.'.-\ choose\ -'.map_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'")' +" if visual == 1 +" exe 'vnoremenu '.a:root_menu.compl_entry.'.-\ choose\ -'.map_entry.' :call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","v")' +" endif + endif + " + endfor + " +endfunction " ---------- end of function s:CreateTemplateMenus ---------- +" +"---------------------------------------------------------------------- +" s:CreateSpecialsMenus : Create menus for a template library. {{{2 +"---------------------------------------------------------------------- +" +function! s:CreateSpecialsMenus ( t_lib, root_menu, global_name, t_lib_name, specials_menu, styles_only ) + " + " remove trailing point + let specials_menu = substitute( a:specials_menu, '\.$', '', '' ) + " + let map_ldr = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::Mapleader' ], 'right' ) + let map_edit = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::EditTemplates::Map' ], 'right' ) + let map_read = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::RereadTemplates::Map' ], 'right' ) + let map_style = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::ChooseStyle::Map' ], 'right' ) + let sc_edit = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::EditTemplates::Shortcut' ], 'right' ) + let sc_read = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::RereadTemplates::Shortcut' ], 'right' ) + let sc_style = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::ChooseStyle::Shortcut' ], 'right' ) + " + " create the specials menu + call s:CreateSubmenu ( a:t_lib, a:root_menu, a:global_name, specials_menu, s:StandardPriority ) + " + if ! a:styles_only + " create edit and reread templates + let entry_edit = s:InsertShortcut ( '.edit\ templates', sc_edit, 1 ).''.map_edit + let entry_read = s:InsertShortcut ( '.reread\ templates', sc_read, 1 ).''.map_read + exe 'anoremenu '.a:root_menu.specials_menu.entry_edit + \ .' :call mmtemplates#core#EditTemplateFiles('.a:t_lib_name.',-1)' + exe 'anoremenu '.a:root_menu.specials_menu.entry_read + \ .' :call mmtemplates#core#ReadTemplates('.a:t_lib_name.',"reload","all")' + endif + " + " create a menu for all the styles + if sc_style == 's' | let entry_styles = '.choose &style'.map_style + else | let entry_styles = s:InsertShortcut ( '.choose style', sc_style, 0 ).''.map_style + endif + call s:CreateSubmenu ( a:t_lib, a:root_menu, a:global_name, specials_menu.entry_styles, s:StandardPriority ) + " + for s in a:t_lib.styles + exe 'anoremenu '.a:root_menu.specials_menu.'.choose\ style.&'.s + \ .' :call mmtemplates#core#ChooseStyle('.a:t_lib_name.','.string(s).')' + endfor + " +endfunction " ---------- end of function s:CreateSpecialsMenus ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#CreateMenus : Create menus for a template library. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#CreateMenus ( library, root_menu, ... ) + " + " check for feature + if ! has ( 'menu' ) + return + endif + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + let s:library = t_lib + else + call s:ErrorMsg ( 'Argument "library" must be given as a string.' ) + return + endif + " + if type( a:root_menu ) != type( '' ) + call s:ErrorMsg ( 'Argument "root_menu" must be given as a string.' ) + return + endif + " + " ================================================== + " setup + " ================================================== + " + " options + let root_menu = substitute( a:root_menu, '&', '', 'g' ) + let global_name = substitute( root_menu, '\.$', '', '' ) + let root_menu = global_name.'.' + let specials_menu = '&Run' + let priority = s:StandardPriority + let existing = [] + " + " jobs + let do_reset = 0 + let do_templates = 0 + let do_specials = 0 " no specials + let submenus = [] + " + " ================================================== + " options + " ================================================== + " + let i = 1 + while i <= a:0 + " + if a:[i] == 'global_name' && i+1 <= a:0 + let global_name = a:[i+1] + let i += 2 + elseif a:[i] == 'existing_menu' && i+1 <= a:0 + if type ( a:[i+1] ) == type ( '' ) | call add ( existing, a:[i+1] ) + else | call extend ( existing, a:[i+1] ) | endif + let i += 2 + elseif a:[i] == 'sub_menu' && i+1 <= a:0 + if type ( a:[i+1] ) == type ( '' ) | call add ( submenus, a:[i+1] ) + else | call extend ( submenus, a:[i+1] ) | endif + let i += 2 + elseif a:[i] == 'specials_menu' && i+1 <= a:0 + let specials_menu = a:[i+1] + let i += 2 + elseif a:[i] == 'priority' && i+1 <= a:0 + let priority = a:[i+1] + let i += 2 + elseif a:[i] == 'do_all' + let do_reset = 1 + let do_templates = 1 + let do_specials = 1 + let i += 1 + elseif a:[i] == 'do_reset' + let do_reset = 1 + let i += 1 + elseif a:[i] == 'do_templates' + let do_templates = 1 + let i += 1 + elseif a:[i] == 'do_specials' + let do_specials = 1 + let i += 1 + elseif a:[i] == 'do_styles' + let do_specials = 2 + let i += 1 + else + if type ( a:[i] ) == type ( '' ) | call s:ErrorMsg ( 'Unknown option: "'.a:[i].'"' ) + else | call s:ErrorMsg ( 'Unknown option at position '.i.'.' ) | endif + let i += 1 + endif + " + endwhile + " + " ================================================== + " do the jobs + " ================================================== + " + " reset + if do_reset + let t_lib.menu_existing = { '!base' : 0 } + endif + " + " existing menus + for name in existing + let name = substitute( name, '&', '', 'g' ) + let name = substitute( name, '\.$', '', '' ) + let t_lib.menu_existing[ name ] = 0 + endfor + " + " sub-menus + for name in submenus + call s:CreateSubmenu ( t_lib, root_menu, global_name, name, priority ) + endfor + " + " templates + if do_templates + call s:CreateTemplateMenus ( t_lib, root_menu, global_name, a:library ) + endif + " + " specials + if do_specials == 1 + " all specials + call s:CreateSpecialsMenus ( t_lib, root_menu, global_name, a:library, specials_menu, 0 ) + elseif do_specials == 2 + " styles only + call s:CreateSpecialsMenus ( t_lib, root_menu, global_name, a:library, specials_menu, 1 ) + endif + " + " ================================================== + " wrap up + " ================================================== + " + unlet s:library " remove script variable + " +endfunction " ---------- end of function mmtemplates#core#CreateMenus ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#EscapeMenu : Escape a string so it can be used as a menu item. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#EscapeMenu ( str, ... ) + " + let mode = 'entry' + " + if a:0 > 0 + if type( a:1 ) != type( '' ) + return s:ErrorMsg ( 'Argument "mode" must be given as a string.' ) + elseif a:1 == 'menu' + let mode = 'menu' + elseif a:1 == 'entry' + let mode = 'entry' + elseif a:1 == 'right' + let mode = 'right' + else + return s:ErrorMsg ( 'Unknown mode: '.a:1 ) + endif + endif + " + " whole menu: do not escape '.' + if mode == 'menu' + let str = escape ( a:str, ' \|' ) + else + let str = escape ( a:str, ' \|.' ) + endif + " + " right-aligned text: do not escape '&' + if mode != 'right' + let str = substitute ( str, '&', '\&\&', 'g' ) + endif + " + return str + " +endfunction " ---------- end of function mmtemplates#core#EscapeMenu ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#ChooseStyle : Choose a style. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#ChooseStyle ( library, style ) + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + call s:ErrorMsg ( 'Argument "library" must be given as a dict or string.' ) + return + endif + " + if type( a:style ) != type( '' ) + call s:ErrorMsg ( 'Argument "style" must be given as a string.' ) + return + endif + " + " ================================================== + " change the style + " ================================================== + " + " pick the style + if a:style == '!pick' + try + let style = s:UserInput( 'Style (currently '.t_lib.current_style.') : ', '', + \ 'customlist', t_lib.styles ) + catch /Template:UserInputAborted/ + return + endtry + else + let style = a:style + endif + " + " check and set the new style + if style == '' + " noop + elseif -1 != index ( t_lib.styles, style ) + if t_lib.current_style != style + let t_lib.current_style = style + echo 'Changed style to "'.style.'".' + elseif a:style == '!pick' + echo 'Style stayed "'.style.'".' + endif + else + call s:ErrorMsg ( 'Style was not changed. Style "'.style.'" is not available.' ) + end + " +endfunction " ---------- end of function mmtemplates#core#ChooseStyle ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#Resource : Access to various resources. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#Resource ( library, mode, ... ) + " + " TODO mode 'special' for |DATE|, |TIME| and |year| + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + return [ '', 'Argument "library" must be given as a dict or string.' ] + endif + " + if type( a:mode ) != type( '' ) + return [ '', 'Argument "mode" must be given as a string.' ] + endif + " + " ================================================== + " special inquiries + " ================================================== + " + if a:mode == 'add' || a:mode == 'get' || a:mode == 'set' + " continue below + elseif a:mode == 'escaped_mapleader' + return [ mmtemplates#core#EscapeMenu( t_lib.properties[ 'Templates::Mapleader' ], 'right' ), '' ] + elseif a:mode == 'jumptag' + return [ t_lib.regex_template.JumpTagBoth, '' ] + elseif a:mode == 'style' + return [ t_lib.current_style, '' ] + else + return [ '', 'Mode "'.a:mode.'" is unknown.' ] + endif + " + " ================================================== + " options + " ================================================== + " + " type of 'resource' + let types = { 'list' : '[ld]', 'macro' : 's', 'path' : 's', 'property' : 's' } + " + if a:mode == 'add' && a:0 != 3 + return [ '', 'Mode "add" requires three additional arguments.' ] + elseif a:mode == 'get' && a:0 != 2 + return [ '', 'Mode "get" requires two additional arguments.' ] + elseif a:mode == 'set' && a:0 != 3 + return [ '', 'Mode "set" requires three additional arguments.' ] + elseif type( a:1 ) != type( '' ) + return [ '', 'Argument "resource" must be given as a string.' ] + elseif type( a:2 ) != type( '' ) + return [ '', 'Argument "key" must be given as a string.' ] + elseif ! has_key ( types, a:1 ) + return [ '', 'Resource "'.a:1.'" does not exist.' ] + elseif a:mode == 'add' && a:1 != 'property' + return [ '', 'Can not execute add for resource of type "'.a:1.'".' ] + endif + " + " ================================================== + " add, get or set + " ================================================== + " + let resource = a:1 + let key = a:2 + " + if a:mode == 'add' + " + let value = a:3 + " + " add (property only) + if type( value ) != type( '' ) + return [ '', 'Argument "value" must be given as a string.' ] + else + let t_lib.properties[ key ] = value + return [ '', '' ] + endif + " + return [ '', '' ] + elseif a:mode == 'get' + " + " get + if resource == 'list' + return [ get( t_lib.resources, 'list!'.key ), '' ] + elseif resource == 'macro' + return [ get( t_lib.macros, key ), '' ] + elseif resource == 'path' + return [ get( t_lib.resources, 'path!'.key ), '' ] + elseif resource == 'property' + if has_key ( t_lib.properties, key ) + return [ t_lib.properties[ key ], '' ] + else + return [ '', 'Property "'.key.'" does not exist.' ] + endif + endif + " + elseif a:mode == 'set' + " + let value = a:3 + " + " check type and set + if s:TypeNames[ type( value ) ] !~ types[ resource ] + return [ '', 'Argument "value" has the wrong type.' ] + elseif resource == 'list' + let t_lib.resources[ 'list!'.key ] = value + elseif resource == 'macro' + let t_lib.macros[ key ] = value + elseif resource == 'path' + let t_lib.resources[ 'path!'.key ] = value + elseif resource == 'property' + if has_key ( t_lib.properties, key ) + let t_lib.properties[ key ] = value + return [ '', '' ] + else + return [ '', 'Property "'.key.'" does not exist.' ] + endif + endif + " + return [ '', '' ] + endif + " +endfunction " ---------- end of function mmtemplates#core#Resource ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#ChangeSyntax : Change the syntax of the templates. {{{1 +"------------------------------------------------------------------------------- +" +function! mmtemplates#core#ChangeSyntax ( library, category, ... ) + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + return s:ErrorMsg ( 'Argument "library" must be given as a dict or string.' ) + endif + " + if type( a:category ) != type( '' ) + return s:ErrorMsg ( 'Argument "category" must be given as an integer or string.' ) + endif + " + " ================================================== + " set the syntax + " ================================================== + " + if a:category == 'comment' + " + if a:0 < 1 + return s:ErrorMsg ( 'Not enough arguments for '.a:category.'.' ) + elseif a:0 == 1 + let t_lib.regex_settings.CommentStart = a:1 + let t_lib.regex_settings.CommentHint = a:1[0] + elseif a:0 == 2 + let t_lib.regex_settings.CommentStart = a:1 + let t_lib.regex_settings.CommentHint = a:2[0] + endif + " + call s:UpdateFileReadRegex ( t_lib.regex_file, t_lib.regex_settings ) + " + else + return s:ErrorMsg ( 'Unknown category: '.a:category ) + endif + " +endfunction " ---------- end of function mmtemplates#core#ChangeSyntax ---------- +" +"------------------------------------------------------------------------------- +" mmtemplates#core#ExpandText : Expand the macros in a text. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#ExpandText ( library, text ) + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + return s:ErrorMsg ( 'Argument "library" must be given as a dict or string.' ) + endif + " + if type( a:text ) != type( '' ) + return s:ErrorMsg ( 'Argument "text" must be given as a string.' ) + endif + " + " ================================================== + " setup + " ================================================== + " + " library and runtime information + let s:library = t_lib + let s:t_runtime = { + \ 'macro_stack' : [], + \ } + " + " renew the predefined macros + let m_local = {} + let m_local[ 'BASENAME' ] = expand( '%:t:r' ) + let m_local[ 'FILENAME' ] = expand( '%:t' ) + let m_local[ 'PATH' ] = expand( '%:p:h' ) + let m_local[ 'SUFFIX' ] = expand( '%:e' ) + " + let m_local[ 'DATE' ] = strftime( t_lib.macros[ 'DATE' ] ) + let m_local[ 'TIME' ] = strftime( t_lib.macros[ 'TIME' ] ) + let m_local[ 'YEAR' ] = strftime( t_lib.macros[ 'YEAR' ] ) + " + " ================================================== + " do the job + " ================================================== + " + let res = '' + " + try + " + let res = s:ReplaceMacros ( a:text, m_local ) + " + catch /Template:MacroRecursion/ + " + let macro = s:t_runtime.macro_stack[ -1 ] + let idx1 = index ( s:t_runtime.macro_stack, macro ) + let cont = idx1 == 0 ? [] : [ '...' ] + call call ( 's:ErrorMsg', [ 'Recursion detected while replacing the macro/s:' ] + cont + + \ s:t_runtime.macro_stack[ idx1 : -1 ] ) + " + catch /Template:.*/ + " + let msg = v:exception[ len( 'Template:') : -1 ] + call s:ErrorMsg ( msg ) + " + finally + " + " ================================================== + " wrap up + " ================================================== + " + unlet s:library " remove script variables + unlet s:t_runtime " ... + " + endtry + " + return res + " +endfunction " ---------- end of function mmtemplates#core#ExpandText ---------- +" +"------------------------------------------------------------------------------- +" mmtemplates#core#EditTemplateFiles : Choose and edit a template file. {{{1 +"------------------------------------------------------------------------------- +" +function! mmtemplates#core#EditTemplateFiles ( library, file ) + " + " ================================================== + " parameters + " ================================================== + " + if type( a:library ) == type( '' ) + exe 'let t_lib = '.a:library + elseif type( a:library ) == type( {} ) + let t_lib = a:library + else + return s:ErrorMsg ( 'Argument "library" must be given as a dict or string.' ) + endif + " + if type( a:file ) == type( 0 ) + if get( t_lib.library_files, a:file, '' ) == '' + return s:ErrorMsg ( 'No template file with index '.a:file.'.' ) + endif + let file = t_lib.library_files[ a:file ] + elseif type( a:file ) == type( '' ) + " + let file = expand ( a:file ) + let file = s:ConcatNormalizedFilename ( file ) + " + if ! filereadable ( file ) + return s:ErrorMsg ( 'The file "'.file.'" does not exist.' ) + elseif index ( t_lib.library_files, file ) == -1 + return s:ErrorMsg ( 'The file "'.file.'" is not part of the template library.' ) + endif + " + else + return s:ErrorMsg ( 'Argument "file" must be given as an integer or string.' ) + endif + " + " ================================================== + " do the job + " ================================================== + " + " get the directory + let dir = fnamemodify ( file, ':h' ) + " + " TODO: method configurable + let method = 'explore' + let templatefile = '' + " + if ! filereadable ( file ) + return s:ErrorMsg ( 'The directory "'.dir.'" does not exist.' ) + elseif method == 'explore' + " open a file explorer + if ! exists ( 'g:loaded_netrwPlugin' ) | return s:ErrorMsg ( 'The plugin "netrw" is not available.' ) | endif + exe 'update! | split | Explore '.dir + elseif method == 'browse' + " open a file browser + if ! has ( 'browse' ) | return s:ErrorMsg ( 'The command "browse" is not available.' ) | endif + let templatefile = browse ( 0, 'edit a template file', dir, '' ) + " returns an empty string if "Cancel" is pressed + endif + " + " open a buffer and start editing + if ! empty ( templatefile ) + exe 'update! | split | edit '.templatefile + endif + " +endfunction " ---------- end of function mmtemplates#core#EditTemplateFiles ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#JumpToTag : Jump to the next tag. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#JumpToTag ( regex ) + " + let match = search( '\m'.a:regex, 'c' ) + if match > 0 + " remove the target + call setline( match, substitute( getline('.'), a:regex, '', '' ) ) + endif + " + return '' +endfunction " ---------- end of function mmtemplates#core#JumpToTag ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#SetMapleader : Set the local mapleader. {{{1 +"---------------------------------------------------------------------- +" +" list of lists: [ "", "" ] +let s:mapleader_stack = [] +" +function! mmtemplates#core#SetMapleader ( localleader ) + " + if empty ( a:localleader ) + call add ( s:mapleader_stack, [] ) + else + if exists ( 'g:maplocalleader' ) + call add ( s:mapleader_stack, [ a:localleader, g:maplocalleader ] ) + else + call add ( s:mapleader_stack, [ a:localleader ] ) + endif + let g:maplocalleader = a:localleader + endif + " +endfunction " ---------- end of function mmtemplates#core#SetMapleader ---------- +" +"---------------------------------------------------------------------- +" mmtemplates#core#ResetMapleader : Reset the local mapleader. {{{1 +"---------------------------------------------------------------------- +" +function! mmtemplates#core#ResetMapleader () + " + let ll_save = remove ( s:mapleader_stack, -1 ) + " + if ! empty ( ll_save ) + if len ( ll_save ) > 1 + let g:maplocalleader = ll_save[1] + else + unlet g:maplocalleader + endif + endif + " +endfunction " ---------- end of function mmtemplates#core#ResetMapleader ---------- +" +" }}}1 +" +" ===================================================================================== +" vim: foldmethod=marker diff --git a/autoload/mmtoolbox/cmake.vim b/autoload/mmtoolbox/cmake.vim new file mode 100644 index 0000000..f83ffd9 --- /dev/null +++ b/autoload/mmtoolbox/cmake.vim @@ -0,0 +1,766 @@ +"=============================================================================== +" +" File: cmake.vim +" +" Description: Part of the C-Support toolbox. +" +" Vim/gVim integration of CMake. +" +" See help file toolboxcmake.txt . +" +" VIM Version: 7.0+ +" Author: Wolfgang Mehner, wolfgang-mehner@web.de +" Organization: +" Version: see variable g:CMake_Version below +" Created: 28.12.2011 +" Revision: --- +" License: Copyright (c) 2012, Wolfgang 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. +"=============================================================================== +" +"------------------------------------------------------------------------------- +" Basic checks. {{{1 +"------------------------------------------------------------------------------- +" +" need at least 7.0 +if v:version < 700 + echohl WarningMsg + echo 'The plugin mmtoolbox/cmake.vim needs Vim version >= 7.' + echohl None + finish +endif +" +" prevent duplicate loading +" need compatible +if &cp || ( exists('g:CMake_Version') && ! exists('g:CMake_DevelopmentOverwrite') ) + finish +endif +let g:CMake_Version= '0.9.1' " version number of this script; do not change +" +"------------------------------------------------------------------------------- +" Auxiliary functions {{{1 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" s:ApplyDefaultSetting : Write default setting to a global variable. {{{2 +" +" Parameters: +" varname - name of the variable (string) +" value - default value (string) +" Returns: +" - +" +" If g: does not exists, assign: +" g: = value +"------------------------------------------------------------------------------- +" +function! s:ApplyDefaultSetting ( varname, value ) + if ! exists ( 'g:'.a:varname ) + exe 'let g:'.a:varname.' = '.string( a:value ) + endif +endfunction " ---------- end of function s:ApplyDefaultSetting ---------- +" +"------------------------------------------------------------------------------- +" s:ErrorMsg : Print an error message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ErrorMsg ( ... ) + echohl WarningMsg + for line in a:000 + echomsg line + endfor + echohl None +endfunction " ---------- end of function s:ErrorMsg ---------- +" +"------------------------------------------------------------------------------- +" s:GetGlobalSetting : Get a setting from a global variable. {{{2 +" +" Parameters: +" varname - name of the variable (string) +" Returns: +" - +" +" If g: exists, assign: +" s: = g: +"------------------------------------------------------------------------------- +function! s:GetGlobalSetting ( varname ) + if exists ( 'g:'.a:varname ) + exe 'let s:'.a:varname.' = g:'.a:varname + endif +endfunction " ---------- end of function s:GetGlobalSetting ---------- +" +"------------------------------------------------------------------------------- +" s:ImportantMsg : Print an important message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ImportantMsg ( ... ) + echohl Search + echo join ( a:000, "\n" ) + echohl None +endfunction " ---------- end of function s:ImportantMsg ---------- +" +"------------------------------------------------------------------------------- +" s:Question : Ask the user a question. {{{2 +" +" Parameters: +" prompt - prompt, shown to the user (string) +" highlight - "normal" or "warning" (string, default "normal") +" Returns: +" retval - the user input (integer) +" +" The possible values of 'retval' are: +" 1 - answer was yes ("y") +" 0 - answer was no ("n") +" -1 - user aborted ("ESC" or "CTRL-C") +"------------------------------------------------------------------------------- +function! s:Question ( prompt, ... ) + " + let ret = -2 + " + " highlight prompt + if a:0 == 0 || a:1 == 'normal' + echohl Search + elseif a:1 == 'warning' + echohl Error + else + echoerr 'Unknown option : "'.a:1.'"' + return + end + " + " question + echo a:prompt.' [y/n]: ' + " + " answer: "y", "n", "ESC" or "CTRL-C" + while ret == -2 + let c = nr2char( getchar() ) + " + if c == "y" + let ret = 1 + elseif c == "n" + let ret = 0 + elseif c == "\" || c == "\" + let ret = -1 + endif + endwhile + " + " reset highlighting + echohl None + " + return ret +endfunction " ---------- end of function s:Question ---------- +" }}}2 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" Modul setup. {{{1 +"------------------------------------------------------------------------------- +" +" platform specifics {{{2 +" +let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") +let s:UNIX = has("unix") || has("macunix") || has("win32unix") +" +let s:SettingsEscChar = ' |"\' +" +if s:MSWIN + " + "------------------------------------------------------------------------------- + " MS Windows + "------------------------------------------------------------------------------- + " + let s:plugin_dir = substitute( expand(':p:h:h:h'), '\\', '/', 'g' ) + " +else + " + "------------------------------------------------------------------------------- + " Linux/Unix + "------------------------------------------------------------------------------- + " + let s:plugin_dir = expand(':p:h:h:h') + " +endif +" +" settings {{{2 +" +let s:ProjectDir = '.' +let s:BuildLocation = '.' +" +if s:MSWIN + let s:CMake_Executable = 'C:\Program Files\CMake\bin\cmake.exe' +else + let s:CMake_Executable = 'cmake' +endif +let s:CMake_MakeTool = 'make' +" +call s:GetGlobalSetting ( 'CMake_Executable' ) +call s:GetGlobalSetting ( 'CMake_MakeTool' ) +call s:ApplyDefaultSetting ( 'CMake_JumpToError', 'cmake' ) +" +let s:Enabled = 1 +" +" check executables {{{2 +" +if ! executable ( s:CMake_Executable ) || ! executable ( s:CMake_MakeTool ) + let s:Enabled = 0 +endif +" +" error formats {{{2 +" +" error format for CMake +let s:ErrorFormat_CMake = escape( + \ '%-DDIR : %f,%-XENDDIR : %f,' + \ .'%-G,' + \ .'%+G-- %.%#,' + \ .'%E%>CMake Error at %f:%l (%[%^)]%#):,' + \ .'%Z %m,' + \ .'%E%>CMake Error: Error in cmake code at,' + \ .'%C%>%f:%l:,' + \ .'%Z%m,' + \ .'%E%>CMake Error in %.%#:,' + \ .'%C%> %m,' + \ .'%C%>,' + \ .'%C%> %f:%l (if),' + \ .'%C%>,' + \ .'%Z %m,' + \ , s:SettingsEscChar ) +" +" error format for make, additional errors +let s:ErrorFormat_MakeAdditions = escape( + \ '%-GIn file included from %f:%l:%.%#,' + \ .'%-G%\s%\+from %f:%l:%.%#,' + \ , s:SettingsEscChar ) +" +" policy list {{{2 +" +let s:Policies_Version = '2.8.12' +let s:Policies_List = [ + \ [ 'CMP0000', 'A minimum required CMake version must be specified.', '2.6.0' ], + \ [ 'CMP0001', 'CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.', '2.6.0' ], + \ [ 'CMP0002', 'Logical target names must be globally unique.', '2.6.0' ], + \ [ 'CMP0003', 'Libraries linked via full path no longer produce linker search paths.', '2.6.0' ], + \ [ 'CMP0004', 'Libraries linked may not have leading or trailing whitespace.', '2.6.0' ], + \ [ 'CMP0005', 'Preprocessor definition values are now escaped automatically.', '2.6.0' ], + \ [ 'CMP0006', 'Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.', '2.6.0' ], + \ [ 'CMP0007', 'list command no longer ignores empty elements.', '2.6.0' ], + \ [ 'CMP0008', 'Libraries linked by full-path must have a valid library file name.', '2.6.1' ], + \ [ 'CMP0009', 'FILE GLOB_RECURSE calls should not follow symlinks by default.', '2.6.2' ], + \ [ 'CMP0010', 'Bad variable reference syntax is an error.', '2.6.3' ], + \ [ 'CMP0011', 'Included scripts do automatic cmake_policy PUSH and POP.', '2.6.3' ], + \ [ 'CMP0012', 'if() recognizes numbers and boolean constants.', '2.8.0' ], + \ [ 'CMP0013', 'Duplicate binary directories are not allowed.', '2.8.0' ], + \ [ 'CMP0014', 'Input directories must have CMakeLists.txt.', '2.8.0' ], + \ [ 'CMP0015', 'link_directories() treats paths relative to the source dir.', '2.8.1' ], + \ [ 'CMP0016', 'target_link_libraries() reports error if only argument is not a target.', '2.8.3' ], + \ [ 'CMP0017', 'Prefer files from the CMake module directory when including from there.', '2.8.4' ], + \ [ 'CMP0018', 'Ignore CMAKE_SHARED_LIBRARY__FLAGS variable.', '2.8.9' ], + \ [ 'CMP0019', 'Do not re-expand variables in include and link information.', '2.8.11' ], + \ [ 'CMP0020', 'Automatically link Qt executables to qtmain target on Windows.', '2.8.11' ], + \ [ 'CMP0021', 'Fatal error on relative paths in INCLUDE_DIRECTORIES target property.', '2.8.12' ], + \ [ 'CMP0022', 'INTERFACE_LINK_LIBRARIES defines the link interface.', '2.8.12' ], + \ [ 'CMP0023', 'Plain and keyword target_link_libraries signatures cannot be mixed.', '2.8.12' ], + \ [ 'CMP????', 'There might be more policies not mentioned here, since this list is not maintained automatically.', '?.?.?' ], + \ ] +" +" custom commands {{{2 +" +if s:Enabled == 1 + command! -bang -nargs=? -complete=file CMakeProjectDir :call mmtoolbox#cmake#Property(''=='!'?'echo':'set','project-dir',) + command! -bang -nargs=? -complete=file CMakeBuildLocation :call mmtoolbox#cmake#Property(''=='!'?'echo':'set','build-dir',) + command! -bang -nargs=* -complete=file CMake :call mmtoolbox#cmake#Run(,''=='!') + command! -nargs=? -complete=file CMakeHelpCommand :call mmtoolbox#cmake#Help('command',) + command! -nargs=? -complete=file CMakeHelpModule :call mmtoolbox#cmake#Help('module',) + command! -nargs=? -complete=file CMakeHelpPolicy :call mmtoolbox#cmake#Help('policy',) + command! -nargs=? -complete=file CMakeHelpProperty :call mmtoolbox#cmake#Help('property',) + command! -nargs=? -complete=file CMakeHelpVariable :call mmtoolbox#cmake#Help('variable',) + command! -nargs=0 CMakeHelp :call mmtoolbox#cmake#HelpPlugin() + command! -bang -nargs=0 CMakeSettings :call mmtoolbox#cmake#Settings(''=='!') +else + " + " Disabled : Print why the script is disabled. {{{3 + function! mmtoolbox#cmake#Disabled () + let txt = "CMake tool not working:\n" + if ! executable ( s:CMake_Executable ) + let txt .= "CMake not executable (".s:CMake_Executable.")\n" + let txt .= "see :help toolbox-cmake-config" + elseif ! executable ( s:CMake_MakeTool ) + let txt .= "make tool not executable (".s:CMake_MakeTool.")\n" + let txt .= "see :help toolbox-cmake-config" + else + let txt .= "unknown reason\n" + let txt .= "see :help toolbox-cmake" + endif + call s:ImportantMsg ( txt ) + return + endfunction " ---------- end of function mmtoolbox#cmake#Disabled ---------- + " }}}3 + " + command! -bang -nargs=* CMake :call mmtoolbox#cmake#Disabled() + command! -nargs=0 CMakeHelp :call mmtoolbox#cmake#HelpPlugin() + command! -bang -nargs=0 CMakeSettings :call mmtoolbox#cmake#Settings(''=='!') + " +endif +" +" }}}2 +" +"------------------------------------------------------------------------------- +" GetInfo : Initialize the script. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#GetInfo () + if s:Enabled + return [ 'CMake', g:CMake_Version ] + else + return [ 'CMake', g:CMake_Version, 'disabled' ] + endif +endfunction " ---------- end of function mmtoolbox#cmake#GetInfo ---------- +" +"------------------------------------------------------------------------------- +" AddMaps : Add maps. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#AddMaps () +endfunction " ---------- end of function mmtoolbox#cmake#AddMaps ---------- +" +"------------------------------------------------------------------------------- +" AddMenu : Add menus. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#AddMenu ( root, esc_mapl ) + " + exe 'amenu '.a:root.'.run\ CMake:CMake! :CMake! ' + exe 'amenu '.a:root.'.&run\ make:CMake :CMake ' + " + exe 'amenu '.a:root.'.-Sep01- ' + " + exe 'amenu '.a:root.'.project\ &directory:CMakeProjectDir :CMakeProjectDir ' + exe 'amenu '.a:root.'.build\ &location:CMakeBuildLocation :CMakeBuildLocation ' + " + exe 'amenu '.a:root.'.-Sep02- ' + " + exe 'amenu '.a:root.'.help\ &commands:CMakeHelpCommand :CMakeHelpCommand' + exe 'amenu '.a:root.'.help\ &modules:CMakeHelpModule :CMakeHelpModule' + exe 'amenu '.a:root.'.help\ &policies:CMakeHelpPolicy :CMakeHelpPolicy' + exe 'amenu '.a:root.'.help\ &property:CMakeHelpProperty :CMakeHelpProperty' + exe 'amenu '.a:root.'.help\ &variables:CMakeHelpVariable :CMakeHelpVariable' + " + exe 'amenu '.a:root.'.-SEP03- ' + " + exe 'amenu '.a:root.'.&help:CMakeHelp :CMakeHelp' + exe 'amenu '.a:root.'.&settings:CMakeSettings :CMakeSettings' + " +endfunction " ---------- end of function mmtoolbox#cmake#AddMenu ---------- +" +"------------------------------------------------------------------------------- +" Property : Various settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#Property ( mode, key, ... ) + " + " check the mode + if a:mode !~ 'echo\|get\|set' + return s:ErrorMsg ( 'CMake : Unknown mode: '.a:mode ) + endif + " + " check 3rd argument for 'set' + if a:mode == 'set' + if a:0 == 0 + return s:ErrorMsg ( 'CMake : Not enough arguments for mode "set".' ) + endif + let val = a:1 + endif + " + " check the key + if a:key == 'enabled' + let var = 's:Enabled' + elseif a:key == 'project-dir' + let var = 's:ProjectDir' + elseif a:key == 'build-dir' + let var = 's:BuildLocation' + else + return s:ErrorMsg ( 'CMake : Unknown option: '.a:key ) + endif + " + " perform the action + if a:mode == 'echo' + exe 'echo '.var + return + elseif a:mode == 'get' + exe 'return '.var + elseif a:key == 'project-dir' + " expand replaces the escape sequences from the cmdline + if val =~ '\S' + let s:ProjectDir = fnamemodify( expand( val ), ":p" ) + elseif s:Question ( 'set project directory to an empty string?' ) == 1 + let s:ProjectDir = '' + endif + elseif a:key == 'build-dir' + " expand replaces the escape sequences from the cmdline + if val =~ '\S' + let s:BuildLocation = fnamemodify( expand( val ), ":p" ) + elseif s:Question ( 'set build location to an empty string?' ) == 1 + let s:BuildLocation = '' + endif + else + " action is 'set', but key is non of the above + return s:ErrorMsg ( 'CMake : Option is read-only, can not set: '.a:key ) + endif + " +endfunction " ---------- end of function mmtoolbox#cmake#Property ---------- +" +"------------------------------------------------------------------------------- +" HelpPlugin : Plugin help. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#HelpPlugin () + try + help toolbox-cmake + catch + exe 'helptags '.s:plugin_dir.'/doc' + help toolbox-cmake + endtry +endfunction " ---------- end of function mmtoolbox#cmake#HelpPlugin ---------- +" +"------------------------------------------------------------------------------- +" Settings : Plugin settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#Settings ( verbose ) + " + if s:MSWIN | let sys_name = 'Windows' + elseif s:UNIX | let sys_name = 'UNIX' + else | let sys_name = 'unknown' | endif + " + let cmake_status = executable( s:CMake_Executable ) ? '' : '' + let make_status = executable( s:CMake_MakeTool ) ? '' : '' + " + let txt = " CMake-Support settings\n\n" + \ .' plug-in installation : toolbox on '.sys_name."\n" + \ .' cmake executable : '.s:CMake_Executable."\n" + \ .' > enabled : '.cmake_status."\n" + \ .' make tool : '.s:CMake_MakeTool."\n" + \ .' > enabled : '.make_status."\n" + \ .' using toolbox : version '.g:Toolbox_Version." by Wolfgang Mehner\n" + if a:verbose + let txt .= "\n" + \ .' jump to error : '.g:CMake_JumpToError."\n" + \ ."\n" + \ .' project directory : '.s:ProjectDir."\n" + \ .' build location : '.s:BuildLocation."\n" + endif + let txt .= + \ "________________________________________________________________________________\n" + \ ." CMake-Tool, Version ".g:CMake_Version." / Wolfgang Mehner / wolfgang-mehner@web.de\n\n" + " + echo txt +endfunction " ---------- end of function mmtoolbox#cmake#Settings ---------- +" +"------------------------------------------------------------------------------- +" Modul setup (abort early?). {{{1 +"------------------------------------------------------------------------------- +if s:Enabled == 0 + finish +endif +" +"------------------------------------------------------------------------------- +" Run : Run CMake or make. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#Run ( args, cmake_only ) + " + let g:CMakeDebugStr = 'cmake#run: ' " debug + " + silent exe 'update' | " write source file if necessary + cclose + " + exe 'lchdir '.fnameescape( s:BuildLocation ) + " + if a:cmake_only == 1 + " + let g:CMakeDebugStr .= 'CMake only, ' " debug + " + " save the current settings + let errorf_saved = &g:errorformat + " + " run CMake and process the errors + exe 'setglobal errorformat='.s:ErrorFormat_CMake + " + if a:args == '' | let args = shellescape ( s:ProjectDir ) + else | let args = a:args + endif + " + let errors = 'DIR : '.s:ProjectDir."\n" + \ .system ( shellescape( s:CMake_Executable ).' '.args ) + \ .'ENDDIR : '.s:ProjectDir + " + if g:CMake_JumpToError == 'cmake' || g:CMake_JumpToError == 'both' + silent exe 'cexpr errors' + else + silent exe 'cgetexpr errors' + endif + " + " restore the old settings + exe 'setglobal errorformat='.escape( errorf_saved, s:SettingsEscChar ) + " + let g:CMakeDebugStr .= 'success: '.( v:shell_error == 0 ).', ' " debug + " + " errors occurred? + if v:shell_error == 0 | echo 'CMake : CMake finished successfully.' + else | botright cwindow + endif + " + else + " + let g:CMakeDebugStr .= 'CMake & make, ' " debug + " + " CMake, run by make, in case of failure: "-- Configuring incomplete, errors occurred!" + " + " run make + let errors = system ( shellescape( s:CMake_MakeTool ).' '.a:args ) + " + " error was produced by CMake? + if v:shell_error != 0 + \ && errors =~ '--\s\+Configuring incomplete, errors occurred!' + " error was produced by CMake + " + let g:CMakeDebugStr .= 'handling CMake error, ' " debug + " + " save the current settings + let errorf_saved = &g:errorformat + " + " process the errors + exe 'setglobal errorformat='.s:ErrorFormat_CMake + " + let errors = 'DIR : '.s:ProjectDir."\n" + \ .errors + \ .'ENDDIR : '.s:ProjectDir + " + if g:CMake_JumpToError == 'cmake' || g:CMake_JumpToError == 'both' + silent exe 'cexpr errors' + else + silent exe 'cgetexpr errors' + endif + " + " restore the old settings + exe 'setglobal errorformat='.escape( errorf_saved, s:SettingsEscChar ) + " + else + " no error or error was produced by make, gcc, ... + " + let g:CMakeDebugStr .= 'handling make error, ' " debug + " + " save the current settings + let errorf_saved = &g:errorformat + " + " process the errors + exe 'setglobal errorformat=' + \ .s:ErrorFormat_MakeAdditions + \ .escape( errorf_saved, s:SettingsEscChar ) + " + if g:CMake_JumpToError == 'make' || g:CMake_JumpToError == 'both' + silent exe 'cexpr errors' + else + silent exe 'cgetexpr errors' + endif + " + " restore the old settings + exe 'setglobal errorformat='.escape( errorf_saved, s:SettingsEscChar ) + " + endif + " + let g:CMakeDebugStr .= 'success: '.( v:shell_error == 0 ).', ' " debug + " + " errors occurred? + if v:shell_error == 0 | echo 'CMake : make finished successfully.' + else | botright cwindow + endif + " + endif + " + lchdir - + " + let g:CMakeDebugStr .= 'done' " debug + " +endfunction " ---------- end of function mmtoolbox#cmake#Run ---------- +" +"------------------------------------------------------------------------------- +" s:TextFromSystem : Get text from a system command. {{{1 +"------------------------------------------------------------------------------- +function! s:TextFromSystem ( cmd ) + " + let text = system ( a:cmd ) + " + if v:shell_error != 0 + return [ 0, '' ] + endif + " + return [ 1, text ] +endfunction " ---------- end of function s:TextFromSystem ---------- +" +"------------------------------------------------------------------------------- +" s:PolicyListText : Get text for policy list. {{{1 +"------------------------------------------------------------------------------- +function! s:PolicyListText () + " + let text = "policy list taken from cmake version ".s:Policies_Version + " + for [ nr, dsc, vrs ] in s:Policies_List + let text .= "\n\n".nr."\n\t".dsc." (".vrs.")" + endfor + " + return [ 1, text ] +endfunction " ---------- end of function s:PolicyListText ---------- +" +"------------------------------------------------------------------------------- +" s:OpenManBuffer : Print help for commands. {{{1 +"------------------------------------------------------------------------------- +function! s:OpenManBuffer ( text_cmd, buf_name, jump_reaction ) + " + " a buffer like this already existing? + if bufnr ( a:buf_name ) != -1 + " yes -> go to the window containing the buffer + exe bufwinnr( a:buf_name ).'wincmd w' + return + endif + " + " no -> open a buffer and insert the text + exe 'let [ success, text ] = '.a:text_cmd + " + if success == 0 + return 0 + endif + " + aboveleft new + silent exe 'put! = text' + :1 + " + " settings of the new buffer + silent exe 'file '.escape( a:buf_name, ' ' ) + setlocal ro + setlocal nomodified + setlocal nomodifiable + setlocal bufhidden=wipe +" setlocal filetype=man + " + silent exe 'nmap '.a:jump_reaction + silent exe 'nmap '.a:jump_reaction + silent exe 'nmap <2-Leftmouse> '.a:jump_reaction + silent exe 'nmap q :close' + " + return 1 +endfunction " ---------- end of function s:OpenManBuffer ---------- +" +"------------------------------------------------------------------------------- +" Help : Print help for commands, modules and variables. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#Help ( type, topic ) + " + " help for which type of object? + if a:type == 'command' + let switch = '--help-command' + elseif a:type == 'module' + let switch = '--help-module' + elseif a:type == 'policy' + let switch = '--help-policy' + elseif a:type == 'property' + let switch = '--help-property' + elseif a:type == 'variable' + let switch = '--help-variable' + else + call s:ErrorMsg ( 'CMake : Unknown type for help: '.type ) + return + endif + " + let esc_exe = shellescape( s:CMake_Executable ) + let esc_exe = substitute( esc_exe, "'", "''", "g" ) + " + " overview or concrete topic? + if a:topic == '' && a:type == 'policy' + " + " get the policy list (requires special treatment) + let cmd = 's:PolicyListText ()' + " + let topic = a:type + let category = 'list' + " + let jump = ':call mmtoolbox#cmake#HelpJump("'.a:type.'")' + elseif a:topic == '' + " + " get the list of topics + let cmd = "s:TextFromSystem ( '".esc_exe." ".switch."-list ".a:topic."' )" + " + let topic = a:type + let category = 'list' + " + let jump = ':call mmtoolbox#cmake#HelpJump("'.a:type.'")' + else + " + " get help for a topic + let cmd = "s:TextFromSystem ( '".esc_exe." ".switch." ".escape( a:topic, '<>[] ' )."' )" + " + if s:MSWIN + " :TODO:18.02.2014 15:09:WM: which characters can we use under Windows? + let topic = substitute( a:topic, '[<>[\]]', '-', 'g' ) + else + let topic = a:topic + endif + let category = a:type + " + let jump = ':call mmtoolbox#cmake#Help("'.a:type.'","")' + endif + " + " get the help + " :TODO:18.02.2014 15:09:WM: can we use brackets under Windows? + let buf = 'CMake help - '.topic.' ('.category.')' + " + if ! s:OpenManBuffer ( cmd, buf, jump ) + echo 'CMake : No help for "'.topic.'".' + endif + " +endfunction " ---------- end of function mmtoolbox#cmake#Help ---------- +" +"------------------------------------------------------------------------------- +" HelpJump : Jump to help for commands, modules and variables. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#cmake#HelpJump ( type ) + " + " get help for the word in the line + " + " the name under the cursor can consist of these characters: + " _ < > [ ] + " but never end with a space + " + let line = getline('.') + let line = matchstr( line, '^[[:alnum:]_<>[\] ]*[[:alnum:]_<>[\]]\ze\s*$' ) + " + " for type "policy": maybe the line above matches (can use simpler regex) + if empty( line ) && a:type == 'policy' && line('.')-1 > 0 + let line = getline( line('.')-1 ) + let line = matchstr( line, '^\w\+\ze\s*$' ) + endif + " + if empty( line ) + echo 'CMake : No '.a:type.' under the cursor.' + return + endif + " + call mmtoolbox#cmake#Help ( a:type, line ) + " +endfunction " ---------- end of function mmtoolbox#cmake#HelpJump ---------- +" }}}1 +"------------------------------------------------------------------------------- +" +" ===================================================================================== +" vim: foldmethod=marker diff --git a/autoload/mmtoolbox/doxygen.vim b/autoload/mmtoolbox/doxygen.vim new file mode 100644 index 0000000..f2e41fc --- /dev/null +++ b/autoload/mmtoolbox/doxygen.vim @@ -0,0 +1,582 @@ +"=============================================================================== +" +" File: doxygen.vim +" +" Description: Part of the C-Support toolbox. +" +" Vim/gVim integration of Doxygen. +" +" See help file toolboxdoxygen.txt . +" +" VIM Version: 7.0+ +" Author: Wolfgang Mehner, wolfgang-mehner@web.de +" Organization: +" Version: see variable g:Doxygen_Version below +" Created: 10.06.2012 +" Revision: --- +" License: Copyright (c) 2012, Wolfgang 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. +"=============================================================================== +" +"------------------------------------------------------------------------------- +" Basic checks. {{{1 +"------------------------------------------------------------------------------- +" +" need at least 7.0 +if v:version < 700 + echohl WarningMsg + echo 'The plugin mmtoolbox/doxygen.vim needs Vim version >= 7.' + echohl None + finish +endif +" +" prevent duplicate loading +" need compatible +if &cp || ( exists('g:Doxygen_Version') && ! exists('g:Doxygen_DevelopmentOverwrite') ) + finish +endif +let g:Doxygen_Version= '0.9.1' " version number of this script; do not change +" +"------------------------------------------------------------------------------- +" Auxiliary functions. {{{1 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" s:ErrorMsg : Print an error message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ErrorMsg ( ... ) + echohl WarningMsg + for line in a:000 + echomsg line + endfor + echohl None +endfunction " ---------- end of function s:ErrorMsg ---------- +" +"------------------------------------------------------------------------------- +" s:GetGlobalSetting : Get a setting from a global variable. {{{2 +" +" Parameters: +" varname - name of the variable (string) +" Returns: +" - +" +" If g: exists, assign: +" s: = g: +"------------------------------------------------------------------------------- +function! s:GetGlobalSetting ( varname ) + if exists ( 'g:'.a:varname ) + exe 'let s:'.a:varname.' = g:'.a:varname + endif +endfunction " ---------- end of function s:GetGlobalSetting ---------- +" +"------------------------------------------------------------------------------- +" s:ImportantMsg : Print an important message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ImportantMsg ( ... ) + echohl Search + echo join ( a:000, "\n" ) + echohl None +endfunction " ---------- end of function s:ImportantMsg ---------- +" +"------------------------------------------------------------------------------- +" s:Question : Ask the user a yes/no question. {{{2 +" +" Parameters: +" prompt - prompt, shown to the user (string) +" highlight - "normal" or "warning" (string, default "normal") +" Returns: +" retval - the user input (integer) +" +" The possible values of 'retval' are: +" 1 - answer was yes ("y") +" 0 - answer was no ("n") +" -1 - user aborted ("ESC" or "CTRL-C") +"------------------------------------------------------------------------------- +function! s:Question ( prompt, ... ) + " + let ret = -2 + " + " highlight prompt + if a:0 == 0 || a:1 == 'normal' + echohl Search + elseif a:1 == 'warning' + echohl Error + else + echoerr 'Unknown option : "'.a:1.'"' + return + end + " + " question + echo a:prompt.' [y/n]: ' + " + " answer: "y", "n", "ESC" or "CTRL-C" + while ret == -2 + let c = nr2char( getchar() ) + " + if c == "y" + let ret = 1 + elseif c == "n" + let ret = 0 + elseif c == "\" || c == "\" + let ret = -1 + endif + endwhile + " + " reset highlighting + echohl None + " + return ret +endfunction " ---------- end of function s:Question ---------- +" +"------------------------------------------------------------------------------- +" s:UserInput : Input using a highlighting prompt. {{{2 +" +" Parameters: +" prompt - prompt, shown to the user (string) +" text - default reply (string) +" compl - type of completion, see :help command-completion (string, optional) +" Returns: +" retval - the user input (string) +" +" Returns an empty string if the input procedure was aborted by the user. +"------------------------------------------------------------------------------- +function! s:UserInput ( prompt, text, ... ) + echohl Search " highlight prompt + call inputsave() " preserve typeahead + if a:0 == 0 || a:1 == '' + let retval = input( a:prompt, a:text ) " read input + else + let retval = input( a:prompt, a:text, a:1 ) " read input (with completion) + end + 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 s:UserInput ---------- +" }}}2 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" Modul setup. {{{1 +"------------------------------------------------------------------------------- +" +" platform specifics {{{2 +" +let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") +let s:UNIX = has("unix") || has("macunix") || has("win32unix") +" +let s:SettingsEscChar = ' |"\' +" +if s:MSWIN + " + "------------------------------------------------------------------------------- + " MS Windows + "------------------------------------------------------------------------------- + " + let s:plugin_dir = substitute( expand(':p:h:h:h'), '\\', '/', 'g' ) + " +else + " + "------------------------------------------------------------------------------- + " Linux/Unix + "------------------------------------------------------------------------------- + " + let s:plugin_dir = expand(':p:h:h:h') + " +endif +" +" settings {{{2 +" +let s:ConfigFile = 'Doxyfile' " doxygen configuration file +let s:LogFile = '.doxygen.log' +let s:WarningFile = '.doxygen.warn' +" +if s:MSWIN + let s:Doxygen_Executable = 'C:\Program Files\Doxygen\bin\doxygen.exe' +else + let s:Doxygen_Executable = 'doxygen' +endif +" +call s:GetGlobalSetting ( 'Doxygen_Executable' ) +" +let s:ErrorFormat = escape( '%f:%l: %m', s:SettingsEscChar ) +" +let s:Enabled = 1 +" +" check Doxygen executable {{{2 +" +if ! executable ( s:Doxygen_Executable ) + let s:Enabled = 0 +endif +" +" custom commands {{{2 +" +if s:Enabled == 1 + command! -bang -nargs=? -complete=file DoxygenConfigFile :call mmtoolbox#doxygen#Property(''=='!'?'echo':'set','config-file',) + command! -bang -nargs=? -complete=file DoxygenLogFile :call mmtoolbox#doxygen#Property(''=='!'?'echo':'set','log-file',) + command! -bang -nargs=? -complete=file DoxygenWarningFile :call mmtoolbox#doxygen#Property(''=='!'?'echo':'set','warning-file',) + command! -nargs=* -complete=file Doxygen :call mmtoolbox#doxygen#Run() + command! -nargs=0 -complete=file DoxygenGenerateConfig :call mmtoolbox#doxygen#GenerateConfig() + command! -nargs=0 -complete=file DoxygenEditConfig :call mmtoolbox#doxygen#EditConfig() + command! -nargs=0 -complete=file DoxygenViewLog :call mmtoolbox#doxygen#ViewLog() + command! -nargs=0 DoxygenWarnings :call mmtoolbox#doxygen#Warnings() + command! -nargs=0 DoxygenHelp :call mmtoolbox#doxygen#Help() + command! -bang -nargs=0 DoxygenSettings :call mmtoolbox#doxygen#Settings(''=='!') +else + " + " Disabled : Print why the script is disabled. {{{3 + function! mmtoolbox#doxygen#Disabled () + let txt = "Doxygen tool not working:\n" + if ! executable ( s:Doxygen_Executable ) + let txt .= "Doxygen not executable (".s:Doxygen_Executable.")\n" + let txt .= "see :help toolbox-doxygen-config" + else + let txt .= "unknown reason\n" + let txt .= "see :help toolbox-doxygen" + endif + call s:ImportantMsg ( txt ) + return + endfunction " ---------- end of function mmtoolbox#doxygen#Disabled ---------- + " }}}3 + " + command! -bang -nargs=* Doxygen :call mmtoolbox#doxygen#Disabled() + command! -nargs=0 DoxygenHelp :call mmtoolbox#doxygen#Help() + command! -bang -nargs=0 DoxygenSettings :call mmtoolbox#doxygen#Settings(''=='!') + " +endif +" +" }}}2 +" +"------------------------------------------------------------------------------- +" GetInfo : Initialize the script. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#GetInfo () + if s:Enabled + return [ 'Doxygen', g:Doxygen_Version ] + else + return [ 'Doxygen', g:Doxygen_Version, 'disabled' ] + endif +endfunction " ---------- end of function mmtoolbox#doxygen#GetInfo ---------- +" +"------------------------------------------------------------------------------- +" AddMaps : Add maps. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#AddMaps () +endfunction " ---------- end of function mmtoolbox#doxygen#AddMaps ---------- +" +"------------------------------------------------------------------------------- +" AddMenu : Add menus. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#AddMenu ( root, esc_mapl ) + " + exe 'amenu '.a:root.'.&run\ Doxygen:Doxygen :Doxygen' + exe 'amenu '.a:root.'.view\ &log:DoxygenViewLog :DoxygenViewLog' + exe 'amenu '.a:root.'.view\ &warnings:DoxygenWarnings :DoxygenWarnings' + " + exe 'amenu '.a:root.'.-SEP01- ' + " + exe 'amenu '.a:root.'.&generate\ config\.:DoxygenGenerateConfig :DoxygenGenerateConfig' + exe 'amenu '.a:root.'.edit\ &config\.:DoxygenEditConfig :DoxygenEditConfig' + " + exe 'amenu '.a:root.'.-SEP02- ' + " + exe 'amenu '.a:root.'.select\ config\.\ &file:DoxygenConfigFile :DoxygenConfigFile ' + exe 'amenu '.a:root.'.select\ log\ &file:DoxygenLogFile :DoxygenLogFile ' + exe 'amenu '.a:root.'.select\ warning\ &file:DoxygenWarningFile :DoxygenWarningFile ' + " + exe 'amenu '.a:root.'.-SEP03- ' + " + exe 'amenu '.a:root.'.&help:DoxygenHelp :DoxygenHelp' + exe 'amenu '.a:root.'.&settings:DoxygenSettings :DoxygenSettings' + " +endfunction " ---------- end of function mmtoolbox#doxygen#AddMenu ---------- +" +"------------------------------------------------------------------------------- +" Property : Various settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#Property ( mode, key, ... ) + " + " check the mode + if a:mode !~ 'echo\|get\|set' + return s:ErrorMsg ( 'Doxygen : Unknown mode: '.a:mode ) + endif + " + " check 3rd argument for 'set' + if a:mode == 'set' + if a:0 == 0 + return s:ErrorMsg ( 'Doxygen : Not enough arguments for mode "set".' ) + endif + let val = a:1 + endif + " + " check the key + if a:key == 'enabled' + let var = 's:Enabled' + elseif a:key == 'config-file' + let var = 's:ConfigFile' + elseif a:key == 'log-file' + let var = 's:LogFile' + elseif a:key == 'warning-file' + let var = 's:WarningFile' + else + return s:ErrorMsg ( 'Doxygen : Unknown option: '.a:key ) + endif + " + " perform the action + if a:mode == 'echo' + exe 'echo '.var + return + elseif a:mode == 'get' + exe 'return '.var + elseif a:key == 'config-file' + " expand replaces the escape sequences from the cmdline + if val =~ '\S' + let s:ConfigFile = fnamemodify( expand( val ), ":p" ) + elseif s:Question ( 'set config file to an empty string?' ) == 1 + let s:ConfigFile = '' + endif + elseif a:key == 'log-file' + " expand replaces the escape sequences from the cmdline + if val =~ '\S' + let s:LogFile = fnamemodify( expand( val ), ":p" ) + elseif s:Question ( 'set local file to an empty string?' ) == 1 + let s:LogFile = '' + endif + elseif a:key == 'warning-file' + " expand replaces the escape sequences from the cmdline + if val =~ '\S' + let s:WarningFile = fnamemodify( expand( val ), ":p" ) + elseif s:Question ( 'set warning file to an empty string?' ) == 1 + let s:WarningFile = '' + endif + else + " action is 'set', but key is non of the above + return s:ErrorMsg ( 'Doxygen : Option is read-only, can not set: '.a:key ) + endif + " +endfunction " ---------- end of function mmtoolbox#doxygen#Property ---------- +" +"------------------------------------------------------------------------------- +" Help : Plugin help. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#Help () + try + help toolbox-doxygen + catch + exe 'helptags '.s:plugin_dir.'/doc' + help toolbox-doxygen + endtry +endfunction " ---------- end of function mmtoolbox#doxygen#Help ---------- +" +"------------------------------------------------------------------------------- +" Settings : Plugin settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#Settings ( verbose ) + " + if s:MSWIN | let sys_name = 'Windows' + elseif s:UNIX | let sys_name = 'UNIX' + else | let sys_name = 'unknown' | endif + " + let doxygen_status = executable( s:Doxygen_Executable ) ? '' : '' + " + let txt = " Doxygen-Support settings\n\n" + \ .' plug-in installation : toolbox on '.sys_name."\n" + \ .' doxygen executable : '.s:Doxygen_Executable."\n" + \ .' > enabled : '.doxygen_status."\n" + \ .' using toolbox : version '.g:Toolbox_Version." by Wolfgang Mehner\n" + if a:verbose + let txt .= "\n" + \ .' configuration file : '.s:ConfigFile."\n" + \ .' log file : '.s:LogFile."\n" + \ .' warnings file : '.s:WarningFile."\n" + endif + let txt .= + \ "________________________________________________________________________________\n" + \ ." Doxygen-Tool, Version ".g:Doxygen_Version." / Wolfgang Mehner / wolfgang-mehner@web.de\n\n" + " + echo txt +endfunction " ---------- end of function mmtoolbox#doxygen#Settings ---------- +" +"------------------------------------------------------------------------------- +" Modul setup (abort early?). {{{1 +"------------------------------------------------------------------------------- +if s:Enabled == 0 + finish +endif +" +"------------------------------------------------------------------------------- +" Run : Run Doxygen. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#Run ( args ) + " + silent exe 'update' | " write source file if necessary + cclose + " + " arguments + if a:args == '' + if ! filereadable( s:ConfigFile ) + " :TODO:27.10.2013 19:09:WM: file not readable? + return s:ErrorMsg ( 'Doxygen : File not readable: '.s:ConfigFile ) + endif + " + let cmdlinearg = shellescape ( s:ConfigFile ) + else + let cmdlinearg = a:args + endif + " :TODO:27.10.2013 19:28:WM: 'cmdlinearg' is not correctly escaped for use under Windows + " + exe 'lchdir '.fnameescape( fnamemodify( s:ConfigFile, ':p:h' ) ) + " + let warn_log_file_configured = '' + " + if ! filereadable( s:ConfigFile ) + call s:ErrorMsg ( 'Doxygen : File not readable: '.s:ConfigFile ) + else + let warn_log_file_configured = matchstr( readfile( s:ConfigFile ), '\s*WARN_LOGFILE\s*=\s*\S' ) + let warn_log_file_configured = matchstr( warn_log_file_configured, '\s*WARN_LOGFILE\s*=\s*\(["'']\?\)\zs.*\S\ze\1\s*$' ) + endif + " + if warn_log_file_configured != '' + " use WARN_LOGFILE from now on? + let warn_log_file_configured = fnamemodify( expand( warn_log_file_configured ), ":p" ) + if s:WarningFile != warn_log_file_configured + if s:Question ( 'use the configured warning file from now on? ('.warn_log_file_configured.')' ) == 1 + call mmtoolbox#doxygen#Property ( 'set', 'warning-file', warn_log_file_configured ) + endif + endif + " the option WARN_LOGFILE is set, do not write s:WarningFile here + silent exe ':!'.shellescape( s:Doxygen_Executable ).' '.cmdlinearg.' > '.shellescape( s:LogFile ) + else + " write both the log and the warning file + silent exe ':!'.shellescape( s:Doxygen_Executable ).' '.cmdlinearg.' 1> '.shellescape( s:LogFile ).' 2> '.shellescape( s:WarningFile ) + endif + " + lchdir - + " + " process the warnings + call mmtoolbox#doxygen#Warnings () + " +endfunction " ---------- end of function mmtoolbox#doxygen#Run ---------- +" +"------------------------------------------------------------------------------- +" GenerateConfig : Generate a Doxygen configuration file. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#GenerateConfig () + " pick a location + if 0 " has('browse') + let doxyfile = browse ( 1, 'generate a doxygen configuration file', '.', 'Doxyfile' ) + else + let doxyfile = s:UserInput ( 'generate a doxygen configuration file ', 'Doxyfile', 'file' ) + endif + " + " check the result + if doxyfile == '' + return + endif + " + " file already exists + if filereadable ( doxyfile ) + if s:UserInput ( 'Config file "'.doxyfile.'" already exists. Overwrite [y/n] : ', 'n' ) != 'y' + return + endif + endif + " + " generate the file and save it name + exe ":!".shellescape( s:Doxygen_Executable ).' -g '.shellescape( doxyfile ) + if ! v:shell_error + call mmtoolbox#doxygen#Property ( 'set', 'config-file', doxyfile ) + endif +endfunction " ---------- end of function mmtoolbox#doxygen#GenerateConfig ---------- +" +"------------------------------------------------------------------------------- +" EditConfig : Edit the Doxygen configuration file. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#EditConfig () + if ! filereadable ( s:ConfigFile ) + " :TODO:27.10.2013 18:49:WM: call mmtoolbox#doxygen#GenerateConfig + return s:ErrorMsg ( 'Doxygen : File not readable: '.s:ConfigFile ) + endif + " + exe 'split '.fnameescape( s:ConfigFile ) +endfunction " ---------- end of function mmtoolbox#doxygen#EditConfig ---------- +" +"------------------------------------------------------------------------------- +" ViewLog : Edit the Doxygen configuration file. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#ViewLog () + " + " go to the directory of 's:ConfigFile', so that the standard for 's:LogFile' works + exe 'lchdir '.fnameescape( fnamemodify( s:ConfigFile, ':p:h' ) ) + " + if ! filereadable ( s:LogFile ) + return s:ErrorMsg ( 'Doxygen : File not readable: '.s:LogFile ) + endif + " + let logfile = fnamemodify( s:LogFile, ":p" ) + " + lchdir - + " + exe 'sview '.fnameescape( logfile ) +endfunction " ---------- end of function mmtoolbox#doxygen#ViewLog ---------- +" +"------------------------------------------------------------------------------- +" Warnings : Send the warning file through QuickFix. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#doxygen#Warnings () + " + silent exe 'update' | " write source file if necessary + cclose + " + " go to the directory of 's:ConfigFile', so that the standard for " 's:WarningFile' works + exe 'lchdir '.fnameescape( fnamemodify( s:ConfigFile, ':p:h' ) ) + " + " any errors? + if getfsize( s:WarningFile ) > 0 + " + " save the current settings + let errorf_saved = &l:errorformat + " + " read the file and process the errors + exe 'setlocal errorformat='.s:ErrorFormat + " + exe 'cgetfile '.fnameescape( s:WarningFile ) + " + " restore the old settings + exe 'setlocal errorformat='.escape( errorf_saved, s:SettingsEscChar ) + " + botright cwindow + else + echo "Doxygen : no warnings/errors" + endif + " + lchdir - + " +endfunction " ---------- end of function mmtoolbox#doxygen#Warnings ---------- +" }}}1 +"------------------------------------------------------------------------------- +" +" ===================================================================================== +" vim: foldmethod=marker diff --git a/autoload/mmtoolbox/helloworld.vim b/autoload/mmtoolbox/helloworld.vim new file mode 100644 index 0000000..fe89512 --- /dev/null +++ b/autoload/mmtoolbox/helloworld.vim @@ -0,0 +1,332 @@ +"=============================================================================== +" +" File: helloworld.vim +" +" Description: Part of the C-Support toolbox. +" +" Small example for a tool, which may serve as a template for +" your own tool. +" +" See help file TODO.txt . +" +" VIM Version: 7.0+ +" Author: TODO +" Organization: +" Version: see variable g:HelloWorld_Version below +" Created: TO.DO.TODO +" Revision: --- +" License: Copyright (c) TODO, TODO +" 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. +"=============================================================================== +" +"------------------------------------------------------------------------------- +" Basic checks. {{{1 +"------------------------------------------------------------------------------- +" +" need at least 7.0 +if v:version < 700 + echohl WarningMsg + echo 'The plugin mmtoolbox/helloworld.vim needs Vim version >= 7.' + echohl None + finish +endif +" +" prevent duplicate loading +" need compatible +if &cp || exists('g:HelloWorld_Version') + finish +endif +let g:HelloWorld_Version= '1.0' " version number of this script; do not change +" +"------------------------------------------------------------------------------- +" Auxiliary functions {{{1 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" s:ErrorMsg : Print an error message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ErrorMsg ( ... ) + echohl WarningMsg + for line in a:000 + echomsg line + endfor + echohl None +endfunction " ---------- end of function s:ErrorMsg ---------- +" +"------------------------------------------------------------------------------- +" s:GetGlobalSetting : Get a setting from a global variable. {{{2 +" +" Parameters: +" varname - name of the variable (string) +" Returns: +" - +" +" If g: exists, assign: +" s: = g: +"------------------------------------------------------------------------------- +function! s:GetGlobalSetting ( varname ) + if exists ( 'g:'.a:varname ) + exe 'let s:'.a:varname.' = g:'.a:varname + endif +endfunction " ---------- end of function s:GetGlobalSetting ---------- +" +"------------------------------------------------------------------------------- +" s:ImportantMsg : Print an important message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ImportantMsg ( ... ) + echohl Search + echo join ( a:000, "\n" ) + echohl None +endfunction " ---------- end of function s:ImportantMsg ---------- +" +"------------------------------------------------------------------------------- +" s:Question : Ask the user a question. {{{2 +" +" Parameters: +" prompt - prompt, shown to the user (string) +" highlight - "normal" or "warning" (string, default "normal") +" Returns: +" retval - the user input (integer) +" +" The possible values of 'retval' are: +" 1 - answer was yes ("y") +" 0 - answer was no ("n") +" -1 - user aborted ("ESC" or "CTRL-C") +"------------------------------------------------------------------------------- +function! s:Question ( prompt, ... ) + " + let ret = -2 + " + " highlight prompt + if a:0 == 0 || a:1 == 'normal' + echohl Search + elseif a:1 == 'warning' + echohl Error + else + echoerr 'Unknown option : "'.a:1.'"' + return + end + " + " question + echo a:prompt.' [y/n]: ' + " + " answer: "y", "n", "ESC" or "CTRL-C" + while ret == -2 + let c = nr2char( getchar() ) + " + if c == "y" + let ret = 1 + elseif c == "n" + let ret = 0 + elseif c == "\" || c == "\" + let ret = -1 + endif + endwhile + " + " reset highlighting + echohl None + " + return ret +endfunction " ---------- end of function s:Question ---------- +" }}}2 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" Modul setup. {{{1 +"------------------------------------------------------------------------------- +" +" platform specifics {{{2 +" +let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") +let s:UNIX = has("unix") || has("macunix") || has("win32unix") +" +if s:MSWIN + " + "------------------------------------------------------------------------------- + " MS Windows + "------------------------------------------------------------------------------- + " + let s:plugin_dir = substitute( expand(':p:h:h:h'), '\\', '/', 'g' ) + " +else + " + "------------------------------------------------------------------------------- + " Linux/Unix + "------------------------------------------------------------------------------- + " + let s:plugin_dir = expand(':p:h:h:h') + " +endif +" +" settings {{{2 +" +let s:WorldAvailable = 1 +" +let s:Enabled = 1 +" +if ! s:WorldAvailable + let s:Enabled = 0 +endif +" +" custom commands {{{2 +" +if s:Enabled == 1 + command! -bang -nargs=* -complete=file Hello :echo "Hello world (): ". + command! -nargs=0 HelloHelp :call mmtoolbox#helloworld#HelpPlugin() +else + " + " Disabled : Print why the script is disabled. {{{3 + function! mmtoolbox#helloworld#Disabled () + let txt = "HelloWorld tool not working:\n" + if ! s:WorldAvailable + let txt .= "world not available (say what!?)" + else + let txt .= "unknown reason" + endif + call s:ImportantMsg ( txt ) + return + endfunction " ---------- end of function mmtoolbox#helloworld#Disabled ---------- + " }}}3 + " + command! -nargs=* HelloHelp :call mmtoolbox#helloworld#Disabled() + " +endif +" +" }}}2 +" +"------------------------------------------------------------------------------- +" GetInfo : Get basic information. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#helloworld#GetInfo () + " + " returns [ , , , , ... ] + " + if s:WorldAvailable + return [ 'Hello World', g:HelloWorld_Version ] + " if you do not want to create a menu: + " return [ 'Hello World', g:HelloWorld_Version, 'nomenu' ] + else + return [ 'Hello World', g:HelloWorld_Version, 'disabled' ] + endif +endfunction " ---------- end of function mmtoolbox#helloworld#GetInfo ---------- +" +"------------------------------------------------------------------------------- +" AddMaps : Add maps. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#helloworld#AddMaps () + " + " create maps for the current buffer only + " + nmap hi :echo "Hello world!"' + " + " TODO + " +endfunction " ---------- end of function mmtoolbox#helloworld#AddMaps ---------- +" +"------------------------------------------------------------------------------- +" AddMenu : Add menus. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#helloworld#AddMenu ( root, esc_mapl ) + " + " create menus using the given 'root' + " + exe 'amenu '.a:root.'.&hello\ world'.a:esc_mapl.'hi :echo "Hello world!"' + " + " TODO + " +endfunction " ---------- end of function mmtoolbox#helloworld#AddMenu ---------- +" +"------------------------------------------------------------------------------- +" Property : Various settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#helloworld#Property ( mode, key, ... ) + " + " check the mode + if a:mode !~ 'echo\|get\|set' + return s:ErrorMsg ( 'HelloWorld : Unknown mode: '.a:mode ) + endif + " + " check 3rd argument for 'set' + if a:mode == 'set' + if a:0 == 0 + return s:ErrorMsg ( 'HelloWorld : Not enough arguments for mode "set".' ) + endif + let val = a:1 + endif + " + " check the key + if a:key == 'enabled' + let var = 's:Enabled' + else + return s:ErrorMsg ( 'HelloWorld : Unknown option: '.a:key ) + endif + " + " perform the action + if a:mode == 'echo' + exe 'echo '.var + return + elseif a:mode == 'get' + exe 'return '.var + else + " action is 'set', but key is non of the above + return s:ErrorMsg ( 'HelloWorld : Option is read-only, can not set: '.a:key ) + endif + " +endfunction " ---------- end of function mmtoolbox#helloworld#Property ---------- +" +"------------------------------------------------------------------------------- +" HelpPlugin : Plugin help. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#helloworld#HelpPlugin () + " TODO: choose a topic other than 'toolbox' + try + help toolbox + catch + exe 'helptags '.s:plugin_dir.'/doc' + help toolbox + endtry +endfunction " ---------- end of function mmtoolbox#helloworld#HelpPlugin ---------- +" +"------------------------------------------------------------------------------- +" Modul setup (abort early?). {{{1 +"------------------------------------------------------------------------------- +if s:Enabled == 0 + finish +endif +" +"------------------------------------------------------------------------------- +" Implement : Implement the tool. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#helloworld#Implement () + " + " TODO + " + return +endfunction " ---------- end of function mmtoolbox#helloworld#Implement ---------- +" }}}1 +"------------------------------------------------------------------------------- +" +" ===================================================================================== +" vim: foldmethod=marker diff --git a/autoload/mmtoolbox/make.vim b/autoload/mmtoolbox/make.vim new file mode 100644 index 0000000..9b42913 --- /dev/null +++ b/autoload/mmtoolbox/make.vim @@ -0,0 +1,338 @@ +"=============================================================================== +" +" File: make.vim +" +" Description: Part of the C-Support toolbox. +" +" Vim/gVim integration of Make. +" +" See help file toolboxmake.txt . +" +" VIM Version: 7.0+ +" Author: Wolfgang Mehner, wolfgang-mehner@web.de +" Organization: +" Version: see variable g:Make_Version below +" Created: 06.05.2013 +" Revision: 10.11.2013 +" License: Copyright (c) 2013, 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. +"=============================================================================== +" +"------------------------------------------------------------------------------- +" Basic checks. {{{1 +"------------------------------------------------------------------------------- +" +" need at least 7.0 +if v:version < 700 + echohl WarningMsg + echo 'The plugin mmtoolbox/make.vim needs Vim version >= 7.' + echohl None + finish +endif +" +" prevent duplicate loading +" need compatible +if &cp || ( exists('g:Make_Version') && ! exists('g:Make_DevelopmentOverwrite') ) + finish +endif +let g:Make_Version= '1.0.1' " version number of this script; do not change +" +"------------------------------------------------------------------------------- +" Auxiliary functions {{{1 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" s:ErrorMsg : Print an error message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +function! s:ErrorMsg ( ... ) + echohl WarningMsg + for line in a:000 + echomsg line + endfor + echohl None +endfunction " ---------- end of function s:ErrorMsg ---------- +" +"------------------------------------------------------------------------------- +" s:GetGlobalSetting : Get a setting from a global variable. {{{2 +" +" Parameters: +" varname - name of the variable (string) +" Returns: +" - +" +" If g: exists, assign: +" s: = g: +"------------------------------------------------------------------------------- +function! s:GetGlobalSetting ( varname ) + if exists ( 'g:'.a:varname ) + exe 'let s:'.a:varname.' = g:'.a:varname + endif +endfunction " ---------- end of function s:GetGlobalSetting ---------- +" }}}2 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" Modul setup. {{{1 +"------------------------------------------------------------------------------- +" +" platform specifics {{{2 +" +let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") +let s:UNIX = has("unix") || has("macunix") || has("win32unix") +" +let s:SettingsEscChar = ' |"\' +" +if s:MSWIN + " + "------------------------------------------------------------------------------- + " MS Windows + "------------------------------------------------------------------------------- + " + let s:plugin_dir = substitute( expand(':p:h:h:h'), '\\', '/', 'g' ) + " +else + " + "------------------------------------------------------------------------------- + " Linux/Unix + "------------------------------------------------------------------------------- + " + let s:plugin_dir = expand(':p:h:h:h') + " +endif +" +" settings {{{2 +" +let s:Makefile = '' +let s:CmdLineArgs = '' +" +let s:Make_Executable = 'make' +" +call s:GetGlobalSetting ( 'Make_Executable' ) +" +let s:Enabled = 1 +" +" check make executable {{{2 +" +if ! executable ( s:Make_Executable ) + let s:Enabled = 0 +endif +" +" custom commands {{{2 +" +if s:Enabled == 1 + command! -bang -nargs=* -complete=file MakeCmdlineArgs :call mmtoolbox#make#Property(''=='!'?'echo':'set','cmdline-args',) + command! -bang -nargs=? -complete=file MakeFile :call mmtoolbox#make#Property(''=='!'?'echo':'set','makefile',) + command! -nargs=* -complete=file Make :call mmtoolbox#make#Run() + command! -nargs=0 MakeHelp :call mmtoolbox#make#Help() + command! -bang -nargs=0 MakeSettings :call mmtoolbox#make#Settings(''=='!') +else + " + " Disabled : Print why the script is disabled. {{{3 + function! mmtoolbox#make#Disabled () + let txt = "Make tool not working:\n" + if ! executable ( s:Make_Executable ) + let txt .= "make not executable (".s:Make_Executable.")\n" + let txt .= "see :help toolbox-make-config" + else + let txt .= "unknown reason\n" + let txt .= "see :help toolbox-make" + endif + echohl Search + echo txt + echohl None + return + endfunction " ---------- end of function mmtoolbox#make#Disabled ---------- + " }}}3 + " + command! -bang -nargs=* Make :call mmtoolbox#make#Disabled() + command! -nargs=0 MakeHelp :call mmtoolbox#make#Help() + command! -bang -nargs=0 MakeSettings :call mmtoolbox#make#Settings(''=='!') + " +endif +" +" }}}2 +" +"------------------------------------------------------------------------------- +" GetInfo : Initialize the script. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#GetInfo () + if s:Enabled + return [ 'Make', g:Make_Version ] + else + return [ 'Make', g:Make_Version, 'disabled' ] + endif +endfunction " ---------- end of function mmtoolbox#make#GetInfo ---------- +" +"------------------------------------------------------------------------------- +" AddMaps : Add maps. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#AddMaps () +endfunction " ---------- end of function mmtoolbox#make#AddMaps ---------- +" +"------------------------------------------------------------------------------- +" AddMenu : Add menus. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#AddMenu ( root, esc_mapl ) + " + exe 'amenu '.a:root.'.run\ &make:Make :Make' + exe 'amenu '.a:root.'.make\ &clean:Make\ clean :Make clean' + exe 'amenu '.a:root.'.make\ &doc:Make\ doc :Make doc' + " + exe 'amenu '.a:root.'.-Sep01- ' + " + exe 'amenu '.a:root.'.&choose\ make&file:MakeFile :MakeFile' + exe 'amenu '.a:root.'.cmd\.\ line\ ar&g\.\ for\ make:MakeCmdlineArgs :MakeCmdlineArgs' + " + exe 'amenu '.a:root.'.-Sep02- ' + " + exe 'amenu '.a:root.'.&help:MakeHelp :MakeHelp' + exe 'amenu '.a:root.'.&settings:MakeSettings :MakeSettings' + " +endfunction " ---------- end of function mmtoolbox#make#AddMenu ---------- +" +"------------------------------------------------------------------------------- +" Property : Various settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#Property ( mode, key, ... ) + " + " check the mode + if a:mode !~ 'echo\|get\|set' + return s:ErrorMsg ( 'Make : Unknown mode: '.a:mode ) + endif + " + " check 3rd argument for 'set' + if a:mode == 'set' + if a:0 == 0 + return s:ErrorMsg ( 'Make : Not enough arguments for mode "set".' ) + endif + let val = a:1 + endif + " + " check the key + if a:key == 'enabled' + let var = 's:Enabled' + elseif a:key == 'cmdline-args' + let var = 's:CmdLineArgs' + elseif a:key == 'makefile' + let var = 's:Makefile' + else + return s:ErrorMsg ( 'Make : Unknown option: '.a:key ) + endif + " + " perform the action + if a:mode == 'echo' + exe 'echo '.var + return + elseif a:mode == 'get' + exe 'return '.var + elseif a:key == 'cmdline-args' + let s:CmdLineArgs = val + elseif a:key == 'makefile' + " expand replaces the escape sequences from the cmdline + if val == '' | let s:Makefile = '' + else | let s:Makefile = fnamemodify( expand( val ), ":p" ) + endif + else + " action is 'set', but key is non of the above + return s:ErrorMsg ( 'Make : Option is read-only, can not set: '.a:key ) + endif + " +endfunction " ---------- end of function mmtoolbox#make#Property ---------- +" +"------------------------------------------------------------------------------- +" Help : Plugin help. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#Help () + try + help toolbox-make + catch + exe 'helptags '.s:plugin_dir.'/doc' + help toolbox-make + endtry +endfunction " ---------- end of function mmtoolbox#make#Help ---------- +" +"------------------------------------------------------------------------------- +" Settings : Plugin settings. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#Settings ( verbose ) + " + if s:MSWIN | let sys_name = 'Windows' + elseif s:UNIX | let sys_name = 'UNIX' + else | let sys_name = 'unknown' | endif + " + let make_status = executable( s:Make_Executable ) ? '' : '' + let make_file = s:Makefile != '' ? s:Makefile : '(default) local Makefile' + " + let txt = " Make-Support settings\n\n" + \ .' plug-in installation : toolbox on '.sys_name."\n" + \ .' make executable : '.s:Make_Executable."\n" + \ .' > enabled : '.make_status."\n" + \ .' using toolbox : version '.g:Toolbox_Version." by Wolfgang Mehner\n" + if a:verbose + let txt .= "\n" + \ .' make file : '.make_file."\n" + \ .' memorized args : "'.s:CmdLineArgs."\"\n" + endif + let txt .= + \ "________________________________________________________________________________\n" + \ ." Make-Tool, Version ".g:Make_Version." / Wolfgang Mehner / wolfgang-mehner@web.de\n\n" + " + echo txt +endfunction " ---------- end of function mmtoolbox#make#Settings ---------- +" +"------------------------------------------------------------------------------- +" Modul setup (abort early?). {{{1 +"------------------------------------------------------------------------------- +if s:Enabled == 0 + finish +endif +" +"------------------------------------------------------------------------------- +" +" Run : Run make. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#make#Run ( args ) + " + silent exe 'update' | " write source file if necessary + cclose + " + " arguments + if a:args == '' | let cmdlinearg = s:CmdLineArgs + else | let cmdlinearg = a:args + endif + " :TODO:18.08.2013 21:45:WM: 'cmdlinearg' is not correctly escaped for use under Windows + " + " run make + if s:Makefile == '' + exe 'make '.cmdlinearg + else + exe 'lchdir '.fnameescape( fnamemodify( s:Makefile, ':p:h' ) ) + " + exe 'make -f '.shellescape( s:Makefile ).' '.cmdlinearg + " + lchdir - + endif + " + botright cwindow + " +endfunction " ---------- end of function mmtoolbox#make#Run ---------- +" }}}1 +"------------------------------------------------------------------------------- +" +" ===================================================================================== +" vim: foldmethod=marker diff --git a/autoload/mmtoolbox/tools.vim b/autoload/mmtoolbox/tools.vim new file mode 100644 index 0000000..aa291b9 --- /dev/null +++ b/autoload/mmtoolbox/tools.vim @@ -0,0 +1,436 @@ +"=============================================================================== +" +" File: tools.vim +" +" Description: Toolbox engine. +" +" Maps & Menus - Toolbox Engine +" +" VIM Version: 7.0+ +" Author: Wolfgang Mehner, wolfgang-mehner@web.de +" Organization: +" Version: see variable g:Toolbox_Version below +" Created: 29.12.2012 +" Revision: 04.01.2014 +" License: Copyright (c) 2012-2014, Wolfgang 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. +"=============================================================================== + +"------------------------------------------------------------------------------- +" Basic checks. {{{1 +"------------------------------------------------------------------------------- +" +" need at least 7.0 +if v:version < 700 + echohl WarningMsg + echo 'The plugin tools/tools.vim needs Vim version >= 7.' + echohl None + finish +endif +" +" prevent duplicate loading +" need compatible +if &cp || ( exists('g:Toolbox_Version') && ! exists('g:Toolbox_DevelopmentOverwrite') ) + finish +endif +let g:Toolbox_Version= '1.0.1' " version number of this script; do not change +" +"------------------------------------------------------------------------------- +" Auxiliary functions {{{1 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" s:ErrorMsg : Print an error message. {{{2 +" +" Parameters: +" line1 - a line (string) +" line2 - a line (string) +" ... - ... +" Returns: +" - +"------------------------------------------------------------------------------- +" +function! s:ErrorMsg ( ... ) + echohl WarningMsg + for line in a:000 + echomsg line + endfor + echohl None +endfunction " ---------- end of function s:ErrorMsg ---------- +" +"------------------------------------------------------------------------------- +" s:GetGlobalSetting : Get a setting from a global variable. {{{2 +" +" Parameters: +" varname - name of the variable (string) +" Returns: +" - +" +" If g: exists, assign: +" s: = g: +"------------------------------------------------------------------------------- +" +function! s:GetGlobalSetting ( varname ) + if exists ( 'g:'.a:varname ) + exe 'let s:'.a:varname.' = g:'.a:varname + endif +endfunction " ---------- end of function s:GetGlobalSetting ---------- +" +"------------------------------------------------------------------------------- +" s:GetToolConfig : Get the configuration from a global variable. {{{2 +" +" Parameters: +" plugin - the name of the plg-in (string) +" name - the name of the tool (string) +" Returns: +" config - 'yes' or 'no' (string) +" +" Returns whether the tool should be loaded. +" If the variable g:_UseTool_ exists, return its value. +" Otherwise returns 'no'. +"------------------------------------------------------------------------------- +function! s:GetToolConfig ( plugin, name ) + " + let name = 'g:'.a:plugin.'_UseTool_'.a:name + if exists ( name ) + return {name} + endif + return 'no' +endfunction " ---------- end of function s:GetToolConfig ---------- +" }}}2 +"------------------------------------------------------------------------------- +" +"------------------------------------------------------------------------------- +" NewToolbox : Create a new toolbox. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#NewToolbox ( plugin ) + " + " properties: + " - plugin : the name (id) if the plugin + " - mapleader : only required for menu creation, + " for map creation, the current mapleader/maplocalleader is + " used, it must already be set accordingly + " - tools : dictionary holding the meta information about the tools + " associates: name -> info + " - names : the names of all the tools, sorted alphabetically + " - n_menu : the number of tools which create a menu + let toolbox = { + \ 'plugin' : a:plugin, + \ 'mapleader' : '\', + \ 'tools' : {}, + \ 'names' : [], + \ 'n_menu' : 0, + \ } + " + return toolbox + " +endfunction " ---------- end of function mmtoolbox#tools#NewToolbox ---------- +" +"------------------------------------------------------------------------------- +" Load : Load the tools from various directories. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#Load ( toolbox, directories ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + elseif type( a:directories ) != type( [] ) + return s:ErrorMsg ( 'Argument "directories" must be given as a list.' ) + endif + " + let a:toolbox.n_menu = 0 + " + " go through all directories + for dir in a:directories + " + " is a directory + if ! isdirectory ( dir ) + continue + endif + " + " go through all dir/*.vim + for file in split( glob (dir.'/*.vim'), '\n' ) + " + " the name is the basename of the file + let name = fnamemodify( file, ':t:r' ) + " + " do not process 'tools.vim' (this script) + if name == 'tools' + continue + endif + " + " do not load multiple times + if has_key ( a:toolbox.tools, name ) + continue + endif + " + " check whether to use the tool + if s:GetToolConfig ( a:toolbox.plugin, name ) != 'yes' + continue + endif + " + " try to load and initialize + try + " + " get tool information + let retlist = mmtoolbox#{name}#GetInfo() + " + " assemble the entry + let entry = { + \ "name" : name, + \ "prettyname" : retlist[0], + \ "version" : retlist[1], + \ "enabled" : 1, + \ "domenu" : 1, + \ "filename" : file, + \ } + " + " process the flags + if len ( retlist ) > 2 + if index ( retlist, 'nomenu', 2 ) != -1 + let entry.domenu = 0 + endif + if index ( retlist, 'disabled', 2 ) != -1 + let entry.enabled = 0 + endif + endif + " + " save the entry + let a:toolbox.tools[ name ] = entry + call add ( a:toolbox.names, name ) + " + if entry.enabled && entry.domenu + let a:toolbox.n_menu += 1 + endif + " + catch /.*/ + " could not load the plugin: ? + call s:ErrorMsg ( "Could not load the tool \"".name."\" (".v:exception.")", + \ " - occurred at " . v:throwpoint ) + endtry + " + endfor + " + endfor + " + " sort the names + call sort ( a:toolbox.names ) + " +endfunction " ---------- end of function mmtoolbox#tools#Load ---------- +" +"------------------------------------------------------------------------------- +" ToolEnabled : Whether a tool is enabled. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#ToolEnabled ( toolbox, name ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + endif + " + if type( a:name ) != type( '' ) + return s:ErrorMsg ( 'Argument "name" must be given as a string.' ) + endif + " + " has been loaded? + if s:GetToolConfig ( a:toolbox.plugin, a:name ) != 'yes' + return 0 + endif + " + let enabled = 0 + " + try + let enabled = mmtoolbox#{a:name}#Property('get','enabled') + catch /.*/ + " fail quietly + endtry + " + return enabled +endfunction " ---------- end of function mmtoolbox#tools#ToolEnabled ---------- +" +"------------------------------------------------------------------------------- +" Property : Get/set a property. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#Property ( toolbox, property, ... ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + endif + " + if type( a:property ) != type( '' ) + return s:ErrorMsg ( 'Argument "property" must be given as a string.' ) + endif + " + " check the property + if a:property == 'mapleader' + " ok + elseif a:property == 'empty-menu' + return a:toolbox.n_menu == 0 + else + return s:ErrorMsg ( 'Unknown property: '.a:property ) + endif + " + " get/set the property + if a:0 == 0 + return a:toolbox[ a:property ] + else + let a:toolbox[ a:property ] = a:1 + endif + " +endfunction " ---------- end of function mmtoolbox#tools#Property ---------- +" +"------------------------------------------------------------------------------- +" GetList : Get the list of all tools. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#GetList ( toolbox ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + endif + " + " assemble the list + let toollist = [] + " + for name in a:toolbox.names + let entry = a:toolbox.tools[ name ] + if entry.enabled + call add ( toollist, entry.prettyname." (".entry.version.")" ) + else + call add ( toollist, entry.prettyname." (".entry.version.", disabled)" ) + endif + endfor + " + return toollist + " +endfunction " ---------- end of function mmtoolbox#tools#GetList ---------- +" +"------------------------------------------------------------------------------- +" Info : Echo debug information. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#Info ( toolbox ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + endif + " + let txt = '' + " + for name in a:toolbox.names + let entry = a:toolbox.tools[ name ] + " + let line = entry.prettyname." (".entry.version."), " + let line .= repeat ( " ", 25-len(line) ) + if entry.enabled | let line .= "enabled, " + else | let line .= "disabled, " | endif + if entry.domenu | let line .= "menu, " + else | let line .= "nomenu, " | endif + let line .= "from: ".entry.filename."\n" + " + let txt .= line + endfor + " + echo txt + " +endfunction " ---------- end of function mmtoolbox#tools#Info ---------- +" +"------------------------------------------------------------------------------- +" AddMaps : Create maps for all tools. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#AddMaps ( toolbox ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + endif + " + " go through all the tools + for name in a:toolbox.names + let entry = a:toolbox.tools[ name ] + " + if ! entry.enabled + continue + endif + " + try + " try to create the maps + call mmtoolbox#{entry.name}#AddMaps() + catch /.*/ + " could not load the plugin: ? + call s:ErrorMsg ( "Could not create maps for the tool \"".name."\" (".v:exception.")", + \ " - occurred at " . v:throwpoint ) + endtry + endfor +endfunction " ---------- end of function mmtoolbox#tools#AddMaps ---------- +" +"------------------------------------------------------------------------------- +" AddMenus : Create menus for all tools. {{{1 +"------------------------------------------------------------------------------- +function! mmtoolbox#tools#AddMenus ( toolbox, root ) + " + " check the parameters + if type( a:toolbox ) != type( {} ) + return s:ErrorMsg ( 'Argument "toolbox" must be given as a dict.' ) + endif + " + if type( a:root ) != type( '' ) + return s:ErrorMsg ( 'Argument "root" must be given as a string.' ) + endif + " + " correctly escape the mapleader + if ! empty ( a:toolbox.mapleader ) | let mleader = a:toolbox.mapleader + elseif exists ( 'g:maplocalleader' ) | let mleader = g:maplocalleader + else | let mleader = '\' + endif + " + if mleader == '' + let mleader = '\' + endif + " + let mleader = escape ( mleader, ' .|\' ) + let mleader = substitute ( mleader, '\V&', '\&&', 'g' ) + " + " go through all the tools + for name in a:toolbox.names + let entry = a:toolbox.tools[ name ] + " + if ! entry.enabled || ! entry.domenu + continue + endif + " + " correctly escape the name + " and add a shortcut + let menu_item_r = escape ( entry.prettyname, ' .|\' ) + let menu_item_l = substitute ( menu_item_r, '\V&', '\&&', 'g' ) + let menu_scut = substitute ( menu_item_l, '\w', '\&&', '' ) + let menu_root = a:root.'.'.menu_scut + " + " create the menu header + exe 'amenu '.menu_root.'.'.menu_item_l.''.menu_item_r.' :echo "This is a menu header."' + exe 'amenu '.menu_root.'.-SepHead- :' + " + try + " try to create the menu + call mmtoolbox#{entry.name}#AddMenu( menu_root, mleader ) + catch /.*/ + " could not load the plugin: ? + call s:ErrorMsg ( "Could not create menus for the tool \"".name."\" (".v:exception.")", + \ " - occurred at " . v:throwpoint ) + endtry + endfor + " +endfunction " ---------- end of function mmtoolbox#tools#AddMenus ---------- +" }}}1 +" +" ===================================================================================== +" vim: foldmethod=marker diff --git a/README.csupport b/c-support/README.csupport similarity index 68% rename from README.csupport rename to c-support/README.csupport index 2f6381b..61d6edd 100644 --- a/README.csupport +++ b/c-support/README.csupport @@ -1,8 +1,8 @@ -README for c.vim (Version 5.18) / March 03 2012 +README for c.vim (Version 6.1.1) / March 22 2014 * DESCRIPTION * INSTALLATION - * RELEASE NOTES + * RELEASE NOTES * FILES * ADDITIONAL TIPS * CREDITS @@ -48,28 +48,37 @@ value of $HOME with ":echo $HOME" from inside Vim). This is the minimal content of the file '$HOME/.vimrc'. Create one if there is none or use the files in $HOME/.vim/c-support/rc as a starting point. -(1.3) Set at least some personal details in the file - '$HOME/.vim/c-support/templates/Templates' +(1.3) Set at least some personal details in the file + '$HOME/.vim/c-support/templates/Templates' Here is the minimal personalization (my settings as an example): - |AUTHOR| = Dr. Fritz Mehner - |AUTHORREF| = fgm - |EMAIL| = mehner@fh-swf.de - |COMPANY| = FH Südwestfalen, Iserlohn - |COPYRIGHT| = Copyright (c) |YEAR|, |AUTHOR| + SetMacro( 'AUTHOR', 'Dr. Fritz Mehner' ) + SetMacro( 'AUTHORREF', 'fgm' ) + SetMacro( 'EMAIL', 'mehner.fritz@fh-swf.de' ) + SetMacro( 'ORGANIZATION','FH Südwestfalen, Iserlohn' ) + SetMacro( 'COPYRIGHT', 'Copyright (c) |YEAR|, |AUTHOR|' ) (Read more about the template system in the plugin documentation) (1.4) Make the plugin help accessable by typing the following command on the Vim command line: - :helptags $HOME/.vim/doc/ - + :helptags $HOME/.vim/doc/ + (1.5) Consider additional settings in the file '$HOME/.vimrc'. The files customization.vimrc and customization.gvimrc are replacements or extensions for your .vimrc and .gvimrc. You may want to use parts of them. The files - are documented. + are documented. + +(1.6) To enable additional tools, add these lines to your '$HOME/.vimrc'. To + enable the CMake and Doxygen tools, use: + + let g:C_UseTool_cmake = 'yes' + let g:C_UseTool_doxygen = 'yes' + + For enabling the Doxygen templates, see chapter 1.10.1 of the documentation: + :help csupport-doxygen-enable (2) WINDOWS ------------ @@ -98,41 +107,51 @@ the value of $HOME with ":echo $HOME" from inside Vim). This is the minimal content of the file '$HOME/_vimrc'. Create one if there is none or use the files in $HOME/vimfiles/c-support/rc as a starting point. -(2.3) Set at least some personal details in the file - '$HOME/vimfiles/c-support/templates/Templates' +(2.3) Set at least some personal details in the file + '$HOME/vimfiles/c-support/templates/Templates' Here is the minimal personalization (my settings as an example): - |AUTHOR| = Dr. Fritz Mehner - |AUTHORREF| = fgm - |EMAIL| = mehner@fh-swf.de - |COMPANY| = FH Südwestfalen, Iserlohn - |COPYRIGHT| = Copyright (c) |YEAR|, |AUTHOR| + SetMacro( 'AUTHOR', 'Dr. Fritz Mehner' ) + SetMacro( 'AUTHORREF', 'fgm' ) + SetMacro( 'EMAIL', 'mehner.fritz@fh-swf.de' ) + SetMacro( 'ORGANIZATION','FH Südwestfalen, Iserlohn' ) + SetMacro( 'COPYRIGHT', 'Copyright (c) |YEAR|, |AUTHOR|' ) (Read more about the template system in the plugin documentation) -(2.4) Make the plugin help accessable by typing the following command on the +(2.4) Make the plugin help accessible by typing the following command on the Vim command line: - :helptags $HOME\vimfiles\doc\ - + :helptags $HOME\vimfiles\doc\ + (2.5) Consider additional settings in the file '$HOME/_vimrc'. The files customization.vimrc and customization.gvimrc are replacements or extensions for your _vimrc and _gvimrc. You may want to use parts of them. The files - are documented. + are documented. + +(2.6) To enable additional tools, add these lines to your '$HOME/_vimrc'. To + enable the CMake and Doxygen tools, use: + + let g:C_UseTool_cmake = 'yes' + let g:C_UseTool_doxygen = 'yes' + + For enabling the Doxygen templates, see chapter 1.10.1 of the documentation: + + :help csupport-doxygen-enable There are a lot of features and options which can be used and influenced: * use of template files and tags * surround marked blocks with statements * using and managing personal code snippets - * generate/remove multiline comments + * generate/remove multiline comments * picking up prototypes * C/C++ dictionaries for keyword completion * (re)moving the root menu Look at csupport help with - :help csupport + :help csupport or use the 'help' item in the root menu of this plug-in. @@ -149,9 +168,27 @@ Any problems ? See the TROUBLESHOOTING section at the end of the help file ================================================================================ RELEASE NOTES ================================================================================ -- Hotkeys \lcs, \ucs removed. -- Bugfix: delayed template initialization missing correct style. -- Wrong cursor position when inserting some templates at the end of a line. + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++ The plug-in version 6.0+ is a rewriting of version 5.19. ++ + ++ The versions 6.0+ are based on a new and more powerful template system ++ + ++ (please see |template-support|for more information). ++ + ++ The template syntax has changed! ++ + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +================================================================================ + RELEASE NOTES FOR VERSION 6.1.1 +================================================================================ +- Added 'C_SetMapLeader' and 'C_ResetMapLeader'. +- Bugfix: Resetting maplocalleader in filetype plug-in after setting it to the + value of g:C_MapLeader. +- Bugfix: Setup of local templates in case of global installation. +- Bugfix: Better compatibility with custom mappings + (use "normal!" and "noremap" consistently). +- 'Help->show manual' shows man page text with appropriate width (UNIX only). +- Extended the documentation. Please see file ./c-support/doc/ChangeLog . @@ -161,8 +198,13 @@ Any problems ? See the TROUBLESHOOTING section at the end of the help file README.csupport This file. -doc/csupport.txt The help file for the local on-line help. - +autoload/mmtemplates/core.vim The template system. +autoload/mmtoolbox/* The toolbox (cmake, doxygen, make, ...). + +doc/csupport.txt The help file for the local on-line help. +doc/templatesupport.txt The help file for the template system. +doc/toolbox*.txt The help files for the toolbox. + ftplugin/c.vim A file type plug-in. Define hotkeys, creates a local dictionary for each C/C++ file. ftplugin/make.vim Access hotkeys for make(1) in makefiles. @@ -170,7 +212,7 @@ ftplugin/make.vim Access hotkeys for make(1) in makefiles. plugin/c.vim The C/C++ plug-in for GVIM. c-support/scripts/wrapper.sh The wrapper script for the use of a xterm. -c-support/templates/* C-style and C++-style template files +c-support/templates/* C-style and C++-style template files (see csupport.txt on how to adapt the templates). @@ -187,6 +229,7 @@ c-support/wordlists/stl_index.list STL: method and type names. c-support/doc/c-hotkeys.pdf Hotkey reference card. c-support/doc/ChangeLog The change log. +rc/customization.cpp.vim Additional mappings for C++. rc/customization.ctags Additional settings I use in .ctags to enable navigation through makefiles ans qmake files with the plug-in taglist.vim. @@ -203,25 +246,31 @@ rc/customization.vimrc Additional settings I use in .vimrc : incremental dictionaries, ... The file is commented. Append it to your .vimrc if you like. +rc/project/in.vim Example for using the project plug-in's "in=" + option (see :help project-syntax) to set up the + toolbox. For example, a project's Makefile could be + set up this way. + ================================================================================ CREDITS ================================================================================ - Most of the people who have contributed ideas, patches, and bug reports, is - thanked in the file ChangeLog. + Most of the people who have contributed ideas, patches, and bug reports, is + thanked in the file ChangeLog. I would like to especially thank my son Wolfgang Mehner, who has repeatedly proposed improvements and introduced new ideas. Some ideas are taken from the following documents: 1. Recommended C Style and Coding Standards (Indian Hill Style Guide) http://ieng9.ucsd.edu/~cs30x/indhill-cstyle.html + http://www.sourceformat.com/pdf/cpp-coding-standard-indianhill.pdf 2. Programming in C++, Ellemtel Telecommunication Systems Laboratories www.it.bton.ac.uk/burks/burks/language/cpp/cppstyle/ellhome.htm 3. C++ Coding Standard, Todd Hoff www.possibility.com/Cpp/CppCodingStandard.html The splint error format is taken from the file splint.vim (Vim standard - distribution). + distribution). ------------------ @@ -230,7 +279,7 @@ rc/customization.vimrc Additional settings I use in .vimrc : incremental Johann Wolfgang von Goethe (1749-1832), the greatest of the German poets, about LINUX, Vim/gVim and other great tools (Ok, almost.) : - Ein Mann, der recht zu wirken denkt, Who on efficient work is bent, + Ein Mann, der recht zu wirken denkt, Who on efficient work is bent, Muß auf das beste Werkzeug halten. Must choose the fittest instrument. Faust, Teil 1, Vorspiel auf dem Theater Faust, Part 1, Prologue for the Theatre diff --git a/c-support/codesnippets/Makefile b/c-support/codesnippets/Makefile index 96bc7a0..aedf875 100644 --- a/c-support/codesnippets/Makefile +++ b/c-support/codesnippets/Makefile @@ -23,7 +23,7 @@ # Prerequisites are generated automatically; makedepend is not # needed (see documentation for GNU make Version 3.81, April 2006, # section 4.13). The utility sed is used. -#========================================== makefile template version 1.9 ====== +#========================================== makefile template version 1.10 ===== # DEBUG can be set to YES to include debugging info, or NO otherwise DEBUG := YES @@ -49,22 +49,6 @@ RELEASE_CFLAGS := -Wall -ansi -pedantic -O3 DEBUG_LDFLAGS := -g RELEASE_LDFLAGS := -ifeq (YES, ${DEBUG}) - CFLAGS := ${DEBUG_CFLAGS} - CXXFLAGS := ${DEBUG_CXXFLAGS} - LDFLAGS := ${DEBUG_LDFLAGS} -else - CFLAGS := ${RELEASE_CFLAGS} - CXXFLAGS := ${RELEASE_CXXFLAGS} - LDFLAGS := ${RELEASE_LDFLAGS} -endif - -ifeq (YES, ${PROFILE}) - CFLAGS := ${CFLAGS} -pg -O3 - CXXFLAGS := ${CXXFLAGS} -pg -O3 - LDFLAGS := ${LDFLAGS} -pg -endif - # ------------ additional system include directories ------------------------- GLOBAL_INC_DIR = @@ -99,6 +83,22 @@ EXE_CMDLINE = # The following statements usually need not to be changed #=============================================================================== +ifeq (YES, ${DEBUG}) + CFLAGS := ${DEBUG_CFLAGS} + CXXFLAGS := ${DEBUG_CXXFLAGS} + LDFLAGS := ${DEBUG_LDFLAGS} +else + CFLAGS := ${RELEASE_CFLAGS} + CXXFLAGS := ${RELEASE_CXXFLAGS} + LDFLAGS := ${RELEASE_LDFLAGS} +endif + +ifeq (YES, ${PROFILE}) + CFLAGS := ${CFLAGS} -pg -O3 + CXXFLAGS := ${CXXFLAGS} -pg -O3 + LDFLAGS := ${LDFLAGS} -pg +endif + C_SOURCES = $(filter %.c, $(SOURCES)) CPP_SOURCES = $(filter-out %.c, $(SOURCES)) ALL_INC_DIR = $(addprefix -I, $(LOCAL_INC_DIR) $(GLOBAL_INC_DIR)) @@ -188,6 +188,7 @@ tarball: @lokaldir=`pwd`; lokaldir=$${lokaldir##*/}; \ rm --force $$lokaldir.tar.gz; \ tar --exclude=$(TARBALL_EXCLUDE) \ + --exclude=$(EXECUTABLE) \ --create \ --gzip \ --verbose \ @@ -196,7 +197,7 @@ tarball: # ------------ zip ------------------------------------------------------------- zip: @lokaldir=`pwd`; lokaldir=$${lokaldir##*/}; \ - zip -r $$lokaldir.zip * -x $(ZIP_EXCLUDE) + zip -r $$lokaldir.zip * -x $(ZIP_EXCLUDE) -x ${EXECUTABLE} .PHONY: clean tarball zip diff --git a/c-support/codesnippets/Makefile.multi-target.template b/c-support/codesnippets/Makefile.multi-target.template index 75da8dd..ab5bc14 100644 --- a/c-support/codesnippets/Makefile.multi-target.template +++ b/c-support/codesnippets/Makefile.multi-target.template @@ -3,27 +3,27 @@ # File: Makefile # Description: # -# Usage: make (generate executable(s) ) -# make clean (remove objects, executables, prerequisits ) -# make tarball (generate compressed archive ) -# make zip (generate compressed archive ) +# Usage: make (generate executable(s) ) +# make clean (remove objects, executables ) +# make tarball (generate compressed archive ) +# make zip (generate compressed archive ) # # Author: Dr.-Ing. Fritz Mehner # Email: mehner@mfh-iserlohn.de -# Created: +# Created: 03.04.2012 # #=============================================================================== +TARGETS = target1 target2 CC = gcc CCP = g++ CFLAGS = -c -g -Wall LFLAGS = -g SYS_LIBS = -lm -TARBALL_EXCLUDE = "*.{o,gz,zip}" -ZIP_EXCLUDE = *.o *.gz *.zip +TARBALL_INCLUDE = *.{c,h,cc,hh} Makefile +ZIP_INCLUDE = $(TARBALL_INCLUDE) -TARGETS = target_1 target_2 #---------- targets -------------------------------------- all: $(TARGETS) @@ -35,36 +35,31 @@ all: $(TARGETS) $(CCP) $(CFLAGS) $*.cc #---------- target 1 ------------------------------------- -# C target -target_1: target_1.o +# ----- C target +target1: target1.o $(CC) $(LFLAGS) -o $@ $@.o $(SYS_LIBS) #---------- target 2 ------------------------------------- -# C++ target -target_2: target_2.o +# ----- C++ target +target2: target2.o $(CCP) $(LFLAGS) -o $@ $@.o $(SYS_LIBS) - -#---------- target 3 ------------------------------------- - - - #---------- tarball -------------------------------------- tarball: - lokaldir=`pwd`; lokaldir=$${lokaldir##*/}; \ + @lokaldir=`pwd`; lokaldir=$${lokaldir##*/};\ rm --force $$lokaldir.tar.gz; \ - tar --exclude=$(TARBALL_EXCLUDE) \ - --create \ + tar --create \ --gzip \ --verbose \ - --file $$lokaldir.tar.gz * + --file $$lokaldir.tar.gz \ + $(TARBALL_INCLUDE) #---------- zip ------------------------------------------ zip: - lokaldir=`pwd`; lokaldir=$${lokaldir##*/}; \ - zip -r $$lokaldir.zip * -x $(ZIP_EXCLUDE) + @lokaldir=`pwd`; lokaldir=$${lokaldir##*/};\ + zip -r $$lokaldir.zip $(ZIP_INCLUDE) #---------- clear up ------------------------------------- clean: - rm --force $(EXECUTABLE) $(OBJECTS) $(PREREQUISITES) + rm --force $(TARGETS) *.o diff --git a/c-support/codesnippets/Makefile.pro b/c-support/codesnippets/Makefile.pro new file mode 100644 index 0000000..f9867a2 --- /dev/null +++ b/c-support/codesnippets/Makefile.pro @@ -0,0 +1,21 @@ +#======================================================================================= +# +# Filename: Makefile.pro +# Description: qmake project file +# +# Usage: qmake +# +# Version: 1.0 +# Created: +# Revision: --- +# Author: +# Company: +# Email: +#======================================================================================= + +TEMPLATE = app +CONFIG = debug warn_on +SOURCES += +HEADERS += +TARGET = + diff --git a/c-support/codesnippets/calloc_double_matrix.c b/c-support/codesnippets/calloc_double_matrix.c index bfa263a..af5c920 100644 --- a/c-support/codesnippets/calloc_double_matrix.c +++ b/c-support/codesnippets/calloc_double_matrix.c @@ -13,7 +13,7 @@ calloc_double_matrix ( int rows, int columns ) double **m; m = calloc ( rows, sizeof(double*) ); /* allocate pointer array */ assert( m != NULL ); /* abort if allocation failed */ - *m = calloc ( rows*columns, sizeof(double) );/* allocate data array */ + m[0] = calloc ( rows*columns, sizeof(double) );/* allocate data array */ assert(*m != NULL ); /* abort if allocation failed */ for ( i=1; i \re. +- New global variable g:C_InsertFileHeader (suppress file description comment for new files). +- Two new ex commands: CCmdlineArgs, CMakeCmdlineArgs. +- 'Run->cmd. line arg.' : tab expansion (files/directories)for all arguments. +- Bugfix: template 'file description header' not loading (thanks to Marco Lasczok). +- Bugfix: unnecessary characters in one template. +- Prototype picker improved. +- Toggle non-C-comments. +- Run debugger. +- Some global variables now changeable on the fly. +- Menus now show the correct mapleader. +- Bugfix: g:C_LoadMenus now works. +- Bugfix: Prevent unnecessary rereading of the template library. +- Added Doxygen templates and 'Doxygen->brief, after member'. +- Added help menu entries: help English, help Doxygen +- Improved "adjust end-of-line comment". +- Bugfix: Setup of local templates in case of global installation. +- Bugfix: Map and menu entry 'Snippets->edit global templates'. +- Several internal improvements. + +================================================================================ + RELEASE NOTES FOR VERSION 6.0 +================================================================================ +- New template system (many thanks to Wolfgang Mehner) +- A few new hotkeys and menu item. +- A few hotkeys and menu items renamed. + +================================================================================ + RELEASE NOTES FOR VERSION 5.19 +================================================================================ +- Resolve home for linked home directories. +- Three C++-items removed (see file 'customization.cpp.vim'). +- Bugfix: global options changed unintentionally. +- Minor improvements and bugfixes. + ================================================================================ RELEASE NOTES FOR VERSION 5.18 ================================================================================ +- Hotkeys \lcs, \ucs removed. +- Bugfix: delayed template initialization missing correct style. +- Wrong cursor position when inserting some templates at the end of a line. ================================================================================ diff --git a/c-support/doc/c-hotkeys.pdf b/c-support/doc/c-hotkeys.pdf new file mode 100644 index 0000000..d10543a Binary files /dev/null and b/c-support/doc/c-hotkeys.pdf differ diff --git a/c-support/doc/c-hotkeys.tex b/c-support/doc/c-hotkeys.tex new file mode 100644 index 0000000..48fbb8c --- /dev/null +++ b/c-support/doc/c-hotkeys.tex @@ -0,0 +1,380 @@ +%%===================================================================================== +%% +%% Filename: c-hotkeys.tex +%% +%% Description: c-support.vim : Key mappings for Vim / gVim without GUI. +%% +%% Version: 1.0 +%% Created: 10.11.2006 +%% Revision: none +%% +%% Author: Dr. Fritz Mehner (fgm), mehner.fritz@fh-swf.de +%% Organization: FH Südwestfalen, Iserlohn, Germany +%% Copyright: Copyright (c) 2006-2014, Dr. Fritz Mehner +%% +%% Notes: +%% +%%===================================================================================== +% +%%====================================================================== +%% LaTeX settings [[[1 +%%====================================================================== +\documentclass[oneside,11pt,landscape,DIV16]{scrartcl} +% +\usepackage[english]{babel} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{times} +\usepackage{lastpage} +\usepackage{multicol} +\usepackage{setspace} +% +\setlength\parindent{0pt} +% +\newcommand{\Pluginversion}{6.1.1} +\newcommand{\ReleaseDate}{\today} +\newcommand{\Rep}{{\tiny{[n]}}} +% +%%---------------------------------------------------------------------- +%% luximono : Type1-font +%% Makes keyword stand out by using semibold letters. +%%---------------------------------------------------------------------- +\usepackage[scaled]{luximono} +% +%%---------------------------------------------------------------------- +%% fancyhdr +%%---------------------------------------------------------------------- +\usepackage{fancyhdr} +\pagestyle{fancyplain} +\fancyfoot[L]{\small \ReleaseDate} +\fancyfoot[C]{c-support.vim} +\fancyfoot[R]{\small \textbf{Page \thepage{} / \pageref{LastPage}}} +\renewcommand{\headrulewidth}{0.0pt} +% +%%---------------------------------------------------------------------- +%% hyperref +%%---------------------------------------------------------------------- +\usepackage[ps2pdf]{hyperref} +\hypersetup{pdfauthor={Dr.-Ing. Fritz Mehner, FH Südwestfalen, Iserlohn, Germany}} +\hypersetup{pdfkeywords={Vim, C/C++}} +\hypersetup{pdfsubject={Vim-plugin, c-support.vim, hot keys}} +\hypersetup{pdftitle={Vim-plugin, c-support.vim, hot keys}} +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% START OF DOCUMENT +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{document}% +% +\begin{multicols}{3} +% +%%====================================================================== +%% title [[[1 +%%====================================================================== +\begin{center} +\textbf{\textsc{\small{Vim-Plugin}}}\\ +\textbf{\LARGE{c-support.vim}}\\ +\textbf{\textsc{\small{Version \Pluginversion}}}\\ +\textbf{\textsc{\Huge{Hot keys}}}\\ +Key mappings for Vim with and without GUI.\\ +{\tiny{http://vim.sourceforge.net/scripts/script.php?script\_id=213}}\\ +\vspace{1.0mm} +{\normalsize (i)} insert mode, {\normalsize (n)} normal mode, {\normalsize (v)} visual mode\\ +\vspace{3.0mm} +% +%%====================================================================== +%% page 1, table, left part [[[1 +%%====================================================================== +%%~~~~~ TABULAR : begin ~~~~~~~~~~ +\begin{tabular}[]{|p{10mm}|p{60mm}|} +%% +%%---------------------------------------------------------------------- +%% show plugin help +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{\textbf{H}elp}}\\ +\hline \verb'\he' & English dictionary \hfill (n,i)\\ +\hline \verb'\hd' & Doxygen command \hfill (n,i)\\ +\hline \verb'\hm' & manual for word under cursor \hfill (n,i)\\ +\hline \verb'\hp' & help (c-support) \hfill (n,i)\\ +\hline +% +\hline +\multicolumn{2}{|r|}{\textsl{\textbf{C}omments}} \\ +\hline \Rep\verb'\cl' & end-of-line comment \hfill (n,v,i)\\ +\hline \Rep\verb'\cj' & adjust end-of-line comment \hfill (n,v,i)\\ +\hline \verb'\cs' & set end-of-line comment column \hfill (n) \\ +\hline \Rep\verb'\c*' & code $\Rightarrow$ comment \verb'/* */' \hfill (n,v,i) \\ +\hline \Rep\verb'\cc' & code $\Rightarrow$ comment \verb'//' \hfill (n,v,i)\\ +\hline \Rep\verb'\co' & comment $\Rightarrow$ code \hfill (n,v,i)\\ +\hline \Rep\verb'\cn' & toggle non-C comment \hfill (n,v,i)\\ +% +\hline \verb'\cfr' & frame comment \hfill (n,i)\\ +\hline \verb'\cfu' & function comment \hfill (n,i)\\ +\hline \verb'\cme' & method description \hfill (n,i)\\ +\hline \verb'\ccl' & class description \hfill (n,i)\\ +\hline \verb'\cfdi'& file description (implementation) \hfill (n,i)\\ +\hline \verb'\cfdh'& file description (header) \hfill (n,i)\\ +% +\hline \verb'\ccs'& C/C++--file sections\hspace{3mm}\footnotesize{(tab compl.)}\hfill \normalsize{(n,i)}\\ +\hline \verb'\chs'& H--file sections\hspace{10mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ +\hline \verb'\ckc'& keyword comment\hspace{5mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ +\hline \verb'\csc'& special comment\hspace{7,5mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ +\hline \verb'\cma'& template macros\hspace{7,5mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ +% +\hline \verb'\cd' & date \hfill (n,v,i)\\ +\hline \verb'\ct' & date \& time \hfill (n,v,i)\\ +\hline \Rep\verb'\cx' & exch. comment style: C $\leftrightarrow$ C++ \hfill (n,v,i)\\ +\hline +\end{tabular}\\ +%%~~~~~ TABULAR : end ~~~~~~~~~~ +% +%%====================================================================== +%% page 1, table, middle part [[[1 +%%====================================================================== +% +%%~~~~~ TABULAR : begin ~~~~~~~~~~ +\begin{tabular}[]{|p{15mm}|p{55mm}|} +%%---------------------------------------------------------------------- +%% menu statements +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{\textbf{S}tatements}} \\ +\hline \verb'\sd' & \verb'do { } while' \hfill (n,v,i)\\ +\hline \verb'\sf' & \verb'for' \hfill (n,i)\\ +\hline \verb'\sfo' & \verb'for { }' \hfill (n,v,i)\\ +\hline \verb'\si' & \verb'if' \hfill (n,i)\\ +\hline \verb'\sif' & \verb'if { }' \hfill (n,v,i)\\ +\hline \verb'\sie' & \verb'if else' \hfill (n,v,i)\\ +\hline \verb'\sife'& \verb'if { } else { }' \hfill (n,v,i)\\ +\hline \verb'\se' & \verb'else { }' \hfill (n,v,i)\\ +\hline \verb'\sw' & \verb'while' \hfill (n,i)\\ +\hline \verb'\swh' & \verb'while { }' \hfill (n,v,i)\\ +\hline \verb'\ss' & \verb'switch' \hfill (n,v,i)\\ +\hline \verb'\sc' & \verb'case' \hfill (n,i)\\ +\hline \verb'\sb' & \verb'{ }' \hfill (n,v,i)\\ +\hline +%%---------------------------------------------------------------------- +%% preprocessor menu +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{\textbf{P}reprocessor}} \\ +\hline \verb'\pih' & include Std. Lib. header \hfill (n,i)\\ +\hline \verb'\pg' & \verb$#include<...>$ (global)\hfill (n,i)\\ +\hline \verb'\pl' & \verb$#include"..."$ (local) \hfill (n,i)\\ +\hline \verb'\pd' & \verb'#define' \hfill (n,i)\\ +\hline \verb'\pu' & \verb'#undef' \hfill (n,i)\\ +\hline \verb'\pif' & \verb'#if #endif' \hfill (n,v,i)\\ +\hline \verb'\pie' & \verb'#if #else #endif' \hfill (n,v,i)\\ +\hline \verb'\pid' & \verb'#ifdef #else #endif' \hfill (n,v,i)\\ +\hline \verb'\pin' & \verb'#ifndef #else #endif' \hfill (n,v,i)\\ +\hline \verb'\pind' & \verb'#ifndef #def #endif' \hfill (n,v,i)\\ +\hline \verb'\pe' & \verb'#error ' \hfill (n,i)\\ +\hline \verb'\pli' & \verb'#line ' \hfill (n,i)\\ +\hline \verb'\pp' & \verb'#pragma' \hfill (n,i)\\ +\hline \verb'\pw' & \verb'#warning' \hfill (n,i)\\ +\hline \verb'\pi0' & \verb'#if 0 #endif' \hfill (n,v,i)\\ +\hline \verb'\pr0' & remove \verb'#if 0 #endif' \hfill (n,i)\\ +\hline +\end{tabular} \\ +%%~~~~~ TABULAR : end ~~~~~~~~~~ +% +%%====================================================================== +%% page 1, table, right part [[[1 +%%====================================================================== +% +%%~~~~~ TABULAR : begin ~~~~~~~~~~ +\begin{tabular}[]{|p{11mm}|p{60mm}|}% +%%---------------------------------------------------------------------- +%% snippet menu +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{S\textbf{n}ippet}} \\ +\hline \verb'\nr' & read code snippet \hfill (n,i)\\ +\hline \verb'\nv' & view code snippet \hfill (n,v,i)\\ +\hline \verb'\nw' & write code snippet \hfill (n,v,i)\\ +\hline \verb'\ne' & edit code snippet \hfill (n,i)\\ +\hline \Rep\verb'\nf' & pick up function prototype\hfill (n,v,i)\\ + \Rep\verb'\np' & \hfill (n,v,i)\\ +\hline \Rep\verb'\nm' & pick up method prototype \hfill (n,v,i)\\ +\hline \verb'\ni' & insert prototype(s) \hfill (n,i)\\ +\hline \verb'\nc' & clear prototype(s) \hfill (n,i)\\ +\hline \verb'\ns' & show prototype(s) \hfill (n,i)\\ +% +\hline \verb'\ntl' & edit local templates \hfill (n,i)\\ +\hline \verb'\ntr' & reread the templates \hfill (n,i)\\ +\hline \verb'\njt' & insert jump tag \hfill (n,i)\\ +\hline +%%---------------------------------------------------------------------- +%% idioms menu +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{\textbf{I}dioms}} \\ +\hline \verb'\if' & function \hfill (n,v,i)\\ +\hline \verb'\isf' & static function \hfill (n,v,i)\\ +\hline \verb'\im' & \verb'main()' \hfill (n,v,i)\\ +\hline \verb'\ie' & \verb'enum' + \verb'typedef' \hfill (n,v,i)\\ +\hline \verb'\is' & \verb'struct' + \verb'typedef' \hfill (n,v,i)\\ +\hline \verb'\iu' & \verb'union' + \verb'typedef' \hfill (n,v,i)\\ +\hline \verb'\ipr' & \verb'printf()' \hfill (n,i)\\ +\hline \verb'\isc' & \verb'scanf()' \hfill (n,i)\\ +\hline \verb'\ica' & \verb'p=calloc()' \hfill (n,i)\\ +\hline \verb'\ima' & \verb'p=malloc()' \hfill (n,i)\\ +\hline \verb'\ire' & \verb'p=realloc()' \hfill (n,i)\\ +\hline \verb'\isi' & \verb'sizeof()' \hfill (n,v,i)\\ +\hline \verb'\ias' & \verb'assert()' \hfill (n,v,i)\\ +\hline \verb'\ii' & open input file \hfill (n,v,i)\\ +\hline \verb'\io' & open output file \hfill (n,v,i)\\ +\hline \verb'\ifsc'& fscanf \hfill (n,i)\\ +\hline \verb'\ifpr'& fprintf \hfill (n,i)\\ +\hline \Rep\verb'\i0' & \verb'for( x=0; x=0; x-=1 )'\hfill (n,v,i)\\ +\hline +\end{tabular} +% +%%====================================================================== +%% page 2, table, left part [[[1 +%%====================================================================== +% +%%~~~~~ TABULAR : begin ~~~~~~~~~~ +\begin{tabular}[]{|p{12mm}|p{60mm}|} +%%---------------------------------------------------------------------- +%% C++ menu +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{C\textbf{++}}} \\ +\hline \verb'\+ih' & \verb$#include$ C++ Std. Lib. header \hfill (n,i)\\ +\hline \verb'\+ich' & \verb$#include$ C Std. Lib. header \hfill (n,i)\\ +\hline \verb'\+om' & output manipulators \hfill (n,i)\\ +\hline \verb'\+fb' & ios flagbits \hfill (n,i)\\ +\hline +\hline \verb'\+c' & class \hfill (n,i)\\ +\hline \verb'\+cn' & class (using \verb'new') \hfill (n,i)\\ +\hline \verb'\+tc' & template class \hfill (n,i)\\ +\hline \verb'\+tcn' & template class (using \verb'new') \hfill (n,i)\\ +\hline \verb'\+ec' & error class \hfill (n,i)\\ +\hline \verb'\+tf' & template function \hfill (n,i)\\ +\hline +\hline \verb'\+tr' & \verb'try' \dots \verb'catch' \hfill (n,v,i)\\ +\hline \verb'\+ca' & \verb'catch' \hfill (n,v,i)\\ +\hline \verb'\+caa' & \verb'catch(...)' \hfill (n,v,i)\\ +\hline +\hline \verb'\+ex' & \verb'extern "C" { }' \hfill (n,v,i)\\ +\hline \verb'\+oif' & open input file \hfill (n,v,i)\\ +\hline \verb'\+oof' & open output file \hfill (n,v,i)\\ +\hline \verb'\+uns' & \verb'using namespace std;' \hfill (n,v,i)\\ +\hline \verb'\+un' & \verb'using namespace xxx;' \hfill (n,v,i)\\ +\hline \verb'\+unb' & \verb'namespace xxx { }' \hfill (n,v,i)\\ +\hline \verb'\+na' & namespace alias \hfill (n,v,i)\\ +\hline \verb'\+rt' & RTTI \hfill (n,v,i)\\ +% +\hline +\hline \verb'\+ic' & class implementation \hfill (n,i)\\ +\hline \verb'\+icn' & class (using \verb'new') implementation \hfill (n,i)\\ +\hline \verb'\+im' & method implementation \hfill (n,i)\\ +\hline \verb'\+ia' & accessor implementation \hfill (n,i)\\ +\hline \verb'\+itc' & template class implementation \hfill (n,i)\\ +\hline \verb'\+itcn'& template class (using \verb'new') impl. \hfill (n,i)\\ +\hline \verb'\+itm' & template method implementation \hfill (n,i)\\ +\hline \verb'\+ita' & template accessor implementation \hfill (n,i)\\ +\hline \verb'\+ioi' & operator >> \hfill (n,i)\\ +\hline \verb'\+ioo' & operator << \hfill (n,i)\\ +\hline +\end{tabular} +% +%%====================================================================== +%% page 2, table, middle part [[[1 +%%====================================================================== +\vspace{100mm} +%%~~~~~ TABULAR : begin ~~~~~~~~~~ +\begin{tabular}[]{|p{12mm}|p{58mm}|} +%%---------------------------------------------------------------------- +%% run menu +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{\textbf{R}un}} \\ +\hline \verb'\rc' & save and compile \hfill (n,i)\\ +\hline \verb'\rl' & link \hfill (n,i)\\ +\hline \verb'\rr' & run \hfill (n,i)\\ +\hline \verb'\ra' & set comand line arguments \hfill (n,i)\\ +\hline \verb'\rd' & start debugger \hfill (n,i)\\ +\hline \verb'\re' & executable to run$^1$ \hfill (n,i)\\ +% +\hline \verb'\rp' & run \texttt{splint}$^2$ \hfill (n,i)\\ +\hline \verb'\rpa' & cmd. line arg. for \texttt{splint} \hfill (n,i)\\ +% +\hline \verb'\rcc' & run \texttt{cppcheck}$^3$ \hfill (n,i)\\ +\hline \verb'\rccs'& severity for \texttt{cppcheck} \hfill (n,i)\\ +% +\hline \verb'\rk' & run \texttt{ CodeCheck}$^4$ \hfill (n,i)\\ +\hline \verb'\rka' & cmd. line arg. for \texttt{CodeCheck} \hfill (n,i)\\ +% +\hline \verb'\ri' & run \texttt{ indent} \hfill (n,i)\\ +\hline \Rep\verb'\rh' & hardcopy buffer \hfill (n,i,v)\\ +\hline \verb'\rs' & show plugin settings \hfill (n,i)\\ +\hline \verb'\rx' & set xterm size \hfill (n,i, only Unix \& GUI)\\ +\hline \verb'\ro' & change output destination \hfill (n,i)\\ +\hline +\end{tabular} +% +%%====================================================================== +%% page 2, table, right part [[[1 +%%====================================================================== +% +\begin{tabular}[]{|p{12mm}|p{58mm}|} +%%---------------------------------------------------------------------- +%% Tool Box : Make +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textsl{Tool Box : \textbf{M}ake}} \\ +\hline \verb'\rm' & run \texttt{ make}$^1$ \hfill (n,i)\\ +\hline \verb'\rmc' & run \texttt{ make clean}$^1$ \hfill (n,i)\\ +\hline \verb'\rmd' & run \texttt{ make doc}$^1$ \hfill (n,i)\\ +\hline \verb'\rcm' & choose a makefile $^1$ \hfill (n,i)\\ +\hline \verb'\rma' & cmd. line arg. for \texttt{make}$^1$ \hfill (n,i)\\ +\hline +%%---------------------------------------------------------------------- +%% Additional mappings +%%---------------------------------------------------------------------- +\hline +\multicolumn{2}{|r|}{\textbf{Additional Mappings}$^5$}\\ +\hline +\hline \textbf{typing}& \textbf{expansion}\\ +\hline \verb'/*' & \verb'/* */' \hfill (i)\\ +\hline \verb'/*' & \verb'/* '\fbox{\small{(multiline) marked text}}\verb' */' \hfill (v)\\ +\hline \verb'/*' & \verb'/*'\hfill (i)\newline\verb' * |'\newline\verb' */'\\ +\hline \verb'{' & \verb'{'\hfill (i)\newline\verb' |'\newline\verb'}' \\ +\hline \verb'{' & \verb'{'\hfill (v)\newline\verb' '\fbox{\small{(multiline) marked text}}\newline\verb'}'\\ +\hline +\end{tabular} +% +%%~~~~~ TABULAR : end ~~~~~~~~~~ +% +\begin{flushleft} +\large{\textbf{Ex Commands}}\\[1.0ex] +% +Set command line arguments (same as \textbackslash\texttt{ra})\\[1.0ex] +\texttt{ :CCmdlineArgs}\\[1.0ex] +% +Set severity for \texttt{cppcheck} (same as \textbackslash\texttt{rccs})\\[1.0ex] +\texttt{ :CppcheckSeverity}\\[1.0ex] +% +\vfill +\begin{minipage}[b]{65mm}% +% +\scriptsize{% +\hrulefill\\ +$^1$ also working for filetype \textbf{make}\\ +$^2$ \textit{www.splint.org}\\ +$^3$ \textit{cppcheck.sourceforge.net}\\ +$^4$ \textbf{CodeCheck}$^{TM}$ is a product of Abraxas Software, Inc.\\ +$^5$ defined in \verb'~/ftplugin/c.vim' +}% +% +\end{minipage} +% +\end{flushleft} +% +\end{center} +\end{multicols} +\end{document} +% vim: foldmethod=marker foldmarker=[[[,]]] diff --git a/c-support/rc/customization.cpp.vim b/c-support/rc/customization.cpp.vim new file mode 100644 index 0000000..3632383 --- /dev/null +++ b/c-support/rc/customization.cpp.vim @@ -0,0 +1,26 @@ +" ------------------------------------------------------------------------------ +" +" Vim filetype plugin file +" +" Language : C++ +" Plugin : c.vim +" Maintainer : Fritz Mehner +" +" ------------------------------------------------------------------------------ +" +" Only do this when not done yet for this buffer +" +if exists("b:did_CPP_ftplugin") + finish +endif +let b:did_CPP_ftplugin = 1 +" +"------------------------------------------------------------------------------- +" additional mapping : C++ I/O +"------------------------------------------------------------------------------- +" +inoremap >> >> +inoremap << << +inoremap <<" << "" +inoremap <<; << "\n"; +" diff --git a/c-support/rc/customization.gvimrc b/c-support/rc/customization.gvimrc index 31befe7..dd90cd5 100644 --- a/c-support/rc/customization.gvimrc +++ b/c-support/rc/customization.gvimrc @@ -4,7 +4,6 @@ " AUTHOR: Dr.-Ing. Fritz Mehner " VERSION: 1.0 " CREATED: 04.04.2009 -" REVISION: $Id: customization.gvimrc,v 1.3 2009/04/04 08:26:21 mehner Exp $ "=================================================================================== " "=================================================================================== diff --git a/c-support/rc/customization.vimrc b/c-support/rc/customization.vimrc index 917018a..74fe92c 100644 --- a/c-support/rc/customization.vimrc +++ b/c-support/rc/customization.vimrc @@ -3,7 +3,6 @@ " DESCRIPTION: suggestion for a personal configuration file ~/.vimrc " AUTHOR: Dr.-Ing. Fritz Mehner " CREATED: 04.04.2009 -" REVISION: $Id: customization.vimrc,v 1.6 2009/10/03 12:24:30 mehner Exp $ "=================================================================================== " "=================================================================================== diff --git a/c-support/rc/project/in.vim b/c-support/rc/project/in.vim new file mode 100644 index 0000000..a4a0ed1 --- /dev/null +++ b/c-support/rc/project/in.vim @@ -0,0 +1,72 @@ +"------------------------------------------------------------------------------- +" example for using the C/C++ toolbox together with the project plug-in's "in=" +" option (a file like this one can be used as the script set by the "in=" +" option): +" :help project.txt +" :help project-syntax +" :help toolbox-cmake +" :help toolbox-doxygen +" :help toolbox-make +"------------------------------------------------------------------------------- + +let s:project_name = 'TODO' + +"------------------------------------------------------------------------------- +" Project +"------------------------------------------------------------------------------- +if ! exists ( 'g:did_project_in_vim' ) || g:did_project_in_vim != s:project_name + + let g:did_project_in_vim = s:project_name + + " in.vim is located in the project's top-level directory: + let s:mypath = expand ( ':p:h' ).'/' + + " --- OR --- + +" " in.vim is located in a directory below the top-level directory +" " (e.g. project/in.vim): +" let s:mypath = expand ( ':p:h:h' ).'/' + +" " C: path for 'project_include' +" call mmtemplates#core#Resource ( g:C_Templates, 'set', 'path', +" \ 'project_include', s:mypath ) + +" " C: set style +" call mmtemplates#core#ChooseStyle ( g:C_Templates, "DOXYGEN" ) + +" " CMake: directories +" " - the build is located in a sub-directory build/ +" call mmtoolbox#cmake#Property ( 'set', 'project-dir', s:mypath ) +" call mmtoolbox#cmake#Property ( 'set', 'build-dir', s:mypath.'build' ) + +" " Doxygen: files +" " - the "Doxyfile" is located in the top-level directory +" " - The setting for "log-file" is actually the default +" " - the "WARN_LOGFILE" option is the in Doxyfile: +" " WARN_LOGFILE = "doxy_warnings.txt" +" call mmtoolbox#doxygen#Property ( 'set', 'config-file', s:mypath.'Doxyfile' ) +" call mmtoolbox#doxygen#Property ( 'set', 'log-file', s:mypath.'.doxygen.log' ) +" call mmtoolbox#doxygen#Property ( 'set', 'error-file', s:mypath.'doxy_warnings.txt' ) + +" " Make: files +" " - the "Makefile" is located in the top-level directory +" call mmtoolbox#make#Property ( 'set', 'makefile', s:mypath.'Makefile' ) + +endif + +"------------------------------------------------------------------------------- +" File +"------------------------------------------------------------------------------- +if ! exists ( 'b:did_project_in_vim' ) + + let b:did_project_in_vim = 1 + +" " Option: spelling +" set spl=en spell + +" " Option: filetype (additional Doxygen documentation) +" if bufname('%') =~ '\V.docu\$' +" set filetype=c +" endif + +endif diff --git a/c-support/rc/sample_template_file b/c-support/rc/sample_template_file new file mode 100644 index 0000000..9a77343 --- /dev/null +++ b/c-support/rc/sample_template_file @@ -0,0 +1,16 @@ +§ ============================================================= +§ User Macros +§ ============================================================= + +SetMacro( 'AUTHOR', 'YOUR NAME' ) +SetMacro( 'AUTHORREF', '' ) +SetMacro( 'COMPANY', '' ) +SetMacro( 'COPYRIGHT', 'Copyright (c) |YEAR|, |AUTHOR|' ) +SetMacro( 'EMAIL', '' ) +SetMacro( 'LICENSE', 'GNU General Public License' ) +SetMacro( 'ORGANIZATION','' ) + +§ ============================================================= +§ File Includes and Shortcuts +§ ============================================================= + diff --git a/c-support/scripts/wrapper.sh b/c-support/scripts/wrapper.sh old mode 100644 new mode 100755 index f78861c..489f896 --- a/c-support/scripts/wrapper.sh +++ b/c-support/scripts/wrapper.sh @@ -9,10 +9,9 @@ # REQUIREMENTS: --- # BUGS: --- # NOTES: --- -# AUTHOR: Dr.-Ing. Fritz Mehner (Mn), mehner@fh-swf.de +# AUTHOR: Dr.-Ing. Fritz Mehner (fgm), mehner.fritz@fh-swf.de # COMPANY: Fachhochschule Südwestfalen, Iserlohn # CREATED: 23.11.2004 18:04:01 CET -# REVISION: $Id: wrapper.sh,v 1.5 2009/06/03 17:47:06 mehner Exp $ #=============================================================================== executable="${1}" # name of the executable diff --git a/c-support/templates/Templates b/c-support/templates/Templates index 74bcd9f..8923469 100644 --- a/c-support/templates/Templates +++ b/c-support/templates/Templates @@ -1,30 +1,76 @@ -$ -$ ============================================================= -$ ========== USER MACROS ====================================== -$ ============================================================= -$ -|AUTHOR| = YOUR NAME -|AUTHORREF| = -|EMAIL| = -|COMPANY| = -|COPYRIGHT| = Copyright (c) |YEAR|, |AUTHOR| -|STYLE| = default -$ -$ ============================================================= -$ ========== FILE INCLUDES ==================================== -$ ============================================================= -$ -|includefile| = c.comments.template -|includefile| = c.cpp.template -|includefile| = c.idioms.template -|includefile| = c.preprocessor.template -|includefile| = c.statements.template -$ -== IF |STYLE| IS CPP == -|includefile| = cpp.comments.template -|includefile| = cpp.cpp.template -|includefile| = cpp.idioms.template -|includefile| = cpp.preprocessor.template -|includefile| = cpp.statements.template -== ENDIF == -$ +§ ========================================================== +§ User Macros +§ ========================================================== + +SetMacro( 'AUTHOR', 'YOUR NAME' ) +SetMacro( 'AUTHORREF', '' ) +SetMacro( 'COMPANY', '' ) +SetMacro( 'COPYRIGHT', '' ) +SetMacro( 'EMAIL', '' ) +SetMacro( 'LICENSE', '' ) +SetMacro( 'ORGANIZATION','' ) + +SetStyle( 'C' ) + +§ prefix used for Doxygen commands, '\' or '@' +SetMacro( 'DOX_CMD', '\' ) + +§ ========================================================== +§ File Includes and Shortcuts +§ ========================================================== + +MenuShortcut( 'Comments', 'c' ) +MenuShortcut( 'Doxygen', 'd' ) +MenuShortcut( 'Statements', 's' ) +MenuShortcut( 'Idioms', 'i' ) +MenuShortcut( 'Preprocessor', 'p' ) +MenuShortcut( 'Snippets', 'n' ) +MenuShortcut( 'C++', 'c' ) + +IncludeFile( 'snippets.template' ) + +§ different comments for styles "C", "CPP" and "Doxygen": + +== USE STYLES : C == +IncludeFile( 'c.comments.template' ) +== ENDSTYLES == + +== USE STYLES : CPP == +IncludeFile( 'cpp.comments.template' ) +== ENDSTYLES == + +§sets the style "Doxygen" internally +§IncludeFile( 'doxygen.template' ) + +§ the rest of the templates are the same for the two styles "C" and "Doxygen"; +§ you may also group "Doxygen" and "CPP" if you like this better: + +== USE STYLES : C, Doxygen == +IncludeFile( 'c.statements.template' ) +IncludeFile( 'c.idioms.template' ) +IncludeFile( 'c.preprocessor.template' ) +IncludeFile( 'c.cpp.template' ) +== ENDSTYLES == + +== USE STYLES : CPP == +IncludeFile( 'cpp.statements.template' ) +IncludeFile( 'cpp.idioms.template' ) +IncludeFile( 'cpp.preprocessor.template' ) +IncludeFile( 'cpp.cpp.template' ) +== ENDSTYLES == + +§ ============================================================= +§ Help +§ ============================================================= + +§ browser for help templates (UNIX) +SetMacro( 'HELP_BROWSER', 'firefox' ) + +§ browser for help templates (Windows) +§SetMacro( 'HELP_BROWSER', '"C:\Program Files\Mozilla Firefox\firefox.exe"' ) + +SetMacro( 'HelpPathEnglish', 'http://en.wiktionary.org/wiki/' ) +SetMacro( 'HelpPathDoxygen', 'http://www.stack.nl/~dimitri/doxygen/commands.html' ) + +IncludeFile( 'help.template' ) + diff --git a/c-support/templates/c.comments.template b/c-support/templates/c.comments.template index 1501628..a018a26 100644 --- a/c-support/templates/c.comments.template +++ b/c-support/templates/c.comments.template @@ -1,21 +1,25 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.end-of-line-comment == append == +§ ============================================================= +§ Comments +§ ============================================================= + +§ ------------------------------------------------------------- +§ frames, descriptions +§ ------------------------------------------------------------- + +== Comments.end-of-line-comment == append, nomenu == /* */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.frame == +== Comments.frame == map:cfr, shortcut:f == /*----------------------------------------------------------------------------- * *-----------------------------------------------------------------------------*/ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.function == +== Comments.function == map:cfu, shortcut:f == /* * === FUNCTION ====================================================================== * Name: |?FUNCTION_NAME| * Description: * ===================================================================================== */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.method == +== Comments.method == map:cme, shortcut:m == /* *-------------------------------------------------------------------------------------- * Class: |?CLASSNAME| @@ -23,16 +27,22 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * Description: *-------------------------------------------------------------------------------------- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.class == +== Comments.class == map:ccl, shortcut:c == /* * ===================================================================================== * Class: |?CLASSNAME| * Description: * ===================================================================================== */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-description == start == +== ENDTEMPLATE == + +§ ------------------------------------------------------------- +§ files, sections +§ ------------------------------------------------------------- + +== SEP: Comments.sep_file == + +== Comments.file description impl == map:cfdi, shortcut:c, start, noindent == /* * ===================================================================================== * @@ -50,9 +60,8 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * * ===================================================================================== */ -#include -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-description-header == start == + +== Comments.file description header == map:cfdh, shortcut:h, start, noindent == /* * ===================================================================================== * @@ -70,110 +79,82 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * * ===================================================================================== */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-header-includes == -/* ##### HEADER FILE INCLUDES ################################################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-macros == -/* ##### MACROS - LOCAL TO THIS SOURCE FILE ################################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-typedefs == -/* ##### TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-data-types == -/* ##### DATA TYPES - LOCAL TO THIS SOURCE FILE ############################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-class-defs == -/* ##### CLASS DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################## */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-local-variables == -/* ##### VARIABLES - LOCAL TO THIS SOURCE FILE ################################ */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-prototypes == -/* ##### PROTOTYPES - LOCAL TO THIS SOURCE FILE ############################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-function-defs-exported == -/* ##### FUNCTION DEFINITIONS - EXPORTED FUNCTIONS ############################ */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-function-defs-local == -/* ##### FUNCTION DEFINITIONS - LOCAL TO THIS SOURCE FILE ##################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-class-implementations-exported == -/* ##### CLASS IMPLEMENTATIONS - EXPORTED CLASSES ############################# */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-class-implementations-local == -/* ##### CLASS IMPLEMENTATIONS - LOCAL CLASSES ################################ */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-header-includes == -/* ##### HEADER FILE INCLUDES ################################################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-macros == -/* ##### EXPORTED MACROS ######################################################## */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-typedefs == -/* ##### EXPORTED TYPE DEFINITIONS ############################################## */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-data-types == -/* ##### EXPORTED DATA TYPES #################################################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-class-defs == -/* ##### EXPORTED CLASS DEFINITIONS ############################################# */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-variables == -/* ##### EXPORTED VARIABLES ##################################################### */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-function-declarations == -/* ##### EXPORTED FUNCTION DECLARATIONS ######################################### */ +== ENDTEMPLATE == + +== LIST: comments_c_sections == hash == + 'HEADER FILE INCLUDES' : 'HEADER FILE INCLUDES ###############################', + 'LOCAL MACROS' : 'MACROS - LOCAL TO THIS SOURCE FILE ###############', + 'LOCAL TYPE DEFINITIONS' : 'TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE #####', + 'LOCAL DATA TYPES' : 'DATA TYPES - LOCAL TO THIS SOURCE FILE ###########', + 'LOCAL VARIABLES' : 'VARIABLES - LOCAL TO THIS SOURCE FILE ############', + 'LOCAL PROTOTYPES' : 'PROTOTYPES - LOCAL TO THIS SOURCE FILE ###########', + 'EXP. FUNCTION DEFINITIONS' : 'FUNCTION DEFINITIONS - EXPORTED FUNCTIONS ########', + 'LOCAL FUNCTION DEFINITIONS' : 'FUNCTION DEFINITIONS - LOCAL TO THIS SOURCE FILE #', + 'LOCAL CLASS DEFINITIONS' : 'CLASS DEFINITIONS - LOCAL TO THIS SOURCE FILE ####', + 'EXP. CLASS IMPLEMENTATIONS' : 'CLASS IMPLEMENTATIONS - EXPORTED CLASSES #########', + 'LOCAL CLASS IMPLEMENTATIONS' : 'CLASS IMPLEMENTATIONS - LOCAL CLASSES ############', +== LIST: comments_h_sections == hash == + 'HEADER FILE INCLUDES' : 'HEADER FILE INCLUDES ###########', + 'EXPORTED MACROS' : 'EXPORTED MACROS ################', + 'EXPORTED TYPE DEFINITIONS' : 'EXPORTED TYPE DEFINITIONS ######', + 'EXPORTED DATA TYPES' : 'EXPORTED DATA TYPES ############', + 'EXPORTED CLASS DEFINITIONS' : 'EXPORTED CLASS DEFINITIONS #####', + 'EXPORTED VARIABLES' : 'EXPORTED VARIABLES #############', + 'EXPORTED FUNCTION DECLARATIONS' : 'EXPORTED FUNCTION DECLARATIONS #', +== LIST: comments_keywords == hash == + 'BUG' : ':BUG:|DATE| |TIME|:|AUTHORREF|:', + 'COMPILER' : ':COMPILER:|DATE| |TIME|:|AUTHORREF|:', + 'REMARK' : ':REMARK:|DATE| |TIME|:|AUTHORREF|:', + 'TODO' : ':TODO:|DATE| |TIME|:|AUTHORREF|:', + 'WARNING' : ':WARNING:|DATE| |TIME|:|AUTHORREF|:', + 'WORKAROUND' : ':WORKAROUND:|DATE| |TIME|:|AUTHORREF|:', + 'new keyword' : ':{+NEW_KEYWORD+}:|DATE| |TIME|:|AUTHORREF|:', +== LIST: comments_special == list == + 'EMPTY' , + 'FALL THROUGH' , + 'IMPLICIT TYPE CONVERSION' , + 'NO RETURN' , + 'NOT REACHED' , + 'TO BE IMPLEMENTED' , + 'constant type is long' , + 'constant type is unsigned' , + 'constant type is unsigned long', +== LIST: comments_macros == list == + 'AUTHOR' , + 'AUTHORREF' , + 'COMPANY' , + 'COPYRIGHT' , + 'EMAIL' , + 'ORGANIZATION', +== ENDLIST == + +== Comments.C file sections == expandmenu, append, map:ccs, shortcut:s == +|PickList( 'C file sections', 'comments_c_sections' )| +/* ##### |PICK|#################### */ +== Comments.H file sections == expandmenu, append, map:chs, shortcut:s == +|PickList( 'H file sections', 'comments_h_sections' )| +/* ##### |PICK|######################################## */ +== ENDTEMPLATE == + +§ ------------------------------------------------------------- +§ keywords, special and macros +§ date and time +§ ------------------------------------------------------------- + +== SEP: Comments.sep_develop == + +== Comments.keyword comments == expandmenu, append, map:ckc, shortcut:k == +|PickList( 'keyword comments', 'comments_keywords' )| + /* |PICK| */ +== Comments.special comments == expandmenu, append, map:csc, shortcut:s == +|PickList( 'special comments', 'comments_special' )| + /* |PICK| */ +== Comments.macros == expandmenu, insert, map:cma, shortcut:m == +|PickList( 'macro', 'comments_macros' )| +||PICK|| +== Comments.date == insert, map:cd, shortcut:d == +|DATE| +== Comments.date time == insert, map:ct, shortcut:t == +|DATE| |TIME| +== ENDTEMPLATE == -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.keyword-bug == append == - /* :BUG:|DATE| |TIME|:|AUTHORREF|: */ -== comment.keyword-compiler == append == - /* :COMPILER:|DATE| |TIME|:|AUTHORREF|: */ -== comment.keyword-todo == append == - /* :TODO:|DATE| |TIME|:|AUTHORREF|: */ -== comment.keyword-tricky == append == - /* :TRICKY:|DATE| |TIME|:|AUTHORREF|: */ -== comment.keyword-warning == append == - /* :WARNING:|DATE| |TIME|:|AUTHORREF|: */ -== comment.keyword-workaround == append == - /* :WORKAROUND:|DATE| |TIME|:|AUTHORREF|: */ -== comment.keyword-keyword == append == - /* :|?KEYWORD:u|:|DATE| |TIME|:|AUTHORREF|: */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.special-empty == append == - /* EMPTY */ -== comment.special-fall-through == append == - /* FALL THROUGH */ -== comment.special-implicit-type-conversion == append == - /* IMPLICIT TYPE CONVERSION */ -== comment.special-no-return == append == - /* NO RETURN */ -== comment.special-not-reached == append == - /* NOT REACHED */ -== comment.special-remains-to-be-implemented == append == - /* REMAINS TO BE IMPLEMENTED */ -== comment.special-constant-type-is-long == append == - /* constant type is long */ -== comment.special-constant-type-is-unsigned == append == - /* constant type is unsigned */ -== comment.special-constant-type-is-unsigned-long == append == - /* constant type is unsigned long */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/c-support/templates/c.cpp.template b/c-support/templates/c.cpp.template index 40fb829..fa3c978 100644 --- a/c-support/templates/c.cpp.template +++ b/c-support/templates/c.cpp.template @@ -1,92 +1,157 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -$ -== cpp.cin == -cin >> ; -$ -== cpp.cout == insert == -cout << << endl; -$ -== cpp.cout-operator == insert == -<< "" -$ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.output-manipulator-boolalpha == insert == -<< boolalpha -== cpp.output-manipulator-dec == insert == -<< dec -== cpp.output-manipulator-endl == insert == -<< endl -== cpp.output-manipulator-fixed == insert == -<< fixed -== cpp.output-manipulator-flush == insert == -<< flush -== cpp.output-manipulator-hex == insert == -<< hex -== cpp.output-manipulator-internal == insert == -<< internal -== cpp.output-manipulator-left == insert == -<< left -== cpp.output-manipulator-oct == insert == -<< oct -== cpp.output-manipulator-right == insert == -<< right -== cpp.output-manipulator-scientific == insert == -<< scientific -== cpp.output-manipulator-setbase == insert == -<< setbase(10) -== cpp.output-manipulator-setfill == insert == -<< setfill() -== cpp.output-manipulator-setiosflag == insert == -<< setiosflags() -== cpp.output-manipulator-setprecision == insert == -<< setprecision(6) -== cpp.output-manipulator-setw == insert == -<< setw(0) -== cpp.output-manipulator-showbase == insert == -<< showbase -== cpp.output-manipulator-showpoint == insert == -<< showpoint -== cpp.output-manipulator-showpos == insert == -<< showpos -== cpp.output-manipulator-uppercase == insert == -<< uppercase -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.method-implementation == -void -|?CLASSNAME|::|?METHODNAME| ( <+argument list+> ) -{ - return ; -} /* ----- end of method |CLASSNAME|::|?METHODNAME| ----- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.accessor-implementation == -/* - *-------------------------------------------------------------------------------------- - * Class: |?CLASSNAME| - * Method: get_|?ATTRIBUTE| - *-------------------------------------------------------------------------------------- - */ -inline |?RETURNTYPE| -|CLASSNAME|::get_|ATTRIBUTE| ( ) const -{ - return |ATTRIBUTE|; -} /* ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- */ - -/* - *-------------------------------------------------------------------------------------- - * Class: |CLASSNAME| - * Method: set_|ATTRIBUTE| - *-------------------------------------------------------------------------------------- - */ -inline void -|CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) -{ - |ATTRIBUTE| = value; - return ; -} /* ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-definition == +== LIST: output_manipulators == hash == + 'boolalpha' : 'boolalpha' , + 'dec' : 'dec' , + 'defaultfloat' : 'defaultfloat' , + 'endl' : 'endl' , + 'ends' : 'ends' , + 'fixed' : 'fixed' , + 'flush' : 'flush' , + 'get_money' : 'get_money' , + 'get_time' : 'get_time' , + 'hexfloat' : 'hexfloat' , + 'hex' : 'hex' , + 'internal' : 'internal' , + 'left' : 'left' , + 'oct' : 'oct' , + 'put_money' : 'put_money' , + 'put_time' : 'put_time' , + 'resetiosflag' : 'resetiosflag' , + 'right' : 'right' , + 'scientific' : 'scientific' , + 'setbase' : 'setbase(10)' , + 'setfill' : 'setfill()' , + 'setiosflags' : 'setiosflags()' , + 'setprecision' : 'setprecision(6)', + 'setw' : 'setw(0)' , + 'showbase' : 'showbase' , + 'showpoint' : 'showpoint' , + 'showpos' : 'showpos' , + 'skipws' : 'skipws' , + 'unitbuf' : 'unitbuf' , + 'uppercase' : 'uppercase' , + 'ws' : 'ws' , +== ENDLIST == + +== LIST: ios_flagbits == list == + 'adjustfield', + 'basefield' , + 'boolalpha' , + 'dec' , + 'fixed' , + 'floatfield' , + 'hex' , + 'internal' , + 'left' , + 'oct' , + 'right' , + 'scientific' , + 'showbase' , + 'showpoint' , + 'showpos' , + 'skipws' , + 'unitbuf' , + 'uppercase' , +== ENDLIST == + +== LIST: include == list == + 'algorithm' , + 'array' , + 'atomic' , + 'bitset' , + 'chrono' , + 'codecvt' , + 'complex' , + 'condition_variable' , + 'deque' , + 'exception' , + 'forward_list' , + 'fstream' , + 'functional' , + 'future' , + 'initializer_list' , + 'iomanip' , + 'ios' , + 'iosfwd' , + 'iostream' , + 'istream' , + 'iterator' , + 'limits' , + 'list' , + 'locale' , + 'map' , + 'memory' , + 'mutex' , + 'new' , + 'numeric' , + 'ostream' , + 'queue' , + 'random' , + 'ratio' , + 'regex' , + 'set' , + 'sstream' , + 'stack' , + 'stdexcept' , + 'streambuf' , + 'string' , + 'strstream' , + 'system_error' , + 'thread' , + 'tuple' , + 'typeindex' , + 'typeinfo' , + 'type_traits' , + 'unordered_map', + 'unordered_set', + 'utility' , + 'valarray' , + 'vector' , +== ENDLIST == + +== LIST: c_include == list == + 'cassert' , + 'ccomplex' , + 'cctype' , + 'cerrno' , + 'cfenv' , + 'cfloat' , + 'cinttypes', + 'ciso646' , + 'climits' , + 'clocale' , + 'cmath' , + 'csetjmp' , + 'csignal' , + 'cstdalign', + 'cstdarg' , + 'cstdbool' , + 'cstddef' , + 'cstdint' , + 'cstdio' , + 'cstdlib' , + 'cstring' , + 'ctgmath' , + 'ctime' , + 'cuchar' , + 'cwchar' , + 'cwctype' , +== ENDLIST == + +== C++.include C++ std lib header == expandmenu, insert, map:+ih, shortcut:i == +|PickList( 'include', 'include' )| +#include <|PICK|> +== C++.include C std lib header == expandmenu, insert, map:+ich, shortcut:c == +|PickList( 'include C', 'c_include' )| +#include <|PICK|> +== C++.output manipulators == expandmenu, insert, map:+om, shortcut:m == +|PickList( 'output manipulators', 'output_manipulators' )| + << |PICK| +== C++.ios flagbits == expandmenu, insert, map:+fb, shortcut:i == +|PickList( 'ios flagbits', 'ios_flagbits' )| +ios::|PICK| +== ENDTEMPLATE == + +== C++.class == map:+c, shortcut:c == /* * ===================================================================================== * Class: |?CLASSNAME:c| @@ -106,28 +171,18 @@ class |CLASSNAME| /* ==================== OPERATORS ======================================= */ protected: + /* ==================== METHODS ======================================= */ + /* ==================== DATA MEMBERS ======================================= */ private: + /* ==================== METHODS ======================================= */ + /* ==================== DATA MEMBERS ======================================= */ }; /* ----- end of class |CLASSNAME| ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-implementation == -/* - *-------------------------------------------------------------------------------------- - * Class: |?CLASSNAME:c| - * Method: |CLASSNAME| - * Description: constructor - *-------------------------------------------------------------------------------------- - */ -|CLASSNAME|::|CLASSNAME| () -{ -} /* ----- end of method |CLASSNAME|::|CLASSNAME| (constructor) ----- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-using-new-definition == +== C++.class using new == map:+cn, shortcut:n == /* * ===================================================================================== * Class: |?CLASSNAME:c| @@ -151,15 +206,114 @@ class |CLASSNAME| |CLASSNAME|& operator = ( const |CLASSNAME| &other ); /* assignment operator */ protected: + /* ==================== METHODS ======================================= */ + /* ==================== DATA MEMBERS ======================================= */ private: + /* ==================== METHODS ======================================= */ + /* ==================== DATA MEMBERS ======================================= */ }; /* ----- end of class |CLASSNAME| ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-using-new-implementation == +== C++.template class == map:+tc, shortcut:t == +/* + * ===================================================================================== + * Class: |?CLASSNAME:c| + * Description: + * ===================================================================================== + */ +template < class T > +class |CLASSNAME| +{ + public: + /* ==================== LIFECYCLE ======================================= */ + |CLASSNAME| (); /* constructor */ + + /* ==================== ACCESSORS ======================================= */ + + /* ==================== MUTATORS ======================================= */ + + /* ==================== OPERATORS ======================================= */ + + protected: + /* ==================== METHODS ======================================= */ + + /* ==================== DATA MEMBERS ======================================= */ + + private: + /* ==================== METHODS ======================================= */ + + /* ==================== DATA MEMBERS ======================================= */ + +}; /* ---------- end of template class |CLASSNAME| ---------- */ + +== C++.template class using new == map:+tcn, shortcut:n == +/* + * ===================================================================================== + * Class: |?CLASSNAME:c| + * Description: + * ===================================================================================== + */ + +template < class T > +class |CLASSNAME| +{ + public: + // ==================== LIFECYCLE ======================================= + |CLASSNAME| (); /* constructor */ + |CLASSNAME| ( const |CLASSNAME| &other ); /* copy constructor */ + ~|CLASSNAME| (); /* destructor */ + + /* ==================== ACCESSORS ======================================= */ + + /* ==================== MUTATORS ======================================= */ + + /* ==================== OPERATORS ======================================= */ + + |CLASSNAME|& operator = ( const |CLASSNAME| &other ); // assignment operator + + protected: + /* ==================== METHODS ======================================= */ + + /* ==================== DATA MEMBERS ======================================= */ + + private: + /* ==================== METHODS ======================================= */ + + /* ==================== DATA MEMBERS ======================================= */ + +}; /* ----- end of template class |CLASSNAME| ----- */ + +== C++.error class == map:+ec, shortcut:e == +/* + * ===================================================================================== + * Class: |?CLASSNAME:c| + * Description: + * ===================================================================================== + */ +class |CLASSNAME| +{ + public: |CLASSNAME| ( string msg = "|CLASSNAME|" ):message(msg) { } + virtual ~|CLASSNAME| ( ) { } + virtual string what ( ) const throw ( ) { return message; } + protected: string message; +}; /* ----- end of class |CLASSNAME| ----- */ + +== C++.IMPLEMENTATION.class == map:+ic , shortcut:c == +/* + *-------------------------------------------------------------------------------------- + * Class: |?CLASSNAME:c| + * Method: |CLASSNAME| + * Description: constructor + *-------------------------------------------------------------------------------------- + */ +|CLASSNAME|::|CLASSNAME| () +{ +} /* ----- end of method |CLASSNAME|::|CLASSNAME| (constructor) ----- */ + +== C++.IMPLEMENTATION.class using new == map:+icn , shortcut:n == /* *-------------------------------------------------------------------------------------- * Class: |?CLASSNAME:c| @@ -208,43 +362,25 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% return *this; } /* ----- end of method |CLASSNAME|::operator = (assignment operator) ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.error-class == -/* - * ===================================================================================== - * Class: |?CLASSNAME:c| - * Description: - * ===================================================================================== - */ -class |CLASSNAME| -{ - public: |CLASSNAME| ( string msg = "|CLASSNAME|" ):message(msg) { } - virtual ~|CLASSNAME| ( ) { } - virtual string what ( ) const throw ( ) { return message; } - protected: string message; -}; /* ----- end of class |CLASSNAME| ----- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-method-implementation == -template < class T > -void |?CLASSNAME|::|?METHODNAME| ( <+argument list+> ) +== C++.IMPLEMENTATION.method == map:+im , shortcut:m == +void +|?CLASSNAME|::|?METHODNAME| ( <+argument_list+> ) { return ; -} /* ----- end of method |CLASSNAME|::|METHODNAME| ----- */ +} /* ----- end of method |CLASSNAME|::|?METHODNAME| ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-accessor-implementation == +== C++.IMPLEMENTATION.accessor == map:+ia , shortcut:a == /* *-------------------------------------------------------------------------------------- * Class: |?CLASSNAME| * Method: get_|?ATTRIBUTE| *-------------------------------------------------------------------------------------- */ -template < class T > -inline |?RETURNTYPE| |CLASSNAME|::get_|ATTRIBUTE| ( ) const +inline |?RETURNTYPE| +|CLASSNAME|::get_|ATTRIBUTE| ( ) const { return |ATTRIBUTE|; -} /* ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- */ +} /* ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- */ /* *-------------------------------------------------------------------------------------- @@ -252,44 +388,14 @@ inline |?RETURNTYPE| |CLASSNAME|::get_|ATTRIBUTE| ( ) const * Method: set_|ATTRIBUTE| *-------------------------------------------------------------------------------------- */ -template < class T > -inline void |CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) +inline void +|CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) { |ATTRIBUTE| = value; return ; -} /* ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-definition == -/* - * ===================================================================================== - * Class: |?CLASSNAME:c| - * Description: - * ===================================================================================== - */ -template < class T > -class |CLASSNAME| -{ - public: - /* ==================== LIFECYCLE ======================================= */ - |CLASSNAME| (); /* constructor */ - - /* ==================== ACCESSORS ======================================= */ - - /* ==================== MUTATORS ======================================= */ - - /* ==================== OPERATORS ======================================= */ - - protected: - /* ==================== DATA MEMBERS ======================================= */ - - private: - /* ==================== DATA MEMBERS ======================================= */ - -}; /* ---------- end of template class |CLASSNAME| ---------- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-implementation == +} /* ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- */ + +== C++.IMPLEMENTATION.template class == map:+itc , shortcut:c == /* *-------------------------------------------------------------------------------------- * Class: |?CLASSNAME:c| @@ -303,42 +409,7 @@ template < class T > } /* ---------- end of constructor of template class |CLASSNAME| ---------- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-using-new-definition == -/* - * ===================================================================================== - * Class: |?CLASSNAME:c| - * Description: - * ===================================================================================== - */ - -template < class T > -class |CLASSNAME| -{ - public: - // ==================== LIFECYCLE ======================================= - |CLASSNAME| (); /* constructor */ - |CLASSNAME| ( const |CLASSNAME| &other ); /* copy constructor */ - ~|CLASSNAME| (); /* destructor */ - - /* ==================== ACCESSORS ======================================= */ - - /* ==================== MUTATORS ======================================= */ - - /* ==================== OPERATORS ======================================= */ - - |CLASSNAME|& operator = ( const |CLASSNAME| &other ); // assignment operator - - protected: - /* ==================== DATA MEMBERS ======================================= */ - - private: - /* ==================== DATA MEMBERS ======================================= */ - -}; /* ----- end of template class |CLASSNAME| ----- */ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-using-new-implementation == +== C++.IMPLEMENTATION.template class using new == map:+itcn , shortcut:n == /* *-------------------------------------------------------------------------------------- * Class: |?CLASSNAME:c| @@ -388,31 +459,60 @@ template < class T > return *this; } /* ---------- end of assignment operator of template class |CLASSNAME| ---------- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-function == +== C++.IMPLEMENTATION.template method == map:+itm , shortcut:m == +template < class T > +void |?CLASSNAME|::|?METHODNAME| ( <+argument_list+> ) +{ + return ; +} /* ----- end of method |CLASSNAME|::|METHODNAME| ----- */ + +== C++.IMPLEMENTATION.template accessor == map:+ita , shortcut:a == +/* + *-------------------------------------------------------------------------------------- + * Class: |?CLASSNAME| + * Method: get_|?ATTRIBUTE| + *-------------------------------------------------------------------------------------- + */ +template < class T > +inline |?RETURNTYPE| |CLASSNAME|::get_|ATTRIBUTE| ( ) const +{ + return |ATTRIBUTE|; +} /* ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- */ + +/* + *-------------------------------------------------------------------------------------- + * Class: |CLASSNAME| + * Method: set_|ATTRIBUTE| + *-------------------------------------------------------------------------------------- + */ +template < class T > +inline void |CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) +{ + |ATTRIBUTE| = value; + return ; +} /* ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- */ + +== C++.template function == map:+tf, shortcut:f == template -void |?TEMPALTE_FUNCTION_NAME| ( <+argument list+> ) +void |?TEMPALTE_FUNCTION_NAME| ( <+argument_list+> ) { return ; } /* ----- end of template function |?TEMPALTE_FUNCTION_NAME| ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.operator-in == +== C++.IMPLEMENTATION.operator, out == map:+ioo, shortcut:o == ostream & -operator << ( ostream & os, const |?CLASSNAME| & obj ) +operator << ( ostream &os, const |?CLASSNAME| &obj ) { os << obj. ; return os; } /* ----- end of function operator << ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.operator-out == +== C++.IMPLEMENTATION.operator, in == map:+ioi, shortcut:i == istream & -operator >> ( istream & is, |?CLASSNAME| & obj ) +operator >> ( istream &is, |?CLASSNAME| &obj ) { is >> obj. ; return is; } /* ----- end of function operator >> ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.try-catch == +== C++.try catch == map:+tr, shortcut:t == try { } catch ( const &ExceptObj ) { /* handle exception: */ @@ -420,20 +520,16 @@ catch ( const &ExceptObj ) { /* handle exception: */ catch (...) { /* handle exception: unspecified */ } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.catch == +== C++.catch == map:+ca, shortcut:c == catch ( const &ExceptObj ) { /* handle exception: */ } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.catch-points == +== C++.catch all == map:+caa, shortcut:c == catch (...) { /* handle exception: unspecified */ } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.extern == +== C++.extern C == map:+ex, shortcut:x == extern "C" { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.open-input-file == +== C++.open input file == map:+oif, shortcut:o == string ifs_file_name = ""; /* input file name */ ifstream ifs; /* create ifstream object */ @@ -442,11 +538,10 @@ if (!ifs) { cerr << "\nERROR : failed to open input file " << ifs_file_name << endl; exit (EXIT_FAILURE); } -{-continue here-} +{-continue_here-} ifs.close (); /* close ifstream */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.open-output-file == -string ofs_file_name = ""; /* input file name */ +== C++.open output file == map:+oof, shortcut:o == +string ofs_file_name = ""; /* output file name */ ofstream ofs; /* create ofstream object */ ofs.open ( ofs_file_name.c_str() ); /* open ofstream */ @@ -454,31 +549,28 @@ if (!ofs) { cerr << "\nERROR : failed to open output file " << ofs_file_name << endl; exit (EXIT_FAILURE); } -{-continue here-} +{-continue_here-} ofs.close (); /* close ofstream */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.namespace-std == +== C++.using namespace std == map:+uns, shortcut:n == using namespace std; -== cpp.namespace == +== C++.using namespace xxx == map:+un, shortcut:n == using namespace |?NAMESPACE|; -== cpp.namespace-block == +== C++.namespace block xxx == map:+unb, shortcut:b == namespace |?NAMESPACE| { } /* ----- end of namespace |NAMESPACE| ----- */ -== cpp.namespace-alias == -namespace |?NAMESPACE_ALIAS| = {-original namespace name-}; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.rtti-typeid == insert == -typeid() -$ -== cpp.rtti-static-cast == insert == -static_cast<>() -$ -== cpp.rtti-const-cast == insert == -const_cast<>() -$ -== cpp.rtti-reinterpret-cast == insert == -reinterpret_cast<>() -$ -== cpp.rtti-dynamic-cast == insert == -dynamic_cast<>() -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== C++.namespace alias == map:+na, shortcut:a == +namespace |?NAMESPACE_ALIAS| = {-original_namespace_name-}; +== ENDTEMPLATE == + +== LIST: rtti == list == + 'const_cast' , + 'dynamic_cast' , + 'reinterpret_cast', + 'static_cast' , + 'typeid' , +== ENDLIST == + +== C++.RTTI == expandmenu, insert, map:+rt, shortcut:i == +|PickList( 'RTTI', 'rtti' )| +|PICK|<>() +== ENDTEMPLATE == diff --git a/c-support/templates/c.idioms.template b/c-support/templates/c.idioms.template index 1ae6940..73c8fd7 100644 --- a/c-support/templates/c.idioms.template +++ b/c-support/templates/c.idioms.template @@ -1,5 +1,4 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.function == +== Idioms.function == map:if, shortcut:f == /* * === FUNCTION ====================================================================== * Name: |?FUNCTION_NAME| @@ -7,12 +6,11 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * ===================================================================================== */ void -|FUNCTION_NAME| ( <+argument list+> ) +|FUNCTION_NAME| ( <+argument_list+> ) { - return <+return value+>; + return <+return_value+>; } /* ----- end of function |FUNCTION_NAME| ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.function-static == +== Idioms.function-static == map:isf, shortcut:t == /* * === FUNCTION ====================================================================== * Name: |?FUNCTION_NAME| @@ -20,12 +18,11 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * ===================================================================================== */ static void -|FUNCTION_NAME| ( <+argument list+> ) +|FUNCTION_NAME| ( <+argument_list+> ) { - return <+return value+>; + return <+return_value+>; } /* ----- end of static function |FUNCTION_NAME| ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.main == +== Idioms.main == map:im, shortcut:m == #include /* @@ -39,66 +36,57 @@ main ( int argc, char *argv[] ) { return EXIT_SUCCESS; } /* ---------- end of function main ---------- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.enum == +== Idioms.enum == map:ie, shortcut:e == enum |?ENUM_NAME| { }; /* ---------- end of enum |ENUM_NAME| ---------- */ typedef enum |ENUM_NAME| |ENUM_NAME:c|; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.struct == +== Idioms.struct == map:is, shortcut:s == struct |?STRUCT_NAME| { }; /* ---------- end of struct |STRUCT_NAME| ---------- */ typedef struct |STRUCT_NAME| |STRUCT_NAME:c|; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.union == +== Idioms.union == map:iu, shortcut:u == union |?UNION_NAME| { }; /* ---------- end of union |UNION_NAME| ---------- */ typedef union |UNION_NAME| |UNION_NAME:c|; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.printf == insert == -printf ( "\n" ); -== idioms.scanf == insert == +== Idioms.scanf == map:isc, shortcut:s, insert == scanf ( "", & ); -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.calloc == +== Idioms.printf == map:ipr, shortcut:p, insert == +printf ( "\n" ); +== Idioms.calloc == map:ica, shortcut:c == |?POINTER| = calloc ( (size_t)(<+COUNT+>), sizeof(<+TYPE+>) ); if ( |POINTER|==NULL ) { fprintf ( stderr, "\ndynamic memory allocation failed\n" ); exit (EXIT_FAILURE); } -free (|POINTER|); +free ( |POINTER| ); |POINTER| = NULL; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.malloc == +== Idioms.malloc == map:ima, shortcut:m == |?POINTER| = malloc ( sizeof(<+TYPE+>) ); if ( |POINTER|==NULL ) { fprintf ( stderr, "\ndynamic memory allocation failed\n" ); exit (EXIT_FAILURE); } -free (|POINTER|); +free ( |POINTER| ); |POINTER| = NULL; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.realloc == +== Idioms.realloc == map:ire, shortcut:r == |?POINTER| = realloc ( |POINTER|, sizeof(<+TYPE+>) ); if ( |POINTER|==NULL ) { fprintf ( stderr, "\ndynamic memory reallocation failed\n" ); exit (EXIT_FAILURE); } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.sizeof == insert == +== Idioms.sizeof == map:isi, shortcut:s, insert == sizeof() -== idioms.assert == insert == -assert(); -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.open-input-file == +== Idioms.assert == map:ias, shortcut:a, insert == +assert( ); +== Idioms.open-input-file == map:ii, shortcut:i == FILE *|?FILEPOINTER|; /* input-file pointer */ char *|FILEPOINTER|_file_name = ""; /* input-file name */ @@ -108,15 +96,14 @@ if ( |FILEPOINTER| == NULL ) { |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -{-continue here-} +{-continue_here-} if( fclose(|FILEPOINTER|) == EOF ) { /* close input file */ fprintf ( stderr, "couldn't close file '%s'; %s\n", |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.open-output-file == +== Idioms.open-output-file == map:io, shortcut:o == FILE *|?FILEPOINTER|; /* output-file pointer */ char *|FILEPOINTER|_file_name = ""; /* output-file name */ @@ -126,16 +113,14 @@ if ( |FILEPOINTER| == NULL ) { |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -{-continue here-} +{-continue_here-} if( fclose(|FILEPOINTER|) == EOF ) { /* close output file */ fprintf ( stderr, "couldn't close file '%s'; %s\n", |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.fprintf == insert == +== Idioms.fprintf == map:ifpr, shortcut:f, insert == fprintf ( |?FILEPOINTER|, "\n", ); -== idioms.fscanf == insert == +== Idioms.fscanf == map:ifsc, shortcut:f, insert == fscanf ( |?FILEPOINTER|, "", & ); -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/c-support/templates/c.preprocessor.template b/c-support/templates/c.preprocessor.template index 27c6356..ef170bd 100644 --- a/c-support/templates/c.preprocessor.template +++ b/c-support/templates/c.preprocessor.template @@ -1,54 +1,94 @@ -$------------------------------------------------------------------------- -== preprocessor.include-global == insert == +== LIST: C_StandardLibs == list == + 'assert.h' , + 'complex.h' , + 'ctype.h' , + 'errno.h' , + 'fenv.h' , + 'float.h' , + 'inttypes.h' , + 'iso646.h' , + 'limits.h' , + 'locale.h' , + 'math.h' , + 'setjmp.h' , + 'signal.h' , + 'stdalign.h' , + 'stdarg.h' , + 'stdatomic.h' , + 'stdbool.h' , + 'stddef.h' , + 'stdint.h' , + 'stdio.h' , + 'stdlib.h' , + 'stdnoreturn.h', + 'string.h' , + 'tgmath.h' , + 'threads.h' , + 'time.h' , + 'uchar.h' , + 'wchar.h' , + 'wctype.h' , +== ENDLIST == + +== Preprocessor.include std lib header == expandmenu, append, map:pih, shortcut:s == +|PickList( 'Std. Libs', 'C_StandardLibs' )| +#include <|PICK|> +== ENDTEMPLATE == + +§------------------------------------------------------------------------- +== Preprocessor.include-global == map:pg, shortcut:g, insert == #include <> -$------------------------------------------------------------------------- -== preprocessor.include-local == insert == +§------------------------------------------------------------------------- +== Preprocessor.include-local == map:pl, shortcut:l, insert == #include "" -$------------------------------------------------------------------------- -== preprocessor.define == insert == +§------------------------------------------------------------------------- +== Preprocessor.define == map:pd, shortcut:d, insert == #define /* */ -$------------------------------------------------------------------------- -== preprocessor.undefine == insert == +§------------------------------------------------------------------------- +== Preprocessor.undefine == map:pu, shortcut:u, insert == #undef /* */ -$------------------------------------------------------------------------- -== preprocessor.if-endif == +§------------------------------------------------------------------------- +== Preprocessor.if-endif == map:pif, shortcut:i == #if |?CONDITION:u| #endif /* ----- |CONDITION| ----- */ -$------------------------------------------------------------------------- -== preprocessor.if-else-endif == +§------------------------------------------------------------------------- +== Preprocessor.if-else-endif == map:pie, shortcut:i == #if |?CONDITION:u| #else /* ----- not |CONDITION| ----- */ <+ELSE PART+> #endif /* ----- not |CONDITION| ----- */ -$------------------------------------------------------------------------- -== preprocessor.ifdef-else-endif == +§------------------------------------------------------------------------- +== Preprocessor.ifdef-else-endif == map:pid, shortcut:f == #ifdef |?CONDITION:u| #else /* ----- not |CONDITION| ----- */ <+ELSE PART+> #endif /* ----- not |CONDITION| ----- */ -$------------------------------------------------------------------------- -== preprocessor.ifndef-else-endif == +§------------------------------------------------------------------------- +== Preprocessor.ifndef-else-endif == map:pin, shortcut:n == #ifndef |?CONDITION:u| #else /* ----- not |CONDITION| ----- */ <+ELSE PART+> #endif /* ----- not |CONDITION| ----- */ -$------------------------------------------------------------------------- -== preprocessor.ifndef-def-endif == +§------------------------------------------------------------------------- +== Preprocessor.ifndef-def-endif == map:pind, shortcut:e == #ifndef |?BASENAME:L|_INC #define |BASENAME|_INC #endif /* ----- #ifndef |BASENAME|_INC ----- */ -$------------------------------------------------------------------------- -== preprocessor.error == +§------------------------------------------------------------------------- +== Preprocessor.error == map:pe, shortcut:o == #error "" /* */ -$------------------------------------------------------------------------- -== preprocessor.line == +§------------------------------------------------------------------------- +== Preprocessor.line == map:pli, shortcut:l == #line /* */ -$------------------------------------------------------------------------- -== preprocessor.pragma == +§------------------------------------------------------------------------- +== Preprocessor.pragma == map:pp, shortcut:p == #pragma /* */ -$------------------------------------------------------------------------- +§------------------------------------------------------------------------- +== Preprocessor.warning == map:pw, shortcut:w == +#warning /* */ +§------------------------------------------------------------------------- diff --git a/c-support/templates/c.statements.template b/c-support/templates/c.statements.template index 574366d..6bebd8e 100644 --- a/c-support/templates/c.statements.template +++ b/c-support/templates/c.statements.template @@ -1,48 +1,46 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.do-while == +== Statements.do while == map:sd, shortcut:d == do { } while ( ); /* ----- end do-while ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.for == +== Statements.for == map:sf, shortcut:o == for ( ; ; ) -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.for-block == -for ( ; ; ) { +§ +§ The names INIT, CONDITION, INCREMENT, and 'for block' are used by the main +§ plugin plugin/c.vim . Please do not change. +§ +== Statements.for block == map:sfo, shortcut:r == +|DefaultMacro( 'CONDITION', '{+CONDITION+}' )| +|DefaultMacro( 'INCREMENT', '{+INCREMENT+}' )| +for ( |INIT|; |CONDITION|; |INCREMENT| ) { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if == +== Statements.range-based for == map:sfr, shortcut:a == +for ( : <-EXPRESSION-> ){ +} +== Statements.if == map:si, shortcut:i == if ( ) -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if-block == +== Statements.if block == map:sif, shortcut:f == if ( ) { -<-IF PART-> +<-IF_PART-> } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if-else == +== Statements.if else == map:sie, shortcut:e == if ( ) else -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if-block-else == +== Statements.if block else == map:sife, shortcut:l == if ( ) { -<-IF PART-> +<-IF_PART-> } else { -<-ELSE PART-> +<-ELSE_PART-> } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.else-block == +== Statements.else block == map:se, shortcut:e == else { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.while == +== Statements.while == map:sw, shortcut:w == while ( ) -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.while-block == +== Statements.while block == map:swh, shortcut:h == while ( ) { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.switch == +== Statements.switch == map:ss, shortcut:s == switch ( ) { case <-LABEL->: break; @@ -56,14 +54,11 @@ switch ( ) { default: break; } /* ----- end switch ----- */ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.case == +== Statements.case == map:sc, shortcut:c == case : break; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.block == +== Statements.block == map:sb, shortcut:b == { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/c-support/templates/cpp.comments.template b/c-support/templates/cpp.comments.template index 5cb19db..2ee8386 100644 --- a/c-support/templates/cpp.comments.template +++ b/c-support/templates/cpp.comments.template @@ -1,168 +1,148 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.end-of-line-comment == append == +§ ============================================================= +§ Comments +§ ============================================================= + +§ ------------------------------------------------------------- +§ frames, descriptions +§ ------------------------------------------------------------- + +== Comments.end-of-line-comment == append, nomenu == // -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.frame == -//---------------------------------------------------------------------- +== Comments.frame == map:cfr, shortcut:f == +//----------------------------------------------------------------------------- // -//---------------------------------------------------------------------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.function == +//----------------------------------------------------------------------------- +== Comments.function == map:cfu, shortcut:f == // === FUNCTION ====================================================================== // Name: |?FUNCTION_NAME| // Description: // ===================================================================================== -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.method == +== Comments.method == map:cme, shortcut:m == //-------------------------------------------------------------------------------------- // Class: |?CLASSNAME| -// Method: |?METHODNAME| +// Method: |?CLASSNAME| :: |?METHODNAME| // Description: //-------------------------------------------------------------------------------------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.class == +== Comments.class == map:ccl, shortcut:c == // ===================================================================================== // Class: |?CLASSNAME| // Description: // ===================================================================================== -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-description == start == +== ENDTEMPLATE == + +§ ------------------------------------------------------------- +§ files, sections +§ ------------------------------------------------------------- + +== SEP: Comments.sep_file == + +== Comments.file description impl == map:cfdi, shortcut:c, start, noindent == // ===================================================================================== -// +// // Filename: |FILENAME| -// +// // Description: -// +// // Version: 1.0 // Created: |DATE| |TIME| // Revision: none // Compiler: g++ -// +// // Author: |AUTHOR| (|AUTHORREF|), |EMAIL| -// Company: |ORGANIZATION| -// +// Organization: |ORGANIZATION| +// // ===================================================================================== -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-description-header == start == +== Comments.file description header == map:cfdh, shortcut:h, start, noindent == // ===================================================================================== -// +// // Filename: |FILENAME| -// +// // Description: -// +// // Version: 1.0 // Created: |DATE| |TIME| // Revision: none // Compiler: g++ -// +// // Author: |AUTHOR| (|AUTHORREF|), |EMAIL| -// Company: |ORGANIZATION| -// +// Organization: |ORGANIZATION| +// // ===================================================================================== -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-header-includes == -// ##### HEADER FILE INCLUDES ################################################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-macros == -// ##### MACROS - LOCAL TO THIS SOURCE FILE ################################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-typedefs == -// ##### TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-data-types == -// ##### DATA TYPES - LOCAL TO THIS SOURCE FILE ############################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-class-defs == -// ##### CLASS DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################## - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-local-variables == -// ##### VARIABLES - LOCAL TO THIS SOURCE FILE ################################ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-prototypes == -// ##### PROTOTYPES - LOCAL TO THIS SOURCE FILE ############################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-function-defs-exported == -// ##### FUNCTION DEFINITIONS - EXPORTED FUNCTIONS ############################ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-function-defs-local == -// ##### FUNCTION DEFINITIONS - LOCAL TO THIS SOURCE FILE ##################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-class-implementations-exported == -// ##### CLASS IMPLEMENTATIONS - EXPORTED CLASSES ############################# - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-cpp-class-implementations-local == -// ##### CLASS IMPLEMENTATIONS - LOCAL CLASSES ################################ - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-header-includes == -// ##### HEADER FILE INCLUDES ################################################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-macros == -// ##### EXPORTED MACROS ######################################################## - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-typedefs == -// ##### EXPORTED TYPE DEFINITIONS ############################################## - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-data-types == -// ##### EXPORTED DATA TYPES #################################################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-class-defs == -// ##### EXPORTED CLASS DEFINITIONS ############################################# - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-variables == -// ##### EXPORTED VARIABLES ##################################################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.file-section-hpp-exported-function-declarations == -// ##### EXPORTED FUNCTION DECLARATIONS ######################################### - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.keyword-bug == append == - // :BUG:|DATE| |TIME|:|AUTHORREF|: -== comment.keyword-compiler == append == - // :COMPILER:|DATE| |TIME|:|AUTHORREF|: -== comment.keyword-todo == append == - // :TODO:|DATE| |TIME|:|AUTHORREF|: -== comment.keyword-tricky == append == - // :TRICKY:|DATE| |TIME|:|AUTHORREF|: -== comment.keyword-warning == append == - // :WARNING:|DATE| |TIME|:|AUTHORREF|: -== comment.keyword-workaround == append == - // :WORKAROUND:|DATE| |TIME|:|AUTHORREF|: -== comment.keyword-keyword == append == - // :|?KEYWORD:u|:|DATE| |TIME|:|AUTHORREF|: -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== comment.special-empty == append == - // EMPTY -== comment.special-fall-through == append == - // FALL THROUGH -== comment.special-implicit-type-conversion == append == - // IMPLICIT TYPE CONVERSION -== comment.special-no-return == append == - // NO RETURN -== comment.special-not-reached == append == - // NOT REACHED -== comment.special-remains-to-be-implemented == append == - // REMAINS TO BE IMPLEMENTED -== comment.special-constant-type-is-long == append == - // constant type is long -== comment.special-constant-type-is-unsigned == append == - // constant type is unsigned -== comment.special-constant-type-is-unsigned-long == append == - // constant type is unsigned long -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== ENDTEMPLATE == + +== LIST: comments_c_sections == hash == + 'HEADER FILE INCLUDES' : 'HEADER FILE INCLUDES ###############################', + 'LOCAL MACROS' : 'MACROS - LOCAL TO THIS SOURCE FILE ###############', + 'LOCAL TYPE DEFINITIONS' : 'TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE #####', + 'LOCAL DATA TYPES' : 'DATA TYPES - LOCAL TO THIS SOURCE FILE ###########', + 'LOCAL VARIABLES' : 'VARIABLES - LOCAL TO THIS SOURCE FILE ############', + 'LOCAL PROTOTYPES' : 'PROTOTYPES - LOCAL TO THIS SOURCE FILE ###########', + 'EXP. FUNCTION DEFINITIONS' : 'FUNCTION DEFINITIONS - EXPORTED FUNCTIONS ########', + 'LOCAL FUNCTION DEFINITIONS' : 'FUNCTION DEFINITIONS - LOCAL TO THIS SOURCE FILE #', + 'LOCAL CLASS DEFINITIONS' : 'CLASS DEFINITIONS - LOCAL TO THIS SOURCE FILE ####', + 'EXP. CLASS IMPLEMENTATIONS' : 'CLASS IMPLEMENTATIONS - EXPORTED CLASSES #########', + 'LOCAL CLASS IMPLEMENTATIONS' : 'CLASS IMPLEMENTATIONS - LOCAL CLASSES ############', +== LIST: comments_h_sections == hash == + 'HEADER FILE INCLUDES' : 'HEADER FILE INCLUDES ###########', + 'EXPORTED MACROS' : 'EXPORTED MACROS ################', + 'EXPORTED TYPE DEFINITIONS' : 'EXPORTED TYPE DEFINITIONS ######', + 'EXPORTED DATA TYPES' : 'EXPORTED DATA TYPES ############', + 'EXPORTED CLASS DEFINITIONS' : 'EXPORTED CLASS DEFINITIONS #####', + 'EXPORTED VARIABLES' : 'EXPORTED VARIABLES #############', + 'EXPORTED FUNCTION DECLARATIONS' : 'EXPORTED FUNCTION DECLARATIONS #', +== LIST: comments_keywords == hash == + 'BUG' : ':BUG:|DATE| |TIME|:|AUTHORREF|:', + 'COMPILER' : ':COMPILER:|DATE| |TIME|:|AUTHORREF|:', + 'REMARK' : ':REMARK:|DATE| |TIME|:|AUTHORREF|:', + 'TODO' : ':TODO:|DATE| |TIME|:|AUTHORREF|:', + 'WARNING' : ':WARNING:|DATE| |TIME|:|AUTHORREF|:', + 'WORKAROUND' : ':WORKAROUND:|DATE| |TIME|:|AUTHORREF|:', + 'new keyword' : ':{+NEW_KEYWORD+}:|DATE| |TIME|:|AUTHORREF|:', +== LIST: comments_special == list == + 'EMPTY' , + 'FALL THROUGH' , + 'IMPLICIT TYPE CONVERSION' , + 'NO RETURN' , + 'NOT REACHED' , + 'TO BE IMPLEMENTED' , + 'constant type is long' , + 'constant type is unsigned' , + 'constant type is unsigned long', +== LIST: comments_macros == list == + 'AUTHOR' , + 'AUTHORREF' , + 'COMPANY' , + 'COPYRIGHT' , + 'EMAIL' , + 'ORGANIZATION', +== ENDLIST == + +== Comments.C file sections == expandmenu, append, map:ccs, shortcut:s == +|PickList( 'C file sections', 'comments_c_sections' )| +// ##### |PICK|#################### +== Comments.H file sections == expandmenu, append, map:chs, shortcut:s == +|PickList( 'H file sections', 'comments_h_sections' )| +// ##### |PICK|######################################## +== ENDTEMPLATE == + +§ ------------------------------------------------------------- +§ keywords, special and macros +§ date and time +§ ------------------------------------------------------------- + +== SEP: Comments.sep_develop == + +== Comments.keyword comments == expandmenu, append, map:ckc, shortcut:k == +|PickList( 'keyword comments', 'comments_keywords' )| + // |PICK| +== Comments.special comments == expandmenu, append, map:csc, shortcut:s == +|PickList( 'special comments', 'comments_special' )| + // |PICK| +== Comments.macros == expandmenu, insert, map:cma, shortcut:m == +|PickList( 'macro', 'comments_macros' )| +||PICK|| +== Comments.date == insert, map:cd, shortcut:d == +|DATE| +== Comments.date time == insert, map:ct, shortcut:t == +|DATE| |TIME| +== ENDTEMPLATE == diff --git a/c-support/templates/cpp.cpp.template b/c-support/templates/cpp.cpp.template index ddcaada..c9fd2fe 100644 --- a/c-support/templates/cpp.cpp.template +++ b/c-support/templates/cpp.cpp.template @@ -1,163 +1,315 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -$ -== cpp.cin == -cin >> ; -$ -== cpp.cout == insert == -cout << << endl; -$ -== cpp.cout-operator == insert == -<< "" -$ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.output-manipulator-boolalpha == insert == -<< boolalpha -== cpp.output-manipulator-dec == insert == -<< dec -== cpp.output-manipulator-endl == insert == -<< endl -== cpp.output-manipulator-fixed == insert == -<< fixed -== cpp.output-manipulator-flush == insert == -<< flush -== cpp.output-manipulator-hex == insert == -<< hex -== cpp.output-manipulator-internal == insert == -<< internal -== cpp.output-manipulator-left == insert == -<< left -== cpp.output-manipulator-oct == insert == -<< oct -== cpp.output-manipulator-right == insert == -<< right -== cpp.output-manipulator-scientific == insert == -<< scientific -== cpp.output-manipulator-setbase == insert == -<< setbase(10) -== cpp.output-manipulator-setfill == insert == -<< setfill() -== cpp.output-manipulator-setiosflag == insert == -<< setiosflags() -== cpp.output-manipulator-setprecision == insert == -<< setprecision(6) -== cpp.output-manipulator-setw == insert == -<< setw(0) -== cpp.output-manipulator-showbase == insert == -<< showbase -== cpp.output-manipulator-showpoint == insert == -<< showpoint -== cpp.output-manipulator-showpos == insert == -<< showpos -== cpp.output-manipulator-uppercase == insert == -<< uppercase -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.method-implementation == -void -|?CLASSNAME|::|?METHODNAME| ( <+argument list+> ) +== LIST: output_manipulators == hash == + 'boolalpha' : 'boolalpha' , + 'dec' : 'dec' , + 'defaultfloat' : 'defaultfloat' , + 'endl' : 'endl' , + 'ends' : 'ends' , + 'fixed' : 'fixed' , + 'flush' : 'flush' , + 'get_money' : 'get_money' , + 'get_time' : 'get_time' , + 'hexfloat' : 'hexfloat' , + 'hex' : 'hex' , + 'internal' : 'internal' , + 'left' : 'left' , + 'oct' : 'oct' , + 'put_money' : 'put_money' , + 'put_time' : 'put_time' , + 'resetiosflag' : 'resetiosflag' , + 'right' : 'right' , + 'scientific' : 'scientific' , + 'setbase' : 'setbase(10)' , + 'setfill' : 'setfill()' , + 'setiosflags' : 'setiosflags()' , + 'setprecision' : 'setprecision(6)', + 'setw' : 'setw(0)' , + 'showbase' : 'showbase' , + 'showpoint' : 'showpoint' , + 'showpos' : 'showpos' , + 'skipws' : 'skipws' , + 'unitbuf' : 'unitbuf' , + 'uppercase' : 'uppercase' , + 'ws' : 'ws' , +== ENDLIST == + +== LIST: ios_flagbits == list == + 'adjustfield', + 'basefield' , + 'boolalpha' , + 'dec' , + 'fixed' , + 'floatfield' , + 'hex' , + 'internal' , + 'left' , + 'oct' , + 'right' , + 'scientific' , + 'showbase' , + 'showpoint' , + 'showpos' , + 'skipws' , + 'unitbuf' , + 'uppercase' , +== ENDLIST == + +== LIST: include == list == + 'algorithm' , + 'array' , + 'atomic' , + 'bitset' , + 'chrono' , + 'codecvt' , + 'complex' , + 'condition_variable' , + 'deque' , + 'exception' , + 'forward_list' , + 'fstream' , + 'functional' , + 'future' , + 'initializer_list' , + 'iomanip' , + 'ios' , + 'iosfwd' , + 'iostream' , + 'istream' , + 'iterator' , + 'limits' , + 'list' , + 'locale' , + 'map' , + 'memory' , + 'mutex' , + 'new' , + 'numeric' , + 'ostream' , + 'queue' , + 'random' , + 'ratio' , + 'regex' , + 'set' , + 'sstream' , + 'stack' , + 'stdexcept' , + 'streambuf' , + 'string' , + 'strstream' , + 'system_error' , + 'thread' , + 'tuple' , + 'typeindex' , + 'typeinfo' , + 'type_traits' , + 'unordered_map', + 'unordered_set', + 'utility' , + 'valarray' , + 'vector' , +== ENDLIST == + +== LIST: c_include == list == + 'cassert' , + 'ccomplex' , + 'cctype' , + 'cerrno' , + 'cfenv' , + 'cfloat' , + 'cinttypes', + 'ciso646' , + 'climits' , + 'clocale' , + 'cmath' , + 'csetjmp' , + 'csignal' , + 'cstdalign', + 'cstdarg' , + 'cstdbool' , + 'cstddef' , + 'cstdint' , + 'cstdio' , + 'cstdlib' , + 'cstring' , + 'ctgmath' , + 'ctime' , + 'cuchar' , + 'cwchar' , + 'cwctype' , +== ENDLIST == + +== C++.include C++ std lib header == expandmenu, insert, map:+ih, shortcut:i == +|PickList( 'include', 'include' )| +#include <|PICK|> +== C++.include C std lib header == expandmenu, insert, map:+ich, shortcut:c == +|PickList( 'include C', 'c_include' )| +#include <|PICK|> +== C++.output manipulators == expandmenu, insert, map:+om, shortcut:m == +|PickList( 'output manipulators', 'output_manipulators' )| + << |PICK| +== C++.ios flagbits == expandmenu, insert, map:+fb, shortcut:i == +|PickList( 'ios flagbits', 'ios_flagbits' )| +ios::|PICK| +== ENDTEMPLATE == + +== C++.class == map:+c, shortcut:c == +// ===================================================================================== +// Class: |?CLASSNAME:c| +// Description: +// ===================================================================================== +class |CLASSNAME| { - return ; -} // ----- end of method |CLASSNAME|::|METHODNAME| ----- + public: + // ==================== LIFECYCLE ======================================= + |CLASSNAME| (); // constructor -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.accessor-implementation == -//-------------------------------------------------------------------------------------- -// Class: |?CLASSNAME| -// Method: get_|?ATTRIBUTE| -//-------------------------------------------------------------------------------------- -inline |?RETURNTYPE| -|CLASSNAME|::get_|ATTRIBUTE| ( ) const -{ - return |ATTRIBUTE|; -} // ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- + // ==================== ACCESSORS ======================================= -//-------------------------------------------------------------------------------------- -// Class: |CLASSNAME| -// Method: set_|ATTRIBUTE| -//-------------------------------------------------------------------------------------- -inline void -|CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) + // ==================== MUTATORS ======================================= + + // ==================== OPERATORS ======================================= + + protected: + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= + + private: + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= + +}; // ----- end of class |CLASSNAME| ----- + +== C++.class using new == map:+cn, shortcut:n == +// ===================================================================================== +// Class: |?CLASSNAME:c| +// Description: +// ===================================================================================== +class |CLASSNAME| { - |ATTRIBUTE| = value; - return ; -} // ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-definition == + public: + // ==================== LIFECYCLE ======================================= + |CLASSNAME| (); // constructor + |CLASSNAME| ( const |CLASSNAME| &other ); // copy constructor + ~|CLASSNAME| (); // destructor + + // ==================== ACCESSORS ======================================= + + // ==================== MUTATORS ======================================= + + // ==================== OPERATORS ======================================= + + |CLASSNAME|& operator = ( const |CLASSNAME| &other ); // assignment operator + + protected: + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= + + private: + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= + +}; // ----- end of class |CLASSNAME| ----- + +== C++.template class == map:+tc, shortcut:t == // ===================================================================================== // Class: |?CLASSNAME:c| // Description: // ===================================================================================== +template < class T > class |CLASSNAME| { public: - // ==================== LIFECYCLE ======================================= - |CLASSNAME| (); // constructor + // ==================== LIFECYCLE ======================================= + |CLASSNAME| (); // constructor - // ==================== ACCESSORS ======================================= + // ==================== ACCESSORS ======================================= - // ==================== MUTATORS ======================================= + // ==================== MUTATORS ======================================= - // ==================== OPERATORS ======================================= + // ==================== OPERATORS ======================================= protected: - // ==================== DATA MEMBERS ======================================= + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= private: - // ==================== DATA MEMBERS ======================================= + // ==================== METHODS ======================================= -}; // ----- end of class |CLASSNAME| ----- + // ==================== DATA MEMBERS ======================================= -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-implementation == -//-------------------------------------------------------------------------------------- -// Class: |?CLASSNAME| -// Method: |CLASSNAME| -// Description: constructor -//-------------------------------------------------------------------------------------- -|CLASSNAME|::|CLASSNAME| () -{ -} // ----- end of method |CLASSNAME|::|CLASSNAME| (constructor) ----- +}; // ---------- end of template class |CLASSNAME| ---------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-using-new-definition == +== C++.template class using new == map:+tcn, shortcut:n == // ===================================================================================== // Class: |?CLASSNAME:c| // Description: // ===================================================================================== + +template < class T > class |CLASSNAME| { public: // ==================== LIFECYCLE ======================================= - |CLASSNAME| (); // constructor - |CLASSNAME| ( const |CLASSNAME| &other ); // copy constructor - ~|CLASSNAME| (); // destructor + |CLASSNAME| (); // constructor + |CLASSNAME| ( const |CLASSNAME| &other ); // copy constructor + ~|CLASSNAME| (); // destructor - // ==================== ACCESSORS ======================================= + // ==================== ACCESSORS ======================================= - // ==================== MUTATORS ======================================= + // ==================== MUTATORS ======================================= - // ==================== OPERATORS ======================================= + // ==================== OPERATORS ======================================= - |CLASSNAME|& operator = ( const |CLASSNAME| &other ); // assignment operator + |CLASSNAME|& operator = ( const |CLASSNAME| &other ); // assignment operator protected: - // ==================== DATA MEMBERS ======================================= + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= private: - // ==================== DATA MEMBERS ======================================= + // ==================== METHODS ======================================= + + // ==================== DATA MEMBERS ======================================= -}; // ----- end of class |CLASSNAME| ----- +}; // ----- end of template class |CLASSNAME| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.class-using-new-implementation == +== C++.error class == map:+ec, shortcut:e == +// ===================================================================================== +// Class: |?CLASSNAME:c| +// Description: +// ===================================================================================== +class |CLASSNAME| +{ + public: |CLASSNAME| ( string msg = "|CLASSNAME|" ):message(msg) { } + virtual ~|CLASSNAME| ( ) { } + virtual string what ( ) const throw ( ) { return message; } + protected: string message; +}; // ----- end of class |CLASSNAME| ----- + +== C++.IMPLEMENTATION.class == map:+ic , shortcut:c == //-------------------------------------------------------------------------------------- -// Class: |?CLASSNAME| +// Class: |?CLASSNAME:c| // Method: |CLASSNAME| // Description: constructor //-------------------------------------------------------------------------------------- |CLASSNAME|::|CLASSNAME| () { -} // ----- end of method |CLASSNAME|::|CLASSNAME| (constructor) ----- +} // ----- end of method |CLASSNAME|::|CLASSNAME| (constructor) ----- + +== C++.IMPLEMENTATION.class using new == map:+icn , shortcut:n == +//-------------------------------------------------------------------------------------- +// Class: |?CLASSNAME:c| +// Method: |CLASSNAME| +// Description: constructor +//-------------------------------------------------------------------------------------- +|CLASSNAME|::|CLASSNAME| () +{ +} // ----- end of method |CLASSNAME|::|CLASSNAME| (constructor) ----- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| @@ -166,7 +318,7 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //-------------------------------------------------------------------------------------- |CLASSNAME|::|CLASSNAME| ( const |CLASSNAME| &other ) { -} // ----- end of method |CLASSNAME|::|CLASSNAME| (copy constructor) ----- +} // ----- end of method |CLASSNAME|::|CLASSNAME| (copy constructor) ----- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| @@ -175,7 +327,7 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //-------------------------------------------------------------------------------------- |CLASSNAME|::~|CLASSNAME| () { -} // ----- end of method |CLASSNAME|::~|CLASSNAME| (destructor) ----- +} // ----- end of method |CLASSNAME|::~|CLASSNAME| (destructor) ----- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| @@ -188,135 +340,59 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if ( this != &other ) { } return *this; -} // ----- end of method |CLASSNAME|::operator = (assignment operator) ----- +} // ----- end of method |CLASSNAME|::operator = (assignment operator) ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.error-class == -// ===================================================================================== -// Class: |?CLASSNAME:c| -// Description: -// ===================================================================================== -class |CLASSNAME| -{ - public: |CLASSNAME| ( string msg = "|CLASSNAME|" ):message(msg) { } - virtual ~|CLASSNAME| ( ) { } - virtual string what ( ) const throw ( ) { return message; } - protected: string message; -}; // ---------- end of class |CLASSNAME| ---------- - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-method-implementation == -template < class T > -void |?CLASSNAME|::|?METHODNAME| ( <+argument list+> ) +== C++.IMPLEMENTATION.method == map:+im , shortcut:m == +void +|?CLASSNAME|::|?METHODNAME| ( <+argument_list+> ) { return ; -} // ----- end of method |CLASSNAME|::|METHODNAME| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-accessor-implementation == +} // ----- end of method |CLASSNAME|::|?METHODNAME| ----- + +== C++.IMPLEMENTATION.accessor == map:+ia , shortcut:a == //-------------------------------------------------------------------------------------- // Class: |?CLASSNAME| // Method: get_|?ATTRIBUTE| //-------------------------------------------------------------------------------------- -template < class T > -inline |?RETURNTYPE| |CLASSNAME|::get_|ATTRIBUTE| ( ) const +inline |?RETURNTYPE| +|CLASSNAME|::get_|ATTRIBUTE| ( ) const { return |ATTRIBUTE|; -} // ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- +} // ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| // Method: set_|ATTRIBUTE| //-------------------------------------------------------------------------------------- -template < class T > -inline void |CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) +inline void +|CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) { |ATTRIBUTE| = value; return ; -} // ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- +} // ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-definition == -// ===================================================================================== -// Class: |?CLASSNAME:c| -// Description: -// ===================================================================================== - -template < class T > -class |CLASSNAME| -{ - public: - // ==================== LIFECYCLE ======================================= - |CLASSNAME| (); // constructor - - // ==================== ACCESSORS ======================================= - - // ==================== MUTATORS ======================================= - - // ==================== OPERATORS ======================================= - - protected: - // ==================== DATA MEMBERS ======================================= - - private: - // ==================== DATA MEMBERS ======================================= - -}; // ----- end of template class |CLASSNAME| ----- - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-implementation == +== C++.IMPLEMENTATION.template class == map:+itc , shortcut:c == //-------------------------------------------------------------------------------------- -// Class: |?CLASSNAME| +// Class: |?CLASSNAME:c| // Method: |CLASSNAME| -// Description: constructor +// Description: //-------------------------------------------------------------------------------------- template < class T > -|CLASSNAME| :: |CLASSNAME| () +|CLASSNAME| < T >::|CLASSNAME| () { -} // ----- end of constructor of template class |CLASSNAME| ----- +} // ---------- end of constructor of template class |CLASSNAME| ---------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-using-new-definition == -// ===================================================================================== -// Class: |?CLASSNAME:c| -// Description: -// ===================================================================================== -template < class T > -class |CLASSNAME| -{ - public: - // ==================== LIFECYCLE ======================================= - |CLASSNAME| (); // constructor - |CLASSNAME| ( const |CLASSNAME| &other ); // copy constructor - ~|CLASSNAME| (); // destructor - - // ==================== ACCESSORS ======================================= - - // ==================== MUTATORS ======================================= - - // ==================== OPERATORS ======================================= - - |CLASSNAME|& operator = ( const |CLASSNAME| &other ); // assignment operator - - protected: - // ==================== DATA MEMBERS ======================================= - - private: - // ==================== DATA MEMBERS ======================================= - -}; // ----- end of template class |CLASSNAME| ----- - -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-class-using-new-implementation == +== C++.IMPLEMENTATION.template class using new == map:+itcn , shortcut:n == //-------------------------------------------------------------------------------------- -// Class: |?CLASSNAME| +// Class: |?CLASSNAME:c| // Method: |CLASSNAME| // Description: constructor //-------------------------------------------------------------------------------------- template < class T > -|CLASSNAME|::|CLASSNAME| () -{ -} // ----- end of constructor of template class |CLASSNAME| ----- +|CLASSNAME|< T >::|CLASSNAME| () +{ +} // ---------- end of constructor of template class |CLASSNAME| ---------- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| @@ -324,9 +400,9 @@ template < class T > // Description: copy constructor //-------------------------------------------------------------------------------------- template < class T > -|CLASSNAME|::|CLASSNAME| ( const |CLASSNAME| &other ) -{ -} // ----- end of copy constructor of template class |CLASSNAME| ----- +|CLASSNAME|< T >::|CLASSNAME| ( const |CLASSNAME| &other ) +{ +} // ---------- end of copy constructor of template class |CLASSNAME| ---------- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| @@ -334,9 +410,9 @@ template < class T > // Description: destructor //-------------------------------------------------------------------------------------- template < class T > -|CLASSNAME|::~|CLASSNAME| () +|CLASSNAME|< T >::~|CLASSNAME| () { -} // ----- end of destructor of template class |CLASSNAME| ----- +} // ---------- end of destructor of template class |CLASSNAME| ---------- //-------------------------------------------------------------------------------------- // Class: |CLASSNAME| @@ -344,104 +420,119 @@ template < class T > // Description: assignment operator //-------------------------------------------------------------------------------------- template < class T > -|CLASSNAME|& |CLASSNAME|::operator = ( const |CLASSNAME| &other ) +|CLASSNAME|< T >& |CLASSNAME|< T >::operator = ( const |CLASSNAME| &other ) { - if ( this != &other ) { - } return *this; -} // ----- end of assignment operator of template class |CLASSNAME| ----- +} // ---------- end of assignment operator of template class |CLASSNAME| ---------- + +== C++.IMPLEMENTATION.template method == map:+itm , shortcut:m == +template < class T > +void |?CLASSNAME|::|?METHODNAME| ( <+argument_list+> ) +{ + return ; +} // ----- end of method |CLASSNAME|::|METHODNAME| ----- + +== C++.IMPLEMENTATION.template accessor == map:+ita , shortcut:a == +//-------------------------------------------------------------------------------------- +// Class: |?CLASSNAME| +// Method: get_|?ATTRIBUTE| +//-------------------------------------------------------------------------------------- +template < class T > +inline |?RETURNTYPE| |CLASSNAME|::get_|ATTRIBUTE| ( ) const +{ + return |ATTRIBUTE|; +} // ----- end of method |CLASSNAME|::get_|ATTRIBUTE| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.template-function == +//-------------------------------------------------------------------------------------- +// Class: |CLASSNAME| +// Method: set_|ATTRIBUTE| +//-------------------------------------------------------------------------------------- +template < class T > +inline void |CLASSNAME|::set_|ATTRIBUTE| ( |RETURNTYPE| value ) +{ + |ATTRIBUTE| = value; + return ; +} // ----- end of method |CLASSNAME|::set_|ATTRIBUTE| ----- + +== C++.template function == map:+tf, shortcut:f == template -void |?TEMPALTE_FUNCTION_NAME| ( <+argument list+> ) +void |?TEMPALTE_FUNCTION_NAME| ( <+argument_list+> ) { return ; -} // ----- end of template function |?TEMPALTE_FUNCTION_NAME| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.operator-in == +} // ----- end of template function |?TEMPALTE_FUNCTION_NAME| ----- +== C++.IMPLEMENTATION.operator, out == map:+ioo, shortcut:o == ostream & -operator << ( ostream & os, const |?CLASSNAME| & obj ) +operator << ( ostream &os, const |?CLASSNAME| &obj ) { os << obj. ; return os; -} // ----- end of function operator << ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.operator-out == +} // ----- end of function operator << ----- +== C++.IMPLEMENTATION.operator, in == map:+ioi, shortcut:i == istream & -operator >> ( istream & is, |?CLASSNAME| & obj ) +operator >> ( istream &is, |?CLASSNAME| &obj ) { is >> obj. ; return is; -} // ----- end of function operator >> ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.try-catch == +} // ----- end of function operator >> ----- +== C++.try catch == map:+tr, shortcut:t == try { } -catch ( const &ExceptObj ) { // handle exception: +catch ( const &ExceptObj ) { // handle exception: } -catch (...) { // handle exception: unspecified +catch (...) { // handle exception: unspecified } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.catch == -catch ( const &ExceptObj ) { // handle exception: +== C++.catch == map:+ca, shortcut:c == +catch ( const &ExceptObj ) { // handle exception: } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.catch-points == -catch (...) { // handle exception: unspecified +== C++.catch all == map:+caa, shortcut:c == +catch (...) { // handle exception: unspecified } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.extern == +== C++.extern C == map:+ex, shortcut:x == extern "C" { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.open-input-file == -string ifs_file_name = ""; // input file name -ifstream ifs; // create ifstream object +== C++.open input file == map:+oif, shortcut:o == +string ifs_file_name = ""; // input file name +ifstream ifs; // create ifstream object -ifs.open ( ifs_file_name.c_str() ); // open ifstream +ifs.open ( ifs_file_name.c_str() ); // open ifstream if (!ifs) { cerr << "\nERROR : failed to open input file " << ifs_file_name << endl; exit (EXIT_FAILURE); } -{-continue here-} -ifs.close (); // close ifstream -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.open-output-file == -string ofs_file_name = ""; // input file name -ofstream ofs; // create ofstream object - -ofs.open ( ofs_file_name.c_str() ); // open ofstream +{-continue_here-} +ifs.close (); // close ifstream +== C++.open output file == map:+oof, shortcut:o == +string ofs_file_name = ""; // output file name +ofstream ofs; // create ofstream object + +ofs.open ( ofs_file_name.c_str() ); // open ofstream if (!ofs) { cerr << "\nERROR : failed to open output file " << ofs_file_name << endl; exit (EXIT_FAILURE); } -{-continue here-} -ofs.close (); // close ofstream -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.namespace-std == +{-continue_here-} +ofs.close (); // close ofstream +== C++.using namespace std == map:+uns, shortcut:n == using namespace std; -== cpp.namespace == +== C++.using namespace xxx == map:+un, shortcut:n == using namespace |?NAMESPACE|; -== cpp.namespace-block == +== C++.namespace block xxx == map:+unb, shortcut:b == namespace |?NAMESPACE| { -} // ----- end of namespace |NAMESPACE| ----- -== cpp.namespace-alias == -namespace |?NAMESPACE_ALIAS| = {-original namespace name-}; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== cpp.rtti-typeid == insert == -typeid() -$ -== cpp.rtti-static-cast == insert == -static_cast<>() -$ -== cpp.rtti-const-cast == insert == -const_cast<>() -$ -== cpp.rtti-reinterpret-cast == insert == -reinterpret_cast<>() -$ -== cpp.rtti-dynamic-cast == insert == -dynamic_cast<>() -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +} // ----- end of namespace |NAMESPACE| ----- +== C++.namespace alias == map:+na, shortcut:a == +namespace |?NAMESPACE_ALIAS| = {-original_namespace_name-}; +== ENDTEMPLATE == + +== LIST: rtti == list == + 'const_cast' , + 'dynamic_cast' , + 'reinterpret_cast', + 'static_cast' , + 'typeid' , +== ENDLIST == + +== C++.RTTI == expandmenu, insert, map:+rt, shortcut:i == +|PickList( 'RTTI', 'rtti' )| +|PICK|<>() +== ENDTEMPLATE == diff --git a/c-support/templates/cpp.idioms.template b/c-support/templates/cpp.idioms.template index 911592d..7f5f163 100644 --- a/c-support/templates/cpp.idioms.template +++ b/c-support/templates/cpp.idioms.template @@ -1,80 +1,80 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.function == +== Idioms.function == map:if, shortcut:f == +// === FUNCTION ====================================================================== +// Name: |?FUNCTION_NAME| +// Description: +// ===================================================================================== void -|?FUNCTION_NAME| ( <+argument list+> ) +|FUNCTION_NAME| ( <+argument_list+> ) { - return <+return value+>; + return <+return_value+>; } // ----- end of function |FUNCTION_NAME| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.function-static == +== Idioms.function-static == map:isf, shortcut:t == +// === FUNCTION ====================================================================== +// Name: |?FUNCTION_NAME| +// Description: +// ===================================================================================== static void -|?FUNCTION_NAME| ( <+argument list+> ) +|FUNCTION_NAME| ( <+argument_list+> ) { - return <+return value+>; + return <+return_value+>; } // ----- end of static function |FUNCTION_NAME| ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.main == -#include +== Idioms.main == map:im, shortcut:m == +#include +// === FUNCTION ====================================================================== +// Name: main +// Description: +// ===================================================================================== int main ( int argc, char *argv[] ) { return EXIT_SUCCESS; } // ---------- end of function main ---------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.enum == +== Idioms.enum == map:ie, shortcut:e == enum |?ENUM_NAME| { }; // ---------- end of enum |ENUM_NAME| ---------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.struct == +== Idioms.struct == map:is, shortcut:s == struct |?STRUCT_NAME| { }; // ---------- end of struct |STRUCT_NAME| ---------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.union == +== Idioms.union == map:iu, shortcut:u == union |?UNION_NAME| { }; // ---------- end of union |UNION_NAME| ---------- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.printf == insert == -printf ( "\n" ); -== idioms.scanf == insert == +== Idioms.scanf == map:isc, shortcut:s, insert == scanf ( "", & ); -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.calloc == +== Idioms.printf == map:ipr, shortcut:p, insert == +printf ( "\n" ); +== Idioms.calloc == map:ica, shortcut:c == |?POINTER| = calloc ( (size_t)(<+COUNT+>), sizeof(<+TYPE+>) ); if ( |POINTER|==NULL ) { fprintf ( stderr, "\ndynamic memory allocation failed\n" ); exit (EXIT_FAILURE); } -free (|POINTER|); +free ( |POINTER| ); |POINTER| = NULL; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.malloc == +== Idioms.malloc == map:ima, shortcut:m == |?POINTER| = malloc ( sizeof(<+TYPE+>) ); if ( |POINTER|==NULL ) { fprintf ( stderr, "\ndynamic memory allocation failed\n" ); exit (EXIT_FAILURE); } -free (|POINTER|); +free ( |POINTER| ); |POINTER| = NULL; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.realloc == +== Idioms.realloc == map:ire, shortcut:r == |?POINTER| = realloc ( |POINTER|, sizeof(<+TYPE+>) ); if ( |POINTER|==NULL ) { fprintf ( stderr, "\ndynamic memory reallocation failed\n" ); exit (EXIT_FAILURE); } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.sizeof == insert == +== Idioms.sizeof == map:isi, shortcut:s, insert == sizeof() -== idioms.assert == insert == -assert(); -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.open-input-file == +== Idioms.assert == map:ias, shortcut:a, insert == +assert( ); +== Idioms.open-input-file == map:ii, shortcut:i == FILE *|?FILEPOINTER|; // input-file pointer char *|FILEPOINTER|_file_name = ""; // input-file name @@ -84,15 +84,14 @@ if ( |FILEPOINTER| == NULL ) { |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -{-continue here-} +{-continue_here-} if( fclose(|FILEPOINTER|) == EOF ) { // close input file fprintf ( stderr, "couldn't close file '%s'; %s\n", |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.open-output-file == +== Idioms.open-output-file == map:io, shortcut:o == FILE *|?FILEPOINTER|; // output-file pointer char *|FILEPOINTER|_file_name = ""; // output-file name @@ -102,16 +101,15 @@ if ( |FILEPOINTER| == NULL ) { |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -{-continue here-} +{-continue_here-} if( fclose(|FILEPOINTER|) == EOF ) { // close output file fprintf ( stderr, "couldn't close file '%s'; %s\n", |FILEPOINTER|_file_name, strerror(errno) ); exit (EXIT_FAILURE); } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== idioms.fprintf == insert == +== Idioms.fprintf == map:ifpr, shortcut:f, insert == fprintf ( |?FILEPOINTER|, "\n", ); -== idioms.fscanf == insert == +== Idioms.fscanf == map:ifsc, shortcut:f, insert == fscanf ( |?FILEPOINTER|, "", & ); -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + diff --git a/c-support/templates/cpp.preprocessor.template b/c-support/templates/cpp.preprocessor.template index 8aba79d..82ba13f 100644 --- a/c-support/templates/cpp.preprocessor.template +++ b/c-support/templates/cpp.preprocessor.template @@ -1,54 +1,94 @@ -$------------------------------------------------------------------------- -== preprocessor.include-global == +== LIST: C_StandardLibs == list == + 'assert.h' , + 'complex.h' , + 'ctype.h' , + 'errno.h' , + 'fenv.h' , + 'float.h' , + 'inttypes.h' , + 'iso646.h' , + 'limits.h' , + 'locale.h' , + 'math.h' , + 'setjmp.h' , + 'signal.h' , + 'stdalign.h' , + 'stdarg.h' , + 'stdatomic.h' , + 'stdbool.h' , + 'stddef.h' , + 'stdint.h' , + 'stdio.h' , + 'stdlib.h' , + 'stdnoreturn.h', + 'string.h' , + 'tgmath.h' , + 'threads.h' , + 'time.h' , + 'uchar.h' , + 'wchar.h' , + 'wctype.h' , +== ENDLIST == + +== Preprocessor.include std lib header == expandmenu, append, map:pih, shortcut:s == +|PickList( 'Std. Libs', 'C_StandardLibs' )| +#include <|PICK|> +== ENDTEMPLATE == + +§------------------------------------------------------------------------- +== Preprocessor.include-global == map:pg, shortcut:g, insert == #include <> -$------------------------------------------------------------------------- -== preprocessor.include-local == +§------------------------------------------------------------------------- +== Preprocessor.include-local == map:pl, shortcut:l, insert == #include "" -$------------------------------------------------------------------------- -== preprocessor.define == -#define // -$------------------------------------------------------------------------- -== preprocessor.undefine == -#undef // -$------------------------------------------------------------------------- -== preprocessor.if-endif == +§------------------------------------------------------------------------- +== Preprocessor.define == map:pd, shortcut:d, insert == +#define // +§------------------------------------------------------------------------- +== Preprocessor.undefine == map:pu, shortcut:u, insert == +#undef // +§------------------------------------------------------------------------- +== Preprocessor.if-endif == map:pif, shortcut:i == #if |?CONDITION:u| -#endif // ----- |CONDITION| ----- -$------------------------------------------------------------------------- -== preprocessor.if-else-endif == +#endif // ----- |CONDITION| ----- +§------------------------------------------------------------------------- +== Preprocessor.if-else-endif == map:pie, shortcut:i == #if |?CONDITION:u| -#else // ----- not |CONDITION| ----- +#else // ----- not |CONDITION| ----- <+ELSE PART+> -#endif // ----- not |CONDITION| ----- -$------------------------------------------------------------------------- -== preprocessor.ifdef-else-endif == +#endif // ----- not |CONDITION| ----- +§------------------------------------------------------------------------- +== Preprocessor.ifdef-else-endif == map:pid, shortcut:f == #ifdef |?CONDITION:u| -#else // ----- not |CONDITION| ----- +#else // ----- not |CONDITION| ----- <+ELSE PART+> -#endif // ----- not |CONDITION| ----- -$------------------------------------------------------------------------- -== preprocessor.ifndef-else-endif == +#endif // ----- not |CONDITION| ----- +§------------------------------------------------------------------------- +== Preprocessor.ifndef-else-endif == map:pin, shortcut:n == #ifndef |?CONDITION:u| -#else // ----- not |CONDITION| ----- +#else // ----- not |CONDITION| ----- <+ELSE PART+> -#endif // ----- not |CONDITION| ----- -$------------------------------------------------------------------------- -== preprocessor.ifndef-def-endif == +#endif // ----- not |CONDITION| ----- +§------------------------------------------------------------------------- +== Preprocessor.ifndef-def-endif == map:pind, shortcut:e == #ifndef |?BASENAME:L|_INC #define |BASENAME|_INC -#endif // ----- #ifndef |BASENAME|_INC ----- -$------------------------------------------------------------------------- -== preprocessor.error == -#error "" // -$------------------------------------------------------------------------- -== preprocessor.line == -#line // -$------------------------------------------------------------------------- -== preprocessor.pragma == -#pragma // -$------------------------------------------------------------------------- +#endif // ----- #ifndef |BASENAME|_INC ----- +§------------------------------------------------------------------------- +== Preprocessor.error == map:pe, shortcut:o == +#error "" // +§------------------------------------------------------------------------- +== Preprocessor.line == map:pli, shortcut:l == +#line // +§------------------------------------------------------------------------- +== Preprocessor.pragma == map:pp, shortcut:p == +#pragma // +§------------------------------------------------------------------------- +== Preprocessor.warning == map:pw, shortcut:w == +#warning /* */ +§------------------------------------------------------------------------- diff --git a/c-support/templates/cpp.statements.template b/c-support/templates/cpp.statements.template index c2fdecb..04a79ac 100644 --- a/c-support/templates/cpp.statements.template +++ b/c-support/templates/cpp.statements.template @@ -1,72 +1,65 @@ -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.do-while == +== Statements.do while == map:sd, shortcut:d == do { -} while ( ); // ----- end do-while ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.for == +} while ( ); // ----- end do-while ----- +== Statements.for == map:sf, shortcut:o == for ( ; ; ) -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.for-block == -for ( ; ; ) { +§ +§ The names INIT, CONDITION, INCREMENT, and 'for block' are used by the main +§ plugin plugin/c.vim . Please do not change. +§ +== Statements.for block == map:sfo, shortcut:r == +|DefaultMacro( 'CONDITION', '{+CONDITION+}' )| +|DefaultMacro( 'INCREMENT', '{+INCREMENT+}' )| +for ( |INIT|; |CONDITION|; |INCREMENT| ) { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if == +== Statements.range-based for == map:sfr, shortcut:a == +for ( : <-EXPRESSION-> ){ +} +== Statements.if == map:si, shortcut:i == if ( ) -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if-block == +== Statements.if block == map:sif, shortcut:f == if ( ) { -<-IF PART-> +<-IF_PART-> } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if-else == +== Statements.if else == map:sie, shortcut:e == if ( ) else -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.if-block-else == +== Statements.if block else == map:sife, shortcut:l == if ( ) { -<-IF PART-> +<-IF_PART-> } else { -<+ELSE PART+> +<-ELSE_PART-> } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.else-block == +== Statements.else block == map:se, shortcut:e == else { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.while == +== Statements.while == map:sw, shortcut:w == while ( ) -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.while-block == +== Statements.while block == map:swh, shortcut:h == while ( ) { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.switch == +== Statements.switch == map:ss, shortcut:s == switch ( ) { - case 1: + case <-LABEL->: break; - case 2: - break; - - case 3: + case <-LABEL->: break; - case 4: + case <-LABEL->: break; default: break; -} // ----- end switch ----- -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.case == +} // ----- end switch ----- +== Statements.case == map:sc, shortcut:c == case : break; -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -== statements.block == +== Statements.block == map:sb, shortcut:b == { } -$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + diff --git a/c-support/templates/doxygen.template b/c-support/templates/doxygen.template new file mode 100644 index 0000000..db909f8 --- /dev/null +++ b/c-support/templates/doxygen.template @@ -0,0 +1,425 @@ +§ ============================================================= +§ Doxygen Comments +§ - the templates in the "Comments" menu are created for the +§ style "Doxygen" +§ - the templates in the "Doxygen" menu are created for the +§ style "default", so that they work for every style +§ ============================================================= + +== USE STYLES: Doxygen == + +§ ------------------------------------------------------------- +§ frames, descriptions +§ ------------------------------------------------------------- + +§ The template "Comments.end-of-line-comment" is used for the menu entry +§ "Comments.end-of-line comment", which is created by the plug-in itself. +§ Do not change the name! + +== Comments.end-of-line-comment == append, nomenu == +// +== ENDTEMPLATE == + +== Comments.frame == map:cfr, shortcut:f == +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +== Comments.function == map:cfu, shortcut:f == +/*! + * |DOX_CMD|brief |DESCRIPTION| + * + * |DOX_CMD|param <+NAME+> <+DESCRIPTION+> + * |DOX_CMD|return <+DESCRIPTION+> + * <+DETAILED+> + */ +== Comments.method == map:cme, shortcut:m == +/*! + * |DOX_CMD|brief |DESCRIPTION| + * + * |DOX_CMD|param <+NAME+> <+DESCRIPTION+> + * |DOX_CMD|return <+DESCRIPTION+> + * <+DETAILED+> + */ +== Comments.class == map:ccl, shortcut:c == +/*! + * |DOX_CMD|brief |DESCRIPTION| + * + * <+DETAILED+> + */ +== ENDTEMPLATE == + +§ ------------------------------------------------------------- +§ files, sections +§ ------------------------------------------------------------- + +== SEP: Comments.sep_file == + +== Comments.file description impl == map:cfdi, shortcut:c, start, noindent == +/*! + * |DOX_CMD|file |FILENAME| + * |DOX_CMD|brief |DESCRIPTION| + * + * <+DETAILED+> + * + * |DOX_CMD|author |AUTHOR| (|AUTHORREF|), |EMAIL| + * + * |DOX_CMD|internal + * Created: |DATE| + * Revision: none + * Compiler: gcc + * Organization: |ORGANIZATION| + * Copyright: |COPYRIGHT| + * + * This source code is released for free distribution under the terms of the + * GNU General Public License as published by the Free Software Foundation. + */ + +== Comments.file description header == map:cfdh, shortcut:h, start, noindent == +/*! + * |DOX_CMD|file |FILENAME| + * |DOX_CMD|brief |DESCRIPTION| + * + * <+DETAILED+> + * + * |DOX_CMD|author |AUTHOR| (|AUTHORREF|), |EMAIL| + * + * |DOX_CMD|internal + * Created: |DATE| + * Revision: none + * Compiler: gcc + * Organization: |ORGANIZATION| + * Copyright: |COPYRIGHT| + * + * This source code is released for free distribution under the terms of the + * GNU General Public License as published by the Free Software Foundation. + */ + +== Comments.C file sections == expandmenu, append, map:ccs, shortcut:s == +|PickList( 'C file sections', 'comments_c_sections' )| +/* ##### |PICK|#################### */ +== Comments.H file sections == expandmenu, append, map:chs, shortcut:s == +|PickList( 'H file sections', 'comments_h_sections' )| +/* ##### |PICK|######################################## */ +== ENDTEMPLATE == + +§ ------------------------------------------------------------- +§ keywords, special and macros +§ ------------------------------------------------------------- + +== SEP: Comments.sep_develop == + +== Comments.keyword comments == expandmenu, append, map:ckc, shortcut:k == +|PickList( 'keyword comments', 'comments_keywords' )| + // |PICK| +== Comments.special comments == expandmenu, append, map:csc, shortcut:s == +|PickList( 'special comments', 'comments_special' )| + // |PICK| +== Comments.macros == expandmenu, insert, map:cma, shortcut:m == +|PickList( 'macro', 'comments_macros' )| +||PICK|| +== Comments.date == insert, map:cd, shortcut:d == +|DATE| +== Comments.date time == insert, map:ct, shortcut:t == +|DATE| |TIME| +== ENDTEMPLATE == + +== ENDSTYLES == + +§ ------------------------------------------------------------- +§ special Doxygen sub-menu +§ ------------------------------------------------------------- + +== USE STYLES: default == + +§ missing: +§ - name + +== LIST: doxygen_command == list, bare == +a +addindex +addtogroup +anchor +arg +attention +author +authors +b +brief +bug +c +callgraph +callergraph +category +cite +class +code +cond +copybrief +copydetails +copydoc +copyright +date +def +defgroup +deprecated +details +dir +docbookonly +dontinclude +dot +dotfile +e +else +elseif +em +endcode +endcond +enddocbookonly +enddot +endhtmlonly +endif +endinternal +endlatexonly +endlink +endmanonly +endmsc +endrtfonly +endsecreflist +endverbatim +endxmlonly +enum +example +exception +extends +file +fn +headerfile +hideinitializer +htmlinclude +htmlonly +idlexcept +if +ifnot +image +implements +include +includelineno +ingroup +internal +invariant +interface +latexonly +li +line +link +mainpage +manonly +memberof +msc +mscfile +n +name +namespace +nosubgrouping +note +overload +p +package +page +par +paragraph +param +post +pre +private +privatesection +property +protected +protectedsection +protocol +public +publicsection +pure +ref +refitem +related +relates +relatedalso +relatesalso +remark +remarks +result +return +returns +retval +rtfonly +sa +secreflist +section +see +short +showinitializer +since +skip +skipline +snippet +struct +subpage +subsection +subsubsection +tableofcontents +test +throw +throws +todo +tparam +typedef +union +until +var +verbatim +verbinclude +version +vhdlflow +warning +weakgroup +xmlonly +xrefitem +== LIST: doxygen_esc_char == list == + '$', + '@', + '&', + '~', + '<', + '>', + '#', + '%', + '"', + '.', + '::', +== LIST: doxygen_page_cmd == hash == + 'mainpage' : '{+TITLE_OPT_+}', + 'page' : '{+REF+} {+TITLE+}', + 'subpage' : '{+REF+} {+TEXT_OPT_+}', + + 'tableofcontents' : '', + + 'section' : '{+REF+} {+TITLE+}', + 'subsection' : '{+REF+} {+TITLE+}', + 'subsubsection' : '{+REF+} {+TITLE+}', + 'paragraph' : '{+REF+} {+TITLE+}', + + 'anchor' : '{+REF+}', + 'ref' : '{+REF+} {+TEXT_OPT_+}', +== ENDLIST == + +§ The template "Doxygen.brief, after member" is used for the menu entry +§ "Doxygen.brief, after member", which is created by the plug-in itself. +§ Do not change the name! + +§ menu and map used for "brief, after member": +SetProperty( 'Doxygen::BriefAM::Menu', 'Doxygen' ) +SetProperty( 'Doxygen::BriefAM::Map', 'dba' ) + +== Doxygen.brief, after member == append, nomenu == +/*!< |DOX_CMD|brief */ +== ENDTEMPLATE == + +§ basic blocks + +== Doxygen.frame == below, map:dfr, sc:f == +/*! + * |DOX_CMD|brief + */ +== Doxygen.overload block == below, map:do, sc:o == +/*! + * |DOX_CMD|overload + */ +== ENDTEMPLATE == + +== SEP: Doxygen.sep1 == + +§ basic commands + +== Doxygen.commands == below, map:dc, sc:c == +|PickList( 'Doxygen command', 'doxygen_command' )| + * |DOX_CMD||KEY| +== Doxygen.brief == below, map:dbr, sc:b == + * |DOX_CMD|brief +== Doxygen.parameter == below, map:dpa, sc:p == + * |DOX_CMD|param +== Doxygen.return == below, map:dre, sc:r == + * |DOX_CMD|return +== Doxygen.escaped char == expandmenu, insert, map:de, sc:e == +|PickList( 'character', 'doxygen_esc_char' )| +|DOX_CMD||KEY| +== ENDTEMPLATE == + +== SEP: Doxygen.sep2 == + +§ groups + +== Doxygen.defgroup block == below, map:dgd, sc:g == +/*! + * |DOX_CMD|defgroup |?DOXYGEN_GROUP| + * + * |DOX_CMD|brief + * + * <+DETAILED+> + */ +== Doxygen.addtogroup blocks == below, noindent, map:dga, sc:g == +/*! + * |DOX_CMD|addtogroup |?DOXYGEN_GROUP| + * |DOX_CMD|{ + */ + + + +/*! + * |DOX_CMD|} + */ +== Doxygen.ingroup == below, map:dgi, sc:i == + * |DOX_CMD|ingroup |?DOXYGEN_GROUP| + * +== Doxygen.member group blocks == below, noindent, map:dgm, sc:m == +/*! + * |DOX_CMD|name {+HEADER+} + */ +/*! |DOX_CMD|{ */ + + + +/*! |DOX_CMD|} */ +== ENDTEMPLATE == + +== SEP: Doxygen.sep3 == + +§ LaTeX formulas + +== Doxygen.LaTeX formula, in-text == insert, map:dfi, sc:f == +|DOX_CMD|f$ |DOX_CMD|f$ +== Doxygen.LaTeX formula, separate == below, map:dfs, sc:f == + * |DOX_CMD|f[ + * + * |DOX_CMD|f] +== Doxygen.LaTeX formula, environment == below, map:dfe, sc:f == + * |DOX_CMD|f{}{ + * {-FORMULA-} + * |DOX_CMD|f} +== ENDTEMPLATE == + +== SEP: Doxygen.sep4 == + +§ pages + +== Doxygen.page command == expandmenu, below, map:dpc, sc:a == +|PickList( 'Doxygen command', 'doxygen_page_cmd' )| + * |DOX_CMD||KEY| |VALUE| +== Doxygen.page block == below, map:dpb, sc:a == +/*! + * |DOX_CMD|page {+REF+} {+TITLE+} + */ +== ENDTEMPLATE == + +== ENDSTYLES == + diff --git a/c-support/templates/help.template b/c-support/templates/help.template new file mode 100644 index 0000000..5a8f26e --- /dev/null +++ b/c-support/templates/help.template @@ -0,0 +1,31 @@ +§ every time a help template is used, it executes a shell command, +§ which follows this general format: +§ |HELP_BROWSER| |HelpPathXYZ| +§ e.g. if you set: +§ SetMacro( 'HELP_BROWSER', 'firefox -new-window' ) +§ the system call would be something like: +§ firefox -new-window http://en.wiktionary.org/wiki/example + +§ help english: +§ we delete non-word characters before calling the help +§ +§ help Doxygen: +§ we do some voodoo to +§ - find all Doxygen commands, preceded by '\' or '@' +§ - get Doxygen command like \f$ or @f{environment}{ to work +§ in case we do not find such a command under the cursor, +§ we open the page anyway, which should put the list of commands on screen + +== HELP: Help.english == map:he, sc:e == +|Word( '' )| +|Substitute( '\W', '', 'g' )| +|System( '|HELP_BROWSER| |HelpPathEnglish||PICK:l|' )| +== HELP: Help.doxygen cmd == map:hd, sc:d == +|Pattern( '[\\@]\zs\%(f{\w\+\*\?}{\?\|f[}\$\[\]]\|\w\+\)' )| +|Substitute( 'f[\$\[\]]', 'fdollar', '' )| +|Substitute( 'f{\w\+\*\?}{\?', 'fcurlyopen', '' )| +|Substitute( 'f}', 'fcurlyclose', '' )| +|System( '|HELP_BROWSER| |HelpPathDoxygen|#cmd|PICK|' )| +|Default( '|HELP_BROWSER| |HelpPathDoxygen|' )| +== ENDTEMPLATE == + diff --git a/c-support/templates/snippets.template b/c-support/templates/snippets.template new file mode 100644 index 0000000..74cfa8b --- /dev/null +++ b/c-support/templates/snippets.template @@ -0,0 +1,11 @@ +== LIST: snippets_jumptags == hash == + 'less-plus' : '<++>', + 'less-minus' : '<-->', + 'brace-plus' : '{++}', + 'brace-minus' : '{--}', +== ENDLIST == + +== Snippets.jump tags == expandmenu, insert, map:njt, shortcut:m == +|PickList( 'jumptags', 'snippets_jumptags' )| +|PICK| +== ENDTEMPLATE == diff --git a/c-support/wordlists/c-c++-keywords.list b/c-support/wordlists/c-c++-keywords.list index 4bcd27a..84cd2bc 100644 --- a/c-support/wordlists/c-c++-keywords.list +++ b/c-support/wordlists/c-c++-keywords.list @@ -1,111 +1,119 @@ -adjustfield -basefield -boolalpha -floatfield -internal -scientific +boolalpha +defaultfloat +endl +ends +fixed +flush +get_money +get_time +hexfloat +internal +left +put_money +put_time +resetiosflag +right +scientific setbase +setfill setiosflags setprecision -showbase -showpoint -showpos +setw +showbase +showpoint +showpos +skipws +unitbuf uppercase +alignas +alignof +and_eq auto +bitand +bitor +bool break case -char -const -continue -default -double -else -enum -extern -float -goto -inline -long -register -restrict -return -short -signed -sizeof -static -struct -switch -typedef -union -unsigned -void -volatile -while -_Bool -_Complex -_Imaginary -EXIT_FAILURE -EXIT_SUCCESS -size_t - -alignas -alignof -bool catch +char char16_t char32_t class -constexpr +compl +const const_cast +constexpr +continue decltype +default delete +do +double dynamic_cast +else +enum explicit export +extern false +float friend +goto +if +inline +long mutable namespace -new -neexcept -nullptr +noexcept +not_eq +nullptr operator +or +or_eq private protected public +register reinterpret_cast +return +short +signed +sizeof +static static_assert static_cast +struct +switch template this thread_local throw true +typedef typeid typename +union +unsigned using virtual +void +volatile wchar_t - -and_eq -bitand -bitor -compl -not_eq -or_eq -xor_eq +while +xor_eq define -defined elif endif error ifdef ifndef include +line pragma undef +warning exception bad_alloc diff --git a/doc/c-hotkeys.pdf b/doc/c-hotkeys.pdf deleted file mode 100644 index 2b6e0ab..0000000 Binary files a/doc/c-hotkeys.pdf and /dev/null differ diff --git a/doc/c-hotkeys.tex b/doc/c-hotkeys.tex deleted file mode 100644 index 434a4b9..0000000 --- a/doc/c-hotkeys.tex +++ /dev/null @@ -1,353 +0,0 @@ -%%===================================================================================== -%% -%% File: c-hotkeys.tex -%% -%% Description: c-support.vim : Key mappings for Vim without GUI. -%% -%% -%% Author: Dr.-Ing. Fritz Mehner -%% Email: mehner@fh-swf.de -%% Copyright: Copyright (C) 2006-2010 Dr.-Ing. Fritz Mehner (mehner@fh-swf.de) -%% Version: 1.0 -%% Created: 10.11.2006 -%% Revision: $Id: c-hotkeys.tex,v 1.50 2012/03/03 19:17:56 mehner Exp $ -%% -%% Notes: -%% -%%===================================================================================== - -\documentclass[oneside,11pt,landscape,DIV17]{scrartcl} - -\usepackage[english]{babel} -\usepackage[utf8]{inputenc} -\usepackage[T1]{fontenc} -\usepackage{times} -\usepackage{lastpage} -\usepackage{multicol} -\usepackage{setspace} - -\setlength\parindent{0pt} - -\newcommand{\Pluginversion}{5.18} -\newcommand{\ReleaseDate}{\today} -\newcommand{\Rep}{{\tiny{[n]}}} - -%%---------------------------------------------------------------------- -%% luximono : Type1-font -%% Makes keyword stand out by using semibold letters. -%%---------------------------------------------------------------------- -\usepackage[scaled]{luximono} - -%%---------------------------------------------------------------------- -%% fancyhdr -%%---------------------------------------------------------------------- -\usepackage{fancyhdr} -\pagestyle{fancyplain} -\fancyfoot[L]{\small \ReleaseDate} -\fancyfoot[C]{c-support.vim} -\fancyfoot[R]{\small \textbf{Page \thepage{} / \pageref{LastPage}}} -\renewcommand{\headrulewidth}{0.0pt} - -%%---------------------------------------------------------------------- -%% hyperref -%%---------------------------------------------------------------------- -\usepackage[ps2pdf]{hyperref} -\hypersetup{pdfauthor={Dr.-Ing. Fritz Mehner, FH Südwestfalen, Iserlohn, Germany}} -\hypersetup{pdfkeywords={Vim, C/C++}} -\hypersetup{pdfsubject={Vim-plugin, c-support.vim, hot keys}} -\hypersetup{pdftitle={Vim-plugin, c-support.vim, hot keys}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% START OF DOCUMENT -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\begin{document}% - -\begin{multicols}{3} -% -%%====================================================================== -%% title -%%====================================================================== -\begin{center} -\textbf{\textsc{\small{Vim-Plugin}}}\\ -\textbf{\LARGE{c-support.vim}}\\ -\textbf{\textsc{\small{Version \Pluginversion}}}\\ -\textbf{\textsc{\Huge{Hot keys}}}\\ -Key mappings for Vim with and without GUI.\\ -Plugin: http://vim.sourceforge.net\\ -\vspace{3.0mm} -{\normalsize (i)} insert mode, {\normalsize (n)} normal mode, {\normalsize (v)} visual mode\\ -\vspace{5.0mm} -% -%%====================================================================== -%% SIDE 1 -%%====================================================================== -%%~~~~~ TABULAR : begin ~~~~~~~~~~ -\begin{tabular}[]{|p{10mm}|p{60mm}|} -% -\hline -\multicolumn{2}{|r|}{\textsl{\textbf{C}omments}} \\ -\hline \Rep\verb'\cl' & end-of-line comment \hfill (n,v,i)\\ -\hline \Rep\verb'\cj' & adjust end-of-line comment \hfill (n,v,i)\\ -\hline \verb'\cs' & set end-of-line comment column \hfill (n) \\ -\hline \Rep\verb'\c*' & code $\Rightarrow$ comment \verb'/* */' \hfill (n,v) \\ -\hline \Rep\verb'\cc' & code $\Rightarrow$ comment \verb'//' \hfill (n,v,o)\\ -\hline \Rep\verb'\co' & comment $\Rightarrow$ code \hfill (n,v,o)\\ - -\hline \verb'\cfr' & frame comment \hfill (n,i)\\ -\hline \verb'\cfu' & function comment \hfill (n,i)\\ -\hline \verb'\cme' & method description \hfill (n,i)\\ -\hline \verb'\ccl' & class description \hfill (n,i)\\ -\hline \verb'\cfdi'& file description (implementation) \hfill (n,i)\\ -\hline \verb'\cfdh'& file description (header) \hfill (n,i)\\ - -\hline \verb'\ccs'& C/C++--file sections\hspace{3mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ -\hline \verb'\chs'& H--file sections\hspace{10mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ -\hline \verb'\ckc'& keyword comment\hspace{5mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ -\hline \verb'\csc'& special comment\hspace{7,5mm}\footnotesize{(tab compl.)} \hfill \normalsize{(n,i)}\\ - -\hline \verb'\cd' & date \hfill (n,v,i)\\ -\hline \verb'\ct' & date \& time \hfill (n,v,i)\\ -\hline \Rep\verb'\cx' & toggle comments: C $\leftrightarrow$ C++ \hfill (n,v,i)\\ -\hline -\end{tabular}\\ -%%~~~~~ TABULAR : end ~~~~~~~~~~ -% -%%====================================================================== -%% table, middle part -%%====================================================================== -% -%%~~~~~ TABULAR : begin ~~~~~~~~~~ -\begin{tabular}[]{|p{15mm}|p{55mm}|} -%%---------------------------------------------------------------------- -%% menu statements -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{\textbf{S}tatements}} \\ -\hline \verb'\sd' & \verb'do { } while' \hfill (n,v,i)\\ -\hline \verb'\sf' & \verb'for' \hfill (n,i)\\ -\hline \verb'\sfo' & \verb'for { }' \hfill (n,v,i)\\ -\hline \verb'\si' & \verb'if' \hfill (n,i)\\ -\hline \verb'\sif' & \verb'if { }' \hfill (n,v,i)\\ -\hline \verb'\sie' & \verb'if else' \hfill (n,v,i)\\ -\hline \verb'\sife'& \verb'if { } else { }' \hfill (n,v,i)\\ -\hline \verb'\se' & \verb'else { }' \hfill (n,v,i)\\ -\hline \verb'\sw' & \verb'while' \hfill (n,i)\\ -\hline \verb'\swh' & \verb'while { }' \hfill (n,v,i)\\ -\hline \verb'\ss' & \verb'switch' \hfill (n,v,i)\\ -\hline \verb'\sc' & \verb'case' \hfill (n,i)\\ -\hline \verb'\s{ \sb' & \verb'{ }' \hfill (n,v,i)\\ -\hline -%%---------------------------------------------------------------------- -%% preprocessor menu -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{\textbf{P}reprocessor}} \\ -\hline \verb'\ps' & choose a Std. Lib. include \hfill (n,i)\\ -\hline \verb'\pc' & choose a C99 include \hfill (n,i)\\ -\hline \verb'\p<' & \verb$#include<...>$ \hfill (n,i)\\ -\hline \verb'\p"' & \verb$#include"..."$ \hfill (n,i)\\ -\hline \verb'\pd' & \verb'#define' \hfill (n,i)\\ -\hline \verb'\pu' & \verb'#undef' \hfill (n,i)\\ -\hline \verb'\pif' & \verb'#if #endif' \hfill (n,v,i)\\ -\hline \verb'\pie' & \verb'#if #else #endif' \hfill (n,v,i)\\ -\hline \verb'\pid' & \verb'#ifdef #else #endif' \hfill (n,v,i)\\ -\hline \verb'\pin' & \verb'#ifndef #else #endif' \hfill (n,v,i)\\ -\hline \verb'\pind' & \verb'#ifndef #def #endif' \hfill (n,v,i)\\ -\hline \verb'\pi0' & \verb'#if 0 #endif' \hfill (n,v,i)\\ -\hline \verb'\pr0' & remove \verb'#if 0 #endif' \hfill (n,i)\\ -\hline \verb'\pe' & \verb'#error ' \hfill (n,i)\\ -\hline \verb'\pl' & \verb'#line ' \hfill (n,i)\\ -\hline \verb'\pp' & \verb'#pragma' \hfill (n,i)\\ -\hline -\end{tabular} \\ -%%~~~~~ TABULAR : end ~~~~~~~~~~ - -%%====================================================================== -%% table, right part -%%====================================================================== -% -%%~~~~~ TABULAR : begin ~~~~~~~~~~ -\begin{tabular}[]{|p{11mm}|p{60mm}|} -%%---------------------------------------------------------------------- -%% snippet menu -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{S\textbf{n}ippet}} \\ -\hline \verb'\nr' & read code snippet \hfill (n,i)\\ -\hline \verb'\nw' & write code snippet \hfill (n,v,i)\\ -\hline \verb'\ne' & edit code snippet \hfill (n,i)\\ -\hline \Rep\verb'\nf' \Rep\verb'\np' & pick up function prototype \hfill (n,v,i)\\ -\hline \Rep\verb'\nm' & pick up method prototype \hfill (n,v,i)\\ -\hline \verb'\ni' & insert prototype(s) \hfill (n,i)\\ -\hline \verb'\nc' & clear prototype(s) \hfill (n,i)\\ -\hline \verb'\ns' & show prototype(s) \hfill (n,i)\\ -% -\hline \verb'\ntl' & edit local templates \hfill (n,i)\\ -\hline \verb'\ntg' & edit global templates$^1$ \hfill (n,i)\\ -\hline \verb'\ntr' & reread the templates \hfill (n,i)\\ -\hline \verb'\nts' & change templates style \hfill (n,i)\\ -\hline -%%---------------------------------------------------------------------- -%% idioms menu -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{\textbf{I}dioms}} \\ -\hline \verb'\if' & function \hfill (n,v,i)\\ -\hline \verb'\isf' & static function \hfill (n,v,i)\\ -\hline \verb'\im' & \verb'main()' \hfill (n,v,i)\\ -\hline \Rep\verb'\i0' & \verb'for( x=0; x=0; x-=1 )' \hfill (n,v,i)\\ -\hline \verb'\ie' & \verb'enum' + \verb'typedef' \hfill (n,v,i)\\ -\hline \verb'\is' & \verb'struct' + \verb'typedef' \hfill (n,v,i)\\ -\hline \verb'\iu' & \verb'union' + \verb'typedef' \hfill (n,v,i)\\ -\hline \verb'\ip' & \verb'printf()' \hfill (n,i)\\ -\hline \verb'\isc' & \verb'scanf()' \hfill (n,i)\\ -\hline \verb'\ica' & \verb'p=calloc()' \hfill (n,i)\\ -\hline \verb'\ima' & \verb'p=malloc()' \hfill (n,i)\\ -\hline \verb'\ire' & \verb'p=realloc()' \hfill (n,i)\\ -\hline \verb'\isi' & \verb'sizeof()' \hfill (n,v,i)\\ -\hline \verb'\ias' & \verb'assert()' \hfill (n,v,i)\\ -\hline \verb'\ii' & open input file \hfill (n,v,i)\\ -\hline \verb'\io' & open output file \hfill (n,v,i)\\ -\hline \verb'\ifs' & fscanf \hfill (n,i)\\ -\hline \verb'\ifp' & fprintf \hfill (n,i)\\ -\hline -\end{tabular}\\ -% -\begin{minipage}[b]{64mm}% -\scriptsize{% -\vspace{1mm} -%\hrulefill\\ -$^1$ {system-wide installation only}\\ -}% -\end{minipage} -% -% -%%====================================================================== -%% SIDE 2 -%%====================================================================== -% -%%~~~~~ TABULAR : begin ~~~~~~~~~~ -\begin{tabular}[]{|p{12mm}|p{60mm}|} -%%---------------------------------------------------------------------- -%% C++ menu -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{C\textbf{++}}} \\ -\hline \verb'\+co' & \verb'cout << << endl; ' \hfill (n,i)\\ -\hline \verb'\+"' & \verb'<< ""' \hfill (n,i)\\ -\hline \verb'\+c' & class \hfill (n,i)\\ -\hline \verb'\+ps' & \verb$#include<...> STL$ \hfill (n,i)\\ -\hline \verb'\+pc' & \verb$#include C$ \hfill (n,i)\\ -\hline \verb'\+cn' & class (using \verb'new') \hfill (n,i)\\ -\hline \verb'\+ci' & class implementation \hfill (n,i)\\ -\hline \verb'\+cni' & class (using \verb'new') implementation \hfill (n,i)\\ -\hline \verb'\+mi' & method implementation \hfill (n,i)\\ -\hline \verb'\+ai' & accessor implementation \hfill (n,i)\\ -\hline \verb'\+tc' & template class \hfill (n,i)\\ -\hline \verb'\+tcn' & template class (using \verb'new') \hfill (n,i)\\ -\hline \verb'\+tci' & template class implementation \hfill (n,i)\\ -\hline \verb'\+tcni'& template class (using \verb'new') impl. \hfill (n,i)\\ -\hline \verb'\+tmi' & template method implementation \hfill (n,i)\\ -\hline \verb'\+tai' & template accessor implementation \hfill (n,i)\\ -\hline \verb'\+tf' & template function \hfill (n,i)\\ -\hline \verb'\+ec' & error class \hfill (n,i)\\ -\hline \verb'\+tr' & \verb'try' \dots \verb'catch' \hfill (n,v,i)\\ -\hline \verb'\+ca' & \verb'catch' \hfill (n,v,i)\\ -\hline \verb'\+c.' & \verb'catch(...)' \hfill (n,v,i)\\ -\hline -%% -%%---------------------------------------------------------------------- -%% show plugin help -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{\textbf{H}elp}}\\ -\hline \verb'\hm' & manual for word under cursor \hfill (n,i)\\ -\hline \verb'\hp' & help (c-support) \hfill (n,i)\\ -\hline -\end{tabular} -\vspace{100mm} -%%~~~~~ TABULAR : begin ~~~~~~~~~~ -\begin{tabular}[]{|p{12mm}|p{58mm}|} -%%---------------------------------------------------------------------- -%% run menu -%%---------------------------------------------------------------------- -\hline -\multicolumn{2}{|r|}{\textsl{\textbf{R}un}} \\ -\hline \verb'\rc' & save and compile \hfill (n,i)\\ -\hline \verb'\rl' & link \hfill (n,i)\\ -\hline \verb'\rr' & run \hfill (n,i)\\ -\hline \verb'\ra' & set comand line arguments \hfill (n,i)\\ -\hline \verb'\rm' & run \texttt{ make}$^1$ \hfill (n,i)\\ -\hline \verb'\rmc' & run \texttt{ make clean}$^1$ \hfill (n,i)\\ -\hline \verb'\rcm' & choose a makefile $^1$ \hfill (n,i)\\ -\hline \verb'\rme' & executable\ to\ run$^1$ \hfill (n,i)\\ -\hline \verb'\rma' & cmd.\ line arg.\ for \texttt{make}$^1$ \hfill (n,i)\\ -% -\hline \verb'\rp' & run \texttt{ splint}$^2$ \hfill (n,i)\\ -\hline \verb'\rpa' & cmd.\ line arg.\ for \texttt{splint} \hfill (n,i)\\ -% -\hline \verb'\rk' & run \texttt{ CodeCheck}$^3$ \hfill (n,i)\\ -\hline \verb'\rka' & cmd.\ line arg.\ for \texttt{CodeCheck} \hfill (n,i)\\ -% -\hline \verb'\rd' & run \texttt{ indent} \hfill (n,i)\\ -\hline \Rep\verb'\rh' & hardcopy buffer \hfill (n,i,v)\\ -\hline \verb'\rs' & show plugin settings \hfill (n,i)\\ -\hline \verb'\rx' & set xterm size \hfill (n,i, only Unix \& GUI)\\ -\hline \verb'\ro' & change output destination \hfill (n,i)\\ -\hline -%\end{tabular} -%\begin{spacing}{1.2} -%\begin{tabular}[]{|p{12mm}|p{58mm}|} -\hline -\multicolumn{2}{|r|}{\textbf{Additional Mappings}}\\ -\hline -\hline \textbf{typing} & \textbf{expansion}\\ -\hline \verb'/*' & \verb'/* */' \hfill (i)\\ -\hline \verb'/*' & \verb'/* '\fbox{\small{(multiline) marked text}}\verb' */' \hfill (v)\\ -\hline \verb'/*' & \verb'/*'\hfill (i)\newline\verb' * |'\newline\verb' */'\\ -\hline \verb'{' & \verb'{'\hfill (i)\newline\verb' |'\newline\verb'}' \\ -\hline \verb'{' & \verb'{'\hfill (v)\newline\verb' '\fbox{\small{(multiline) marked text}}\newline\verb'}'\\ -\hline -\end{tabular} -%\end{spacing} -%%~~~~~ TABULAR : end ~~~~~~~~~~ -%\vspace{60mm} -% -% -\begin{minipage}[b]{60mm}% -%\vspace{10mm} -% -\begin{flushleft} -% -\textit{Ex commands:} -\begin{description} -% -\item [CFileSection] C/C++--file sections (same as \verb'\ccs') -\item [HFileSection] H--file sections (same as \verb'\chs') -\item [KeywordComment] keyword comment (same as \verb'\ckc') -\item [SpecialComment] special comment (same as \verb'\csc') -\item [IncludeStdLibrary] standard library includes (same as \verb'\ps') -\item [IncludeC99Library] C99 includes (same as \verb'\pc') -\item [IncludeCppLibrary] STL includes (same as \verb'\+ps') -\item [IncludeCppCLibrary] C includes (same as \verb'\+pc') -\item [CStyle] C99 include (same as \verb'\nts') -% -\end{description} -% -\scriptsize{Use tab expansion to show the items to choose from.} -% -\end{flushleft} -\scriptsize{% -%\vspace{10mm} -\hrulefill\\ -$^1$ also working for filetype \textbf{make}\\ -$^2$ \textit{www.splint.org}\\ -$^3$ \textbf{CodeCheck}$^{TM}$ is a product of Abraxas Software, Inc. -}% -% -\end{minipage} -% -\end{center} -\end{multicols} -\end{document} diff --git a/doc/csupport.txt b/doc/csupport.txt index d99d7d5..dc5285d 100644 --- a/doc/csupport.txt +++ b/doc/csupport.txt @@ -1,7 +1,7 @@ -*csupport.txt* C/C++ Support January 06 2012 +*csupport.txt* C/C++ Support March 22 2014 C/C++ Support *c-support* *csupport* - Plugin version 5.18 + Plugin version 6.1.1 for Vim version 7.0 and above Fritz Mehner @@ -11,18 +11,28 @@ code snippets, templates, and comments. Syntax checking, compiling, running a program, running a code checker or a reformatter can be done with a keystroke. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++ The plug-in version 6.0+ is a rewriting of version 5.19+. ++ +++ The versions 5.0+ are based on a new and more powerful template system ++ +++ (please see |template-support| for more information). ++ +++ The template syntax has changed! ++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1. Usage |csupport-usage-gvim| 1.1 Menu 'Comments' |csupport-comm| 1.1.1 Append aligned comments |csupport-comm-aligned| 1.1.2 Adjust end-of-line comments |csupport-comm-realign| 1.1.3 Code to comment |csupport-code-to-comm| 1.1.4 Comment to code |csupport-comm-to-code| - 1.1.5 Frame comments, file header, ... |csupport-comm-frame| - 1.1.6 File section comments .. |csupport-comm-sections| - 1.1.7 Keyword comment, special comment |csupport-comm-keyword| - 1.1.8 Tags (plugin) |csupport-comm-tags| - 1.1.9 Date and date+time |csupport-comm-date| - 1.1.10 C to C++ comments and vice versa |csupport-comm-c-cpp| + 1.1.5 Toggle non-C comments |csupport-comm-non-c| + 1.1.6 Frame comments, file header, ... |csupport-comm-frame| + 1.1.7 File section comments .. |csupport-comm-sections| + 1.1.8 Keyword comment, special comment |csupport-comm-keyword| + 1.1.9 Macros |csupport-comm-macros| + 1.1.10 Date and date+time |csupport-comm-date| + 1.1.11 C to C++ comments and vice versa |csupport-comm-c-cpp| 1.2 Menu 'Statements' |csupport-stat| 1.2.1 Normal mode, insert mode. |csupport-stat-normal-mode| 1.2.2 Visual mode. |csupport-stat-visual-mode| @@ -30,7 +40,6 @@ keystroke. 1.3.1 Normal mode, insert mode. |csupport-prep-normal-mode| 1.3.2 Visual mode. |csupport-prep-visual-mode| 1.3.3 Block out code with #if 0 .. #endif |csupport-prep-if0| - 1.3.4 Ex-commands |csupport-prep-ex| 1.4 Menu 'Idioms' |csupport-idioms| 1.4.1 Item 'function' |csupport-idioms-function| 1.4.2 for-loop control |csupport-idioms-for-loop| @@ -43,25 +52,26 @@ keystroke. 1.6 Menu 'C++' |csupport-c++| 1.6.1 Normal mode, insert mode. |csupport-c++-normal-mode| 1.6.2 Visual mode. |csupport-c++-visual-mode| - 1.6.3 Method implementation |csupport-c++-method-impl| - 1.6.4 Ex commands |csupport-c++-ex| + 1.6.3 Implementation |csupport-c++-impl| 1.7 Menu 'Run' |csupport-run| - 1.7.1 Minimal make functionality |csupport-run-buffer| + 1.7.1 Compile, link, run |csupport-run-buffer| 1.7.2 Command line arguments |csupport-run-cmdline-args| - 1.7.3 Run make |csupport-run-make| - 1.7.4 Choose Makefile |csupport-choose-makefile| - 1.7.4 Executable to run |csupport-run-make-run| - 1.7.6 Run make clean |csupport-run-make-clean| - 1.7.7 Command line arguments for make |csupport-run-make-args| - 1.7.8 Splint |csupport-run-splint| - 1.7.9 CodeCheck |csupport-run-codecheck| - 1.7.10 Indent |csupport-run-indent| - 1.7.11 Hardcopy |csupport-run-hardcopy| - 1.7.12 Rebuild templates |csupport-run-templates| - 1.7.13 Xterm size |csupport-run-xterm| - 1.7.14 Output redirection |csupport-run-output| - 1.8 Help |csupport-help| - + 1.7.3 Executable to run |csupport-run-make-run| + 1.7.4 Run debugger |csupport-run-debugger| + 1.7.5 Splint |csupport-run-splint| + 1.7.6 Cppcheck |csupport-run-cppcheck| + 1.7.7 CodeCheck |csupport-run-codecheck| + 1.7.8 Indent |csupport-run-indent| + 1.7.9 Hardcopy |csupport-run-hardcopy| + 1.7.10 Xterm size |csupport-run-xterm| + 1.7.11 Output redirection |csupport-run-output| + 1.8 Tool Box |csupport-toolbox| + 1.8.1 Make |csupport-toolbox-make| + 1.8.2 Other Tools |csupport-toolbox-others| + 1.9 Menu 'Help' |csupport-help| + 1.10 Menu 'Doxygen' |csupport-doxygen| + 1.10.1 Enabling the menu |csupport-doxygen-enable| + 2. Usage without GUI |csupport-usage-vim| 3. Hotkeys |csupport-hotkeys| 4. Customization and configuration |csupport-custom| @@ -73,12 +83,9 @@ keystroke. 5.2 Macros |csupport-templates-macros| 5.2.1 User defined formats for date and time |csupport-templates-date| 5.3 Templates |csupport-templates-names| - 5.3.1 Template names |csupport-templates-names| - 5.3.2 Template definition |csupport-templates-definition| - 5.3.3 Template expansion |csupport-templates-expansion| - 5.3.4 The macros <+text+> etc. |csupport-templates-jump| - 5.3.5 Command Ctrl-j |csupport-Ctrl-j| - 5.4 Switching between template sets |csupport-templates-sets| + 5.3.1 Template definition |csupport-templates-definition| + 5.3.2 The jump tags <+text+> etc. |csupport-templates-jumptags| + 5.3.3 Command Ctrl-j |csupport-Ctrl-j| 5.5 Binding a style to a file extension |csupport-templates-bind| 6. C/C++ Dictionaries |csupport-dictionary| 7. Extend ctags |csupport-ctags| @@ -116,102 +123,101 @@ In NORMAL MODE, the menu item 'end-of-line comment' will append a comment to the current line. In VISUAL MODE, this item will append aligned comments to all marked lines. Marking the first 4 lines - +> print_double_array ( double array[], int n, int columns, char* arrayname ) - -and choosing 'end-of-line com. /**/' will yield. - +< +and choosing 'end-of-line comment' will yield +> print_double_array ( double array[], /* */ int n, /* */ int columns, /* */ char* arrayname /* */ - ) /* */ - + ) +< If one or more lines go beyond the starting column (s.below), the comments will start at the second column after the longest line. The cursor will then be positioned inside the first comment. The default starting column is 49 ( = (multiple of 2,4, or 8) + 1 ). This can be changed by setting a global variable in the file ~/.vimrc , e.g. : - +> let g:C_LineEndCommColDefault = 45 - -The starting column can also be set by the menu item -'Comments->set end-of-line com. col'. Just position the cursor in an -arbitrary column (column number is shown in the Vim status line) and choose -this menu item. This setting is buffer related. - +< +The starting column can also be set by the menu item 'Comments->set +end-of-line com. col'. Just position the cursor in an arbitrary column +(column number is shown in the Vim status line) and choose this menu item. +This setting is buffer related. If the cursor was at the end of a line you will be asked for a column number -because this position is most likely not the desired starting column. -Your choice will be confirmed. +because this position is most likely not the desired starting column. Your +choice will be confirmed. ------------------------------------------------------------------------------ 1.1.2 ADJUST END-OF-LINE COMMENTS *csupport-comm-realign* After some changes end-of-line comments may be no longer aligned: - +> print_double_array ( double array[], /* */ long int n, /* */ unsigned int columns, /* */ char* a_name /* */ - ) /* */ - + ) +< Realignment can be achieved with the menu item 'adjust end-of-line com.' In normal mode the comment (if any) in the current line will be aligned to the end-of-line comment column (see above) if possible. In visual mode the comments in the marked block will be aligned: - +> print_double_array ( double array[], /* */ long int n, /* */ unsigned int columns, /* */ char* a_name /* */ - ) /* */ - + ) +< The realignment will not be done for comments with nothing else than leading whitespaces. These comments are usually captions: - +> max = other.max; /* the maximum value */ len = other.len; /* the length */ /* ===== the next section ===== */ pos = (x+y+z)/3.0; /* the next position */ - +< After the alignment we have: - +> max = other.max; /* the maximum value */ len = other.len; /* the length */ /* ===== the next section ===== */ pos = (x+y+z)/3.0; /* the next position */ - +< ------------------------------------------------------------------------------ 1.1.3 CODE TO COMMENT *csupport-code-to-comm* The marked block - -xxxxxxxx -xxxxxxxx -xxxxxxxx - +> + xxxxxxxx + xxxxxxxx + xxxxxxxx +< will be changed by the menu item 'code->comment /**/' into the multiline comment (all (partially) marked lines): - -/* xxxxxxxx - * xxxxxxxx - * xxxxxxxx - */ - +> + /* xxxxxxxx + * xxxxxxxx + * xxxxxxxx + */ +< The marked block will be changed by the menu item 'code->comment //' into the multiline comment - -//xxxxxxxx -//xxxxxxxx -//xxxxxxxx - +> + //xxxxxxxx + //xxxxxxxx + //xxxxxxxx +< The menu items works also for a single line. A single line needs not to be marked. @@ -222,7 +228,7 @@ marked. If one (or more) complete comment (i.e. all lines belonging to the comment) is marked the item 'comment->code' will uncomment it. If the following lines are marked - +> * printf ("\n"); */ @@ -234,9 +240,9 @@ are marked /* * printf ("\n"); */ - +< uncommenting will yield - +> * printf ("\n"); */ @@ -247,7 +253,7 @@ uncommenting will yield printf ("\n"); - +< The first 2 lines are only a part of a C-comment and remain unchanged. A C-comment can start with /* , /** or /*! . @@ -256,107 +262,100 @@ needs not to be marked. ------------------------------------------------------------------------------ -1.1.5 FRAME COMMENTS, FILE HEADER, ... *csupport-comm-frame* +1.1.5 TOGGLE NON-C COMMENTS *csupport-comm-non-c* + +This menu item toggles the non-C comment for a single line or a marked range +of lines for embedded non-C code. The default comment uses the hash characters +'#'. The non-C comment can start with any string. You can change the default +by setting a global variable in '~/.vimrc': +> + let g:C_NonCComment = '^^' + +------------------------------------------------------------------------------ + +1.1.6 FRAME COMMENTS, FILE HEADER, ... *csupport-comm-frame* Frame comments, file header comments and function, methods, class descriptions are read as templates from the appropriate files (see |csupport-templates|). -There are two file description templates (menu items 'file description (impl.)' -and 'file description (header)', see also |csupport-templates|): +There are two file description templates (menu items 'file description impl' +and 'file description header', see also |csupport-templates|): - comment.file-description : files *.c *.cc *.cp *.cxx *.cpp *.CPP *.c++ - *.C *.i *.ii + implementation : files *.c *.cc *.cp *.cxx *.cpp *.CPP *.c++ + *.C *.i *.ii - comment.file-description-header : everything else with filetype 'c' or 'cpp' + header : everything else with filetype 'c' or 'cpp' -The appropriate template will also be included into a new file. The plugin +The appropriate template will also be included into a new file. The plugin decides on the basis of the file extension. The default is shown above. You can change the list by setting a global variable in '~/.vimrc': - - au BufRead,BufNewFile *.XYZ set filetype=c +> + autocmd BufRead,BufNewFile *.XYZ set filetype=c let g:C_SourceCodeExtensions = 'XYZ c cc cp cxx cpp CPP c++ C i ii' - -A new file named 'test.XYZ' will now be considered a C implementation file. +< +A new file named 'test.XYZ' will now be considered a C implementation file. ------------------------------------------------------------------------------ -1.1.6 FILE SECTION COMMENTS *csupport-comm-sections* +1.1.7 FILE SECTION COMMENTS *csupport-comm-sections* File section comments can be uses to separate typical C- and H-file sections with comments of similar appearance, e.g. +> + /* ##### HEADER FILE INCLUDES ################################################### */ -/* ##### HEADER FILE INCLUDES ################################################### */ - -/* ##### MACROS - LOCAL TO THIS SOURCE FILE ################################### */ - -/* ##### TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################### */ + /* ##### MACROS - LOCAL TO THIS SOURCE FILE ################################### */ + /* ##### TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################### */ +< These section comments can also be inserted using the hotkey \ccs for C/C++ -files, or \chs for H-files. These hotkeys will start the command -'CFileSection' or 'HFileSection' on the command line: - - :CFileSection - :HFileSection - -Now type a to start the selection menu to choose from. +files, or \chs for H-files. ------------------------------------------------------------------------------ -1.1.7 KEYWORD COMMENT, SPECIAL COMMENT *csupport-comm-keyword* +1.1.8 KEYWORD COMMENT, SPECIAL COMMENT *csupport-comm-keyword* Keword comments are end-of-line comments: - +> /* :::: */ +y +Keywords are -Keywords are - - BUG COMPILER TODO TRICKY WARNING WORKAROUND user-defined-keyword + BUG COMPILER REMARK TODO TRICKY WARNING WORKAROUND user-defined-keyword These are preliminary comments to document places where work will be resumed shortly. They are usually not meant for the final documentation. These comments are easily found by searching for the keyword. -The keyword comments can also be inserted using the hotkey \ckc . This hotkey -starts the command 'KeywordComment' on the command line: - - :KeywordComment - -Now type a to start the selection menu to choose from. +The keyword comments can also be inserted using the hotkey \ckc . Special comments are occasionally used to mark special features of a code construct (e.g. a fall through cases in a switch statement, an empty loop): - +> /* EMPTY */ /* NOT REACHED */ /* REMAINS TO BE IMPLEMENTED */ .... - -The special comments can also be inserted using the hotkey \csc . This hotkey -starts the command 'SpecialComment' on the command line: - - :SpecialComment - -Now type a to start the selection menu to choose from. +< +The special comments can also be inserted using the hotkey \csc . ------------------------------------------------------------------------------ -1.1.8 TAGS (PLUGIN) *csupport-comm-tags* +1.1.9 MACROS (PLUGIN) *csupport-comm-macros* -The submenu 'tags (plugin)' let you insert the predefined macros from the -template system (see|csupport-templates-macros|). In visual mode the marked -string will be replaced by the macro. +The submenu 'macros' let you insert the predefined macros from the template +system (see|csupport-templates-macros|). ------------------------------------------------------------------------------ -1.1.9 DATE AND DATE+TIME *csupport-comm-date* +1.1.10 DATE AND DATE+TIME *csupport-comm-date* The format for 'date' and 'date time' can be defined by the user (see -|csupport-templates-date|). In visual mode the marked string will be replaced -by the macro (e.g. to update date and time). +|csupport-templates-date|). ------------------------------------------------------------------------------ -1.1.10 C TO C++ COMMENTS AND VICE VERSA *csupport-comm-c-cpp* +1.1.11 C TO C++ COMMENTS AND VICE VERSA *csupport-comm-c-cpp* The menu item '/* xxx */ <-> // xxx' changes a C++ comment into a C comment and a C++ comment into a C comment (toggle). @@ -372,25 +371,24 @@ changes the current line and the next 2 lines. 1.2.1 NORMAL MODE, INSERT MODE. *csupport-stat-normal-mode* -An empty statement will be inserted and properly indented. The item 'if{}' +An empty statement will be inserted and properly indented. The item 'if block' will insert an if-statement: - -if ( ) -{ -} - - +> + if ( ) { + <-IF_PART-> + } +< 1.2.2 VISUAL MODE. *csupport-stat-visual-mode* STATEMENTS WITH BLOCKS AND CASE LABEL. -------------------------------------- The highlighted area - -xxxxx -xxxxx - +> + xxxxx + xxxxx +< can be surrounded by one of the following statements: - +> +----------------------------+-----------------------------+ | if ( ) | if ( ) | | { | { | @@ -431,14 +429,14 @@ can be surrounded by one of the following statements: | break; | | } | +----------------------------+-----------------------------+ - +< The whole statement will be indented after insertion. STATEMENTS WITHOUT BLOCKS. -------------------------- One of the following statements can be inserted: - +> +-------------------------------+--------------------------+ | if ( ) | for ( ; ; ) | +-------------------------------+--------------------------+ @@ -448,7 +446,7 @@ One of the following statements can be inserted: | case : | | | break; | | +-------------------------------+--------------------------+ - +< ------------------------------------------------------------------------------ 1.3 MENU 'Preprocessor' *csupport-prep* @@ -463,12 +461,12 @@ The preprocessor statements will be inserted and properly indented. STATEMENTS WITH BLOCKS ---------------------- The highlighted area - -xxxxx -xxxxx - +> + xxxxx + xxxxx +< can be surrounded by one of the following statements: - +> +----------------------------+-----------------------------+ | #if CONDITION | | xxxxx | @@ -501,18 +499,18 @@ can be surrounded by one of the following statements: | | | #endif /* ----- #if 0 : If0Label_1 ----- */ | +----------------------------------------------------------+ - +< The macro name for an include guard (e.g. INC_TEST above) will be derived as a suggestion from the file name. 1.3.3 BLOCK OUT CODE WITH #if 0 ... #endif *csupport-prep-if0* The menu item #if 0 #endif inserts the lines - +> #if 0 /* ----- #if 0 : If0Label_1 ----- */ #endif /* ----- #if 0 : If0Label_1 ----- */ - +< In visual mode the marked block of lines will be surrounded by these lines. This is usually done to temporarily block out some code. The label names like @@ -531,22 +529,6 @@ The menu item 'remove #if #endif' removes such a construct if the cursor is in the middle of such a section or on one of the two enclosing lines. Nested constructs will be untouched. -1.3.4 EX-COMMANDS *csupport-prep-ex* - -There are 4 additional Ex command which can be used to insert include -statements: - - Ex command hotkey includes - ------------------------------------------------------------------------- - :IncludeStdLibrary \ps C standard library - :IncludeC99Library \pc C99 library - :IncludeCppLibrary \+ps C++ standard library - :IncludeCppCLibrary \+pc C standard library ( #include ) - -Type :Inc and choose one of the commands. Now type an additional space -and a to show the whole list list or type a space and a few leading -characters to reduce this list. - ------------------------------------------------------------------------------ 1.4 MENU 'Idioms' *csupport-idioms* ------------------------------------------------------------------------------ @@ -556,16 +538,17 @@ characters to reduce this list. NORMAL MODE, INSERT MODE: The name of the function is asked for and the following lines (for function name "f") will be inserted: - - void - f ( ) - { - return ; - } /* ---------- end of function f ---------- */ - +> + void + f ( <+argument_list+> ) + { + return <+return_value+>; + } /* ----- end of function f ----- */ + void +< VISUAL MODE: -Main or [static] function: the highlighted lines will go inside the new -function or main. +Main or function: the highlighted lines will go inside the new function or +main. for-loops: the highlighted lines will be set in braces. 1.4.2 for-loop control *csupport-idioms-for-loop* @@ -578,7 +561,7 @@ start an input dialog asking for at least the name of the loop variable. The other parameters are optional. The type is restricted to the following integral data types: - +> char int long @@ -588,7 +571,7 @@ optional. The type is restricted to the following integral data types: short short int size_t - unsigned + unsigned unsigned char unsigned int unsigned long @@ -597,7 +580,7 @@ optional. The type is restricted to the following integral data types: unsigned long long int unsigned short unsigned short int - +< One of these types can be specified by typing it completely or by typing zero or more characters of its name and completing them to the full name by using the tab key (tab completion). If the start of the type name is ambiguous (e.g. @@ -623,9 +606,10 @@ Code snippets are pieces of code which are kept in separate files in a special directory (e.g. a few lines of code or a complete template for a Makefile). File names are used to identify the snippets. The snippet directory will be created during the installation ( $HOME/.vim/codesnippets-c is the default). -Snippets are managed with the 3 items +Snippets are managed with the 4 items C/C++ -> Snippets -> read code snippet + C/C++ -> Snippets -> view code snippet C/C++ -> Snippets -> write code snippet C/C++ -> Snippets -> edit code snippet @@ -642,6 +626,9 @@ The inserted lines will be indented. EDIT A SNIPPET This is a normal edit. +VIEW A SNIPPET +Show file in a read-only buffer. + INDENTATION / NO INDENTATION Code snippets are normally indented after insertion. To suppress indentation add the file extension "ni" or "noindent" to the snippet file name, e.g. @@ -653,10 +640,10 @@ Snippet browser Under a GUI a file requester will be put up. Without GUI the filename will be read from the command line. You can change this behavior by setting a global variable in your ~/.vimrc : - +> let g:C_GuiSnippetBrowser = 'commandline' - -The default value is 'gui'. +< +The default value is 'gui'. 1.5.2 PICKING UP PROTOTYPES *csupport-proto* @@ -665,7 +652,7 @@ PICK UP FUNCTION PROTOTYPES (key mappings \np, \nf). To make a prototype from a function head mark the function head and choose 'Snippets -> pick up funct. prototype'. From the first six lines of - +> void print_double_array ( double array[], /* array to print */ int n, /* number of elements to print */ @@ -675,11 +662,11 @@ To make a prototype from a function head mark the function head and choose { ... } /* ---------- end of function print_double_array ---------- */ - +< the prototype - +> void print_double_array ( double array[], int n, int columns, char* arrayname ); - +< is produced and put in an internal buffer. - Leading and trailing whitespaces are removed. - All inner whitespaces are squeezed. @@ -694,27 +681,27 @@ PICK UP METHOD PROTOTYPES (key mapping \nm). For C++ methods the menu item 'Snippets -> pick up method prototype' should be used. Namespace names and class names will be removed (exception: 'std::' ). The first two lines of - +> std::string ROBOT::Robot::get_name ( void ) { return type_name; } /* ----- end of method Robot::get_name ----- */ - +< result in the prototype - +> std::string get_name ( void ); - -The 3 lines - +< +The 3 lines +> template const Stack& Stack::operator = ( const Stack &other ) - +< result in the prototype - +> const Stack& operator = ( const Stack &other ); - +< Folding may help picking up prototypes (see |csupport-folding|). @@ -731,11 +718,11 @@ The prototype buffer can be cleared with 'Snippets -> clear prototype(s)' . SHOW PROTOTYPES The list of gathered prototypes can be shown with 'Snippets -> show prototype(s)'. The number and the filename are shown, e.g. - +> (1) matrix.c # double** calloc_double_matrix ( int rows, int columns ); (2) matrix.c # void free_double_matrix ( double **m ); (3) foomain.c # void foo ( ); - +< REMARK. Generating prototypes this way is nice in a small project. You may want to use an extractor like cextract or something else. @@ -754,21 +741,27 @@ loaded from the main file. Now change whatever file you want, save it, and click on the menu item 'reread templates' to read in the file(s) and to rebuild the internal representation of the templates. -The menu item 'edit global templates' opens the main template file in a -system-wide plugin installation (see |csupport-system-wide|). This is -usually the file '$VIM./vimfiles/c-support/templates/Templates'. - Template browser ---------------- Under a GUI a file requester will be put up. Without GUI the filename will be read from the command line. You can change this behavior by setting a global variable in your ~/.vimrc : - +> let g:C_GuiTemplateBrowser = 'explorer' - +< The default value is 'gui'. 'explorer' will start the file explorer (see help|:Explore|). To use the commandline asign 'commandline'. +Template Style +-------------- +The template system supports different template styles. If there are more than +one style the menu item 'choose style' let you choose a style on the fly. + +Template Jump Tags +------------------ +You can use different jump tags in a template, e.g. {-tagname-}. The allowed +tags can be chosen from this menu.(see|csupport-templates-jumptags|) + ------------------------------------------------------------------------------ 1.6 MENU 'C++' *csupport-c++* ------------------------------------------------------------------------------ @@ -776,30 +769,30 @@ The default value is 'gui'. 'explorer' will start the file explorer 1.6.1 NORMAL MODE, INSERT MODE. *csupport-c++-normal-mode* An empty statement will be inserted and in some cases properly indented. The -item 'try .. catch' will insert the following lines: - +item 'try catch' will insert the following lines: +> try { } catch ( const &ExceptObj ) { // handle exception: } catch (...) { // handle exception: unspecified } - +< The cursor will go into the try block. 1.6.2 VISUAL MODE. *csupport-c++-visual-mode* The highlighted area can be surrounded by one of the following statements: - try - catch + try catch catch - catch(...) - namespace { } - extern "C" { } + catch all + extern C + namespace block xxx The whole statement will be indented after insertion. -1.6.3 METHOD IMPLEMENTATION *csupport-c++-method-impl* +1.6.3 IMPLEMENTATION *csupport-c++-impl* The menu item 'method implement.' asks for a method name. If this item is called the first time you will see just an scope resolution operator. If you @@ -807,16 +800,11 @@ specify the scope this is used the next time you call this item. If you use one of the menu items to generate a class (see |csupport-templates|) the scope will be extracted and used for the next method. -1.6.4 EX COMMANDS *csupport-c++-ex* - -There are 4 additional Ex command which can be used to insert include -statements. Please see |csupport-prep-ex|. - ------------------------------------------------------------------------------ 1.7 MENU 'Run' *csupport-run* ------------------------------------------------------------------------------ -1.7.1 MINIMAL MAKE FUNCTIONALITY *csupport-run-buffer* +1.7.1 COMPILE, LINK, RUN *csupport-run-buffer* The 'Run' menu provides a minimal make functionality for single file projects (e.g. in education) : @@ -829,16 +817,18 @@ An error window will be opened if the compiler reports errors and/or warnings. Quickfix commands can now be used to jump to an error location. Consider using maps like +> map :cprevious map :cnext +< in your ~/.vimrc file to jump over the error locations and make navigation easier. The error list and the error locations in your source buffer will be synchronized. The filename extension for an object file can be set in ~.vimrc : - +> let g:C_ObjExtension = '.obj' - +< The default is '.o' ('.obj' for Windows). LINK @@ -851,66 +841,45 @@ function. The behavior of the compiler / linker is determined by the options assigned to the variables described in |csupport-custom-glob-vars| (4.group). +Note: The source is first compiled using the settings g:C_CFlags and then + linked using g:C_LFlags. Every time one setting is changed, the other has to + be changed accordingly. The flags in g:C_CFlags have to cause compilation + only. The same holds for g:C_CplusCFlags and g:C_CplusLFlags. + RUN 'run' runs the executable with the same name as the current buffer. If the buffer is not saved, or no executable is available or the executable is older then the source steps 'save and compile' and 'link' are executed first. The filename extension for an executable can be set in ~.vimrc : - +> let g:C_ExeExtension = '.exe' - +< The default is the empty string. + 1.7.2 COMMAND LINE ARGUMENTS *csupport-run-cmdline-args* The item 'command line arguments' calls an input dialog which asks for command line arguments. These arguments are forwarded to the program which is run by -the 'run' item. The arguments are kept until you change them. -For the first and only the first argument file name expansion will work (use -the Tab-key). Only the first string of the input can be expanded due to a -restriction of the Vim input function. To expand two or more filenames -specify them in reverse order: type the first characters of the last filename -and expand them. Go to the start of the input and type the beginning of the -last but one filename and expand it. +the 'run' item. The arguments are kept until you change them. Tab expansion +can be used for filenames and directory names. The input will also be kept in +the internal history. The ex command +> + :CCmdlineArgs ... +< +can also be used to set the command line arguments. The arguments belong to the current buffer (that is, each buffer can have its -own arguments). -If the buffer gets a new name with "save as" the arguments will now belong to -the buffer with the new name. +own arguments). If the buffer gets a new name with "save as" the arguments +will now belong to the buffer with the new name. The command line arguments can be followed by pipes and redirections: - +> 11 22 | sort -rn | head -10 > out +< -Caveat: If you look for the current arguments by calling this menu item again -be sure to leave it with a CR (not Esc !). Due to a limitation of an internal -Vim function CR will keep the arguments, Esc will discard them. - - -1.7.3 RUN make *csupport-run-make* - -The item 'make' runs the external make program. An error window will be -opened if the compiler or linker reports errors or warnings during the make -process. Quickfix commands can now be used to jump to an error location. -Make looks for a makefile in the current directory (but see below). - -When inside a makefile the hotkeys \rm, \rmc, \rcm, and \rma are working (see -|csupport-usage-vim|). -The snippets collection contains a sample makefile which can easily adepted -for small projcts. - - -1.7.4 Choose Makefile *csupport-choose-makefile* - -The menu item 'choose makefile' let you specify a makefile in another -directory than the current one. Now this makefile will be used instead of the -one in the current directory (if any). Make is started from the directory in -which the makefile is contained. The working directory for the current buffer -will not be changed. - - -1.7.5 EXECUTABLE TO RUN *csupport-run-make-run* +1.7.3 EXECUTABLE TO RUN *csupport-run-make-run* The item 'executable to run' asks for the name of the executable built by make. If the name given is nonempty this executable will be run by the menu @@ -919,24 +888,29 @@ To return to the default behavior (see |csupport-run-buffer|) remove the name with the another 'executable to run'. -1.7.6 RUN make clean *csupport-run-make-clean* +1.7.4 RUN DEBUGGER *csupport-run-debugger* + +Start a debugger from the menu item Run->'run debugger', with hotkey \rd. One of +three debuggers can be started. The preference can be set with the variable +g:C_Debugger (possible values: 'gdb', 'kdbg', 'ddd' ). The default is 'gdb'). -The item 'make' runs the external make program with the standard target -'clean'. If an alternate makefile has been chosen -(see|csupport-choose-makefile|), this one will be run from the directory in -which the makefile is contained. +(1) gdb +The program will be run as 'gdb executable arguments' in an xterm. +(2) kdbg +The debugger kdbg will be started as an independent process. -1.7.7 COMMAND LINE ARGUMENTS FOR make *csupport-run-make-args* +(3) ddd +The data display debugger ddd is a graphical front end for gdb. It will be +started as an independent process. The debugger ddd is not available under +MS-Windows. -The item 'command line arguments for make' calls an input dialog which asks -for command line arguments for make. These arguments are forwarded to make -when called by the menu item 'make'. -For the first and only the first argument the file name expansion will work -(use the Tab-key). +If the executable to run was specified via Run->'executable to run' than this +executable will be used for debugging. If no executable was specified yet you +will be asked. -1.7.8 SPLINT *csupport-run-splint* +1.7.5 SPLINT *csupport-run-splint* Splint is a tool for statically checking C programs (see http://www.splint.org). Of course it has to be installed in order to be used within Vim. The menu @@ -954,7 +928,24 @@ When vim is started this plugin will check whether splint is executable. If not, the menu item will *NOT' be visible. -1.7.9 CODECHECK *csupport-run-codecheck* +1.7.6 CPPCHECK *csupport-run-cppcheck* + +Cppcheck (http://sourceforge.net/apps/mediawiki/cppcheck/) is tool for static +C++ code analysis. Cppcheck only detects the types of bugs that the compilers +normally fail to detect. + +An error window will be opened if cppcheck has something to complain about. +Quickfix commands can now be used to jump to an error location. For easier +navigation see tip under 'SAVE AND COMPILE' |csupport-run-buffer|. Cppcheck +has many options. Predefined groups of checks can be enabled by the menu item +'cppcheck severity'. The ex command +> + :CppcheckSeverity ... +< +can also be used to set the severity for cppcheck. Please see the original +documentation for more information. + +1.7.7 CODECHECK *csupport-run-codecheck* CodeCheck (TM) is a commercial code analyzing tool produced by Abraxas Software, Inc. (www.abraxas-software.com). @@ -971,20 +962,20 @@ CodeCheck has many options. For a quick try you can use the menu item CodeCheck will be run with default options (see |csupport-custom-glob-vars|). The default options can be overwritten by placing a global variable in ~/.vimrc , e.g. - +> let g:C_CodeCheckOptions = "-K13 -Rmeyers" - +< The default name for the executable is 'check'. There are other names in use on different platforms. The name can be changed by placing a global variable in ~/.vimrc , e.g. - +> let g:C_CodeCheckExeName = "chknt.exe" - +< When vim is started this plugin will check whether CodeCheck is executable. If not, the menu item will *NOT' be visible. -1.7.10 INDENT *csupport-run-indent* +1.7.8 INDENT *csupport-run-indent* The formatter 'indent' can be run over the whole buffer. Before formatting a buffer this buffer will be saved to disk and you will be asked for a @@ -994,7 +985,7 @@ Indent has many options. These are kept in the file '.indent.pro' in your home directory. See the indent manual for more information. -1.7.11 HARDCOPY *csupport-run-hardcopy* +1.7.9 HARDCOPY *csupport-run-hardcopy* Generates a PostScript file from the whole buffer or from a marked region. On a Windows system a printer dialog is displayed. @@ -1004,34 +995,28 @@ goes to the HOME directory. The output destination will be shown in a message. The print header contains date and time for the current locale. The definition used is - +> let s:C_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} Page %N" - +< The current locale can be overwritten by changing the language, e.g. - +> :language C - +< or by setting a global variable in the file ~/.vimrc , e.g. : - +> let g:C_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} SEITE %N" - +< See :h printheader and :h strftime() for more details. -1.7.12 REBUILD TEMPLATES *csupport-run-templates* - -After editing one or more template files a click on this item rereads the -template files and rebuilds all templates. - - -1.7.13 XTERM SIZE *csupport-run-xterm* +1.7.10 XTERM SIZE *csupport-run-xterm* The size of the xterm used for running a program (below) can be set by this menu item. The default is 80 columns with 24 lines. This feature is not available under Windows. -1.7.14 OUTPUT REDIRECTION *csupport-run-output* +1.7.11 OUTPUT REDIRECTION *csupport-run-output* Running a program can be done in one of three ways: (1) Run the program from the gVim command line. @@ -1063,23 +1048,138 @@ The default is "-fa courier -fs 12 -geometry 80x24" : See 'xterm -help' for more options. Xterms are not available under Windows. ------------------------------------------------------------------------------ -1.8 'help' *csupport-help* +1.8 MENU 'Tool Box' *csupport-toolbox* +------------------------------------------------------------------------------ + +Tools which can be used by several plugins are located in the Tool Box. +Examples are tools for make(1) or doxygen. The Tool Box has its own +documentation:|toolbox|. +To switch the Tool Box off add the following line to the file .vimrc +> + let g:C_UseToolbox = 'no' +< +1.8.1 Make *csupport-toolbox-make* + +The tool box for make provides a small set hotkeys, menu items, and ex commands +for controlling make. Please see|toolbox-make|. +To switch the make tool box off add the following line to the file .vimrc +> + let g:C_UseTool_make = 'no' +< +The hotkeys for the make tool are defined in the file ~/.vim/ftplugin/c.vim . + +1.8.2 Other Tools *csupport-toolbox-others* + +In general, to enable a tool called , add the following line to your +.vimrc: +> + let g:C_UseTool_ = 'yes' +< +For example: +> + let g:C_UseTool_cmake = 'yes' + let g:C_UseTool_doxygen = 'yes' +< ------------------------------------------------------------------------------ +1.9 MENU 'Help' *csupport-help* +------------------------------------------------------------------------------ + Plugin help ----------- -The root menu item 'help (plugin)' shows this plugin help in a help window. -The help tags must have been generated with +The menu item 'help (plugin)' shows this plugin help in a help window. The +help tags must have been generated with +> :helptags ~/.vim/doc +< The hotkey is \hp (for "help plugin"). Displaying a manual ------------------- -The root menu item 'show manual' shows the manual for the word under the -cursor. If there is more than one manual a selection list will be presented. -If there is no word under the cursor you can type in a name. An interface to -the on-line reference manuals must be installed (usually man(1) for -Linux/Unix, see|csupport-custom-glob-vars|). -The hotkey is \hm (for "help manual"). +The menu item 'show manual' shows the manual for the word under the cursor. If +there is more than one manual a selection list will be presented. If there is +no word under the cursor you can type in a name. An interface to the on-line +reference manuals must be installed (usually man(1) for Linux/Unix, see +|csupport-custom-glob-vars|). The hotkey is \hm (for "help manual"). + +English dictionary +------------------ +The menu item 'english' opens an online dictionary for the word under the +cursor. + +Doxygen reference +----------------- +The menu item 'doxygen cmd' opens the online reference for the Doxygen command +under the cursor. + +------------------------------------------------------------------------------ + +Under Windows, the browser for opening the online documentation has to be +configured. To set the executable, the template library has to be modified. +In case of a local installation (the default), choose: + C/C++ -> Snippets -> edit local templates +and for a global installation: + C/C++ -> Snippets -> edit global templates +Open the main template file 'Templates' and uncomment the line > + §SetMacro( 'HELP_BROWSER', '"C:\Program Files\Mozilla Firefox\firefox.exe"' ) +by removing the leading '§' > + SetMacro( 'HELP_BROWSER', '"C:\Program Files\Mozilla Firefox\firefox.exe"' ) +Then set the right executable. Mind the double quotes which escape the name of +the executable. +Finally, reread the template library using: + C/C++ -> Snippets -> reread templates + +------------------------------------------------------------------------------ +1.10 MENU 'Doxygen' *csupport-doxygen* +------------------------------------------------------------------------------ + +A menu 'Doxygen' with templates for writing Doxygen comments can optionally be +included. It contains two kinds of entries. If the name includes a "block", +the template inserts a whole Doxygen comment block. Other templates insert a +line extending an existing block. + +The special entry 'brief, after member' can be used to append a brief +description after a member. Similarly to 'Comments->end-of-line comment', it +will append the comment to several lines when in visual mode. When marking the +four lines within the enum +> + enum Color + { + Background, + Transparent, + Black, + White + }; // ----- end of enum Color ----- +< +and then choosing 'brief, after member', the result will look like this +> + enum Color + { + Background, /*!< \brief */ + Transparent, /*!< \brief */ + Black, /*!< \brief */ + White, /*!< \brief */ + }; // ----- end of enum Color ----- +< +Now the elements can be documented one by one. +This feature works like 'Comments->end-of-line comment' in every other aspect. +The comments can be aligned using 'Comments->adjust end-of-line com.' and +respect the column set by 'Comments->set end-of-line com. col' (see +|csupport-comm-aligned|). + + +1.10.1 ENABLING THE MENU *csupport-doxygen-enable* + +The 'Doxygen' submenu is disabled by default. To enable it, the template +library has to be modified. In case of a local installation (the default), +choose: + C/C++ -> Snippets -> edit local templates +and for a global installation: + C/C++ -> Snippets -> edit global templates +Open the main template file 'Templates' and uncomment the line > + §IncludeFile( 'doxygen.template' ) +by removing the leading '§' > + IncludeFile( 'doxygen.template' ) +After a restart of the editor, the 'Doxygen' menu will appear. ============================================================================== 2. USAGE WITHOUT GUI (Vim) *csupport-usage-vim* @@ -1091,9 +1191,13 @@ part of this package). Hint: Typing speed matters. The combination of a leader ('\') and the following character(s) will only be recognized for a short time. Some mappings can be used with range (of lines). In normal mode +> \cl -appends a end-of-line comment to the current line, whereas +< +appends a end-of-line comment to the current line, whereas +> 4\cl +< appends end-of-line comments to the 4 lines starting with the current line. Legend: (i) insert mode, (n) normal mode, (v) visual mode @@ -1101,6 +1205,10 @@ Legend: (i) insert mode, (n) normal mode, (v) visual mode -- Help --------------------------------------------------------------- + \he open an English dictionary for the (n,i) + word under the cursor + \hd open the reference for the Doxygen (n,i) + command under the cursor \hm show manual for word under the cursor (n,i) \hp show plugin help (n,i) @@ -1109,9 +1217,10 @@ Legend: (i) insert mode, (n) normal mode, (v) visual mode [n]\cl end-of-line comment (n,v,i) [n]\cj adjust end-of-line comment(s) (n,v,i) \cs set end-of-line comment column (n) - [n]\c* code -> comment /* */ (n,v) - [n]\cc code -> comment // (n,v) - [n]\co comment -> code (n,v) + [n]\c* code -> comment /* */ (n,v,i) + [n]\cc code -> comment // (n,v,i) + [n]\co comment -> code (n,v,i) + [n]\cn toggle non-C comment (n,v,i) \cfr frame comment (n,i) \cfu function comment (n,i) \cme method description (n,i) @@ -1122,6 +1231,7 @@ Legend: (i) insert mode, (n) normal mode, (v) visual mode \chs H-file section (tab. compl.) (n,i) \ckc keyword comment (tab. compl.) (n,i) \csc special comment (tab. compl.) (n,i) + \cma plugin macros (tab. compl.) (n,i) \cd date (n,v,i) \ct date \& time (n,v,i) [n]\cx toggle comments: C <--> C++ (n,v,i) @@ -1140,39 +1250,18 @@ Legend: (i) insert mode, (n) normal mode, (v) visual mode \swh while { } (n,v,i) \ss switch (n,v,i) \sc case (n,i) - \s{ \sb { } (n,v,i) - - -- Preprocessor ------------------------------------------------------- - - \ps choose a standard library include (n,i) - \pc choose a C99 include (n,i) - \p< #include <> (n,i) - \p" #include "" (n,i) - \pd #define (n,i) - \pu #undef (n,i) - \pif #if #endif (n,v,i) - \pie #if #else #endif (n,v,i) - \pid #ifdef #else #endif (n,v,i) - \pin #ifndef #else #endif (n,v,i) - \pind #ifndef #def #endif (n,v,i) - \pi0 #if 0 #endif (n,v,i) - \pr0 remove #if 0 #endif (n,i) - \pe #error (n,i) - \pl #line (n,i) - \pp #pragma (n,i) + \sb {} (n,v,i) -- Idioms ------------------------------------------------------------- \if function (n,v,i) - \isf static function (n,v,i) + \isf function static (n,v,i) \im main() (n,v,i) - [n]\i0 for( x=0; x=0; x-=1 ) (n,v,i) \ie enum + typedef (n,i) \is struct + typedef (n,i) \iu union + typedef (n,i) - \ip printf() (n,i) \isc scanf() (n,i) + \ipr printf() (n,i) \ica p=calloc() (n,i) \ima p=malloc() (n,i) \ire p=realloc() (n,i) @@ -1180,49 +1269,82 @@ Legend: (i) insert mode, (n) normal mode, (v) visual mode \ias assert() (n,v) \ii open input file (n,i) \io open output file (n,i) - \ifs fscanf (n,i) - \ifp fprintf (n,i) + \ifsc fscanf (n,i) + \ifpr fprintf (n,i) + [n]\i0 for( x=0; x=0; x-=1 ) (n,v,i) + + -- Preprocessor ------------------------------------------------------- + + \pih include standard library header (n,i) + \pg #include <> (global) (n,i) + \pl #include "" (local) (n,i) + \pd #define (n,i) + \pu #undef (n,i) + \pif #if #endif (n,v,i) + \pie #if #else #endif (n,v,i) + \pid #ifdef #else #endif (n,v,i) + \pin #ifndef #else #endif (n,v,i) + \pind #ifndef #def #endif (n,v,i) + \pe #error (n,i) + \pl #line (n,i) + \pp #pragma (n,i) + \pw #warning (n,i) + \pi0 #if 0 #endif (n,v,i) + \pr0 remove #if 0 #endif (n,i) -- Snippets ----------------------------------------------------------- \nr read code snippet (n,i) + \nv view code snippet (read-only) (n,i) \nw write code snippet (n,v,i) \ne edit code snippet (n,i) + [n]\nf pick up function prototype (n,v,i) [n]\np pick up function prototype (n,v,i) [n]\nm pick up method prototype (n,v,i) \ni insert prototype(s) (n,i) \nc clear prototype(s) (n,i) \ns show prototype(s) (n,i) + \ntl edit local templates (n,i) - \ntg edit global templates (n,i) - \ntr rebuild templates (n,i) + \ntr reread templates (n,i) + \njt include jump tags (n,i) -- C++ ---------------------------------------------------------------- - \+co cout << << endl; (n,i) - \+" << "" (n,i) + \+ih include C++ standard library header (n,i) + \+ich include C standard library header (n,i) + \+om output manipulators (n,i) + \+fb ios flag bits (n,i) \+c class (n,i) - \+ps #include <...> STL (n,i) - \+pc #include C (n,i) \+cn class (using new) (n,i) - \+ci class implementation (n,i) - \+cni class (using new) implementation (n,i) - \+mi method implementation (n,i) - \+ai accessor implementation (n,i) - \+tc template class (n,i) \+tcn template class (using new) (n,i) - \+tci template class implementation (n,i) - \+tcni template class (using new) impl. (n,i) - \+tmi template method implementation (n,i) - \+tai template accessor implementation (n,i) - - \+tf template function (n,i) \+ec error class (n,i) + \+tf template function (n,i) \+tr try ... catch (n,v,i) \+ca catch (n,v,i) - \+c. catch(...) (n,v,i) + \+caa catch(...) (n,v,i) + \+ex extern "C" { } (n,v,i) + \+oif open input file (n,v,i) + \+oof open output file (n,v,i) + \+uns using namespace std; (n,v,i) + \+un using namespace xxx; (n,v,i) + \+unb namespace xxx { } (n,v,i) + \+na namespace alias (n,v,i) + \+rt RTTI (n,v,i) + + \+ic class implementation (n,i) + \+icn class (using new) implementation (n,i) + \+im method implementation (n,i) + \+ia accessor implementation (n,i) + \+itc template class implementation (n,i) + \+itcn template class (using new) impl. (n,i) + \+itm template method implementation (n,i) + \+ita template accessor implementation (n,i) + \+ioi operator >> (n,i) + \+ioo operator << (n,i) -- Run ---------------------------------------------------------------- @@ -1230,35 +1352,50 @@ Legend: (i) insert mode, (n) normal mode, (v) visual mode \rl link (n,i) \rr run (n,i) \ra set comand line arguments (n,i) - \rm run make (n,i) - \rmc run 'make clean' (n,i) - \rcm choose makefile (n,i) - \rme executable to run (n,i) - \rma cmd. line arg. for make (n,i) + \rd run debugger (n,i) + + \re executable to run (n,i) + \rp run splint (n,i) \rpa cmd. line arg. for splint (n,i) + \rcc run cppcheck (n,i) + \rccs severity for cppcheck (n,i) \rk run CodeCheck (TM) (n,i) \rka cmd. line arg. for CodeCheck (TM) (n,i) - \rd run indent (n,v,i) + \ri run indent (n,v,i) [n]\rh hardcopy buffer (n,v,i) \rs show plugin settings (n,i) \rx set xterm size (n, only Linux/UNIX & GUI) \ro change output destination (n,i) -The hotkeys are defined in the file type plugin c.vim (part of this csupport -plugin package) and described in the document c-hot-keys.pdf +The file c-hotkeys.pdf contains a reference card for these key mappings. +Multi-line inserts and code snippets will be indented after insertion. + +The hotkeys are defined in the template files (part of this csupport +plugin package) and described in the document c-hotkeys.pdf Changing the default map leader '\' ----------------------------------- The map leader can be changed by the user by setting a global variable in the -file .vimrc - +file .vimrc +> let g:C_MapLeader = ',' - +< The map leader is now a comma. The 'line end comment' command is now defined as ',cl'. This setting will be used as a so called local leader and influences only files with filetype 'c' and 'cpp'. +The configured mapleader can also be used in the ftplugin, by calling the +functions *C_SetMapLeader()* and *C_ResetMapLeader()* . The maps created +between the two calls will use |g:C_MapLeader| as the ||: +> + call C_SetMapLeader () + + map eg :echo "Example Map :)" + + call C_ResetMapLeader () +< + ============================================================================== 3. HOTKEYS *csupport-hotkeys* ============================================================================== @@ -1279,17 +1416,17 @@ Shift-F2 can be used to switch between source files and header files if the plugin a.vim (http://vim.sourceforge.net/scripts/script.php?script_id=31) is present. To suppress the creation of a new header file when switching from a source file the file ~/.vimrc should contain a line - +> let g:alternateNoDefaultAlternate = 1 - +< A header file will only be opened if it already exists. The Shift-key is dead when you are working with Vim in a console terminal -(non-Gui). You could add - +(non-Gui). You could add +> noremap \a :A inoremap \a :A - +< to get a hot key for this case. ============================================================================== @@ -1302,124 +1439,149 @@ to get a hot key for this case. Several global variables are checked by the script to customize it: - ---------------------------------------------------------------------------- - GLOBAL VARIABLE DEFAULT VALUE TAG (see below) - ---------------------------------------------------------------------------- - g:C_GlobalTemplateFile plugin_dir.'c-support/templates/Templates' - g:C_LocalTemplateFile $HOME.'/.vim/c-support/templates/Templates' - g:C_TemplateOverwrittenMsg 'yes' - g:C_Ctrl_j 'on' - - g:C_CodeSnippets plugin_dir.'/c-support/codesnippets/' - g:C_Dictionary_File '' - g:C_LoadMenus 'yes' - g:C_MenuHeader 'yes' - g:C_OutputGvim 'vim' - g:C_Root '&C\/C\+\+.' - g:C_XtermDefaults '-fa courier -fs 12 -geometry 80x24' - g:C_Printheader "%<%f%h%m%< %=%{strftime('%x %X')} Page %N" - g:C_MapLeader '\' - g:C_GuiSnippetBrowser 'gui' - g:C_GuiTemplateBrowser 'gui' - - Linux/UNIX: - g:C_ObjExtension '.o' - g:C_ExeExtension '' - g:C_CCompiler 'gcc' - g:C_CplusCompiler 'g++' - g:C_Man 'man' - Windows: - g:C_ObjExtension '.obj' - g:C_ExeExtension '.exe' - g:C_CCompiler 'gcc.exe' - g:C_CplusCompiler 'g++.exe' - g:C_Man 'man.exe' - g:C_VimCompilerName gcc - g:C_CFlags '-Wall -g -O0 -c' - g:C_LFlags '-Wall -g -O0' - g:C_Libs '-lm' - g:C_LineEndCommColDefault 49 - g:C_CExtension 'c' - g:C_TypeOfH 'cpp' - g:C_SourceCodeExtensions 'c cc cp cxx cpp CPP c++ C i ii' - - g:C_CodeCheckExeName 'check' - g:C_CodeCheckOptions '-K13' + ---------------------------------------------------------------------------- + GLOBAL VARIABLE DEFAULT VALUE TAG (see below) + ---------------------------------------------------------------------------- + g:C_CExtension 'c' + g:C_CFlags '-Wall -g -O0 -c' + g:C_CodeCheckExeName 'check' + g:C_CodeCheckOptions '-K13' + g:C_CodeSnippets plugin_dir.'/c-support/codesnippets/' + g:C_Ctrl_j 'on' + g:C_Debugger 'gdb' + g:C_Dictionary_File '' + g:C_GlobalTemplateFile plugin_dir.'c-support/templates/Templates' + g:C_GuiSnippetBrowser 'gui' + g:C_GuiTemplateBrowser 'gui' + g:C_InsertFileHeader 'yes' + g:C_LFlags '-Wall -g -O0' + g:C_Libs '-lm' + g:C_LineEndCommColDefault 49 + g:C_LoadMenus 'yes' + g:C_CreateMenusDelayed 'no' + g:C_LocalTemplateFile $HOME.'/.vim/c-support/templates/Templates' + g:C_MapLeader '\' + g:C_MenuHeader 'yes' + g:C_NonCComment '#' + g:C_OutputGvim 'vim' + g:C_Printheader "%<%f%h%m%< %=%{strftime('%x %X')} Page %N" + g:C_RootMenu '&C\/C\+\+.' + g:C_SourceCodeExtensions 'c cc cp cxx cpp CPP c++ C i ii' + g:C_TypeOfH 'cpp' + g:C_VimCompilerName gcc + g:C_XtermDefaults '-fa courier -fs 12 -geometry 80x24' + + Linux/UNIX: + g:C_CCompiler 'gcc' + g:C_CplusCompiler 'g++' + g:C_ExeExtension '' + g:C_Man 'man' + g:C_ObjExtension '.o' + Windows: + g:C_CCompiler 'gcc.exe' + g:C_CplusCompiler 'g++.exe' + g:C_ExeExtension '.exe' + g:C_Man 'man.exe' + g:C_ObjExtension '.obj' The variable plugin_dir will automatically be set to one of the following values: $HOME.'/.vim/' for Linux/Unix $VIM.'/vimfiles/' for Windows - ---------------------------------------------------------------------------- - - 1. group: g:C_GlobalTemplateFile : Sets the master template file (see|csupport-templates|) - g:C_LocalTemplateFile : Sets the local template file (see|csupport-templates|) - g:C_TemplateOverwrittenMsg : message if template is overwritten - g:C_Ctrl_j : hotkey Ctrl-j 'on'/'off' (see|csupport-Ctrl-j|) - - 2. group: g:C_CodeSnippets : The name of the code snippet directory - (see |csupport-snippets|). - g:C_Dictionary_File : The name(s) of the dictionary file(s) used for - word completion (see also |csupport-dictionary|) - g:C_LoadMenus : Load menus and mappings ("yes", "no") at startup. - g:C_MenuHeader : Switch the submenu header on/off. - g:C_OutputGvim : when program is running output goes to the vim - command line ("vim"), to a buffer ("buffer") or to - an xterm ("xterm"). - g:C_Root : The name of the root menu entry of this plugin - (see |csupport-custom-root|). - g:C_XtermDefaults : the xterm defaults - g:C_Printheader : hardcopy: definition of the page header - g:C_MapLeader : the map leader for hotkeys (see|csupport-usage-vim|) - g:C_GuiSnippetBrowser : code snippet browser: 'gui', 'commandline' - g:C_GuiTemplateBrowser : code template browser: 'gui', 'explorer', 'commandline' - - 3. group: g:C_CExtension : Extension of C files. Everything else is C++. - g:C_TypeOfH : filetype of header files with extension 'h' (c,cpp) - g:C_SourceCodeExtensions : filename extensions for C/C++ - implementation files - g:C_CCompiler : The name of the C compiler. - g:C_CplusCompiler : The name of the C++ compiler. - g:C_VimCompilerName : the compiler name used by :compiler - g:C_Man : The name of the man utility. - g:C_CFlags : Compiler flags used for a compilation. - g:C_LFlags : Compiler flags used for linkage. - g:C_Libs : Libraries to link with. - g:C_ObjExtension : C/C+ file extension for objects - (leading point required if not empty) - g:C_ExeExtension : C/C+ file extension for executables - (leading point required if not empty) - g:C_LineEndCommColDefault : Default starting column for end-of-line comments. - g:C_CodeCheckExeName : The name of the CodeCheck (TM) executable - (the default is 'check') - g:C_CodeCheckOptions : Default options for CodeCheck (TM) - (see |csupport-run-codecheck|). + + ---------------------------------------------------------------------------- + GLOBAL VARIABLE SHORT EXPLANATION + ---------------------------------------------------------------------------- + g:C_CCompiler : The name of the C compiler. + g:C_CExtension : Extension of C files. Everything else is C++. + g:C_CFlags : Compiler flags used for a compilation. + g:C_CodeCheckExeName : The name of the CodeCheck (TM) executable (the + default is 'check') + g:C_CodeCheckOptions : Default options for CodeCheck (TM) (see + |csupport-run-codecheck|). + g:C_CodeSnippets : The name of the code snippet directory (see + |csupport-snippets|). + g:C_CplusCompiler : The name of the C++ compiler. + g:C_Ctrl_j : hotkey Ctrl-j 'on'/'off' (see |csupport-Ctrl-j|) + g:C_Debugger : the default debugging: 'gdb', 'kdbg', or 'ddd' + g:C_Dictionary_File : The name(s) of the dictionary file(s) used for + word completion (see also |csupport-dictionary|) + g:C_ExeExtension : C/C+ file extension for executables (leading + point required if not empty) + g:C_GlobalTemplateFile : sets the global template file (see |csupport-templates|) + g:C_GuiSnippetBrowser : code snippet browser: 'gui', 'commandline' + g:C_GuiTemplateBrowser : code template browser: 'gui', 'explorer', 'commandline' + g:C_InsertFileHeader : insert file prolog in a new file ('yes', 'no') + g:C_LFlags : Compiler flags used for linkage. + g:C_Libs : Libraries to link with. + g:C_LineEndCommColDefault : Default starting column for end-of-line comments. + g:C_LoadMenus : Load menus and mappings ("yes", "no") at startup. + g:C_CreateMenusDelayed : Load menus only with filetypes 'c' or 'cpp' + g:C_LocalTemplateFile : sets the local template file (see |csupport-templates|) + g:C_Man : The name of the man utility. + g:C_MapLeader : the map leader for hotkeys (see ||csupport-usage-vim|) + g:C_MenuHeader : Switch the submenu header on/off. + g:C_NonCComment : comment leader string for a non-C comment + g:C_ObjExtension : C/C+ file extension for objects (leading point + required if not empty) + g:C_OutputGvim : when program is running output goes to the vim command + line ("vim"), to a buffer ("buffer") or to an xterm ("xterm"). + g:C_Printheader : hardcopy: definition of the page header + g:C_RootMenu : The name of the root menu entry of this plugin + (see |csupport-custom-root|). + g:C_SourceCodeExtensions : filename extensions for C/C++ implementation files + g:C_TypeOfH : filetype of header files with extension 'h' (c,cpp) + g:C_VimCompilerName : the compiler name used by :compiler + g:C_XtermDefaults : the xterm defaults To override the default add appropriate assignments to ~/.vimrc . +The following global variables can be changed on the fly from the Vim command +line, i.e. without restarting the editor: +> + C_CCompiler + C_CFlags + C_LFlags + C_Libs + C_CplusCFlags + C_CplusCompiler + C_CplusLFlags + C_CplusLibs + C_Debugger +< +If you change g:C_CFlags or g:C_LFlags, you have change to change the other +accordingly. The same holds for g:C_CplusCFlags and g:C_CplusLFlags (see also +|csupport-run-buffer|). ------------------------------------------------------------------------------ 4.2 THE ROOT MENU *csupport-custom-root* ------------------------------------------------------------------------------ -The variable g:C_Root, if set (in '.vimrc' or in '.gvimrc'), gives the name -of the single gVim root menu entry in which the C/C++ submenus will be put. -The default is - +The variable g:C_RootMenu, if set (in '.vimrc' or in '.gvimrc'), gives the +name of the single gVim root menu entry in which the C/C++ submenus will be +put. The default is +> '&C\/C\+\+.' - '' -Note the terminating dot. +< '' +Note the terminating dot. If you want to set the plugin root menu into another menu, e.g. 'Plugin', this is done by the following line in '.vimrc' - - let g:C_Root = '&Plugin.&C\/C\+\+.' - +> + let g:C_RootMenu = '&Plugin.&C\/C\+\+.' +< ------------------------------------------------------------------------------ 4.3 SYSTEM-WIDE INSTALLATION *csupport-system-wide* ------------------------------------------------------------------------------ -A system-wide installation (one installation for all users) is done as -follows. +A system-wide installation (one installation for all users) of the plug-in can +be done. This will mean however, that a user can not edit the template +library, for example to set his own name. So in case of a system-wide +installation, every user can have an own set of templates (called local +templates), which are localed in each users' home directory. +Note: As you might have guessed, this behavior is much more inspired by Linux +than Windows. + +A system-wide installation is done as follows. As *** SUPERUSER *** : @@ -1444,39 +1606,38 @@ directories. SUSE has a directory '/usr/share/vim/site' to put plugins in. These directories will not be found automatically. After installing the plugin below '/usr/share/vim/site' the use of the templates will be enabled by the following line in '~/.vimrc': - +> let g:C_GlobalTemplateFile = '/usr/share/vim/site/c-support/templates/Templates' - +< As *** USER *** : Create your private snippet directory: - +> mkdir --parents ~/.vim/c-support/codesnippets - +< You may want to copy the snippets coming with this plugin (in $VIM/vimfiles/c-support/codesnippets) into the new directory or to set a link to the global directory. Create your private template directory: - +> mkdir --parents ~/.vim/c-support/templates - +< Create a private template file 'Templates' (compulsory) in this directory to overwrite some macros, e.g. - - *|AUTHOR|* = your name - *|AUTHORREF|* = ... - *|EMAIL|* = ... - *|COMPANY|* = ... - *|COPYRIGHT|* = ... - -You can also have local templates which overwrite the global ones. To suppress -the messages in this case set a global variable in '~/.vimrc' (Windows: -'~\_vimrc') : - - let g:C_TemplateOverwrittenMsg= 'no' - -The default is 'yes'. +> + SetMacro( 'AUTHOR', 'Dr. Fritz Mehner' ) + SetMacro( 'AUTHORREF', 'fgm' ) + SetMacro( 'EMAIL', 'mehner.fritz@fh-swf.de' ) + SetMacro( 'ORGANIZATION','FH Südwestfalen, Iserlohn' ) + SetMacro( 'COPYRIGHT', 'Copyright (c) |YEAR|, |AUTHOR|' ) +< +You can also have local templates which override the global ones. To see a +messages in this case set a global variable in '~/.vimrc' (Windows: '~\_vimrc'): +> + let g:Templates_MapInUseWarn = 0 +< +The default is '1'. ============================================================================== 5. TEMPLATE FILES AND TAGS *csupport-templates* @@ -1486,51 +1647,86 @@ The default is 'yes'. 5.1 TEMPLATE FILES *csupport-templates-files* ------------------------------------------------------------------------------ -Nearly all menu entries insert code snippets or comments. All of these are +Nearly all menu items insert code snippets or comments. All of these are contained within template files and can be changed by the user to meet their -requirements. +requirements. The menu shortcuts (e.g. 'c' for the Comments menu) and the +menu item hotkeys (e.g. '\ct' insert date and time) are also defined in the +templates. +The template engine comes as a separate plug-in contributed by Wolfgang Mehner. +This section is a short introduction to this template system. Please see +|templatesupport.txt| for more information. -The master template file is '$HOME/.vim/c-support/templates/Templates' for a -user installation and '$VIM/vimfiles/c-support/templates/Templates' for a -system-wide installation (see|csupport-system-wide|). +The master template file is '$HOME/.vim/c-support/templates/Templates' for +a user installation and '$VIM/vimfiles/c-support/templates/Templates' for +a system-wide installation (see |csupport-system-wide|). The master template file starts with a macro section followed by templates for single menu items or better by including other template files grouping the -templates according to the menu structure of this plugin. The master file -could look like this: - - $ - $ ============================================================= - $ ========== USER MACROS ====================================== - $ ============================================================= - $ - *|AUTHOR|* = Dr. Fritz Mehner - *|AUTHORREF|* = mn - *|EMAIL|* = mehner@fh-swf.de - *|COMPANY|* = FH Südwestfalen, Iserlohn - *|COPYRIGHT|* = Copyright (c)*|YEAR|,|AUTHOR|* - $ - $ ============================================================= - $ ========== FILE INCLUDES ==================================== - $ ============================================================= - $ - *|includefile|* = c.comments.template - *|includefile|* = c.cpp.template - *|includefile|* = c.idioms.template - *|includefile|* = c.preprocessor.template - *|includefile|* = c.statements.template - -Lines starting with a dollar sign are comments. The section starting -with *|AUTHOR|* assigns values to predefined tags -(see|csupport-templates-macros|) to personalize some templates. Other -predefined tags with given default values can be used (e.g. *|YEAR|* ). - -User defined tags are possible. They have the following syntax: - - *|macroname|* = replacement - -A macroname starts with a letter (uppercase or lowercase) followed by zero or -more letters, digits or underscores. +templates according to the menu structure of this plug-in. The master file +usually looks like this (my settings as an example): +> + § ========================================================== + § User Macros + § ========================================================== + + SetMacro( 'AUTHOR', 'Dr. Fritz Mehner' ) + SetMacro( 'AUTHORREF', 'fgm' ) + SetMacro( 'COMPANY', '' ) + SetMacro( 'COPYRIGHT', 'Copyright (c) |YEAR|, |AUTHOR|' ) + SetMacro( 'EMAIL', 'mehner.fritz@fh-swf.de' ) + SetMacro( 'LICENSE', 'GNU General Public License' ) + SetMacro( 'ORGANIZATION','FH Südwestfalen, Iserlohn' ) + + SetStyle( 'C' ) + + § ========================================================== + § File Includes and Shortcuts + § ========================================================== + + MenuShortcut( 'Comments', 'c' ) + MenuShortcut( 'Statements', 's' ) + MenuShortcut( 'Idioms', 'i' ) + MenuShortcut( 'Preprocessor', 'p' ) + MenuShortcut( 'Snippets', 'n' ) + MenuShortcut( 'C++', 'c' ) + § + IncludeFile( 'snippets.template' ) + § + == USE STYLES : C == + IncludeFile( 'c.comments.template' ) + IncludeFile( 'c.cpp.template' ) + IncludeFile( 'c.idioms.template' ) + IncludeFile( 'c.preprocessor.template' ) + IncludeFile( 'c.statements.template' ) + == ENDSTYLES == + § + == USE STYLES : CPP == + IncludeFile( 'cpp.comments.template' ) + IncludeFile( 'cpp.cpp.template' ) + IncludeFile( 'cpp.idioms.template' ) + IncludeFile( 'cpp.preprocessor.template' ) + IncludeFile( 'cpp.statements.template' ) + == ENDSTYLES == + +Lines starting with a section sign (§) are comments. The section starting with +> + SetMacro( 'AUTHOR', 'Dr. Fritz Mehner' ) +< +assigns values to predefined tags (macros). Arbitrary user-defined macros are +possible. The macro name must follows the rules for a C language identifier: +first character letter or underscore; case matters; digits are allowed +beginning with the second character. + +The statement +> + IncludeFile( 'c.comments.templates' ) +< +includes the templates from the file 'c.comments.templates' (in the same +directory). An absolute path would also be possible. The statement +> + MenuShortcut( 'Comments', 'c' ) +< +sets 'c' as the shortcut for the Comments menu. ------------------------------------------------------------------------------ 5.2 MACROS *csupport-templates-macros* @@ -1538,459 +1734,98 @@ more letters, digits or underscores. The following macro names are predefined. The first group is used to personalize templates. - - ---------------------------------------------------------------------------- - PREDEFINED MACROS DEFAULT VALUE - ---------------------------------------------------------------------------- -*|AUTHOR|* "" -*|AUTHORREF|* "" -*|EMAIL|* "" -*|COMPANY|* "" -*|PROJECT|* "" -*|COPYRIGHTHOLDER|* "" -*|STYLE|* "" -*|includefile|* "" - -*|BASENAME|* filename without path and suffix -*|DATE|* the preferred date representation for the current locale +> + |BASENAME| filename without path and suffix + |DATE| the preferred date representation for the current locale without the time -*|FILENAME|* filename without path -*|PATH|* path without filename -*|SUFFIX|* filename suffix -*|TIME|* the preferred time representation for the current locale + |FILENAME| filename without path + |PATH| path without filename + |SUFFIX| filename suffix + |TIME| the preferred time representation for the current locale without the date and the time zone or name or abbreviation -*|YEAR|* the year as a decimal number including the century - -The macro *|includefile|* can be used to include an additional template file. -A file will be included only once. Commenting and uncommenting include macros -is a simple way to switch between several sets of templates (see also -|csupport-run-templates|). Overwriting existing macros and templates is -possible. - + |YEAR| the year as a decimal number including the century +< ---------------------------------------------------------------------------- - PREDEFINED TAGS + PREDEFINED TAGS USED IN TEMPLATES ---------------------------------------------------------------------------- - ,{CURSOR} The cursor position after insertion of a template - <+text+>,<-text->, Jump targets in templates. Jump with Ctrl-j. - {+text+},{-text-} See |csupport-templates-jump|. + The cursor position after insertion of a template. + <+text+>,<-text-> See |csupport-templates-jumptags|. + {+text+},{-text-} - The split point when inserting in visual mode - (see|csupport-templates-definition|) + The split point when inserting in visual mode + (see|csupport-templates|) -A dependent template file can start with its own macro section. There is no +A dependent template file can start with its own command section. There is no need to have all user defined macros in the master file. -When the first template definition is found (see below) macro definitions are -no longer recognized. -Use the tag variant with curly braces if the indentation of the following line -is wrong after template insertion. + ------------------------------------------------------------------------------ -5.2.1 USER DEFINED FORMATS FOR DATE AND TIME *csupport-templates-date* +5.2.1 USER DEFINED FORMATS FOR DATE AND TIME *csupport-templates-date* ------------------------------------------------------------------------------ The format for *|DATE|* ,*|TIME|* , and*|YEAR|* can be set by the user. The defaults are - *|DATE|* '%x' - *|TIME|* '%X' - *|YEAR|* '%Y' +Example: +> + |DATE| '%x' + |TIME| '%X' + |YEAR| '%Y' +< See the manual page of the C function strftime() for the format. The accepted format depends on your system, thus this is not portable! The maximum length of the result is 80 characters. -User defined formats can be set using the following global variables in -~/.vimrc , e.g. - let g:C_FormatDate = '%D' - let g:C_FormatTime = '%H:%M' - let g:C_FormatYear = 'year %Y' +User defined formats can be set using the following function calls in the +master template file is '$HOME/.vim/c-support/templates/Templates', e.g. +> + SetFormat( 'DATE', '%D' ) + SetFormat( 'TIME', '%H:%M' ) + SetFormat( 'YEAR', 'year %Y' ) ------------------------------------------------------------------------------ 5.3 TEMPLATES *csupport-templates-names* ------------------------------------------------------------------------------ -5.3.1 Template names - +5.3.1 Template definition *csupport-templates-definition* The template behind a menu entry is identified by a given name. The first part -of the name identifies the menu, the second part identifies the item. The -modes are also hard coded (see|csupport-templates-definition|for the use of -). - - TEMPLATE NAME MODES - -------------------------------------------------------------------------- - - comment.class normal - comment.end-of-line-comment normal - comment.file-description normal - comment.file-description-header normal - comment.file-section-cpp-class-defs normal - comment.file-section-cpp-class-implementations-exported normal - comment.file-section-cpp-class-implementations-local normal - comment.file-section-cpp-data-types normal - comment.file-section-cpp-function-defs-exported normal - comment.file-section-cpp-function-defs-local normal - comment.file-section-cpp-header-includes normal - comment.file-section-cpp-local-variables normal - comment.file-section-cpp-macros normal - comment.file-section-cpp-prototypes normal - comment.file-section-cpp-typedefs normal - comment.file-section-hpp-exported-class-defs normal - comment.file-section-hpp-exported-data-types normal - comment.file-section-hpp-exported-function-declarations normal - comment.file-section-hpp-exported-typedefs normal - comment.file-section-hpp-exported-variables normal - comment.file-section-hpp-header-includes normal - comment.file-section-hpp-macros normal - comment.frame normal - comment.function normal - comment.keyword-bug normal - comment.keyword-compiler normal - comment.keyword-keyword normal - comment.keyword-todo normal - comment.keyword-tricky normal - comment.keyword-warning normal - comment.keyword-workaround normal - comment.method normal - comment.special-constant-type-is-long normal - comment.special-constant-type-is-unsigned-long normal - comment.special-constant-type-is-unsigned normal - comment.special-empty normal - comment.special-fall-through normal - comment.special-implicit-type-conversion normal - comment.special-no-return normal - comment.special-not-reached normal - comment.special-remains-to-be-implemented normal - - cpp.accessor-implementation normal - cpp.catch normal, visual - cpp.catch-points normal, visual - cpp.cin normal - cpp.class-definition normal - cpp.class-implementation normal - cpp.class-using-new-definition normal - cpp.class-using-new-implementation normal - cpp.cout-operator normal - cpp.cout normal - cpp.error-class normal - cpp.extern normal, visual - cpp.method-implementation normal - cpp.namespace-block normal, visual - cpp.namespace normal - cpp.namespace-std normal - cpp.open-input-file normal - cpp.open-output-file normal - cpp.operator-in normal - cpp.operator-out normal - cpp.output-manipulator-boolalpha normal - cpp.output-manipulator-dec normal - cpp.output-manipulator-endl normal - cpp.output-manipulator-fixed normal - cpp.output-manipulator-flush normal - cpp.output-manipulator-hex normal - cpp.output-manipulator-internal normal - cpp.output-manipulator-left normal - cpp.output-manipulator-oct normal - cpp.output-manipulator-right normal - cpp.output-manipulator-scientific normal - cpp.output-manipulator-setbase normal - cpp.output-manipulator-setfill normal - cpp.output-manipulator-setiosflag normal - cpp.output-manipulator-setprecision normal - cpp.output-manipulator-setw normal - cpp.output-manipulator-showbase normal - cpp.output-manipulator-showpoint normal - cpp.output-manipulator-showpos normal - cpp.output-manipulator-uppercase normal - cpp.rtti-const-cast normal - cpp.rtti-dynamic-cast normal - cpp.rtti-reinterpret-cast normal - cpp.rtti-static-cast normal - cpp.rtti-typeid normal - cpp.template-accessor-implementation normal - cpp.template-class-definition normal - cpp.template-class-implementation normal - cpp.template-class-using-new-definition normal - cpp.template-class-using-new-implementation normal - cpp.template-function normal - cpp.template-method-implementation normal - cpp.try-catch normal, visual - - idioms.assert normal - idioms.calloc normal - idioms.enum normal, visual - idioms.fprintf normal - idioms.fscanf normal - idioms.function normal, visual - idioms.function-static normal, visual - idioms.main normal, visual - idioms.malloc normal - idioms.open-input-file normal - idioms.open-output-file normal - idioms.printf normal - idioms.scanf normal - idioms.sizeof normal - idioms.struct normal, visual - idioms.union normal, visual - - preprocessor.define normal - preprocessor.ifdef-else-endif normal, visual - preprocessor.if-else-endif normal, visual - preprocessor.ifndef-def-endif normal, visual - preprocessor.ifndef-else-endif normal, visual - preprocessor.include-global normal - preprocessor.include-local normal - preprocessor.undefine normal - - statements.block normal, visual - statements.case normal - statements.do-while normal, visual - statements.for-block normal - statements.for normal - statements.if-block-else normal, visual - statements.if-block normal, visual - statements.if-else normal, visual - statements.if normal - statements.switch normal, visual - statements.while-block normal, visual - statements.while normal - - -5.3.2 Template definition *csupport-templates-definition* - -A template definition starts with a template head line with the following -syntax: - - == templatename == [ position == ] - -The templatename is one of the above template identifiers. The position -attribute is optional. Possible attribute values are: - - above insert the template before the current line - append append the template to the current line - below insert the template below the current line - insert insert the template at the cursor position - start insert the template before the first line of the buffer - -An example: - - == comment.function == - /* - * === FUNCTION ======================================================= - * Name: - * Description: - * ====================================================================== - */ - -The definition of a template ends at the next head line or at the end of the -file. - -Templates for the visual mode can use . The text before will -than be inserted above the marked area, the text after will be -inserted behind the marked area. An example: - - == statements.if-block-else == - if ( ) { - } else { - } - -If applied to the marked block - - xxxxxxxxxxx - xxxxxxxxxxx - -this template yields - - if ( ) { - xxxxxxxxxxx - xxxxxxxxxxx - } else { - } - -The templates with a visual mode are shown in the table under -|csupport-templates-names|. - -5.3.3 Template expansion *csupport-templates-expansion* - -There are additional ways to control the expansion of a template. - -USER INPUT ----------- -If the usage of a yet undefined user macro starts with a question mark the -user will be asked for the replacement first, e.g. with the following template - - == idioms.function == - void - *|?FUNCTION_NAME|* ( ) - { - return ; - } /* ----- end of function*|FUNCTION_NAME|* ----- */ - -The user can specify the function name which then will be applied twice. If -the macro was already in use the old value will be suggested as default. - -MACRO MANIPULATION ------------------- - -A macro expansion can be controlled by the following attributes +of the name identifies the menu name, the second part identifies the item. +A template definition starts with a template header with the following syntax: - :l change macro text to lowercase - :u change macro text to uppercase - :c capitalize macro text - :L legalize name + == menu_name.template_name == options == -The include guard template is an example for the use of ':L' : +The options are described here: |template-support-options|. - == preprocessor.ifndef-def-endif == - #ifndef *|?BASENAME:L|_INC* - #define *|BASENAME|_INC* - - #endif // ----- #ifndef*|BASENAME|_INC* ----- +5.3.2 The jump tags <+text+> etc. *csupport-templates-jumptags* -The base name of the file shall be used as part of the include guard name. -The predefined macro*|BASENAME|* is used to ask for this part because this -macro has already a defined value. That value can accepted or replaced by the -user. For the filename 'test test++test.h' the legalized base name -'TEST_TEST_TEST' will be suggested. - -Legalization means: - - replace all whitespaces by underscores - - replace all non-word characters by underscores - - replace '+' and '-' by underscore - -5.3.4 The macros <+text+> etc. *csupport-templates-jump* - -There are four macro types which can be used as jump targets in templates: +There are four jump tag types which can be used as jump targets in templates: <+text+> Can be jumped to by hitting Ctrl-j. {+text+} Same as <+text+>. Used in cases where indentation gives unwanted results with the first one. - + <-text-> Same as the two above. Will be removed if the template is used {-text-} in visual mode. -The text inside the brackets is userdefined and can be empty. The text -can be composed from letters (uppercase and lowercase), digits, underscores -and blanks. After the insertion of an template these jump targets will be -highlighted. +The text inside the brackets is userdefined and can be empty. The text can be +composed from letters (uppercase and lowercase), digits, and underscores. +After the insertion of an template these jump targets will be highlighted. -5.3.5 Command Ctrl-j *csupport-Ctrl-j* +5.3.3 Command Ctrl-j *csupport-Ctrl-j* Use the command Ctrl-j to jump to the next target. The target will be removed and the mode will switched to insertion. Ctrl-j works in normal and in insert -mode. - -The template for a function can be written as follows: - - == idioms.function == - void - |?FUNCTION_NAME| ( <+argument list+> ) - { - return <+return value+>; - } /* ----- end of function |FUNCTION_NAME| ----- */ - -The cursor will be set behind 'void'. You can remove 'void' easily with -Ctrl-w (delete word before cursor) and insert a new type. A Ctrl-j leads you -to the argument list. The target disappears and you can type on. When the -function body is written a final Ctrl-j brings you to the return statement. - -The following example shows the usage of the type {-text-}. The idiom for the -opening of a file marks the line before the file is closed. This is also the -line where the template will be split to surround a marked area. In this case -(visual mode) the target is not needed and therefore removed (minus signs as -mnemonic). In normal and insert mode the target is meaningful and will be -therefore be present. The form <-...-> would result in a wrong indentation of -the file close statement. The brace type will be handled as a block and the -indentation will be correct. - - == cpp.open-input-file == - char *ifs_file_name = ""; /* input file name */ - ifstream ifs; /* create ifstream object */ - - ifs.open (ifs_file_name); /* open ifstream */ - if (!ifs) { - cerr << "\nERROR : failed to open input file " << ifs_file_name << endl; - exit (EXIT_FAILURE); - } - {-continue here-} - ifs.close (); /* close ifstream */ - -Extra feature of Ctrl-j ------------------------ -If none of the above described targets is left Ctrl-j can be used to jump -behind closing brackets, parenthesis, braces, or string terminators ('"`). -This feature is limited to the current line. Ctrl-j does not jump behind the -last character in a line. - - -How to switch the mapping for Ctrl-j off ----------------------------------------- -The original meaning of Ctrl-j is 'move [n] lines downward' (see |CTRL-j|). -If you are accustomed to use the deafult and don't like these jump targets you -can switch them off. Put the following line in the file .vimrc : - - let g:C_Ctrl_j = 'off' - -The default value of g:C_Ctrl_j is 'on'. You do not have to change the -template files. All jump targets will be removed before a template will be -inserted. - -============================================================================== -5.4 SWITCHING BETWEEN TEMPLATE SETS *csupport-templates-sets* -============================================================================== - -This plugin comes with two sets of templates. These are suggestions. You may -want to have additional sets for different projects or occasionally want to -use doxygen style comments. To facilitate switching use the macro*|STYLE|* -(|csupport-templates-files|) to define a unique name and the -IF-ENDIF-construct to choose a particular set of files for example: - - ... - - *|STYLE|* = C - $ - $ ============================================================= - $ ========== FILE INCLUDES ==================================== - $ ============================================================= - $ - == IF *|STYLE|* IS C == - $ - |includefile| = c.comments.template - |includefile| = c.cpp.template - |includefile| = c.idioms.template - |includefile| = c.preprocessor.template - |includefile| = c.statements.template - $ - == ENDIF == - - ... - -The syntax is as follows: - - == IF macro_name IS macro_value == - - == ENDIF == - -Includes outside an IF-ENDIF construct are associated with the default style -'default'. A style set does not have to a complete set of templates. For an -incomplete set the other templates are taken from the default style. - -IF, IS, and ENDIF are keywords. - -HINT. Use these constructs to avoid overwriting your templates when updating -csupport. Copy and rename the set of files you want to change and surround the -includes with an appropriate IF-construct: - - *|STYLE|* = MY_C - $ - ... - $ - == IF *|STYLE|* IS MY_C == - |includefile| = my_c.comments.template - |includefile| = my_c.cpp.template - |includefile| = my_c.idioms.template - |includefile| = my_c.preprocessor.template - |includefile| = my_c.statements.template - == ENDIF == - -Keep a copy of the main template file 'Templates' because this file will be -overwritten if you do not update manually. +mode. The template for an if-else-statement can be written as follows: +> + == Statements.if, else == map:sie, sc:i == + if + <-IF_PART-> + else + <+ELSE_PART+> + endif +< +The cursor will be set as shown. When the condition is specified a Ctrl-j let +you jump to the target <-IF PART-> and deletes it. When the block is written +a Ctrl-j leads you to the else-part. The target <+ELSE_PART+> disappears and +you can type on. ============================================================================== 5.5 BINDING A STYLE TO A FILE EXTENSION *csupport-templates-bind* @@ -1998,9 +1833,9 @@ overwritten if you do not update manually. You can bind the existing styles to one or more filename extensions. To do so assign a Dictionary to the global variable g:C_Styles in '~/.vimrc' : - -let g:C_Styles = { '*.c,*.h' : 'default', '*.cc,*.cpp,*.hh' : 'CPP' } - +> + let g:C_Styles = { '*.c,*.h' : 'C', '*.cc,*.cpp,*.c++,*.C,*.hh,*.h++,*.H' : 'CPP' } +< A Dictionary is created with a comma separated list of entries in curly braces. Each entry has a key and a value, separated by a colon. Each key can only appear once. The keys are themselves a comma separated list of filename @@ -2033,12 +1868,12 @@ following values: $VIM.'/vimfiles/' for Windows If you want to use an additional list MyC.list put the following lines into ~/.vimrc : - - let g:C_Dictionary_File = PLUGIN_DIR.'/c-support/wordlists/c-c++-keywords.list,'. - \ PLUGIN_DIR.'/c-support/wordlists/k+r.list,'. - \ PLUGIN_DIR.'/c-support/wordlists/stl_index.list,'. - \ PLUGIN_DIR.'/c-support/wordlists/MyC.list' - +> + let g:C_Dictionary_File = PLUGIN_DIR.'/c-support/wordlists/c-c++-keywords.list,'. + \ PLUGIN_DIR.'/c-support/wordlists/k+r.list,'. + \ PLUGIN_DIR.'/c-support/wordlists/stl_index.list,'. + \ PLUGIN_DIR.'/c-support/wordlists/MyC.list' +< When in file ~/.vimrc the name PLUGIN_DIR has to be replaced by $HOME or $VIM (see above). Whitespaces in the pathnames have to be escaped with a backslash. @@ -2064,7 +1899,7 @@ in the taglist window. 1) Append the file customization.ctags to the file $HOME/.ctags . 2) Add the following lines (from customization.vimrc) to $HOME/.vimrc : - +> " "------------------------------------------------------------------- " taglist.vim : toggle the taglist window @@ -2081,7 +1916,7 @@ in the taglist window. " ---------- qmake : set file type for *.pro ---------- autocmd BufNewFile,BufRead *.pro set filetype=qmake endif " has("autocmd") - +< 3) restart vim/gvim The two maps will toggle the taglist window (hotkey F11) in all editing modes. @@ -2097,22 +1932,22 @@ If you frequently change the plugin templates and you are using the taglist plugin (section above) you may want to use this plugin for navigation. This is achieved in two steps. First add a new language definition to the file $HOME/.ctags : - +> --langdef=template --langmap=template:.template,TEMPLATE --regex-template=/^==\s+([^=]+)\s+==\s*(\s+==\s+([^=]+)\s+==)?/\1/t,template/ - +< Now add the following lines to the file $HOME/.vimrc : - +> let tlist_template_settings = 'template;t:template' "--------------------------------------------------------------- - " plugin templates : set filetype for *.template + " plugin templates : set filetype for *.template "--------------------------------------------------------------- if has("autocmd") autocmd BufNewFile,BufRead Templates set filetype=template autocmd BufNewFile,BufRead *.template set filetype=template endif " has("autocmd") - +< The assignment defines the heading for the template section in the taglist window. The autocmds set the file type 'template' for the main template file 'Templates' and the includefiles '*.template' (if any). @@ -2138,12 +1973,12 @@ and a warning will be shown. Visual mode ----------- A range of lines containing closed folds can be surrounded by constructs which -have a visual mode, e.g. a for-loop: - +have a visual mode, e.g. a for-loop: +> for ( ; ; ) { +--- 4 lines: {------------------------------------------------------------ } - +< See |folding| for more information on folding. ============================================================================== @@ -2155,7 +1990,7 @@ There are a few additional filetype specific key mappings defined in Complete a classical C comment: '/*' => '/* | */' (modes: i,v). -Complete a classical C multi-line comment (mode: i): +Complete a classical C multi-line comment (mode: i): '/*' => /* * | */ @@ -2166,11 +2001,21 @@ Open a block (modes: i,v): } In visual mode the content of the new block will be indented. +The file customization.cpp.vim provides additional insert mode mappings to +facilitate writting cin and cout statements, e.g. +> + '<<' -> ' << |' + '<<"' -> ' << "|" ' + '<<;' -> ' << "|\n";' + '>>' -> ' >> |' +< +Copy this file to ~/.vim/ftplugin and rename it to 'cpp.vim'. + ============================================================================== 10. WINDOWS PARTICULARITIES *csupport-windows* ============================================================================== -For a user installation the plugin should go into the directory structure below +For a user installation the plugin should go into the directory structure below $HOME/vimfiles/ for a system installation below $VIM/vimfiles/ @@ -2223,30 +2068,36 @@ directory): * How can I see what was loaded? - Use ':scriptnames' from the Vim command line. -* No main menu item. - - Loading of plugin files must be enabled. If not use - :filetype plugin on - This is the minimal content of the file '$HOME/.vimrc'. Create one if there - is none, or better use customization.vimrc. - -* Most key mappings do not work. - - They are defined in a filetype plugin in '$HOME/.vim/ftplugin/'. Use - ':filetype' to check if filetype plugins are enabled. If not, add the line - filetype plugin on - to the file '~/.vimrc'. - * Some hotkeys do not work. - - The hotkeys might be in use by your graphical desktop environment. Under - KDE Ctrl-F9 is the hotkey which let you switch to the 9. desktop. The key + - The hotkeys might be in use by your graphical desktop environment. Under + KDE Ctrl-F9 is the hotkey which let you switch to the 9. desktop. The key settings can usually be redefined. +* The plug-in loads slowly. + - By default, the template library is read while the plug-in is loading, + since the templates also define most of the menu structure. To not slow + down the startup of Vim, you can choose to only create the C/C++-menu when + opening the first C/C++-file. For that, add this line to your ~/.vimrc: + let g:C_CreateMenusDelayed = 'yes' + The only downside is that you won't see the C/C++-menu before you start + working on a C-file, or use the menu entry "Tools->Load C Support". + +* After changing g:C_LFlags / g:C_CplusLFlags my source can not be linked or + run. + - The settings g:C_CFlags / g:C_CplusCFlags have to be changed accordingly + (see |csupport-run-buffer|) + * Splint and/or CodeCheck menu item not visible. - The program is not installed or not found (path not set) or not executable. +* Code incorrectly indented after template insertion. The indentation may be + incorrect inside blocks, if the tag also appears inside the block. + See |template-support-templ-tags| for a detailed explanation. + ============================================================================== 13. RELEASE NOTES *csupport-release-notes* ============================================================================== See file c-support/doc/ChangeLog . ============================================================================== -vim:tw=78:noet:ts=2:ft=help:norl: +vim:tw=78:noet:ts=2:ft=help:norl:expandtab: diff --git a/doc/templatesupport.txt b/doc/templatesupport.txt new file mode 100644 index 0000000..b8558c9 --- /dev/null +++ b/doc/templatesupport.txt @@ -0,0 +1,2368 @@ +*templatesupport.txt* MM Template Support Mar 28 2014 + +MM Template Support *template-support* + + Plug-in version 0.9.3 + for Vim version 7.0 and above + Wolfgang Mehner + + + --- The Maps & Menus Template Support ... --- + +-- ... for Vim Users -- + +This plug-in aims at providing extendible template libraries. A template +library can assist in speeding up the writing of code, while at the same time +ensuring a consistent style. The templates are written in an easy to use +markup language, which enables the user to customize templates without much +hassle. + +Menus and maps to access the templates are created automatically. While maps +might or might not be the preferred way of inserting templates (as well as +using Vim in general), the menus always provide an overview of the templates +and the associated maps. This makes it quite easy to use the templates and +learn their maps at the same time. + +-- ... for Plug-Ins -- + +The template support is controlled by an API and thus can be integrated into +another plug-in. A template library is essentially an object, several of which +can exist in parallel. This makes it relatively easy to write a plug-in for +the programming language of your choice. + +Here is a list of high profile plug-ins which use the template support: +- Bash-Support (www.vim.org/scripts/script.php?script_id=365) +- C-Support (www.vim.org/scripts/script.php?script_id=213) +- Perl-Support (www.vim.org/scripts/script.php?script_id=556) + +============================================================================== +0. TABLE OF CONTENTS *template-support-contents* +============================================================================== + + 1. Introduction |template-support-intro| + 2. Basic Usage |template-support-basics| + 3. Template Library |template-support-library| + 3.1 Personalization |template-support-lib-person| + 4. Templates |template-support-templates| + 4.1 Macros |template-support-templ-macro| + 4.1.1 Predefined Macros |template-support-templ-predef| + 4.2 Tags |template-support-templ-tags| + 4.3 Placement |template-support-templ-place| + 4.3.1 Visual Mode |template-support-templ-visual| + 4.4 Maps & Menus |template-support-templ-maps| + 5. Lists |template-support-lists| + 5.1 Formats |template-support-lists-format| + 5.2 Hashes |template-support-lists-hash| + 6. Advanced Features |template-support-advanced| + 6.1 Coding Styles |template-support-adv-styles| + 6.2 File Pickers |template-support-adv-files| + 7. Menus |template-support-menus| + 8. Help Templates |template-support-help-templ| + + 9. API |template-support-api| + 9.1 Basic Usage |template-support-api-basic| + 9.2 Creating Maps and Menus |template-support-api-maps| + 9.3 Access |template-support-api-access| + 9.4 Miscellany |template-support-api-misc| + 10. Backwards Compatibility |template-support-backwards| + + A. Syntax |template-support-syntax| + A.1 Command Section |template-support-syntax-cmd| + A.2 Templates |template-support-syntax-templ| + A.3 Lists |template-support-syntax-list| + B. Commands |template-support-commands| + B.1 Command Section |template-support-cmd-cmd-sct| + B.2 Templates |template-support-cmd-templates| + C. Options |template-support-options| + C.1 Templates |template-support-opt-templ| + C.2 List |template-support-opt-list| + D. Change Log |template-support-change-log| + +============================================================================== +1. INTRODUCTION *template-support-intro* +============================================================================== + +The manual at hand documents the Maps & Menus Template Support. The next +chapter |template-support-basics|, gives a short preview of the capabilities of +the template support. Templates are listed, together with further +configuration, in a so-called template library. Template libraries are +explained in |template-support-library|, followed by the description of +templates in |template-support-templates|. These chapters will enable the +average user to configure his or her templates. + +Advanced topics are addressed in the following chapters. Lists are explained +in |template-support-lists|, followed in |template-support-advanced| by more +advanced features. The customization of the automatic menu creation is +explained in |template-support-menus|. Help templates offer a mechanism to +quickly access different documentations, they are documented in +|template-support-help-templ|. + +Plug-In developers will find information on the API in |template-support-api|. + +============================================================================== +2. BASIC USAGE *template-support-basics* +============================================================================== + +Templates are short pieces of text which can be included into source code or +text of any other kind. But they are not just plain text, they can be extended +with macros and tags to provide further convenience. Macros can be +automatically replaced with the date or the filename, or they can be replaced +with input from the user, for example the name of a new function. + +The following example shows two templates, as they appear in a so-called +template library. A template library is a text file which lists several +templates, along with their maps and menu shortcuts. +> + == file description == start == + // ================================================== + // File: |FILENAME| + // Description: + // + // Author: |AUTHOR| + // Version: 1.0 + // Created: |DATE| + // ================================================== + + == function == below == + void |?FUNCTION_NAME| ( ) + { + + } /* end of function |FUNCTION_NAME| */ + == ENDTEMPLATE == +< +Each line (the so-called header) > + == == == +starts a new template, > + == ENDTEMPLATE == +marks the end of the template "function". + +When the template "file description" is inserted, it is placed at the start of +the file (option "start"). The filename and the date are inserted where the +macros *|FILENAME|* and *|DATE|* appear, the name of the user is also inserted. +After insertion, the cursor is placed where the tag appears (the +cursor is represented by "|"): +> + // ================================================== + // File: helloworld.cc + // Description: | + // + // Author: Me! + // Version: 1.0 + // Created: 29.2.2000 + // ================================================== +< +The template "function" is inserted below the current line (option "below"). +The user is asked to provide a replacement for the macro *|FUNCTION_NAME|* (it +is marked with "?"), which is then inserted into the text: +> + void say_hello ( | ) + { + + } /* end of function say_hello */ +< +The macro can also be used in visual mode (it contains the tag ). The +template is then inserted surrounding the selected lines, which appear at the +position of the split tag. + +Assume the line "printf(...)" is selected: +> + // ... +< + printf ( "Hello world!" ); ~ +> + // ... +< +After inserting the template, the code looks like this: +> + // ... + + void say_hello ( | ) + { + printf ( "Hello world!" ); + } /* end of function say_hello */ + + // ... +< +============================================================================== +3. TEMPLATE LIBRARY *template-support-library* +============================================================================== + +A template library is a text file which lists several templates, along with +other objects, and commands to configure the behavior of the templates. This +file must be given to the template support in order to be loaded. If you are +working with a plug-in which uses the template support, the plug-in itself +will take care of that. + +Along with templates, a library file can contain comments. Comments always +start at the beginning of a line. The standard is for comments to start with +the character '§'. This may vary, depending on which plug-in uses the template +support. +Comment lines end the current template, so comments should only be used +outside of templates. + +Outside of templates, the library can contain commands. Among other things, +they configure the behavior of the templates and the menus the template +support creates. +Commands always start at the beginning of the line and, as all other names in +the library, are case sensitive. + +A template library can be organized in several files. The command: > + IncludeFile ( "/" ) +loads templates from another file (|template-support-IncludeFile|). The path +is given relative to the including file. The call: > + IncludeFile ( "/", "abs" ) +interprets the path as a absolute path instead. + +The names of the templates also define the menu structure which the template +support creates. Dots appearing in the names place the templates into +submenus. The following library will create two menus and a submenu "special". +> + == Comments.special.GNU license == below == + // License: Copyright (c) |YEAR|, |AUTHOR| + // + // 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. + == Comments.file description == start == + // ================================================== + // File: |FILENAME| + // Description: + // + // Author: |AUTHOR| + // Version: 1.0 + // Created: |DATE| + // ================================================== + + == Idioms.function definition == below == + void |?FUNCTION_NAME| ( ) + { + + } /* end of function |FUNCTION_NAME| */ + == ENDTEMPLATE == +< +Menus and entries are generated in the order in which the corresponding +templates are encountered in the library. The above example will generate this +menu structure: +> + Plug-In Menu + >-+ Comments + | >-+ Special + | | >--- GNU license + | >-- file description + >-+ Idioms + | >-- function definition +< +This also means that a new menu entry can be added by simply putting a new +template at that position in the library. Details on the menu creation can be +found in |template-support-menus|. + +------------------------------------------------------------------------------ +3.1 PERSONALIZATION *template-support-lib-person* +------------------------------------------------------------------------------ + +A personalization of the template library can be achieved by using macros. The +command 'SetMacro' (|template-support-SetMacro|) is used to set replacements +for various macros (my settings as an example): +> + SetMacro( 'AUTHOR', 'Wolfgang Mehner' ) + SetMacro( 'AUTHORREF', 'wm' ) + SetMacro( 'EMAIL', 'wolfgang-mehner@web.de' ) + SetMacro( 'ORGANIZATION', '' ) + SetMacro( 'COPYRIGHT', 'Copyright (c) |YEAR|, |AUTHOR|' ) +< +The replacements may contain other macros. When a template is inserted all +macros will be substituted by the respective replacements. + +Other macros and replacements can be added at will, e.g. the following could +be used in a template library for Bash: > + SetMacro( 'INTERPRETER', '/bin/sh' ) +Then the template for the file description may look as follows: +> + == file description == start == + #! |INTERPRETER| + # ================================================== + # File: |FILENAME| + # Description: + # + # Author: |AUTHOR| + # Version: 1.0 + # Created: |DATE| + # ================================================== + + == ENDTEMPLATE == +< +The format of the included dates and times can be set in a similar fashion, +using 'SetFormat' (|template-support-SetFormat|): +> + SetFormat( 'DATE', '%D' ) + SetFormat( 'TIME', '%H:%M' ) + SetFormat( 'YEAR', 'year %Y' ) +< +These special macros can never be set by 'SetMacro'. The following call will +have no effect and produce a warning: > + SetMacro( 'DATE', "April Fools' Day" ) +< +During template insertion, the macros *|DATE|* , *|TIME|* and *|YEAR|* will be +replaced with the current date and time. + +============================================================================== +4. TEMPLATES *template-support-templates* +============================================================================== + +Templates are short pieces of text which are enhanced by so-called macros and +tags. They define a simple markup language which determines the preparation of +the text before it is inserted and control is handed back to the user. +Beyond that, every template has a name which also determines its place in the +menu structure the template support creates. Together with the template, its +menu shortcut and map are defined. The whole accessibility of the template is +specified in this one place. + +Each template starts with a header: > + == == [ == ] +For consistency with other constructs, the following format is also supported: > + == TEMPLATE: == [ == ] +The list of options can be omitted. + +The name of the template starts with a letter or underscore, and can not end +with a whitespace. Whitespaces in between the name and "==" will be ignored. +The name can contain these characters: + a-z, A-Z, 0-9 + _ + - . , +Dots have a special meaning. They determine the menu structure the template +support will create (see |template-support-library| for a short introduction). + +The list of option defines the map and menu shortcut of the template, and some +aspects of its behavior during insertion into a text, such as its placement +relative to the position of the cursor. + +The following example shows a possible template for the C statement "if": +> + == Statements.if == below, map:si, sc:i == + if ( ) + { + + } + == ENDTEMPLATE == +< +The option "below" specifies that the template should always be inserted in +the lines below the current cursor position. The map is set by the option +"map", it will be ||si. The option "sc" sets the shortcut of the +entry within the menu "Statements". + +------------------------------------------------------------------------------ +4.1 MACROS *template-support-templ-macro* +------------------------------------------------------------------------------ + +Templates are useful because in source code, certain structures are repeated +regularly. Within this structures however, certain parts a variable. Templates +represent those via macros. Macros have a name, which has to follow the same +rules as C identifiers. They start with a letter or underscore, and can +contain numbers after that. Within a template, macros are written as their +names, surrounded by two bars: + *|AUTHOR|* +Replacement for macros can be given in the template library itself: > + SetMacro( 'AUTHOR', 'Wolfgang Mehner' ) +These macros are replaced when inserting the template: +> + == Comments.file description == start == + # ================================================== + # File: |FILENAME| + # Description: + # + # Author: |AUTHOR| + # Version: 1.0 + # Created: |DATE| + # ================================================== + + == ENDTEMPLATE == +< +The template library will appropriately replace *|FILENAME|* and *|DATE|* and +take the replacement for *|AUTHOR|* from the template library. + +Another option is to ask the user for a replacement every time the template is +inserted: +> + == Idioms.function == below == + void |?FUNCTION_NAME| ( ) + { + + } /* end of function |FUNCTION_NAME| */ + == ENDTEMPLATE == +< +The question mark in front of the name means the user will be prompted for a +replacement for "FUNCTION_NAME". This replacement is then inserted twice. This +becomes particularly useful if this name appears in another template. If a +replacement for a certain macro has been given before, this replacement will +be suggested the next time the user has to replace this macro: +> + == Comments.function description == below == + # ================================================== + # Function: |?FUNCTION_NAME| + # Purpose: + # Description: TODO + # ================================================== + + == ENDTEMPLATE == +< +Certain uses come with special requirements on the format of the replacement. +Consider an include guard, where usually an upper case version of the files +name is used to name the guard, such as "_THISFILE_INC": +> + == Preprocessor.include guard == below, noindent == + #ifndef _|BASENAME:u|_INC + #define _|BASENAME:u|_INC + + #endif // ----- #ifndef _|BASENAME:u|_INC ----- + == ENDTEMPLATE == +< +The macro *|BASENAME|* is automatically replaced with the name of the current +file, not including the extension. The flag ":u" means the replacement will be +inserted with all letters in uppercase. So a file named "string.h" will have +an include guard named "_STRING_INC". + +The possible flags are listed below: + :l - change text to lowercase + :u - change text to uppercase + :c - capitalize text (change first letter to uppercase) + :L - legalize name (replace all non-word characters with underscores) + +------------------------------------------------------------------------------ + +4.1.1 Predefined Macros *template-support-templ-predef* + +The replacements for various macros are handles automatically by the template +support. Mostly, they will help with the basic documentation of the file: What +was edited and when? + + *|PATH|* : the path of the current file + *|FILENAME|* : the name of the file + *|BASENAME|* : the name of the file without the suffix + *|SUFFIX|* : the suffix of the file + +Except for using flags, the user has no further influence on the replacements +of these macros, they can not be set via SetMacro(). + + *|TIME|* : the current time + *|DATE|* : the current date + *|YEAR|* : the current year + +The format of the inserted dates and times can be set via SetFormat (see +|template-support-SetFormat|). + +------------------------------------------------------------------------------ +4.2 TAGS *template-support-templ-tags* +------------------------------------------------------------------------------ + +Templates can contain tags, which influence the behavior after the template +has been inserted into the current buffer. The simplest one is , +which specifies the position of the cursor after the template has been +inserted. Consider the following example: +> + == Statements.if == below == + if ( ) + { + + } + == ENDTEMPLATE == +< +After template insertion the cursor is placed between the round brackets and +the user can write down the condition. + +The cursor tag may cause the indentation to be slightly off after template +insertion. Therefore a second version of the cursor tag exists: {CURSOR}. You +should always choose the one which is more naturally compatible with the +languages syntax, and in extension its automatic indentation: +> + == Statements.block == below == + { + {CURSOR} + } + == ENDTEMPLATE == +< +Further convenience is introduced by jump tags. Instead of moving into the +block using arrow keys, the user can be given the possibility to jump to the +next position where editing is required: +> + == Statements.if == below == + if ( ) + { + <+IF_PART+> + } + == ENDTEMPLATE == +< +The standard map for jumping is , also it may vary with each plug-in +using the template support. +Jump tags have one of the following formats: + <+NAME+> <-NAME-> + {+NAME+} {-NAME-} +The text will be indented automatically with the jump tags still appearing in +it, so for every language the appropriate version has to be chosen. The name +consists of arbitrary word characters (letters, digits and underscores) and +can even be empty. The name has no other function than "documenting" the +inserted code: +> + == Statements.if, else == below == + if ( ) + { + <+IF_PART+> + } + else + { + <+ELSE_PART+> + } + == ENDTEMPLATE == + +------------------------------------------------------------------------------ +4.3 PLACEMENT *template-support-templ-place* +------------------------------------------------------------------------------ + +Templates can be placed at different positions relative to the cursor. In most +examples above the option "below" has been used. It means the template is +inserted below the current line. The opposite can be achieved using "above", +while "start" places the template at the beginning of the file, which makes +sense for example for file descriptions: +> + == Comments.file description == start == + ... + == Idioms.function definition == below == + ... + == ENDTEMPLATE == +< +These options cause whole lines to be inserted. Two other options exist: +> + == Comments.end-of-line comment == append == + /* */ + == Comments.date and time == insert == + |DATE|, |TIME| + == ENDTEMPLATE == +< +The template "Comments.end-of-line comment" will be inserted at the end of the +current line, while "Comments.date and time" will insert a timestamp at the +cursor position. + +These placement modes are available: + start - the text is placed above the first line + above - the text is placed above the current line + below - the text is placed below the current line (default) + append - the text is appended to the current line + insert - the text is inserted at the cursor position + +By default, the lines containing a newly inserted template are automatically +indented. To suppress this behavior use the option "noindent". This can be +used for code fragments which contain constructs the indentation program does +not handle correctly. + +------------------------------------------------------------------------------ + +4.3.1 Visual Mode *template-support-templ-visual* + +Oftentimes, existing code needs to be rearranged, for example some lines of +code must be surrounded with an if-statement. For this reason, the +tag exists: +> + == Statements.if == below == + if ( ) + { + + } + == ENDTEMPLATE == +< +If the template is inserted in normal or insert mode, nothing changes. The tag +will be removed automatically. In visual mode however, the selected line will +be surrounded with the template. Consider these lines of code, where the lines +containing "printf" are selected: +> + // ... +< + printf ( "Loading the file ..." ); ~ + printf ( "... reading %d bytes.", n ) ~ +> + // ... +< +After inserting the template "Statements.if", the code looks like this: +> + // ... + + if ( | ) + { + printf ( "Loading the file ..." ); ~ + printf ( "... reading %d bytes.", n ) ~ + } + + // ... +< +Now the user can type in the condition. + +Jump and split tags might be in conflict. Consider the following example: +> + == Statements.if, else == below == + if ( ) + { + <+IF_PART+> + } + else + { + <+ELSE_PART+> + } + == ENDTEMPLATE == +< +When using the template in visual mode, the jump tag <+IF_PART+> should not +appear, since the if block already contains the selected line. This is why +jump tag exist in different versions. The two version <-NAME-> and {-NAME-} +are removed in visual mode. They behave opposite to the tag, which is +removed in every other mode. A better version of the above example looks like +this: +> + == Statements.if, else == below == + if ( ) + { + <-IF_PART-> + } + else + { + <+ELSE_PART+> + } + == ENDTEMPLATE == +< +For templates containing a split tag, the option "noindent" is particularly +useful, since it can prevent large sections of code from being indented +unnecessarily. The following example shows a template for an include guard, +using a C-macro "_THISFILE_INC": +> + == Preprocessor.include guard == below, noindent == + #ifndef _|BASENAME:u|_INC + #define _|BASENAME:u|_INC + + #endif // ----- #ifndef _|BASENAME:u|_INC ----- + == ENDTEMPLATE == +< +Here, running the indentation program after insertion is an unnecessary effort +and may potentially destroy hand-crafted indentation in a large piece of code. + +------------------------------------------------------------------------------ +4.4 MAPS & MENUS *template-support-templ-maps* +------------------------------------------------------------------------------ + +The template support automatically creates maps and menu entries for the +templates in the library. The menu entries appear in the order the templates +have been read. Including a file via > + IncludeFile ( "/" ) +will cause this file to be processed first, then the rest of the including +file is read. + +The map and menu shortcut of a template are defined together with the +template: +> + == Statements.if == below, map:si, sc:i == + if ( ) + { + <+IF_PART+> + } + == ENDTEMPLATE == +< +The templates will have the map ||si and the shortcut "i". + +Menu entries are created by default. The option "nomenu" suppresses this +behavior: +> + == Comments.fix this == nomenu, append, map:cfx == + // TODO: fix this + == ENDTEMPLATE == +< +This template will not clutter the menu and can only be inserted via its map. + +An overview of all the options: + nomenu - no menu entry is created + sc: - a shortcut is created for the menu entry of this template + shortcut: - long version of sc: + map: - a map is created for this template + +============================================================================== +5. LISTS *template-support-lists* +============================================================================== + +Template libraries would regularly contain a huge number of templates with a +repetitive structure. Consider these templates for a C template library: +> + == Preprocessor.include math, map: pim == + #include + == Preprocessor.include stdlib, map:pisl == + #include + == Preprocessor.include stdio, map:pisio == + #include + == Preprocessor.include string, map:pistr == + #include + == ENDTEMPLATE == +< +This has several disadvantages. Besides being difficult to write and maintain, +these templates would not be well accessible. The user would have to memorize +a map for each and every one of them. + +This is why lists exist. They appear as objects in the template library. The +header of a list starts with "LIST:" and then contains a name, which has to +follow the same rules as C identifiers. They start with a letter or +underscore, and can contain numbers after that. +> + == LIST: C_StandardLibs == + 'math', + 'stdlib', + 'stdio', + 'string', + == ENDLIST == + + == Preprocessor.c libs == below, map:pcl == + |PickList( '#include <~.h>', 'C_StandardLibs' )| + #include <|PICK|.h> + == ENDTEMPLATE == +< +The template "Preprocessor.c libs" uses this list. The command: > + "|PickList( '', '' )|" +determines which list is used. During template insertion the user is prompted +to choose an entry from the list, but can also type another name. The prompt +supports tab-completion and navigation with arrow keys. The first argument is +a string which is displayed on the command line, to clarify the meaning of the +choice. After the users makes the choice, the macro *|PICK|* is created, which +contains the chosen item. +Lists can be used again in another context, for example to support C++ +programming: +> + == Preprocessor.c++, c libs == below, map:ppc == + |PickList( '#include ', 'C_StandardLibs' )| + #include + == ENDTEMPLATE == +< +When the template is inserted via a map, the user is prompted to choose an +entry from the list, thus only one map is required to choose from a huge +number of options. When the template is accessed via the menu, two +possibilities exists. Without further changes, the same prompt opens as when +the template is used via a map. But whenever the template includes the +"expandmenu" option, a submenu is created which lists all the entries, which +allows the user to choose in the menu, rather than on the command line: > + == Preprocessor.c libs == below, expandmenu, map:pcl == +< +------------------------------------------------------------------------------ +5.1 FORMATS *template-support-lists-format* +------------------------------------------------------------------------------ + +Lists also support options. The standard format for lists is named "list": +> + == LIST: C_StandardLibs == list == + 'math', 'stdlib', + 'stdio', 'string', + == ENDLIST == +< +The text contained between "== LIST: name ==" and "== ENDLIST ==" is a +comma-separated list of strings, which come as |expr-string| in double quotes +or |literal-string| in single quotes. + +An easier way of writing lists are bare lists, defined with the option "bare": +> + == LIST: C_StandardLibs == list, bare == + math + stdlib + stdio + string + == ENDLIST == +< +They contain each entry on a new line, leading and trailing whitespaces are +ignored. + +------------------------------------------------------------------------------ +5.2 HASHES *template-support-lists-hash* +------------------------------------------------------------------------------ + +Hashes, or dictionaries, are another type of lists. They associate a key with +a value: +> + == LIST: String_Functions == hash == + "strcpy" : "{+DEST+}, {+SRC+}", + "strncpy" : "{+DEST+}, {+SRC+}, {+N+}", + "strcmp" : "{+STR1+}, {+STR2+}", + "strncmp" : "{+STR1+}, {+STR2+}, {+N+}", + "strlen" : "{+STR+}", + == ENDLIST == +< +A hash is a comma-separated list of entries. Each entry contains a key and a +value, separated by a colon. + +During template insertion, the user has to choose one of the keys. Then two +macros *|KEY|* and *|VALUE|* are created, containing the chosen key and its +associated value. Both can be used in the template. +In this example, a function call is inserted, with jump tags named for the +parameters: +> + == Idioms.string function == insert, expandmenu == + |PickList( "function: ", "String_Functions" )| + |KEY| ( |VALUE| ) + == ENDTEMPLATE == +< +These templates also support the option "expandmenu". The menu will list all +the keys. + +============================================================================== +6. ADVANCED FEATURES *template-support-advanced* +============================================================================== + +Editing source code comes with challenges common to many different languages +and systems. + +Different projects may require different coding styles. Template libraries can +be written to support multiple styles (|template-support-adv-styles|). + +Many languages deal with files placed in one or more significant directory, +such as C's include directories or modules in other languages. File pickers +assist in working with these directories (|template-support-adv-files|). + +------------------------------------------------------------------------------ +6.1 CODING STYLES *template-support-adv-styles* +------------------------------------------------------------------------------ + +Different software projects may require different styles for comments and +code. In the case of C/C++, different kinds of comments can be chosen, with +Doxygen introducing even more possibilities. The template engine assists with +these problems by offering so called styles. Styles are named using the same +rules as macros (see |template-support-templ-macro|). + +Every template is assigned to one or more styles. By default, all templates are +assigned to the style "default". Templates can be associated with different +styles by placing them inside a "USE STYLES" statement: +> + == USE STYLES : CPP == + + == Comments.function description == == + # ================================================== + # Function: |?FUNCTION_NAME| + # Purpose: + # Description: TODO + # ================================================== + + == ENDTEMPLATE == + + == ENDSTYLES == + + == USE STYLES : Doxygen == + + == Comments.function description == == + /*! + * \brief + * + * TODO + */ + + == ENDTEMPLATE == + + == ENDSTYLES == +< +Now the "function description" template inserts different code, depending on +whether the style "CPP" or "Doxygen" is chosen (see the documentation of your +plug-in for how to change the style). + +The "USE STYLES" statement can contain the names of several styles. Templates +inside are associated with all the styles appearing in the list. This makes +reuse of templates for different styles possible. +> + == USE STYLES : CPP, Doxygen == + + == Comments.end-of-line command == == + // + == ENDTEMPLATE == + + == USE STYLES : CPP == + + == Comments.function description == == + ... + == ENDTEMPLATE == + + == ENDSTYLES == + + == USE STYLES : Doxygen == + + == Comments.function description == == + ... + == ENDTEMPLATE == + + == ENDSTYLES == + + == ENDSTYLES == +< +The template "end-of-line comment" inserts the same text for both styles, +while "function description" is different. If a template is not associated +with a given style it can be inserted anyway, using the version of the +template associated with the "default" style as a fallback. Only if a template +does not exist for the current style or the default style, an error message is +displayed and nothing inserted. + +Using nested "USE STYLES" statement is also possible. The styles listed in a +nested statement have to be a subset of the styles listed in the one +surrounding it. +Templates inside nested statements are only associated with the styles +listed in the innermost "USE STYLES" statement. + +When files are included inside a "USE STYLES" statement (see +|template-support-IncludeFile|), the templates inside the file are associated +with the style, as they would if they appeared in the including file itself. +The rules for nested "USE STYLES" statements also hold across included files. + +------------------------------------------------------------------------------ +6.2 FILE PICKERS *template-support-adv-files* +------------------------------------------------------------------------------ + +In many languages files are addressed in relation to some significant +directory, such the include mechanism of the C preprocessor or LaTeX's +\graphicspath{} command. To assist in dealing with those files, the template +support offers so-called file pickers. + +File pickers are templates which use the command PickFile( , ) +(|template-support-PickFile|), which asks the user to interactively select a +file: +> + SetPath( 'global_include', '/usr/include/' ) + + == Include.global include == below == + |PickFile( 'global include directory', 'global_include' )| + #include "|PICK|" + == Include.global, filename only == below == + |PickFile( 'global include directory', 'global_include' )| + #include <|FILENAME|> + == ENDTEMPLATE == +< +The first argument to the function is a prompt which is being displayed while +the user selects the file. The second argument is the name of a path set +beforehand, such as "global_include". After the user selects a file, several +macros are created which can be used in the template. *|PICK|* is the path and +name of the file, relative to the path given as the second argument. +*|FILENAME|* is only the name of the file. For a list of all macros, see +|template-support-PickFile|. + +Names for paths are created using the function SetPath( , ) +(see |template-support-SetPath|), which is a lot like SetMacro. + +For example, if the user picks "/usr/include/GL/gl.h", the first template +would result in the line > + #include "GL/gl.h" +being inserted, while the second template would insert > + #include +The paths "/usr/include" or "/usr/include/GL" would have to be in the include +path, of course. + +The second argument can also be a path. In fact, if it does not match an +identifier, it is always assumed to be a path: +> + == Include.local include == below == + |PickFile( 'local include directory', './' )| + #include "|PICK|" + == ENDTEMPLATE == +< +This template lets the user pick a file relative to the current working +directory. + +============================================================================== +7. MENUS *template-support-menus* +============================================================================== + +The template support automatically creates menus for every template. The user +has a measure of influence on the result. Some of these options where already +explained in |templates-support-templ-maps|, this chapter will introduce further +capabilities. + +The menu entries appear in the order the templates have been read. Including a +file via > + IncludeFile ( "/" ) +will cause this file to be processed first, then the rest of the including +file is read. + +The menu structure is defined by the names of the menus. Dots appearing in the +names place the templates into submenus: +> + == Comments.file description == start, sc:f == + ... + == Statements.if == below, sc:i == + ... + == ENDTEMPLATE == +< +The shortcut for the menu entry is defined in the header. The automatic +creation of a menu entry for a template can be suppressed using the option +"nomenu". + +The maps of submenus are set via the command 'MenuShortcut' +(see |template-support-MenuShortcut()|): +> + MenuShortcut ( "Comments.Special", "p" ) + MenuShortcut ( "Comments", "c" ) + MenuShortcut ( "Statements", "s" ) +< +Each call sets the shortcut for the last submenu mentioned. So the above +example sets the shortcut "c" for the menu "Comments", "s" for "Statements" +and "p" for the submenu "Special" within "Comments". The placement of these +calls has no influence on the order of menu creation, only the appearance of +their names in template headers. + +The template library can also contain menu separators, a solid line appearing +between two menu entries. They can help to provide a better overview in a menu +with lots of entries. Menu separators are defined outside of templates using +the syntax: > + == SEP: Statements.sep1 == +The header start with "SEP:" and then contains the name of the separator. The +dots in the name again define which submenu the separator will appear in, +while the relative position in relation to the other templates defines the +placement. The last part of the name following the last dot has no influence, +but must be unique. +Unlike templates and lists, separators do not have to be ended with a line +like "== ENDTEMPLATE ==". Separators only span one line. Separators could +utilize the syntax of function calls, such as "SetMacro()". However, they have +been designed in this way to visually be on the same level as templates. + +------------------------------------------------------------------------------ + +Note: A short remark for plug-in developers. + +Each menu entry also displays the map of the template, if it has one. By +default, it is prefixes with the standard mapleader, a backslash. Using the +API, this can be changed to the mapleader the user has set: > + call mmtemplates#core#Resource ( + \ , "set", "Templates::Mapleader", "" ) +(see |mmtemplates#core#Resource()|). This mapleader may also appear in menu +entries the plug-in itself creates. As a convenience, the mapleader is +provided by the API, already correctly escaped for menu creation: > + let [ esc_mapleader, msg ] = mmtemplates#core#Resource ( + \ g:My_C_Templates, "escaped_mapleader" ) +< +============================================================================== +8. HELP TEMPLATES *template-support-help-templ* +============================================================================== + +A quick access to the documentation is important for every language. Help +templates offer a mechanism to pick up a word under the cursor and make a +system call using this text. For example, a browser could be opened with help +for a certain command. + +Help templates look a lot like templates in the library, but do not insert +text. They share a lot of other features with regular templates though, they +will create a menu entry and can have shortcuts and maps. + +The syntax of help templates is very close to that of regular templates, +except that their name is prefixed by "HELP:" +> + SetMacro( 'HELP_BROWSER', 'firefox' ) + SetMacro( 'HelpPathEnglish', 'http://en.wiktionary.org/wiki/' ) + + == HELP: Help.english == map:he, sc:e == + |Word( '' )| + |Substitute( '\W', '', 'g' )| + |System( '|HELP_BROWSER| |HelpPathEnglish||PICK:l|' )| + == ENDTEMPLATE == +< +The help template "Help.english" picks up the word under the cursor, removes +every non-word character from that string and then calls > + firefox http://en.wiktionary.org/wiki/... +This will open a new tab containing the article about the word under the +cursor, which is very helpful while writing documentation. + +A help template always performs three steps: +1. Pick up text under the cursor. +2. Change the text (optional). +3. Make a system call or a call on the Vim command line. + +1. Picking Text + +To pick up text under the cursor, the function Word() is used. If the +flag is 'W', the |WORD| under the cursor is picked up: > + |Word('W')| +Otherwise the |word| under the cursor is picked: > + |Word('')| +Lastly, the word can be picked using a regular expression (see |regex|): > + |Pattern( '[\\@]\w\+' )| +This call picks a word prefix by "\" or "@", which in a C comment could be a +Doxygen command. +The text which has just been picked up is then stored in a sort of register, +which for the purpose of the further explanation shall be called "acc". + +2. Editing the Text + +After picking up text, the register "acc" can be changed by one or more calls +to the function Substitute( , , ). For example, to remove +every non-word character: > + |Substitute( '\W', '', 'g' )| +Substitute replaces the contents of "acc" using Vim's |substitute()| function: + acc = substitute( acc, , , ) +If the flag is an empty string, the first occurrence of is replaced +with . If flag equals "g", all occurrences are replaced. The function +LiteralSub(,,) works similarly, except that the first +argument is not interpreted as a regular expression. + +3. Calling Help + +After picking up and changing the text, a call is made using System() or +Vim(). The argument is a string and it can contain macros which are +replaced before the call. The macro *|PICK|* is replaced with "acc", the +picked and changed text. The call is however only made if "acc" is not the +empty string. +If either an empty string has been picked up in step 1, or the string is empty +after step 2, the call is made using the command given in Default(). If +no default call is given, no action is performed for an empty string. + +The following help template shows help for Doxygen commands: +> + SetMacro( 'HelpPathDoxygen', 'http://www.stack.nl/~dimitri/doxygen/commands.html' ) + + == HELP: Help.doxygen cmd == map:hd, sc:d == + |Pattern( '[\\@]\w\+' )| + |Substitute( '[\\@]', '', '' )| + |System( '|HELP_BROWSER| |HelpPathDoxygen|#cmd|PICK|' )| + |Default( '|HELP_BROWSER| |HelpPathDoxygen|' )| + == ENDTEMPLATE == +< +First, a Doxygen command is picked up under the cursor, then the leading "\" +or "@" is removed. Then a system call such as: > + firefox http://www.stack.nl/~dimitri/doxygen/commands.html#cmdparam +is made. If there was no Doxygen command under the cursor, the following call +is made instead, which will show a table of all Doxygen commands: > + firefox http://www.stack.nl/~dimitri/doxygen/commands.html +< +Note: The examples still worked in November, 2013. + + + + -------------------------------------------------------------------------- ~ + + -------------------------------------------------------------------------- ~ + + -------------------------------------------------------------------------- ~ + + + +============================================================================== +9. API *template-support-api* +============================================================================== + +This chapter is only relevant if you want to use the template system with your +own plug-in! + +The API enables other plug-ins to use the template system. + +Each template library is stored in a dictionary (|Dictionary|). +- This dictionary must be a global variable, because it it used for purposes + such as callback functions for menu entries and maps. +- Do not change the entries of the dictionary directly, since the internal + structure may change. The API provides access to the stored information. + +------------------------------------------------------------------------------ +9.1 BASIC USAGE *template-support-api-basic* +------------------------------------------------------------------------------ + +These functions provide the basic functionality to load template libraries and +insert templates into a buffer. A further function expands macros in a text. + +------------------------------------------------------------------------------ + *mmtemplates#core#NewLibrary()* +To create a new template library call: + + library = mmtemplates#core#NewLibrary ( ... ) ~ + +Optional parameters: + "debug", level - View debug information with the given level of detail. + (integer, default: show no debug information) +Returns: + library - The template library. (dict) + +Example: + +Create a new library and store it in the variable 'g:My_C_Templates': > + let g:My_C_Templates = mmtemplates#core#NewLibrary () +< +------------------------------------------------------------------------------ + *mmtemplates#core#ReadTemplates()* +Templates are loaded using the function: + + mmtemplates#core#ReadTemplates ( library, ... ) ~ + +Parameters: + library - The template library. (string or dict) +Optional parameters: + "load", file - Load templates from 'file'. (string) + "reload", what - Reload templates according to 'what', see below. + (string or integer) + "overwrite_warning" - Print a warning each time a template is overwritten. + "debug", level - View debug information with the given level of detail. + (integer, default: show no debug information) +No returns. + +The library can either be given directly, or as the name of the global +variable containing the library. + +When loading a new file, it must be given with a path and filename. > + mmtemplates#core#ReadTemplates ( library, "load", "path/file.templates" ) +< +The entire library can be reloaded by calling: > + mmtemplates#core#ReadTemplates ( library, "reload", "all" ) +A file can be reloaded, but only if it has been loaded before: > + mmtemplates#core#ReadTemplates ( library, "reload", "path/file.templates" ) +The i'th file which has been loaded can be reloaded via: > + mmtemplates#core#ReadTemplates ( library, "reload", i ) +< +With the switch "overwrite_warning", a warning is displayed whenever a +template is encountered which already has been set for the current style. + + +Example 1: + +Load a file: > + call mmtemplates#core#ReadTemplates ( g:My_C_Templates, + \ "load", "$HOME/.vim/c-support/templates/lib.templates", + \ "debug", 1, "overwrite_warning" ) +Load the templates in the given file and print very little debug information. +Print a warning whenever a template is overwritten. + + +Example 2.1: + +Load several files: > + call mmtemplates#core#ReadTemplates ( g:My_C_Templates, + \ "load", "/usr/share/vim/.../global.templates" ) + + call mmtemplates#core#ReadTemplates ( g:My_C_Templates, + \ "load", "$HOME/.vim/.../local.templates" ) +Loads the templates in the two files. + + +Example 2.2: + +Reload specific templates: > + call mmtemplates#core#ReadTemplates ( g:My_C_Templates, "reload", -1 ) +Reload the last template which has been loaded. +(".../local.templates" from above) + + +Example 2.3: + +Reload templates by name: > + call mmtemplates#core#ReadTemplates ( g:My_C_Templates, + \ "reload", "$HOME/.vim/.../local.templates" ) +< +------------------------------------------------------------------------------ + *mmtemplates#core#InsertTemplate()* +To insert templates into the current buffer use: + + mmtemplates#core#InsertTemplate ( library, name, ... ) ~ + +Parameters: + library - The template library. (string or dict) + name - The name of the template. (string) +Optional parameters: + "i" - > "insert" + "insert" - Insert mode, special treatment of placement 'insert'. + "v" - > "visual" + "visual" - Visual mode, use the tag. + "placement", place - Overwrite the template's placement. (string) + "range", a, b - Use the range from lines 'a' to 'b'. (integers) + "", replace - Set the replacement for the given macro. The string + must match a macro, e.g. *|FUNCTION_NAME|* . + (string) + "pick", choice - When inserting a list use 'choice', do not ask the user + to pick an entry. (string) + "debug", level - View debug information with the given level of detail. + (integer, default: show no debug information) +No returns. + +The library can either be given directly, or as the name of the global +variable containing the library. +It the template 'name' does not exist, an error message is displayed. + +Examples: + +Include "Statement.If", surround the selected lines: > + call mmtemplates#core#InsertTemplate ( g:My_C_Templates, + \ "Statement.If", "v" ) + +------------------------------------------------------------------------------ + *mmtemplates#core#ExpandText()* +To perform macro expansion in a text use: + + rtext = mmtemplates#core#ExpandText ( library, text ) ~ + +Parameters: + library - The template library. (string or dict) + text - A text. (string) +Returns: + rtext - The text after the macro expansion (string). + +The library can either be given directly, or as the name of the global +variable containing the library. +The expansion is done using all the settings in the library, as well as the +global macro replacements such as *|AUTHOR|* . + +Examples: + +Calling the function: > + let text = mmtemplates#core#ExpandText ( g:My_C_Templates, "|DATE| |TIME|" ) +returns "29.2.2000 12:00", depending on the format set in the library. + +This can be used for special menu entries such as: > + exe 'amenu Comments.Special.Date\ Time ' + \ .':exe "normal! a".mmtemplates#core#ExpandText ( ' + \ .'g:My_C_Templates, "\|DATE\| \|TIME\|" )' +< +------------------------------------------------------------------------------ + *mmtemplates#core#EditTemplateFiles()* +Open the library for editing: + + mmtemplates#core#EditTemplateFiles ( library, file ) ~ + +Parameters: + library - The template library. (string or dict) + file - A file. (string or integer) +No returns. + +The library can either be given directly, or as the name of the global +variable containing the library. + +The argument 'file' can be given as a filename, in which case it must have +been loaded before via |mmtemplates#core#ReadTemplates()|. +'file' can also be an integer i, which refers to the i'th file that has been +loaded. + +A file browser is then opened for the directory containing the file. + +Example: + +Open a file browser in the directory "$HOME/.vim/.../templates/": +> + " load the last template file: + call mmtemplates#core#ReadTemplates ( g:My_C_Templates, + \ "load", "$HOME/.vim/.../templates/local.templates" ) + + " ... + + " edit the library + call mmtemplates#core#EditTemplateFiles ( g:My_C_Templates, -1 ) +< +------------------------------------------------------------------------------ + *mmtemplates#core#JumpToTag()* +The jump to the next tag is performed by: + + e = mmtemplates#core#JumpToTag ( regex ) ~ + +Parameters: + regex - The regex to jump to. (string) +Returns: + e - An empty string. + +Jumps to the next occurrence of 'regex' and removes it from the buffer. Then +the function returns an empty string. +The regular expression can be obtained from the template library via the +function |mmtemplates#core#Resource()|. + +Example: + +This function is best used in maps such as this: +> + let regex = mmtemplates#core#Resource ( g:My_C_Templates, "jumptag" )[0] + + " ... + + nnoremap i=mmtemplates#core#JumpToTag ( regex ) + inoremap =mmtemplates#core#JumpToTag ( regex ) +< +This maps can be created automatically using |mmtemplates#core#CreateMaps()|. + +------------------------------------------------------------------------------ +9.2 CREATING MENUS AND MAPS *template-support-api-maps* +------------------------------------------------------------------------------ + +The automated generation of maps and menus is carried out by these functions. + +------------------------------------------------------------------------------ + *mmtemplates#core#CreateMaps()* +The automatic creation of maps is carried out by the function: + + mmtemplates#core#CreateMaps ( library, localleader, ... ) ~ + +Parameters: + library - The name of the variable containing the library. (string) + localleader - The local mapleader. (string) +Optional parameters: + "do_jump_map" - Create a map for |mmtemplates#core#JumpToTag()|. + "do_special_maps" - Create maps for the special operations. +No returns. + +If 'localleader' is an empty string, the standard mapleader is used. +Otherwise > + let maplocalleader = localleader +is executed before the maps are created. (see |mapleader|) + +The maps for the jump and the special operations (choose a template/style, +reread/edit the library) are not created unless the corresponding options are +given. + +This function creates maps which are local to the buffer, so it must be called +in the appropriate filetype-plugin, or by an autocommand. +An error message is displayed whenever a mapping already exists. The existing +mapping will not be overwritten. + +Example: + +Create maps using the standard mapleader: > + call mmtemplates#core#CreateMaps ( "g:My_C_Templates", "", "do_jump_map" ) +A map to jump to the next tag is also created. + +Technical Details: +- The library must be given as the name of the global variable, since this + name is required to create the maps. +- The function creates maps of the following types: + noremap, inoremap, vnoremap + +------------------------------------------------------------------------------ + *mmtemplates#core#CreateMenus()* +The automatic creation of menus is carried out by the function: + + mmtemplates#core#CreateMenus ( library, rootmenu, ... ) ~ + +Parameters: + library - The name of the variable containing the library. (string) + rootmenu - The name of the root menu. (string) +Optional parameters: + "global_name", name - The name used in the menu headers. + (string, default: the value of 'rootmenu') + "existing_menu", names - The menus which already exist. + (string or list of strings) + "sub_menu", names - Additional sub-menus which should be created. + (string or list of strings) + "specials_menu", name - The name of the menu containing the special + operations. (string, default: "Run") + "priority", p - Create the sub-menu with priority p. + (integer, default: 500) + "do_all" - Action: Reset and create all menus. + "do_reset" - Action: Reset. + "do_templates" - Action: Create menus for all the templates. + "do_specials" - Action: Create a menu with the special entries. + "do_styles" - Action: Create a menu for selecting the style. +No returns. + +"do_all", "do_templates", "do_specials" and "do_styles" starts the automatic +creation of menu entries. Sub-menus are created automatically as needed. +The special operations are: choose a template/style, reread/edit the library. +The corresponding menu entries are put in the sub-menus given by the option +"specials_menu". + +Each sub-menu looks like this, starting with a header: +> + + --- ------------- + + + ... ... +< +The global name (option "global_name") helps to keep track of tear-off menus. +"sub_menu" can be used to create additional menus, which have the same header. +When a sub-menu is created through use of the API like this, an optional +priority can be specified. + +The library keeps track of all created sub-menus, to be able to add the +headers correctly. "existing_menu" adds menus to this list. +"do_reset" resets this list and allows for the menus to be created once more. +"do_all" also reset the list before it carries out further operations. + +The "&" and the trailing points in 'rootmenu' and "existing_menus" are +ignored. "sub_menus" and "specials_menu" also ignore trailing points, but use +the "&" to create shortcuts. However, if a shortcut for the menu has been set +in the library, that one is preferred. + + +Example 1: Basic usage. + +Suppose a plug-in creates the following menus: +> + C-Support + >-+ Comments + | >-- code->comment + | >-- comment->code + | >-+ Special + | | >--- ... + >-+ Run + | >-- run + | >-- ... +< +Then the call has to look like this: > + call mmtemplates#core#CreateMenus ( "g:My_C_Templates", "&C-Support", + \ "do_all", "existing_menu", [ "&Comments","Comments.&Special.","&Run." ] ) +< +To create headers for each sub-menu, similar to those the template support +creates, use code like this: +> + let root_menu = "&C-Support" + let global_name = "C/C++" + exe 'amenu '.root_menu.'.'.root_menu.' ' + exe 'amenu '.root_menu.'.-Sep0- ' + exe 'amenu '.root_menu.'.&Run.Run'.global_name.' ' + exe 'amenu '.root_menu.'.Run.-Sep00- ' +< + +Example 2: Advanced usage. + +This facility can be used to create all the menu headers. +It also gives more control over the order of the menu entries. + +First, reset the list of created menus: > + call mmtemplates#core#CreateMenus ( "g:My_C_Templates", "C-Support", + \ "do_reset" ) +Then create a sub-menu (shortcut "c"): > + call mmtemplates#core#CreateMenus ( "g:My_C_Templates", "C-Support", + \ "sub_menu", "&Comments" ) + " entries: comment/uncomment/... : + ... +Create entries for the templates: > + call mmtemplates#core#CreateMenus ( "g:My_C_Templates", "C-Support", + \ "do_templates" ) +Create a run menu (shortcut "r"): > + call mmtemplates#core#CreateMenus ( "g:My_C_Templates", "C-Support", + \ "sub_menu", "&Run" ) + " entries: compile/run/test/... : + ... +Create the special entries at the end of the run menu: > + call mmtemplates#core#CreateMenus ( "g:My_C_Templates", "C-Support", + \ "do_specials", "specials_menu", "Run." ) +> + +Technical Details: +- The library must be given as the name of the global variable, since this + name is required to create the menus. +- The function creates menus of the following types: + amenu, imenu and vmenu (where appropriate) + +------------------------------------------------------------------------------ +9.3 ACCESS *template-support-api-access* +------------------------------------------------------------------------------ + +The following functions are used to query and change the resources of a +template library. For example, they are used to change the style or to change +the format of the date and time. + +------------------------------------------------------------------------------ + *mmtemplates#core#ChooseStyle()* +The style is changed using the function: + + mmtemplates#core#ChooseStyle ( library, style ) ~ + +Parameters: + library - The template library. (string or dict) + style - The name of the style or "!pick". (string) +No returns. + +The library can either be given directly, or as the name of the global +variable containing the library. +If 'style' is "!pick", the user is presented with a list of all styles, and +can choose one. +It the style 'style' does not exist, an error message is displayed and the +style remains unchanged. + +Example: + +Prompt the user for a new style: > + call mmtemplates#core#ChooseStyle ( g:My_C_Templates, "!pick" ) + +------------------------------------------------------------------------------ + *mmtemplates#core#Resource()* +Access to a number of resources is provided by: + + [ rval, msg ] = mmtemplates#core#Resource ( library, mode, ... ) ~ + + [ rval, msg ] ~ + = mmtemplates#core#Resource ( library, "get", resource, key ) ~ + [ rval, msg ] ~ + = mmtemplates#core#Resource ( library, "set", resource, key, val ) ~ + +Parameters: + library - The template library. (string or dict) + mode - The operation which should be executed. (string) +Optional parameters: + ... - Depending on 'mode'. +Returns: + rval - Content and type depending on 'mode'. + msg - In case of success: An empty string. (string) + In case of failure: An error message. (string) + +The library can either be given directly, or as the name of the global +variable containing the library. + +Special resources: + +- "escaped_mapleader" : Return the mapleader, escaped for use in a menu. +- "jumptag" : Return the regex used to find jump tags. +- "style" : Return the name of the current style. + +Regular resources: + +- "add" : Add the property with the given key and set it to 'val'. +- "get" : Return the resource with the given key or 0. +- "set" : Change the resource with the given key to 'val'. + +The mode "get" supports the following resources: +- "list", "l": The list as generated by: == List: l == ... == +- "macro", "m": A macro as set by: SetMacro( "m", ... ) +- "path", "p": A path as set by: SetPath( "p", ... ) +- "property", "p": An existing resource named "p". +It returns the integer 0, if the resource 'key' does not exist. +The mode "set" can be used to overwrite these resources. +The resource "list" is returned as a reference, use it responsibly. + +For "add" and "set" 'rval' is undefined. + +Macros: + +Setting the special macros "DATE", "TIME", and "YEAR" changes the format of +the date and time. they use the same format as the function |strftime()|. +Setting "BASENAME", "FILENAME", "PATH" and "SUFFIX" has no effect. + +Properties: + +The mode "get" returns the property named 'key', but only if it already +exists. Only an existing property can be set in the mode "set". To create and +set a new property, the mode "add" must be used. + + +Example 1: + +The format of the macro *|TIME|* can be changed by calling: > + call mmtemplates#core#Resource ( + \ g:My_C_Templates, "set", "macro", "TIME", "%H:%M" ) +< + +Example 2: + +Suppose there is a template like this: +> + == Include.project include == insert, pick-file == + |Prompt( "project include directory" )| + |GetPath( "project_include" )| + #include "|PICK|" + == ENDTEMPLATE == +< +When switching to a new project, execute: > + call mmtemplates#core#Resource ( + \ g:My_C_Templates, "set", "path", "project_include", project_incl_dir ) +< +The next time the template "Include.project include" is inserted, the file +browser will already be set to the project include directory. + + +Example 3: + +Set the property "Templates::Mapleader": > + call mmtemplates#core#Resource ( + \ g:My_C_Templates, "set", "Templates::Mapleader", "." ) +< +Create a new property "C::RunCompiler::Map": > + call mmtemplates#core#Resource ( + \ g:My_C_Templates, "add","C::RunCompiler::Map", "rc" ) +< +Get the mapleader (already escaped): > + let [ esc_mapleader, msg ] = mmtemplates#core#Resource ( + \ g:My_C_Templates, "escaped_mapleader" ) +< +Get the map (not escaped!): > + let [ map_run, msg ] = mmtemplates#core#Resource ( + \ g:My_C_Templates, "get", "C::RunCompiler::Map" ) + +Create the menu entry: > + if empty ( msg ) + exe 'amenu '.root_menu + \ .'.Run.run\ &compiler'.esc_mapleader.map_run.' :call Run()' + else + " handle error ... + endif +< + +Example 4: + +Get the current style: > + let [ current_style, msg ] = mmtemplates#core#Resource ( + \ g:My_C_Templates, "style" ) +< +------------------------------------------------------------------------------ +9.4 MISCELLANY *template-support-api-misc* +------------------------------------------------------------------------------ + +This section describes various functions, provided for convenience. + +------------------------------------------------------------------------------ + *mmtemplates#core#SetMapleader()* + *mmtemplates#core#ResetMapleader()* +Set and reset |maplocalleader|: + + mmtemplates#core#SetMapleader ( localleader ) ~ + mmtemplates#core#ResetMapleader () ~ + +Parameters: + localleader - The new value for |maplocalleader|. (string) +No returns. + +A call to mmtemplates#core#SetMapleader sets maplocalleader to the given +value. A subsequent call to mmtemplates#core#ResetMapleader restores the +previous setting, which can also mean that maplocalleader is undefined again. +Calls to SetMapleader and ResetMapleader can be nested. +If the argument 'localleader' is an empty string, maplocalleader remains +unchanged. + +------------------------------------------------------------------------------ + *mmtemplates#core#EscapeMenu()* +Escape a string to be used as a menu entry: + + str = mmtemplates#core#EscapeMenu ( str ) ~ + +Parameters: + str - The menu item. (string) +Optional parameters: + mode - How to escape the string. (string, default "entry") +Returns: + str - The same string with appropriately escaped characters. (string) + +The following modes are supported: +- "menu" : A menu name with possible submenus, escapes \ | & +- "entry" : A menu entry, dots are escaped as well, escapes . \ | & +- "right" : The right-aligned side of a menu entry, escapes . \ | + +In mode "entry" the function even escapes '.', so the menu and the entry must +be escaped separately, otherwise the entry 'frame comment' in the menu +'Comments': > + "Comments.frame comment" +would turn into the entry: > + "Comments\.frame\ comment" + +============================================================================== +10. BACKWARDS COMPATIBILITY *template-support-backwards* +============================================================================== + +The following behavior is not compatible with the old template systems of +various plug-ins. This list does not include new features which are now +supported. + +c-support: +doxygen-support: +perl-support: +- No automatic uppercase for *|BASENAME|* . +- The format for *|DATE|* , *|TIME|* and *|YEAR|* is now configured via the + template library. Plug-ins may provide other ways to do the configuration. + +perl-support: +- The template header can not have the format > + == templatename == [ position == ] [ indentation == ] +< anymore, since the last part would be ignored. Use the list of template + options instead: > + == templatename == [ position, indentation == ] +< Both 'position' and 'indentation' are optional, of course. + + + + -------------------------------------------------------------------------- ~ + + -------------------------------------------------------------------------- ~ + + -------------------------------------------------------------------------- ~ + + + +============================================================================== +A. SYNTAX *template-support-syntax* +============================================================================== + +The standards for the idioms are as follows, but may be changed via the API: + +Idiom Changeable? Standard + +CommentStart yes $ +BlockDelimiter no == + +CommandName no same as MacroName +MacroName no a-z, A-Z, 0-9 and _ + starting with a letter or underscore +OptionName no same as MacroName +ResourceName no same as MacroName +SeparatorName no same as MacroName +StyleName no same as MacroName +TemplateName no a-z, A-Z, 0-9 and _ + - . , + starting with a letter or underscore, + not ending with a whitespace +Mapping no a-z, A-Z, 0-9 and _ + - + +The rules in the next sections use the following notation: + +- Syntax category: StartsWithCapitalLetters +- Keyword: ALLCAPS +- Various items: -something- +- Square brackets [ ] mark an optional part of the rule. +- All other characters are as printed. +- Whitespaces are ignored, except where marks the start of the line. + Whitespaces can not appear there. + +------------------------------------------------------------------------------ +A.1 COMMAND SECTION *template-support-syntax-cmd* +------------------------------------------------------------------------------ + +MacroAssignment (one of): + -text- + ' -text- ' + " -text- " + +Note: Trailing whitespaces are ignored, even with the first rule. + + +Statement (one of): + -empty line- + CommentStart -anything- + CommandName ( ParameterList ) + *|MacroName|* = MacroAssignment + StyleBlock1 + StyleBlock2 + Template + HelpTemplate + MenuSeparator + List + + +StyleBlock1 (sequence): + == IF *|STYLE|* IS MacroName == + StatementList + == ENDIF == + + +StyleBlock2 (sequence): + == USE STYLES : MacroNameList == + StatementList + == ENDSTYLES == + + +Template (sequence): + == [ TEMPLATE : ] TemplateName == [ OptionList == ] + -several lines- + == ENDTEMPLATE == + +Note: The " TEMPLATE : " in the first line is optional, as opposed to the + structure of the next three rules. + + +HelpTemplate (sequence): + == HELP : TemplateName == [ OptionList == ] + -several lines- + == ENDTEMPLATE == + + +MenuSeparator (one line): + == SEP : SeparatorName == + + +List (sequence): + == LIST : MacroName == [ OptionList == ] + -several lines- + == ENDLIST == + + +MacroNameList (one of): + MacroName + MacroName , MacroNameList + + +OptionList (one of): + -empty- + Option + Option , OptionList + + +Option (one of): + OptionName + OptionName : MacroName + OptionName : Mapping + +------------------------------------------------------------------------------ +A.2 TEMPLATES *template-support-syntax-templ* +------------------------------------------------------------------------------ + + *Todo syntax templates + +------------------------------------------------------------------------------ +A.3 LISTS *template-support-syntax-list* +------------------------------------------------------------------------------ + +Lists can either be lists or dictionaries. (Corresponding to the types Vim +uses: |List| and |Dictionary|.) + +Lists are a comma separated list of strings: +> + == LIST: Options == list == + "tabstop", "shiftwidth", + "wrap", "nowrap", + "filetype" + == ENDLIST == +< +Bare lists do not require quotes, each line is interpreted as an entry. +Leading and trailing whitespaces are ignored: +> + == LIST: Options == list, bare == + tabstop + shiftwidth + wrap + nowrap + filetype + == ENDLIST == +< +Dictionaries associate a key with a value. Key and value are separated by a +colon, different entries by a comma. +> + == LIST: FileEndings == dict == + "C" : ".c" , + "C++" : ".cc" , + "Perl" : ".pl" , + "Shell" : ".sh" , + "Vimscript" : ".vim" , + == ENDLIST == +< +============================================================================== +B. COMMANDS *template-support-commands* +============================================================================== + +This sections list the commands supported by the template system. + +------------------------------------------------------------------------------ +B.1 COMMAND SECTION *template-support-cmd-cmd-sct* +------------------------------------------------------------------------------ + +The following commands can be used outside of templates, in the so-called +command section. + +------------------------------------------------------------------------------ + *template-support-IncludeFile()* +Include the file 'filename': + + IncludeFile ( filename [, "abs"] ) ~ + +'filename' can contain a path which can be absolute or relative. Relative +paths are interpreted in relation to the directory of the file containing the +command. The path is always understood to be relative, except when the +optional second argument "abs" is given. + +------------------------------------------------------------------------------ + *template-support-SetFormat()* +Set the format of 'item' to 'format': + + SetFormat ( item, format ) ~ + +This changes the way the macros "TIME", "DATE" and "YEAR" are replaced. It +sets the format of the date and time. They use the same format as the function +|strftime()|. + +Example: > + SetFormat ( "TIME", "%H:%M" ) +The macro *|TIME|* will now be replaced by something like 10:24. + +------------------------------------------------------------------------------ + *template-support-SetMacro()* +Set the macro 'name' to 'text': + + SetMacro ( name, text ) ~ + +This is used to set replacements for macros. + +Setting the macros "TIME", "DATE", "YEAR", "BASENAME", "FILENAME" , "PATH" and +"SUFFIX" is not allowed. They are set to the appropriate values before +insertion of a template. + +Example: > + SetMacro ( "AUTHOR", "My cat." ) + +------------------------------------------------------------------------------ + *template-support-SetPath()* +Set the resource 'name' to the given path. + + SetPath ( name, path ) ~ + +Subsequently the path can be used in templates. + +------------------------------------------------------------------------------ + *template-support-SetProperty()* +Set the property 'name' to the given value. + + SetProperty ( name, value ) ~ + +Only existing properties can be set. If 'name' does not refer to an existing +property, an error will be printed. + +------------------------------------------------------------------------------ + *template-support-SetStyle()* +Set the active style to 'name': + + SetStyle ( name ) ~ + +This style will be used after the library has been loaded. + +------------------------------------------------------------------------------ + *template-support-MenuShortcut()* +Set the shortcut for the submenu 'menu' to 'shortcut': + + MenuShortcut ( menu, shortcut ) ~ + +The shortcut is set for the menu named by the last component of 'menu', which +can consist of several parts, separated by points. Trailing points are +ignored. + +Example: > + MenuShortcut ( "Comments.Frames.", "r" ) +Sets the shortcut for the submenu "Frames", not "Comments". + +------------------------------------------------------------------------------ +B.2 TEMPLATES *template-support-cmd-templates* +------------------------------------------------------------------------------ + +Templates themselves support various commands, either in the command block at +the beginning of the template, or in the text itself. + +------------------------------------------------------------------------------ + *template-support-PickFile()* +Open a prompt and let the user select a file: + + |PickFile ( prompt, path )| ~ + +Displays 'prompt' and lets the user select a file. The file browser starts out +in the directory named by 'path'. If 'path' matches an identifier, the path +resource by this name serves as the path. Otherwise the string path is used as +the path directly. + +After the user selected a file, several replacements for macros are created, +which can be inserted into the template: +- *|PICK_COMPL|* : the complete path and name of the selected file +- *|PATH_COMPL|* : the complete path of the selected file +- *|PICK|* : the selected path and file relative to the directory given + in 'path' +- *|PATH|* : the path in *|PICK|* +- *|FILENAME|* : the name of the file +- *|BASENAME|* : the name of the file without the suffix +- *|SUFFIX|* : the suffix of the file + +Example: > + + SetPath ( "global", "/usr/include/" ) + + == global include == below == + |PickFile( "select a file: ", "global" )| + #include <|PICK|> + == local include == below == + |PickFile( "select a file: ", "global/" )| + #include "|PICK|" + == ENDTEMPLATE == +< +The path in the first template is the resource "global", which in turn is +"/usr/include/". The path in the second template will be "global/", since the +string does not match an identifier. + +If the user inserts the template "global include", he will be asked to select +a file, starting in the directory "/usr/include/". If we selects the file: > + /usr/include/QtGui/QPushButton +the macro *|PICK|* will be set to "QtGui/QPushButton", and *|PATH|* to +"QtGui". + +------------------------------------------------------------------------------ + *template-support-PickList()* +Open a prompt and let the user select an entry from a list: + + |PickList ( prompt, list )| ~ + +Displays 'prompt' and lets the user select an entry from a list. If 'list' is +a string and matches an identifier, the list resource by this name is used. +If 'list' is a list or a dictionary, it is used directly. + +In case of lists, the user has to choose an entry from the list. In case of +dictionaries, the user has to choose one of the keys. + +After the user selected an entry, several replacements for macros are created, +which can be inserted in the template: +- *|VALUE|* : the selected entry from the list or dictionary +- *|KEY|* : the selected key (dictionaries only) +- *|PICK|* : same as *|VALUE|* + +Example: +> + == LIST: headers == list == + "stdlib", + "stdio", + "string", + == LIST: functions == hash == + "strcpy" : "{+DEST+}, {+SRC+}", + "strncpy" : "{+DEST+}, {+SRC+}, {+N+}", + "strcmp" : "{+STR1+}, {+STR2+}", + "strncmp" : "{+STR1+}, {+STR2+}, {+N+}", + "strlen" : "{+STR+}", + == ENDLIST == + + == header include == below == + |PickList( "header file: ", "headers" )| + #include <|PICK|.h> + == function call == insert == + |PickList( "function: ", "functions" )| + |KEY| ( |VALUE| ) + == ENDTEMPLATE == +< +The first template is quite simple. The user selects a header from the list, +then the preprocessor directive is inserted. + +The second template uses a dictionary. The user has to pick an entry from the +list of function names. The template is inserted using both the selected key +and value. Each value is a list of jump tags, named for the arguments of the +corresponding function. + +Inserting the template "function call" and selecting "strcpy" will results in +the following text to be inserted: > + strcpy | ( {+DEST+}, {+SRC+} ) +The position of the cursor is marked by "|". The jump key can be used to jump +ahead and replace the tags. + +------------------------------------------------------------------------------ + *template-support-Prompt()* +Prompt the user for a replacement of the macro: + + |Prompt ( macro, flag )| ~ + +The user is prompted for a replacement of 'macro'. After the user has entered +a text, the flag is applied. The replacement is saved to be reused later. + +Flags: +- "" : no change to the text +- "l" : change text to lowercase +- "u" : change text to uppercase +- "c" : capitalize text (change first letter to uppercase) +- "L" : legalize name (replace all non-word characters with underscores) + +Example: +> + == chapter, alt1 == below == + ============================================================================ + |?NUMBER| |?NAME:u| + ============================================================================ + + + + == chapter, alt2 == below == + |Prompt( 'NAME', '' )| + |Prompt( 'NUMBER', '' )| + ============================================================================ + |NUMBER| |NAME:u| + ============================================================================ + + + + == chapter, toc == below == + |NUMBER| |NAME:c| + == ENDTEMPLATE == +< +This inserts captions for chapters as used in this document. With the first +alternative, the user is first prompted for a replacement of *|NUMBER|* , +because of the order both macros appear in the text. The name is saved in +uppercase. +Using the second alternative, the user is prompted for the name first. The +name is saved as entered and only inserted in uppercase. Now it can be +inserted into the table of contents as entered by the user. + +============================================================================== +C. OPTIONS *template-support-options* +============================================================================== + +The following sections list the options for templates and lists. + +------------------------------------------------------------------------------ +C.1 TEMPLATES *template-support-opt-templ* +------------------------------------------------------------------------------ + +The template options appear in the header of the template: + == == == ~ + +It is not required to specify any options. The defaults are given below. +Help templates use the same options as normal templates. + +------------------------------------------------------------------------------ + *template-support-start* *template-support-append* + *template-support-above* *template-support-insert* + *template-support-below* +Placement: + + start - The text is placed above the first line. + above - The text is placed above the current line. + below - The text is placed below the current line (default). + append - The text is appended to the current line. + insert - The text is inserted at the cursor position. + +Note: "below" and "insert" support split tag in visual mode. + +------------------------------------------------------------------------------ + *template-support-visual* *template-support-indent* + *template-support-novisual* *template-support-noindent* +Insertion: + + visual - Use the split tag in visual mode (default?). + novisual - No special behavior in visual mode (default?). + + indent - The inserted text is indented (default). + noindent - No automatic indentation. + +Note: "visual" is the default for templates containing the split tag, + "novisual" for templates without the split tag. + +------------------------------------------------------------------------------ + *template-support-sc* *template-support-nomenu* + *template-support-shortcut* *template-support-expandmenu* + *template-support-map* +Menus and Maps: + + nomenu - No menu entry is created. + expandmenu - A submenu is created for this template with entries matching + those of a given list. + sc: - A shortcut is created for the menu entry of this template. + shortcut: - Long version of sc:. + map: - A map is created for this template. + +Note: The default is for a menu entry to be created. +Note: A shortcut can only be one character long. A map can be several + characters long. It is always preceded by the local mapleader. + +------------------------------------------------------------------------------ +C.2 LISTS *template-support-opt-list* +------------------------------------------------------------------------------ + +The list options appear in the header of the list: + == List: OutputModifiers == == ~ + +It is not required to specify any options. The defaults are given below. + +------------------------------------------------------------------------------ + *template-support-list* *template-support-dict* + *template-support-hash* *template-support-dictionary* +Type: + + list - The object is given as a list. (default) + hash - The object is a hash, or dictionary. + dict - Same as hash. + dictionary - Same as hash. + +For a description see |template-support-syntax-list|. + +------------------------------------------------------------------------------ + *template-support-bare* +Interpretation: + + bare - The list is interpreted as a bare list. Each line is considered to be + a new entry. + +Note: Bare lists are not the default. + +============================================================================== +D. CHANGE LOG *template-support-change-log* +============================================================================== + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9.3 +------------------------------------------------------------------------------ + +- Change: In case several version of autoload/mmtemplates/core.vim are + available on 'runtimepath', pick out the newest one to load. + +Includes the patches 0.9.2-1 to 0.9.2-2: +- Change: More checks when rereading templates. +- Change: Better compatibility with custom mappings + (use "normal!", "noremap" and "noremenu" consistently). +- Change: During template insertion, find tag independent of the + settings 'magic' and 'startofline'. +- Added: API functions "mmtemplates#core#SetMapleader" and + "mmtemplates#core#ResetMapleader". +- Extended the documentation. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9.2 +------------------------------------------------------------------------------ + +- Added: 'SetProperty' to set properties using a template library. +- Change: Improved list picker. + +API: +- Change: Extended 'mmtemplates#core#EscapeMenu'. + +Includes the patches 0.9.1-1 to 0.9.1-3: +- Bugfix: Problem with macro replacements containing macros with flags. +- Change: Syntax highlighting. +- Change: Warnings about overwritten maps are only printed once for every + filetype. +- Bugfix: Inserting templates in visual mode with placement "insert" could + cause rare problems interacting with the indent program. +- Extended the documentation. + +------------------------------------------------------------------------------ + +PATCH 0.9.2-1: +- Released with slight changes in the core functionality. +- Change: More checks when rereading templates. +- Extended the documentation. + +------------------------------------------------------------------------------ + +PATCH 0.9.2-2: +- Released with slight changes in the core functionality. +- Change: Better compatibility with custom mappings + (use "normal!", "noremap" and "noremenu" consistently). +- Change: During template insertion, find tag independent of the + settings 'magic' and 'startofline'. +- Added: API functions "mmtemplates#core#SetMapleader" and + "mmtemplates#core#ResetMapleader". + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9.1 +------------------------------------------------------------------------------ + +- Change: When checking for already existing maps: Check each mode individually. +- Added: Menu separators can be inserted via the template library. +- Bugfix: Changing the mapleader now works. +- Bugfix: Inserting templates with placement "insert" did not work in some + cases. +- Minor improvements and bugfixes. + +API: +- Added: Sub-menus can be created with priorities. +- Added: Properties. +- Added: The mapleader shown in the menu is configurable. +- Added: The maps for "edit templates", "reread templates" and "choose style" + are configurable. + +Internal Changes: +- Changes to the template data structure. +- Major code cleanup. + +------------------------------------------------------------------------------ + +PATCH 0.9.1-1: +- Released with no changes in the core functionality. +- Change: Some commands are now executed silently. +- Bugfix: Syntax highlighting. +- Extended the documentation. + +PATCH 0.9.1-2: +- Released with slight changes in the core functionality. +- Bugfix: Problem with macro replacements containing macros with flags. +- Change: Syntax highlighting. +- Slightly extended the documentation. + +PATCH 0.9.1-3: +- Released with slight changes in the core functionality. +- Change: Warnings about overwritten maps are only printed once for every + filetype. +- Bugfix: Inserting templates in visual mode with placement "insert" could + cause rare problems interacting with the indent program. +- Extended the documentation. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9 +------------------------------------------------------------------------------ + +- Initial upload. + +============================================================================== +vim:tw=78:noet:ts=2:ft=help:norl:expandtab: diff --git a/doc/toolbox.txt b/doc/toolbox.txt new file mode 100644 index 0000000..d5a05a0 --- /dev/null +++ b/doc/toolbox.txt @@ -0,0 +1,402 @@ +*toolbox.txt* MM Toolbox Support Jan 04 2014 + +MM Toolbox Support *toolbox* + + Plug-in version 1.0.1 + for Vim version 7.0 and above + Wolfgang Mehner + Fritz Mehner + + --- The Maps & Menus Toolbox Support --- + +Toolboxes are selection of tools, which are made available to a plug-in. Tools +mostly stand on their own. The purpose of the toolbox is to provide an easy +interface between a plug-in and the tools, switching tool on and off and +triggering the creation of maps and menus. The plug-in does not need any prior +knowledge of what tools are available. + +The toolbox support is controlled by an API and thus can be integrated into +another plug-in. A toolbox is essentially an object, several of which can +exist in parallel. This makes it easy to integrate a toolbox into your +plug-in. + +Here is a list of high profile plug-ins which use the toolbox support: +- C-Support (www.vim.org/scripts/script.php?script_id=213) +- Perl-Support (www.vim.org/scripts/script.php?script_id=556) + +============================================================================== +0. TABLE OF CONTENTS *toolbox-support-contents* +============================================================================== + + 1. Introduction |toolbox-support-intro| + 2. Integration |toolbox-support-integration| + 3. Tool Development |toolbox-support-tools| + 3.1 Minimal Tool API |toolbox-support-tools-api| + 3.2 Common Tool Functionality |toolbox-support-tools-common| + 4. API |toolbox-support-api| + + A. Change Log |toolbox-support-change-log| + +============================================================================== +1. INTRODUCTION *toolbox-support-intro* +============================================================================== + +The manual at hand documents the Maps & Menus Toolbox Support. If your are not +a plug-In developer, this will not be interesting, tools should come with a +separate documentation. + +The next chapter |toolbox-support-integration| describes how to integrate the +toolbox support into a plug-in. Then the tool development is addressed in +|toolbox-support-tools|. The whole API of the toolbox support is documented in +|toolbox-support-api|. + +============================================================================== +2. INTEGRATION *toolbox-support-integration* +============================================================================== + +This chapter explains the basic steps for integrating the toolbox into a +plug-in. A complete description of all the commands can be found in +|toolbox-support-api|. + +------------------------------------------------------------------------------ + +Firstly, the toolbox needs to be created using |mmtoolbox#tools#NewToolbox()| +and then loading via |mmtoolbox#tools#Load()|. +> + let s:ToolID = 'MyPlugin' " the toolboxes ID + let s:MapLeader = '\' " configurable mapl. + let s:ToolboxDir = [ vim_dir.'/autoload/mmtoolbox/' ] " list of directories + + let s:Toolbox = mmtoolbox#tools#NewToolbox ( s:ToolID ) + call mmtoolbox#tools#Property ( s:Toolbox, 'mapleader', s:MapLeader ) + + call mmtoolbox#tools#Load ( s:Toolbox, s:ToolboxDir ) + + " debugging only: + "call mmtoolbox#tools#Info ( s:Toolbox ) +< +The function |mmtoolbox#tools#Property()| is used for basic configuration. +During development |mmtoolbox#tools#Info()| helps with some debug output. + +Each tool is only loaded if the following condition holds: > + g:_UseTool_ == "yes" +The ID is the ID set by the call to |mmtoolbox#tools#NewToolbox()|. +If the above toolbox "MyPlugin" should load a tool called "align", then the +following variable assignment must be made: > + let g:MyPlugin_UseTool_align == "yes" +< +------------------------------------------------------------------------------ + +Menu creation is done using |mmtoolbox#tools#AddMenus()|: +> + if mmtoolbox#tools#Property ( s:Toolbox, 'empty-menu' ) == 0 + " create menu header + " ... + + call mmtoolbox#tools#AddMenus ( s:Toolbox, 'My\ PlugIn.&Tool\ Box' ) + endif +< +------------------------------------------------------------------------------ +> +For each appropriate buffer, map creation is triggered via +|mmtoolbox#tools#AddMaps()|: +> + call mmtoolbox#tools#AddMaps ( s:Toolbox ) +< +============================================================================== +3. TOOL DEVELOPMENT *toolbox-support-tools* +============================================================================== + +This chapter shows the basic steps to implementing a tool. The tool has to +fulfill some minimal requirements to work with the toolbox. Other requirements +are suggestions to provide a common user experience. + +------------------------------------------------------------------------------ +3.1 MINIMAL TOOL API *toolbox-support-tools-api* +------------------------------------------------------------------------------ + +Tools must implement a minimal API in order to work with the toolbox support. +Initially, the GetInfo() function is called to obtain some basic information +about the tool. For map creation, AddMaps(...) is called and for menus +AddMenu(). + + Function Call Further Information + ---------------------------------------------------------------------------- + ret_list = mmtoolbox##GetInfo() |toolbox-support-GetInfo()| + mmtoolbox##AddMaps() |toolbox-support-AddMaps()| + mmtoolbox##AddMenu( menu_sub, mleader ) |toolbox-support-AddMenu()| + ---------------------------------------------------------------------------- + +------------------------------------------------------------------------------ + *toolbox-support-GetInfo()* + ret_list = mmtoolbox##GetInfo () ~ + +No parameters. +Returns: + ret_list - information about the tool, see below (list) + +To initialize a tool , the 'GetInfo' function is called: > + let ret_list = mmtoolbox##GetInfo() +The tool must provide some basic information in the return argument: + ret_list = [ , , , , ... ] +With the first two entries: + prettyname - the name of the tool, can be different from (string), + for example the pretty name of cmake is "CMake" + version - the version of the tool (string), + for debugging purposes +Followed by a list of optional flags: + "nomenu" - the tool does not have an own menu + "disabled" - the tool is disabled, no maps or menus are created + +------------------------------------------------------------------------------ + *toolbox-support-AddMaps()* + mmtoolbox##AddMaps ( toolbox ) ~ + +No parameters: +No returns. + +Creates maps for the tool. A tool should only create buffer-local mappings. +The function will be called for each appropriate buffer. The settings for + are handled before calling 'mmtoolbox##AddMaps'. + +------------------------------------------------------------------------------ + *toolbox-support-AddMenu()* + mmtoolbox##AddMenu ( menu_sub, mapl ) ~ + +Parameters: + menu_sub - the submenu set up for the toolbox (string) + mapl - the mapleader configured for the toolbox (string) +No returns. + +Creates a menu for the tool. The arguments 'menu_sub' and 'mapl' are provided +correctly escaped for menu creation, so they can be used for |amenu| commands +without further preparation: +> + function! mmtoolbox#cmake#AddMenu ( menu_sub, mapl ) + + exe 'amenu '.a:menu_sub.'.&run\ make'.a:mapl.'rm :CMake ' + + " ... + endfunction +< +Before calling AddMenu, a menu header is created for the tool's submenu, +showing the pretty name of the tool. + +------------------------------------------------------------------------------ +3.2 COMMON TOOL FUNCTIONALITY *toolbox-support-tools-common* +------------------------------------------------------------------------------ + +In order to achieve a consistent user experience, it is recommended that tools +provide a set of common features. It is not strictly necessary to implement +all of them, but it will help users who already use other tools. + +The call: > + mmtoolbox##Property( 'get', 'enabled' ) +should return a non-zero integer if the tool is working correctly. This also +means that |mmtoolbox#tools#ToolEnabled()| will work correctly with the tool. + +A tool might not be enabled because some resources are missing. For example, +the CMake tool will be disabled, if the "cmake" executable is missing. In this +case the ex-command like > + :ToolnameHelp +should show the reason while the tool is not working (see |:MakeHelp|). +Otherwise, :ToolnameHelp should open the documentation of the tool. + +Settings which might change during runtime, like the Makefile used for a +build, should also be set by a call to: > + mmtoolbox##Property( 'set', 'some-setting', 'new-value' ) +This enabled users to change these settings using scripts (see +|mmtoolbox#make#Property()|). + +============================================================================== +4. API *toolbox-support-api* +============================================================================== + +This describes the usage of the toolbox support from the view of a plug-in +using it. For a discussion of all the necessary step see the chapter +|toolbox-support-integration|. + +------------------------------------------------------------------------------ + *mmtoolbox#tools#NewToolbox()* + + toolbox = mmtoolbox#tools#NewToolbox ( plugin ) ~ + +Parameters: + plugin - the "id" of the plug-in (string) +Returns: + toolbox - the new toolbox (dict) + +Creates a new toolbox object. The plug-in ID is important for the user's +configuration of the toolbox. + +------------------------------------------------------------------------------ + *mmtoolbox#tools#Load()* + mmtoolbox#tools#Load ( toolbox, directories ) ~ + +Parameters: + toolbox - the toolbox (dict) + directories - list of directories containing the tools (list of string) +No returns. + +Loads the tools in the given directories. A tool is only loaded if the +following condition holds: > + g:_UseTool_ == "yes" +Here, is the ID set by |mmtoolbox#tools#NewToolbox()|. + +For each tool, the 'GetInfo' function is called: > + let ret_list = mmtoolbox##GetInfo() +For a description of the interface, see |toolbox-support-GetInfo()|. + +------------------------------------------------------------------------------ + *mmtoolbox#tools#ToolEnabled()* + enabled = mmtoolbox#tools#ToolEnabled ( toolbox, name ) ~ + +Parameters: + toolbox - the toolbox (dict) + name - the name of the tool (dict) +Returns: + enabled - non-zero if the tool is enabled (integer) + +This function can be used to check whether a tool is enabled, regardless of +whether it exists or is loaded. + +------------------------------------------------------------------------------ + *mmtoolbox#tools#Property()* + [ value = ] mmtoolbox#tools#Property ( toolbox, property [, value] ) ~ + +Parameters: + toolbox - the toolbox (dict) + property - the name of the property (string) + value - the new value of the property (optional, type depends on + 'property') +Returns: + value - the value of the property, only if called with two arguments + (type depends on 'property') + +Gets (two arguments) or sets (three arguments) a property. + +The following properties exists: + mapleader - the map leader used for menu creation (string) + empty-menu - non-zero, if no tool that creates a menu is loaded (integer) + +Note: The property 'mapleader' is only used for menu creation, see +|mmtoolbox#tools#AddMenus()|. + +Examples: + +Set a mapleader: +> + call mmtoolbox#tools#Property ( My_Toolbox, "mapleader", "#" ) +< + +Check whether any tool creates a menu: +> + if mmtoolbox#tools#Property ( My_Toolbox, "empty-menu" ) == 0 + " ... create a sub menu for the toolbox, then + call mmtoolbox#tools#AddMenus ( My_Toolbox, "C/C++.Toolbox." ) + endif +< +------------------------------------------------------------------------------ + *mmtoolbox#tools#GetList()* + list = mmtoolbox#tools#GetList ( toolbox ) ~ + +Parameters: + toolbox - the toolbox (dict) +Returns: + list - information about each tool (list of strings) + +Produces a list of strings containing some information about each tool. It can +be used to create nice debug information. The output looks something like +this: > + [ 'CMake (1.2)', + \ 'Doxygen (2.0, disabled)', + \ 'Make (1.1)' ] +< +------------------------------------------------------------------------------ + *mmtoolbox#tools#Info()* + mmtoolbox#tools#Info ( toolbox ) ~ + +Parameters: + toolbox - the toolbox (dict) +No returns. + +Echoes debug information about the loaded tools. + +------------------------------------------------------------------------------ + *mmtoolbox#tools#AddMaps()* + mmtoolbox#tools#AddMaps ( toolbox ) ~ + +Parameters: + toolbox - the toolbox (dict) +No returns. + +Creates maps. For each tool the 'AddMaps' function is called: > + call mmtoolbox##AddMaps() +A tool should only create buffer-local mappings. + +Plug-ins should call mmtoolbox#tools#AddMaps for each appropriate buffer. The +settings for should also be handled by the plug-in, before +calling 'mmtoolbox#tools#AddMaps'. + +See also |toolbox-support-AddMaps()|. + +------------------------------------------------------------------------------ + *mmtoolbox#tools#AddMenus()* + mmtoolbox#tools#AddMenus ( toolbox, root ) ~ + +Parameters: + toolbox - the toolbox (dict) + root - the root menu used by the toolbox (string) +No returns. + +Creates menus. For each tool the 'AddMenus' function is called: > + call mmtoolbox##AddMenus( menu_sub, mapleader ) +The arguments 'menu_sub' and 'mapleader' are provided correctly escaped for +menu creation. +The name of the tool's sub menu 'menu_sub' is different for each tool and +computed using 'root' and the pretty name: > + let menu_sub = root.".".prettyname +Before calling AddMenus, a menu header is created for each sub menu, showing +the name of the tool. + +The mapleader is supposed to be the local mapleader the plug-in also uses for +|mmtoolbox#tools#AddMaps()|. + +See also |toolbox-support-AddMenu()|. + + + + -------------------------------------------------------------------------- ~ + + -------------------------------------------------------------------------- ~ + + -------------------------------------------------------------------------- ~ + + + +============================================================================== +A. CHANGE LOG *toolbox-support-change-log* +============================================================================== + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 1.0.1 +------------------------------------------------------------------------------ + +- Change: Do not load a tool multiple times. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 1.0 +------------------------------------------------------------------------------ + +- Added: Extended the API with 'mmtoolbox#tools#ToolEnabled'. +- Added the documentation. +- Internal changes. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 1.0pre +------------------------------------------------------------------------------ + +- Initial upload. + +============================================================================== +vim:tw=78:noet:ts=2:ft=help:norl:expandtab: diff --git a/doc/toolboxcmake.txt b/doc/toolboxcmake.txt new file mode 100644 index 0000000..c59692d --- /dev/null +++ b/doc/toolboxcmake.txt @@ -0,0 +1,245 @@ +*toolboxcmake.txt* CMake Tool Dec 28 2013 + +CMake Tool *toolbox-cmake* + + Plug-in version 0.9.1 + for Vim version 7.0 and above + Wolfgang Mehner + +The CMake tool offers an integration of CMake's makefile generator. It also +helps with calling the make tool in the build location, independently of the +current working directory. CMake's help can be quickly accessed within Vim. + +============================================================================== +0. TABLE OF CONTENTS *toolbox-cmake-contents* +============================================================================== + + 1. Introduction |toolbox-cmake-intro| + 2. Commands |toolbox-cmake-commands| + 2.1 API |toolbox-cmake-api| + 3. Configuration |toolbox-cmake-config| + 4. Known Issues |toolbox-cmake-issues| + + A. Change Log |toolbox-cmake-change-log| + +============================================================================== +1. INTRODUCTION *toolbox-cmake-intro* +============================================================================== + +After configuring the project's top-level directory with |:CMakeProjectDir| +and setting the build location using |:CMakeBuildLocation|, CMake can be run +by calling the ex-command |:CMake|! (with a bang). Command line arguments can +be given directly, for example: > + :CMake! -DDO_TESTS=1 +After that, :CMake (without a bang) can be used to execute the make tool in +the build location: > + :CMake -j3 +Errors will be listed in the quick-fix buffer. + +Help for CMake's commands can be accessed using |:CMakeHelpCommand|: > + :CMakeHelpCommand add_library +This will open a new buffer containing the help. Calling the command without +parameters will open a buffer showing a list of all commands: > + :CMakeHelpCommand +Similar ex-commands exist for modules, policies, properties and variables, see +below. + + Command Short Description + ---------------------------------------------------------------------------- + |:CMake|! [] run CMake with the given arguments + |:CMake| [] run make with the given arguments + + |:CMakeProjectDir| [] set the project directory + |:CMakeBuildLocation| [] set the build location + + |:CMakeHelpCommand| [] help for commands + |:CMakeHelpModule| [] help for modules + |:CMakeHelpPolicy| [] help for policies + |:CMakeHelpProperty| [] help for properties + |:CMakeHelpVariable| [] help for variables + + |:CMakeHelp| help for the CMake tool + |:CMakeSettings| shows the plug-in settings + ---------------------------------------------------------------------------- + +Detailed explanations are given in the next section |toolbox-cmake-commands|. + +============================================================================== +2. COMMANDS *toolbox-cmake-commands* +============================================================================== + +This chapter provides detailed explanations of all the commands. + +------------------------------------------------------------------------------ + *:CMake* + :CMake! [] ~ + +Runs cmake with the given arguments. If no arguments are given, calls cmake +with the directory set by |:CMakeProjectDir|. + +If the tool is not working properly, prints the reason. + + :CMake [] ~ + +Runs make with the given arguments. Beforehand, the working directory is set +to the directory configured with |:CMakeBuildLocation|. + +------------------------------------------------------------------------------ + *:CMakeProjectDir* *:CMakeBuildLocation* + :CMakeProjectDir [] ~ + :CMakeBuildLocation [] ~ + +Sets the project directory or build location. + + :CMakeProjectDir! ~ + :CMakeBuildLocation! ~ + +Echoes the current project directory or build location. + +------------------------------------------------------------------------------ + *:CMakeHelpCommand* *:CMakeHelpModule* + *:CMakeHelpPolicy* *:CMakeHelpProperty* + *:CMakeHelpVariable* + :CMakeHelpCommand [] ~ + :CMakeHelpModule [] ~ + :CMakeHelpPolicy [] ~ + :CMakeHelpProperty [] ~ + :CMakeHelpVariable [] ~ + +Open a buffer containing the help for the topic in each category. If no topic +is given, shows a list of all commands, modules, variables, ... + +In each of the help buffers, several maps are defined. + + Map Meaning + ---------------------------------------------------------------------------- + doubleclick jump to the topic under the cursor/back to the list + CTRL-] jump to the topic under the cursor/back to the list + jump to the topic under the cursor/back to the list + q close the buffer + ---------------------------------------------------------------------------- + +------------------------------------------------------------------------------ + *:CMakeHelp* + :CMakeHelp ~ + +Opens the help for the CMake tool. + +------------------------------------------------------------------------------ + *:CMakeSettings* + :CMakeSettings ~ + :CMakeSettings! ~ + +Shows the plug-in settings. The second version is verbose. + +------------------------------------------------------------------------------ +2.1 API *toolbox-cmake-api* +------------------------------------------------------------------------------ + +The various directories can be set via an API. This allows for setting up the +configuration via a script. + +------------------------------------------------------------------------------ + *mmtoolbox#cmake#Property()* +The project and build directory can be set using: + + mmtoolbox#cmake#Property ( mode, key [, value] ) ~ + +Parameters: + mode - "echo", "get" or "set" (string) + key - the name of one of the properties (string) + value - the new value of the property, + only with mode "set" (string, optional) +Returns: + value - the current value of the property, + only with mode "get" (various) + +The property is one of the following: + "enabled" - non-zero if the tool is enabled (integer, no "set") + "project-dir" - the project's top-level directory (string) + "build-dir" - the build location (string) + +To set the directories for a project, use: > + call mmtoolbox#cmake#Property ( "set", + \ "project-dir", "$HOME/Projects/MyProject" ) + call mmtoolbox#cmake#Property ( "set", + \ "build-dir", "$HOME/Projects/MyProject/build" ) +< +============================================================================== +3. CONFIGURATION *toolbox-cmake-config* +============================================================================== + +The tool is configured via a number of global variables, which can be set in +the .vimrc file. + + Variable Default Description and further information + ---------------------------------------------------------------------------- + |g:CMake_Executable| 'cmake' the CMake executable + |g:CMake_MakeTool| 'make' the make executable + |g:CMake_JumpToError| 'cmake' whether to jump to the first error + automatically + ---------------------------------------------------------------------------- + +------------------------------------------------------------------------------ + *g:CMake_Executable* +The executable is set by g:CMake_Executable: > + let g:CMake_Executable = 'cmake' +< +------------------------------------------------------------------------------ + *g:CMake_MakeTool* +The make executable is set by g:CMake_MakeTool: > + let g:CMake_MakeTool = 'make' +< +------------------------------------------------------------------------------ + *g:CMake_JumpToError* +After running cmake or make, quickfix will automatically jump to the location +of the first error, depending on the setting g:CMake_JumpToError. With > + let g:CMake_JumpToError = 'both' +quickfix will jump to the first error for both make and cmake. To only jump to +the first error automatically after running cmake, use > + let g:CMake_JumpToError = 'cmake' +< +The possible settings are listed below: + + Value Jump automatically after ... + ---------------------------------------------------------------------------- + 'both' cmake and make + 'cmake' cmake + 'make' make + 'none' none of the above + ---------------------------------------------------------------------------- + +The behavior can be changed on the fly by settings the variable to a different +value on the command line. + +============================================================================== +4. KNOWN ISSUES *toolbox-cmake-issues* +============================================================================== + +* Some of the errors are not recognized by the quickfix mechanism. + - Unfortunately, CMake's automatically generated Makefiles seem to output + some errors which can not be recognized by Vim's standard error format + for C. If you come across any such errors, please send use an example and + we will try to extend the error format. + +============================================================================== +A. CHANGE LOG *toolbox-cmake-change-log* +============================================================================== + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9.1 +------------------------------------------------------------------------------ + +- Change: The commands :CMake and :CMake! only jump to the first error + automatically if the setting g:CMake_JumpToError is set accordingly. +- Change: Improved jumping in help buffers. +- Minor changes. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9 +------------------------------------------------------------------------------ + +- Initial upload. + +============================================================================== +vim:tw=78:noet:ts=2:ft=help:norl:expandtab: diff --git a/doc/toolboxdoxygen.txt b/doc/toolboxdoxygen.txt new file mode 100644 index 0000000..958f51a --- /dev/null +++ b/doc/toolboxdoxygen.txt @@ -0,0 +1,239 @@ +*toolboxdoxygen.txt* Doxygen Tool Dec 28 2013 + +Doxygen Tool *toolbox-doxygen* + + Plug-in version 0.9.1 + for Vim version 7.0 and above + Wolfgang Mehner + +The Doxygen tool integrates Doxygen. After generating a documentation, the +warnings can be displayed in a quickfix list at any time. The tool assists +with generating Doxygen configuration files and with handling other Doxygen- +related files. + +============================================================================== +0. TABLE OF CONTENTS *toolbox-doxygen-contents* +============================================================================== + + 1. Introduction |toolbox-doxygen-intro| + 2. Commands |toolbox-doxygen-commands| + 2.1 API |toolbox-doxygen-api| + 3. Configuration |toolbox-doxygen-config| + + A. Change Log |toolbox-doxygen-change-log| + +============================================================================== +1. INTRODUCTION *toolbox-doxygen-intro* +============================================================================== + +As a first step, the Doxygen configuration file can be set using the ex- +command |:DoxygenConfigFile|: > + :DoxygenConfigFile ./Doxyfile +This file will now be used, independently of the working directory. Now +Doxygen can be run via |:Doxygen|. Afterwards, the warnings are displayed in a +|quickfix| list. They can be shown later using |:DoxygenWarnings|. + +A new configuration file can be generated using |:DoxygenGenerateConfig|. The +user is prompted for a location and name of the new config file. This file is +then generated and its name stored as it would be using |:DoxygenConfigFile|. +The file can be conveniently accessed later via |:DoxygenEditConfig|. + +Whenever Doxygen is run, the output is written into log files. The output is +split into the |:DoxygenLogFile| and the |:DoxygenWarningFile|. If the option +'WARN_LOGFILE' is set in the Doxygen config file, the name of the warning file +is automatically recognized. Then the quickfix lists generated by |:Doxygen| +and |:DoxygenWarnings| will read the warnings from this file. + + Command Short Description + ---------------------------------------------------------------------------- + |:Doxygen| [] run Doxygen with the given arguments + + |:DoxygenGenerateConfig| generate a configuration file + |:DoxygenEditConfig| edit the configuration file + |:DoxygenViewLog| view the log file + |:DoxygenWarnings| |quickfix| list for Doxygen warnings + + |:DoxygenConfigFile| [] set the configuration file + |:DoxygenLogFile| [] set the log file + |:DoxygenWarningFile| [] set the warning file + + |:DoxygenHelp| help for the Doxygen tool + |:DoxygenSettings| shows the plug-in settings + ---------------------------------------------------------------------------- + +Detailed explanations are given in the next section |toolbox-doxygen-commands|. + +============================================================================== +2. COMMANDS *toolbox-doxygen-commands* +============================================================================== + +This chapter provides detailed explanations of all the commands. + +------------------------------------------------------------------------------ + *:Doxygen* + :Doxygen [] ~ + +Runs Doxygen. If called without arguments, uses the config file set via +|:DoxygenConfigFile|. The output produced by Doxygen is written into the log +file (see |:DoxygenViewLog| and |:DoxygenLogFile|) and the warning file (see +|:DoxygenWarnings| and |:DoxygenWarningFile|). +The warnings are then read back from the warning file (see +|:DoxygenWarningFile|) to produce a |quickfix| list. The warnings can also be +viewed later using |:DoxygenWarnings|. +If an warning file is set in the Doxyfile configuration file (option +"WARN_LOGFILE"), it is recognized and used as the warning file. + +If the tool is not working properly, prints the reason. + +------------------------------------------------------------------------------ + *:DoxygenConfigFile* + :DoxygenConfigFile [] ~ + +Sets the Doxygen configuration file. If a specific file has been selected, it +is always used, independent of the current working directory. The directory of +the file is used as the working directory for running Doxygen (see |:Doxygen|). + + :DoxygenConfigFile! ~ + +Echoes the current configuration file on the command line. + +------------------------------------------------------------------------------ + *:DoxygenLogFile* + :DoxygenLogFile [] ~ + +Sets the Doxygen log file. If a specific file has been selected, it is always +used, independent of the current working directory. The file can be viewed by +calling |:DoxygenViewLog|. + + :DoxygenLogFile! ~ + +Echoes the current log file on the command line. + +------------------------------------------------------------------------------ + *:DoxygenWarningFile* + :DoxygenWarningFile [] ~ + +Sets the Doxygen warning file. If a specific file has been selected, it is +always used, independent of the current working directory. The file is used to +read the warnings for |:DoxygenWarnings|. + + :DoxygenWarningFile! ~ + +Echoes the current warning file on the command line. + +------------------------------------------------------------------------------ + *:DoxygenGenerateConfig* + :DoxygenGenerateConfig ~ + +The user is asked to pick a location and name for a new config file, which is +then generated automatically. Upon successful completion, the name of the +config file is set as it would be using |:DoxygenConfigFile|. + +------------------------------------------------------------------------------ + *:DoxygenEditConfig* + :DoxygenEditConfig ~ + +Opens the configuration file set via |:DoxygenConfigFile| for editing. + +------------------------------------------------------------------------------ + *:DoxygenViewLog* + :DoxygenViewLog ~ + +Views the log file set via |:DoxygenLogFile|. + +------------------------------------------------------------------------------ + *:DoxygenWarnings* + :DoxygenWarnings ~ + +Reads the warnings from the warning file set via |:DoxygenWarningFile| and +generates a |quickfix| list. + +------------------------------------------------------------------------------ + *:DoxygenHelp* + :DoxygenHelp ~ + +Opens the help for the Doxygen tool. + +------------------------------------------------------------------------------ + *:DoxygenSettings* + :DoxygenSettings ~ + :DoxygenSettings! ~ + +Shows the plug-in settings. The second version is verbose. + +------------------------------------------------------------------------------ +2.1 API *toolbox-doxygen-api* +------------------------------------------------------------------------------ + +The various filenames can be set via an API. This allows for setting up the +configuration via a script. + +------------------------------------------------------------------------------ + *mmtoolbox#doxygen#Property()* +The filenames can be set using: + + mmtoolbox#doxygen#Property ( mode, key [, value] ) ~ + +Parameters: + mode - "echo", "get" or "set" (string) + key - the name of one of the properties (string) + value - the new value of the property, + only with mode "set" (string, optional) +Returns: + value - the current value of the property, + only with mode "get" (various) + +The property is one of the following: + "enabled" - non-zero if the tool is enabled (integer, no "set") + "config-file" - the configuration file (string) + "log-file" - the log file (string) + "warning-file" - the warning file (string) + +To set the configuration file for a project, use: > + call mmtoolbox#doxygen#Property ( "set", + \ "config-file", "$HOME/Projects/MyProject/doc/Doxyfile" ) +< +To set the warning file: > + call mmtoolbox#doxygen#Property ( "set", "warning-file", + \ "$HOME/Projects/MyProject/doc/doxy_warnings.txt" ) +This requires the Doxygen configuration file to include the following line: > + WARN_LOGFILE = "doxy_warnings.txt" +< +============================================================================== +3. CONFIGURATION *toolbox-doxygen-config* +============================================================================== + +The tool is configured via a number of global variables, which can be set in +the .vimrc file. + + Variable Default Description and further information + ---------------------------------------------------------------------------- + |g:Doxygen_Executable| 'doxygen' the Doxygen executable + ---------------------------------------------------------------------------- + +------------------------------------------------------------------------------ + *g:Doxygen_Executable* +The executable is set by g:Doxygen_Executable: > + let g:Doxygen_Executable = 'doxygen' +< +============================================================================== +A. CHANGE LOG *toolbox-doxygen-change-log* +============================================================================== + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9.1 +------------------------------------------------------------------------------ + +- Change: Commands :Doxygen and :DoxygenWarnings do not jump to the first + warning anymore. The old behavior was inappropriate for large projects with + lots of warnings. +- Minor changes. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 0.9 +------------------------------------------------------------------------------ + +- Initial upload. + +============================================================================== +vim:tw=78:noet:ts=2:ft=help:norl:expandtab: diff --git a/doc/toolboxmake.txt b/doc/toolboxmake.txt new file mode 100644 index 0000000..c445fc5 --- /dev/null +++ b/doc/toolboxmake.txt @@ -0,0 +1,184 @@ +*toolboxmake.txt* Make Tool Dec 28 2013 + +Make Tool *toolbox-make* + + Plug-in version 1.0.1 + for Vim version 7.0 and above + Wolfgang Mehner + +The Make tool offers minimal make functionality, such as running make with the +makefile located in a different directory. + +============================================================================== +0. TABLE OF CONTENTS *toolbox-make-contents* +============================================================================== + + 1. Introduction |toolbox-make-intro| + 2. Commands |toolbox-make-commands| + 2.1 API |toolbox-make-api| + 3. Configuration |toolbox-make-config| + + A. Change Log |toolbox-make-change-log| + +============================================================================== +1. INTRODUCTION *toolbox-make-intro* +============================================================================== + +Make is run using the ex-command |:Make|. Command line arguments can either be +given directly, > + :Make -j3 + :Make clean +or specified by using |:MakeCmdlineArgs|. Arguments given to :MakeCmdlineArgs +are passed on to make every time :Make is called without arguments. This +feature can be used to "memorize" complicated argument lists which have to be +passed to make repeatedly. Even if an argument list has been memorized, :Make +can always be called with other arguments to disregard the memorized list. A +call to :MakeCmdlineArgs without arguments clears the memorized argument list. + +By default, :Make runs in the current working directory and therefore uses the +local makefile. The command |:MakeFile| sets a specific makefile, which is +used every time, even when :Make is call in a different directory. This makes +it possible to use the tool for larger projects, which are organized in +multiple directories. The specified file is used until another is chosen or +the default behavior is restored by calling :MakeFile without arguments. + + Command Short Description + ---------------------------------------------------------------------------- + |:Make| [] run make with the given arguments + + |:MakeCmdlineArgs| [] memorize cmd. line arguments for make + |:MakeCmdlineArgs|! echo memorized cmd. line arguments + |:MakeFile| [] choose a makefile + |:MakeFile|! echo the current makefile + + |:MakeHelp| help for the Make tool + |:MakeSettings| shows the plug-in settings + ---------------------------------------------------------------------------- + +Detailed explanations are given in the next section |toolbox-make-commands|. + +============================================================================== +2. COMMANDS *toolbox-make-commands* +============================================================================== + +This chapter provides detailed explanations of all the commands. + +------------------------------------------------------------------------------ + *:Make* + :Make [] ~ + +Runs make with the given arguments. If no arguments are given, uses the ones +specified with |:MakeCmdlineArgs|, which can be an empty argument list as well. + +Uses the local makefile, unless a makefile has been chosen using |:MakeFile|. + +If the tool is not working properly, prints the reason. + +------------------------------------------------------------------------------ + *:MakeCmdlineArgs* + :MakeCmdlineArgs [] ~ + +Sets command line arguments for :Make. If make is called without arguments, +these "memorized" arguments are used. The command can be called without +arguments to delete the memorized argument list. + + :MakeCmdlineArgs! ~ + +Echoes the currently memorized arguments on the command line. + +------------------------------------------------------------------------------ + *:MakeFile* + :MakeFile [] ~ + +Sets the makefile. If a specific file has been selected, it is always used, +independent of the current working directory. If the makefile has not been +chosen, or reset by calling :MakeFile without arguments, the makefile in the +current working directory is used. + + :MakeFile! ~ + +Echoes the current makefile on the command line. + +------------------------------------------------------------------------------ + *:MakeHelp* + :MakeHelp ~ + +Opens the help for the Make tool. + +------------------------------------------------------------------------------ + *:MakeSettings* + :MakeSettings ~ + :MakeSettings! ~ + +Shows the plug-in settings. The second version is verbose. + +------------------------------------------------------------------------------ +2.1 API *toolbox-make-api* +------------------------------------------------------------------------------ + +The Makefile and command-line arguments can be set via an API. This allows for +setting up the configuration via a script. + +------------------------------------------------------------------------------ + *mmtoolbox#make#Property()* +The Makefile and command-line arguments can be set using: + + mmtoolbox#make#Property ( mode, key [, value] ) ~ + +Parameters: + mode - "echo", "get" or "set" (string) + key - the name of one of the properties (string) + value - the new value of the property, + only with mode "set" (string, optional) +Returns: + value - the current value of the property, + only with mode "get" (various) + +The property is one of the following: + "enabled" - non-zero if the tool is enabled (integer, no "set") + "cmdline-args" - the memorized command-line arguments (string) + "makefile" - the name and location of the makefile (string) + +To set the makefile for a project, use: > + call mmtoolbox#make#Property ( "set", + \ "makefile", "$HOME/Projects/MyProject" ) +< +To always run three jobs in parallel: > + call mmtoolbox#make#Property ( "set", "cmdline-args", "-j3" ) +< +============================================================================== +3. CONFIGURATION *toolbox-make-config* +============================================================================== + +The tool is configured via a number of global variables, which can be set in +the .vimrc file. + + Variable Default Description and further information + ---------------------------------------------------------------------------- + |g:Make_Executable| 'make' the make executable + ---------------------------------------------------------------------------- + +------------------------------------------------------------------------------ + *g:Make_Executable* +The executable is set by g:Make_Executable: > + let g:Make_Executable = 'make' +< +============================================================================== +A. CHANGE LOG *toolbox-make-change-log* +============================================================================== + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 1.0.1 +------------------------------------------------------------------------------ + +- Added: Command :MakeSettings to show the configuration. +- Minor changes. + +------------------------------------------------------------------------------ + RELEASE NOTES FOR VERSION 1.0 +------------------------------------------------------------------------------ + +- Initial upload. + +============================================================================== +vim:tw=78:noet:ts=2:ft=help:norl:expandtab: diff --git a/ftplugin/c.vim b/ftplugin/c.vim index 16344da..5e83e7f 100644 --- a/ftplugin/c.vim +++ b/ftplugin/c.vim @@ -5,7 +5,6 @@ " Language : C / C++ " Plugin : c.vim " Maintainer : Fritz Mehner -" Revision : $Id: c.vim,v 1.71 2011/12/27 21:04:33 mehner Exp $ " " ------------------------------------------------------------------------------ " @@ -16,449 +15,6 @@ if exists("b:did_C_ftplugin") endif let b:did_C_ftplugin = 1 " -" ---------- system installation or local installation ---------- -" -let s:installation = 'local' -if match( expand(""), escape( $VIM, ' \' ) ) == 0 - let s:installation = 'system' -endif -" -" ---------- Do we have a mapleader other than '\' ? ------------ -" -if exists("g:C_MapLeader") - let maplocalleader = g:C_MapLeader -endif -" -" ---------- C/C++ dictionary ----------------------------------- -" This will enable keyword completion for C and C++ -" using Vim's dictionary feature |i_CTRL-X_CTRL-K|. -" Set the new dictionaries in front of the existing ones -" -if exists("g:C_Dictionary_File") - let save=&dictionary - silent! exe 'setlocal dictionary='.g:C_Dictionary_File - silent! exe 'setlocal dictionary+='.save -endif -" -" ---------- F-key mappings ------------------------------------ -" -" Alt-F9 write buffer and compile -" F9 compile and link -" Ctrl-F9 run executable -" Shift-F9 command line arguments -" - map :call C_Compile():call C_HlMessage() -imap :call C_Compile():call C_HlMessage() -" - map :call C_Link():call C_HlMessage() -imap :call C_Link():call C_HlMessage() -" - map :call C_Run() -imap :call C_Run() -" - map :call C_Arguments() -imap :call C_Arguments() -" -" ---------- alternate file plugin (a.vim) ---------------------- -" -if exists("loaded_alternateFile") - map :A -imap :A -endif -" -command! -nargs=1 -complete=customlist,C_CFileSectionList CFileSection call C_CFileSectionListInsert () -command! -nargs=1 -complete=customlist,C_HFileSectionList HFileSection call C_HFileSectionListInsert () -command! -nargs=1 -complete=customlist,C_KeywordCommentList KeywordComment call C_KeywordCommentListInsert () -command! -nargs=1 -complete=customlist,C_SpecialCommentList SpecialComment call C_SpecialCommentListInsert () -command! -nargs=1 -complete=customlist,C_StdLibraryIncludesList IncludeStdLibrary call C_StdLibraryIncludesInsert () -command! -nargs=1 -complete=customlist,C_C99LibraryIncludesList IncludeC99Library call C_C99LibraryIncludesInsert () -command! -nargs=1 -complete=customlist,C_CppLibraryIncludesList IncludeCppLibrary call C_CppLibraryIncludesInsert () -command! -nargs=1 -complete=customlist,C_CppCLibraryIncludesList IncludeCppCLibrary call C_CppCLibraryIncludesInsert() -command! -nargs=1 -complete=customlist,C_StyleList CStyle call C_Style () - -" ---------- KEY MAPPINGS : MENU ENTRIES ------------------------------------- -" ---------- comments menu ------------------------------------------------ -" - noremap cl :call C_EndOfLineComment() -inoremap cl :call C_EndOfLineComment() -vnoremap cl :call C_EndOfLineComment() -" -nnoremap cj :call C_AdjustLineEndComm() -vnoremap cj :call C_AdjustLineEndComm() -inoremap cj :call C_AdjustLineEndComm()a -" - noremap cs :call C_GetLineEndCommCol() - - noremap c* :call C_CodeToCommentC():nohlsearchj -vnoremap c* :call C_CodeToCommentC():nohlsearchj - - noremap cc :call C_CodeToCommentCpp():nohlsearchj -vnoremap cc :call C_CodeToCommentCpp():nohlsearchj - noremap co :call C_CommentToCode():nohlsearch -vnoremap co :call C_CommentToCode():nohlsearch - - noremap cfr :call C_InsertTemplate("comment.frame") - noremap cfu :call C_InsertTemplate("comment.function") - noremap cme :call C_InsertTemplate("comment.method") - noremap ccl :call C_InsertTemplate("comment.class") - noremap cfdi :call C_InsertTemplate("comment.file-description") - noremap cfdh :call C_InsertTemplate("comment.file-description-header") - -inoremap cfr :call C_InsertTemplate("comment.frame") -inoremap cfu :call C_InsertTemplate("comment.function") -inoremap cme :call C_InsertTemplate("comment.method") -inoremap ccl :call C_InsertTemplate("comment.class") -inoremap cfdi :call C_InsertTemplate("comment.file-description") -inoremap cfdh :call C_InsertTemplate("comment.file-description-header") - - noremap cd :call C_InsertDateAndTime('d') -inoremap cd :call C_InsertDateAndTime('d')a -vnoremap cd s:call C_InsertDateAndTime('d')a - noremap ct :call C_InsertDateAndTime('dt') -inoremap ct :call C_InsertDateAndTime('dt')a -vnoremap ct s:call C_InsertDateAndTime('dt')a -" - noremap cx :call C_CommentToggle( ) -inoremap cx :call C_CommentToggle( ) -vnoremap cx :call C_CommentToggle( ) -" -" call the above defined commands: -" - noremap ccs :CFileSection - noremap chs :HFileSection - noremap ckc :KeywordComment - noremap csc :SpecialComment -" -inoremap ccs :CFileSection -inoremap chs :HFileSection -inoremap ckc :KeywordComment -inoremap csc :SpecialComment -" -" ---------- statements menu ------------------------------------------------ -" - noremap sd :call C_InsertTemplate("statements.do-while") -vnoremap sd :call C_InsertTemplate("statements.do-while", "v") -inoremap sd :call C_InsertTemplate("statements.do-while") - - noremap sf :call C_InsertTemplate("statements.for") -inoremap sf :call C_InsertTemplate("statements.for") - - noremap sfo :call C_InsertTemplate("statements.for-block") -vnoremap sfo :call C_InsertTemplate("statements.for-block", "v") -inoremap sfo :call C_InsertTemplate("statements.for-block") - - noremap si :call C_InsertTemplate("statements.if") -inoremap si :call C_InsertTemplate("statements.if") - - noremap sif :call C_InsertTemplate("statements.if-block") -vnoremap sif :call C_InsertTemplate("statements.if-block", "v") -inoremap sif :call C_InsertTemplate("statements.if-block") - - noremap sie :call C_InsertTemplate("statements.if-else") -vnoremap sie :call C_InsertTemplate("statements.if-else", "v") -inoremap sie :call C_InsertTemplate("statements.if-else") - - noremap sife :call C_InsertTemplate("statements.if-block-else") -vnoremap sife :call C_InsertTemplate("statements.if-block-else", "v") -inoremap sife :call C_InsertTemplate("statements.if-block-else") - - noremap se :call C_InsertTemplate("statements.else-block") -vnoremap se :call C_InsertTemplate("statements.else-block", "v") -inoremap se :call C_InsertTemplate("statements.else-block") - - noremap sw :call C_InsertTemplate("statements.while") -inoremap sw :call C_InsertTemplate("statements.while") - - noremap swh :call C_InsertTemplate("statements.while-block") -vnoremap swh :call C_InsertTemplate("statements.while-block", "v") -inoremap swh :call C_InsertTemplate("statements.while-block") - - noremap ss :call C_InsertTemplate("statements.switch") -vnoremap ss :call C_InsertTemplate("statements.switch", "v") -inoremap ss :call C_InsertTemplate("statements.switch") - - noremap sc :call C_InsertTemplate("statements.case") -inoremap sc :call C_InsertTemplate("statements.case") - - noremap s{ :call C_InsertTemplate("statements.block") -vnoremap s{ :call C_InsertTemplate("statements.block", "v") -inoremap s{ :call C_InsertTemplate("statements.block") - - noremap sb :call C_InsertTemplate("statements.block") -vnoremap sb :call C_InsertTemplate("statements.block", "v") -inoremap sb :call C_InsertTemplate("statements.block") -" -" ---------- preprocessor menu ---------------------------------------------- -" - noremap ps :IncludeStdLibrary -inoremap ps :IncludeStdLibrary - noremap pc :IncludeC99Library -inoremap pc :IncludeC99Library - noremap +ps :IncludeCppLibrary -inoremap +ps :IncludeCppLibrary - noremap +pc :IncludeCppCLibrary -inoremap +pc :IncludeCppC9Library -" - noremap p< :call C_InsertTemplate("preprocessor.include-global") - noremap p" :call C_InsertTemplate("preprocessor.include-local") - noremap pd :call C_InsertTemplate("preprocessor.define") - noremap pu :call C_InsertTemplate("preprocessor.undefine") -" -inoremap p< :call C_InsertTemplate("preprocessor.include-global") -inoremap p" :call C_InsertTemplate("preprocessor.include-local") -inoremap pd :call C_InsertTemplate("preprocessor.define") -inoremap pu :call C_InsertTemplate("preprocessor.undefine") - - noremap pif :call C_InsertTemplate("preprocessor.if-endif") - noremap pie :call C_InsertTemplate("preprocessor.if-else-endif") - noremap pid :call C_InsertTemplate("preprocessor.ifdef-else-endif") - noremap pin :call C_InsertTemplate("preprocessor.ifndef-else-endif") - noremap pind :call C_InsertTemplate("preprocessor.ifndef-def-endif") - -vnoremap pif :call C_InsertTemplate("preprocessor.if-endif", "v") -vnoremap pie :call C_InsertTemplate("preprocessor.if-else-endif", "v") -vnoremap pid :call C_InsertTemplate("preprocessor.ifdef-else-endif", "v") -vnoremap pin :call C_InsertTemplate("preprocessor.ifndef-else-endif", "v") -vnoremap pind :call C_InsertTemplate("preprocessor.ifndef-def-endif", "v") - -inoremap pif :call C_InsertTemplate("preprocessor.if-endif") -inoremap pie :call C_InsertTemplate("preprocessor.if-else-endif") -inoremap pid :call C_InsertTemplate("preprocessor.ifdef-else-endif") -inoremap pin :call C_InsertTemplate("preprocessor.ifndef-else-endif") -inoremap pind :call C_InsertTemplate("preprocessor.ifndef-def-endif") - - noremap pi0 :call C_PPIf0("a")2ji -inoremap pi0 :call C_PPIf0("a")2ji -vnoremap pi0 :call C_PPIf0("v") - - noremap pr0 :call C_PPIf0Remove() -inoremap pr0 :call C_PPIf0Remove() -" - noremap pe :call C_InsertTemplate("preprocessor.error") - noremap pl :call C_InsertTemplate("preprocessor.line") - noremap pp :call C_InsertTemplate("preprocessor.pragma") -" -inoremap pe :call C_InsertTemplate("preprocessor.error") -inoremap pl :call C_InsertTemplate("preprocessor.line") -inoremap pp :call C_InsertTemplate("preprocessor.pragma") -" -" ---------- idioms menu ---------------------------------------------------- -" - noremap if :call C_InsertTemplate("idioms.function") -vnoremap if :call C_InsertTemplate("idioms.function", "v") -inoremap if :call C_InsertTemplate("idioms.function") - noremap isf :call C_InsertTemplate("idioms.function-static") -vnoremap isf :call C_InsertTemplate("idioms.function-static", "v") -inoremap isf :call C_InsertTemplate("idioms.function-static") - noremap im :call C_InsertTemplate("idioms.main") -vnoremap im :call C_InsertTemplate("idioms.main", "v") -inoremap im :call C_InsertTemplate("idioms.main") -" - noremap i0 :call C_CodeFor("up" ) -vnoremap i0 :call C_CodeFor("up" ) -inoremap i0 :call C_CodeFor("up" )i - noremap in :call C_CodeFor("down") -vnoremap in :call C_CodeFor("down") -inoremap in :call C_CodeFor("down")i -" - noremap ie :call C_InsertTemplate("idioms.enum") -vnoremap ie :call C_InsertTemplate("idioms.enum" , "v") -inoremap ie :call C_InsertTemplate("idioms.enum") - noremap is :call C_InsertTemplate("idioms.struct") -vnoremap is :call C_InsertTemplate("idioms.struct", "v") -inoremap is :call C_InsertTemplate("idioms.struct") - noremap iu :call C_InsertTemplate("idioms.union") -vnoremap iu :call C_InsertTemplate("idioms.union" , "v") -inoremap iu :call C_InsertTemplate("idioms.union") -" - noremap ip :call C_InsertTemplate("idioms.printf") -inoremap ip :call C_InsertTemplate("idioms.printf") - noremap isc :call C_InsertTemplate("idioms.scanf") -inoremap isc :call C_InsertTemplate("idioms.scanf") -" - noremap ica :call C_InsertTemplate("idioms.calloc") -inoremap ica :call C_InsertTemplate("idioms.calloc") - noremap ima :call C_InsertTemplate("idioms.malloc") -inoremap ima :call C_InsertTemplate("idioms.malloc") - noremap ire :call C_InsertTemplate("idioms.realloc") -inoremap ire :call C_InsertTemplate("idioms.realloc") -" - noremap isi :call C_InsertTemplate("idioms.sizeof") -inoremap isi :call C_InsertTemplate("idioms.sizeof") -vnoremap isi :call C_InsertTemplate("idioms.sizeof", "v") - - noremap ias :call C_InsertTemplate("idioms.assert") -vnoremap ias :call C_InsertTemplate("idioms.assert", "v") -inoremap ias :call C_InsertTemplate("idioms.assert") -" - noremap ii :call C_InsertTemplate("idioms.open-input-file") -inoremap ii :call C_InsertTemplate("idioms.open-input-file") -vnoremap ii :call C_InsertTemplate("idioms.open-input-file", "v") - noremap io :call C_InsertTemplate("idioms.open-output-file") -inoremap io :call C_InsertTemplate("idioms.open-output-file") -vnoremap io :call C_InsertTemplate("idioms.open-output-file", "v") -" - noremap ifs :call C_InsertTemplate("idioms.fscanf") -inoremap ifs :call C_InsertTemplate("idioms.fscanf") - noremap ifp :call C_InsertTemplate("idioms.fprintf") -inoremap ifp :call C_InsertTemplate("idioms.fprintf") -" -" ---------- snippet menu : snippets ----------------------------------------- -" - noremap nr :call C_CodeSnippet("r") - noremap nw :call C_CodeSnippet("w") -vnoremap nw :call C_CodeSnippet("wv") - noremap ne :call C_CodeSnippet("e") -" -inoremap nr :call C_CodeSnippet("r") -inoremap nw :call C_CodeSnippet("w") -inoremap ne :call C_CodeSnippet("e") -" -" ---------- snippet menu : prototypes --------------------------------------- -" - noremap np :call C_ProtoPick("function") -vnoremap np :call C_ProtoPick("function") -inoremap np :call C_ProtoPick("function") -" - noremap nf :call C_ProtoPick("function") -vnoremap nf :call C_ProtoPick("function") -inoremap nf :call C_ProtoPick("function") -" - noremap nm :call C_ProtoPick("method") -vnoremap nm :call C_ProtoPick("method") -inoremap nm :call C_ProtoPick("method") -" - noremap ni :call C_ProtoInsert() -inoremap ni :call C_ProtoInsert() -" - noremap nc :call C_ProtoClear() -inoremap nc :call C_ProtoClear() -" - noremap ns :call C_ProtoShow() -inoremap ns :call C_ProtoShow() -" -" ---------- snippet menu : templates ---------------------------------------- -" - noremap ntl :call C_BrowseTemplateFiles("Local") -inoremap ntl :call C_BrowseTemplateFiles("Local") - if s:installation == 'system' - noremap ntg :call C_BrowseTemplateFiles("Global") - inoremap ntg :call C_BrowseTemplateFiles("Global") - endif - noremap ntr :call C_RereadTemplates() - noremap nts :CStyle -inoremap ntr :call C_RereadTemplates() -inoremap nts :CStyle -" -" ---------- C++ menu ---------------------------------------------------- -" - noremap +" :call C_InsertTemplate("cpp.cout-operator") -inoremap +" :call C_InsertTemplate("cpp.cout-operator") - noremap +co :call C_InsertTemplate("cpp.cout") -inoremap +co :call C_InsertTemplate("cpp.cout") -" - noremap +c :call C_InsertTemplate("cpp.class-definition") -inoremap +c :call C_InsertTemplate("cpp.class-definition") - noremap +cn :call C_InsertTemplate("cpp.class-using-new-definition") -inoremap +cn :call C_InsertTemplate("cpp.class-using-new-definition") - - noremap +ci :call C_InsertTemplate("cpp.class-implementation") -inoremap +ci :call C_InsertTemplate("cpp.class-implementation") - noremap +cni :call C_InsertTemplate("cpp.class-using-new-implementation") -inoremap +cni :call C_InsertTemplate("cpp.class-using-new-implementation") - - noremap +mi :call C_InsertTemplate("cpp.method-implementation") -inoremap +mi :call C_InsertTemplate("cpp.method-implementation") - noremap +ai :call C_InsertTemplate("cpp.accessor-implementation") -inoremap +ai :call C_InsertTemplate("cpp.accessor-implementation") - - noremap +tc :call C_InsertTemplate("cpp.template-class-definition") -inoremap +tc :call C_InsertTemplate("cpp.template-class-definition") - noremap +tcn :call C_InsertTemplate("cpp.template-class-using-new-definition") -inoremap +tcn :call C_InsertTemplate("cpp.template-class-using-new-definition") - - noremap +tci :call C_InsertTemplate("cpp.template-class-implementation") -inoremap +tci :call C_InsertTemplate("cpp.template-class-implementation") - noremap +tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation") -inoremap +tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation") - - noremap +tmi :call C_InsertTemplate("cpp.template-method-implementation") -inoremap +tmi :call C_InsertTemplate("cpp.template-method-implementation") - noremap +tai :call C_InsertTemplate("cpp.template-accessor-implementation") -inoremap +tai :call C_InsertTemplate("cpp.template-accessor-implementation") - - noremap +tf :call C_InsertTemplate("cpp.template-function") -inoremap +tf :call C_InsertTemplate("cpp.template-function") - - noremap +ec :call C_InsertTemplate("cpp.error-class") -inoremap +ec :call C_InsertTemplate("cpp.error-class") - - noremap +tr :call C_InsertTemplate("cpp.try-catch") -vnoremap +tr :call C_InsertTemplate("cpp.try-catch", "v") -inoremap +tr :call C_InsertTemplate("cpp.try-catch") - - noremap +ca :call C_InsertTemplate("cpp.catch") -vnoremap +ca :call C_InsertTemplate("cpp.catch", "v") -inoremap +ca :call C_InsertTemplate("cpp.catch") - - noremap +c. :call C_InsertTemplate("cpp.catch-points") -vnoremap +c. :call C_InsertTemplate("cpp.catch-points", "v") -inoremap +c. :call C_InsertTemplate("cpp.catch-points") -" -" ---------- run menu -------------------------------------------------------- -" - map rc :call C_Compile():call C_HlMessage() - map rl :call C_Link():call C_HlMessage() - map rr :call C_Run() - map ra :call C_Arguments() - map rm :call C_Make() - map rcm :call C_ChooseMakefile() - map rmc :call C_MakeClean() - map rme :call C_MakeExeToRun() - map rma :call C_MakeArguments() - map rp :call C_SplintCheck():call C_HlMessage() - map rpa :call C_SplintArguments() - map rd :call C_Indent() - map rh :call C_Hardcopy() - map rs :call C_Settings() -" -vmap rh :call C_Hardcopy() -" -imap rc :call C_Compile():call C_HlMessage() -imap rl :call C_Link():call C_HlMessage() -imap rr :call C_Run() -imap ra :call C_Arguments() -imap rm :call C_Make() -imap rmc :call C_MakeClean() -imap rme :call C_MakeExeToRun() -imap rma :call C_MakeArguments() -imap rp :call C_SplintCheck():call C_HlMessage() -imap rpa :call C_SplintArguments() -imap rd :call C_Indent() -imap rh :call C_Hardcopy() -imap rs :call C_Settings() - if has("unix") - map rx :call C_XtermSize() - imap rx :call C_XtermSize() - endif - map ro :call C_Toggle_Gvim_Xterm() -imap ro :call C_Toggle_Gvim_Xterm() -" -" Abraxas CodeCheck (R) -" -if executable("check") - map rk :call C_CodeCheck():call C_HlMessage() - map rka :call C_CodeCheckArguments() - imap rk :call C_CodeCheck():call C_HlMessage() - imap rka :call C_CodeCheckArguments() -endif -" ---------- plugin help ----------------------------------------------------- -" - map hp :call C_HelpCsupport() -imap hp :call C_HelpCsupport() - map hm :call C_Help("m") -imap hm :call C_Help("m") -" "------------------------------------------------------------------------------- " additional mapping : complete a classical C comment: '/*' => '/* | */' "------------------------------------------------------------------------------- @@ -479,9 +35,25 @@ inoremap /* /*/kA inoremap { {}O vnoremap { S{}Pk=iB " +"------------------------------------------------------------------------------- +" set "maplocalleader" as configured using "g:C_MapLeader" +"------------------------------------------------------------------------------- +call C_SetMapLeader () " -if !exists("g:C_Ctrl_j") || ( exists("g:C_Ctrl_j") && g:C_Ctrl_j != 'off' ) - nmap i=C_JumpCtrlJ() - imap =C_JumpCtrlJ() -endif +"------------------------------------------------------------------------------- +" additional mapping : Make tool +"------------------------------------------------------------------------------- + noremap rm :Make +inoremap rm :Make + noremap rmc :Make clean +inoremap rmc :Make clean + noremap rma :MakeCmdlineArgs +inoremap rma :MakeCmdlineArgs + noremap rcm :MakeFile +inoremap rcm :MakeFile +" +"------------------------------------------------------------------------------- +" reset "maplocalleader" +"------------------------------------------------------------------------------- +call C_ResetMapLeader () " diff --git a/ftplugin/make.vim b/ftplugin/make.vim index 9c35243..d1f01f8 100644 --- a/ftplugin/make.vim +++ b/ftplugin/make.vim @@ -1,31 +1,30 @@ " ------------------------------------------------------------------------------ " -" Vim filetype plugin file (part of the c.vim plugin) +" Vim filetype plugin file " -" Language : make -" Plugin : c.vim +" Language : Make +" Plugin : make.vim " Maintainer : Fritz Mehner -" Revision : $Id: make.vim,v 1.4 2011/12/27 21:04:33 mehner Exp $ " " ------------------------------------------------------------------------------ " " Only do this when not done yet for this buffer " -if exists("b:did_make_ftplugin") +if exists("b:did_Make_ftplugin") finish endif -let b:did_make_ftplugin = 1 - - map :call C_Make() -imap :call C_Make() - map rm :call C_Make() -imap rm :call C_Make() - map rcm :call C_ChooseMakefile() -imap rcm :call C_ChooseMakefile() - map rmc :call C_MakeClean() -imap rmc :call C_MakeClean() - map rme :call C_MakeExeToRun() -imap rme :call C_MakeExeToRun() - map rma :call C_MakeArguments() -imap rma :call C_MakeArguments() - +let b:did_Make_ftplugin = 1 +" +" ---------- Maps for the Make tool ----------------------------- +" + noremap rm :Make +inoremap rm :Make + noremap rmc :Make clean +inoremap rmc :Make clean + noremap rmd :Make doc +inoremap rmd :Make doc + noremap rma :MakeCmdlineArgs +inoremap rma :MakeCmdlineArgs + noremap rcm :MakeFile +inoremap rcm :MakeFile +" diff --git a/plugin/c.vim b/plugin/c.vim index 1f57206..54ed27b 100644 --- a/plugin/c.vim +++ b/plugin/c.vim @@ -13,11 +13,11 @@ " (see the files README.csupport and csupport.txt). " " Author: Dr.-Ing. Fritz Mehner, FH Südwestfalen, 58644 Iserlohn, Germany -" Email: mehner@fh-swf.de +" Email: mehner.fritz@fh-swf.de " " Version: see variable g:C_Version below " Created: 04.11.2000 -" License: Copyright (c) 2000-2011, Fritz Mehner +" License: Copyright (c) 2000-2013, 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 @@ -27,12 +27,11 @@ " 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.162 2012/02/25 15:15:30 mehner Exp $ " "------------------------------------------------------------------------------ " if v:version < 700 - echohl WarningMsg | echo 'The plugin c-support.vim needs Vim version >= 7 .'| echohl None + echohl WarningMsg | echo 'The plugin c.vim needs Vim version 7+.'| echohl None finish endif " @@ -41,7 +40,38 @@ endif if exists("g:C_Version") || &cp finish endif -let g:C_Version= "5.17" " version number of this script; do not change +let g:C_Version= "6.1.1" " version number of this script; do not change +" +"=== FUNCTION ================================================================ +" NAME: C_CheckGlobal +" DESCRIPTION: Assign a value to a local variable if a corresponding global +" variable exists. +" PARAMETERS: name - variable to set +"=============================================================================== +function! s:C_CheckGlobal ( name ) + if exists('g:'.a:name) + exe 'let s:'.a:name.' = g:'.a:name + endif +endfunction " ---------- end of function s:C_CheckGlobal ---------- +" +"=== FUNCTION ================================================================ +" NAME: C_SetGlobalVariable {{{1 +" DESCRIPTION: Define a global variable and assign a default value if not +" already defined. +" PARAMETERS: name - global variable +" default - default value +"=============================================================================== +function! s:C_SetGlobalVariable ( name, default ) + if !exists('g:'.a:name) + exe 'let g:'.a:name." = '".a:default."'" + else + " check for an empty initialization + exe 'let val = g:'.a:name + if empty(val) + exe 'let g:'.a:name." = '".a:default."'" + endif + endif +endfunction " ---------- end of function s:C_SetGlobalVariable ---------- " "################################################################################# " @@ -54,36 +84,37 @@ let g:C_Version= "5.17" " version number of this script; do not change let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") let s:UNIX = has("unix") || has("macunix") || has("win32unix") " -let s:installation = '*undefined*' +let g:C_Installation = '*undefined*' let s:plugin_dir = '' " let s:C_GlobalTemplateFile = '' -let s:C_GlobalTemplateDir = '' let s:C_LocalTemplateFile = '' -let s:C_LocalTemplateDir = '' let s:C_FilenameEscChar = '' +let s:C_ToolboxDir = [] + if s:MSWIN " ========== MS Windows ====================================================== + " + let s:plugin_dir = substitute( expand(':p:h:h'), '\', '/', 'g' ) " " change '\' to '/' to avoid interpretation as escape character if match( substitute( expand(""), '\', '/', 'g' ), \ substitute( expand("$HOME"), '\', '/', 'g' ) ) == 0 " " USER INSTALLATION ASSUMED - let s:installation = 'local' - let s:plugin_dir = substitute( expand(':p:h:h'), '\', '/', 'g' ) + let g:C_Installation = 'local' let s:C_LocalTemplateFile = s:plugin_dir.'/c-support/templates/Templates' - let s:C_LocalTemplateDir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' + let s:C_ToolboxDir += [ s:plugin_dir.'/autoload/mmtoolbox/' ] else " " SYSTEM WIDE INSTALLATION - let s:installation = 'system' - let s:plugin_dir = $VIM.'/vimfiles' - let s:C_GlobalTemplateDir = s:plugin_dir.'/c-support/templates' - let s:C_GlobalTemplateFile = s:C_GlobalTemplateDir.'/Templates' + let g:C_Installation = 'system' + let s:C_GlobalTemplateFile = s:plugin_dir.'/c-support/templates/Templates' let s:C_LocalTemplateFile = $HOME.'/vimfiles/c-support/templates/Templates' - let s:C_LocalTemplateDir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' + let s:C_ToolboxDir += [ + \ s:plugin_dir.'/autoload/mmtoolbox/', + \ $HOME.'/vimfiles/autoload/mmtoolbox/' ] endif " let s:C_FilenameEscChar = '' @@ -91,20 +122,21 @@ if s:MSWIN else " ========== Linux/Unix ====================================================== " - if match( expand(""), expand("$HOME") ) == 0 + let s:plugin_dir = expand(':p:h:h') + " + if match( expand(""), resolve( expand("$HOME") ) ) == 0 " USER INSTALLATION ASSUMED - let s:installation = 'local' - let s:plugin_dir = expand(':p:h:h') + let g:C_Installation = 'local' let s:C_LocalTemplateFile = s:plugin_dir.'/c-support/templates/Templates' - let s:C_LocalTemplateDir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' + let s:C_ToolboxDir += [ s:plugin_dir.'/autoload/mmtoolbox/' ] else " SYSTEM WIDE INSTALLATION - let s:installation = 'system' - let s:plugin_dir = $VIM.'/vimfiles' - let s:C_GlobalTemplateDir = s:plugin_dir.'/c-support/templates' - let s:C_GlobalTemplateFile = s:C_GlobalTemplateDir.'/Templates' + let g:C_Installation = 'system' + let s:C_GlobalTemplateFile = s:plugin_dir.'/c-support/templates/Templates' let s:C_LocalTemplateFile = $HOME.'/.vim/c-support/templates/Templates' - let s:C_LocalTemplateDir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' + let s:C_ToolboxDir += [ + \ s:plugin_dir.'/autoload/mmtoolbox/', + \ $HOME.'/.vim/autoload/mmtoolbox/' ] endif " let s:C_FilenameEscChar = ' \%#[]' @@ -127,97 +159,97 @@ 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 + call s:C_SetGlobalVariable ( 'C_CCompiler', 'gcc.exe' ) + call s:C_SetGlobalVariable ( 'C_CplusCompiler', 'g++.exe' ) 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 + call s:C_SetGlobalVariable ( 'C_CCompiler', 'gcc' ) + call s:C_SetGlobalVariable ( 'C_CplusCompiler', 'g++' ) 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_VimCompilerName = 'gcc' " the compiler name used by :compiler +" +call s:C_SetGlobalVariable ( 'C_CFlags', '-Wall -g -O0 -c') +call s:C_SetGlobalVariable ( 'C_LFlags', '-Wall -g -O0' ) +call s:C_SetGlobalVariable ( 'C_Libs', '-lm' ) +" +call s:C_SetGlobalVariable ( 'C_CplusCFlags', '-Wall -g -O0 -c') +call s:C_SetGlobalVariable ( 'C_CplusLFlags', '-Wall -g -O0' ) +call s:C_SetGlobalVariable ( 'C_CplusLibs', '-lm' ) +call s:C_SetGlobalVariable ( 'C_Debugger', 'gdb' ) +" +call s:C_SetGlobalVariable ( 'C_MapLeader', '' ) " default: do not overwrite 'maplocalleader' " 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_ExecutableToRun = '' let s:C_LineEndCommColDefault = 49 let s:C_LoadMenus = 'yes' -let s:C_CreateMenusDelayed = 'no' +let s:C_CreateMenusDelayed = 'no' 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_RootMenu = '&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_UseToolbox = 'yes' +call s:C_SetGlobalVariable ( 'C_UseTool_cmake', 'no' ) +call s:C_SetGlobalVariable ( 'C_UseTool_doxygen', 'no' ) +call s:C_SetGlobalVariable ( 'C_UseTool_make', 'yes' ) " -let s:C_TemplateOverriddenMsg = 'no' 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' +let s:C_CppcheckSeverity = 'all' +let s:C_InsertFileHeader = 'yes' +let s:C_NonCComment = '#' +" +let s:C_MenusVisible = 'no' " state variable controlling the C-menus " "------------------------------------------------------------------------------ " " 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_CreateMenusDelayed ') -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_TemplateOverriddenMsg') -call C_CheckGlobal('C_TypeOfH ') -call C_CheckGlobal('C_VimCompilerName ') -call C_CheckGlobal('C_XtermDefaults ') - -if exists('g:C_GlobalTemplateFile') && !empty(g:C_GlobalTemplateFile) - let s:C_GlobalTemplateDir = fnamemodify( s:C_GlobalTemplateFile, ":h" ) -endif -" +call s:C_CheckGlobal('C_CodeCheckExeName ') +call s:C_CheckGlobal('C_CodeCheckOptions ') +call s:C_CheckGlobal('C_CodeSnippets ') +call s:C_CheckGlobal('C_CreateMenusDelayed ') +call s:C_CheckGlobal('C_Ctrl_j ') +call s:C_CheckGlobal('C_ExeExtension ') +call s:C_CheckGlobal('C_GlobalTemplateFile ') +call s:C_CheckGlobal('C_GuiSnippetBrowser ') +call s:C_CheckGlobal('C_GuiTemplateBrowser ') +call s:C_CheckGlobal('C_IndentErrorLog ') +call s:C_CheckGlobal('C_InsertFileHeader ') +call s:C_CheckGlobal('C_LineEndCommColDefault') +call s:C_CheckGlobal('C_LoadMenus ') +call s:C_CheckGlobal('C_LocalTemplateFile ') +call s:C_CheckGlobal('C_Man ') +call s:C_CheckGlobal('C_MenuHeader ') +call s:C_CheckGlobal('C_NonCComment ') +call s:C_CheckGlobal('C_ObjExtension ') +call s:C_CheckGlobal('C_OutputGvim ') +call s:C_CheckGlobal('C_Printheader ') +call s:C_CheckGlobal('C_RootMenu ') +call s:C_CheckGlobal('C_SourceCodeExtensions ') +call s:C_CheckGlobal('C_TypeOfH ') +call s:C_CheckGlobal('C_UseToolbox ') +call s:C_CheckGlobal('C_XtermDefaults ') + "----- some variables for internal use only ----------------------------------- " +let s:stdbuf = '' +if executable( 'stdbuf' ) + " stdbuf : the output stream will be unbuffered + let s:stdbuf = 'stdbuf -o0 ' +endif " " set default geometry if not specified " @@ -236,62 +268,21 @@ let s:C_HlMessage = "" 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 +let s:C_SplintIsExecutable = executable( "splint" ) +let s:C_CppcheckIsExecutable = executable( "cppcheck" ) +let s:C_CodeCheckIsExecutable = executable( s:C_CodeCheckExeName ) +let s:C_IndentIsExecutable = executable( "indent" ) " "------------------------------------------------------------------------------ " 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_Com1 = '/*' " C-style : comment start -let s:C_Com2 = '*/' " C-style : comment end -" -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|' : '', - \ '|COMPANY|' : '', - \ '|COPYRIGHTHOLDER|': '', - \ '|EMAIL|' : '', - \ '|LICENSE|' : 'GNU General Public License', - \ '|ORGANIZATION|' : '', - \ '|PROJECT|' : '', - \ '|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_TemplatesLoaded = 'no' +" +let s:C_Com1 = '/*' " C-style : comment start +let s:C_Com2 = '*/' " C-style : comment end +" +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_ForTypes = [ \ 'char' , @@ -314,811 +305,338 @@ let s:C_ForTypes = [ \ 'unsigned short int' , \ ] -let s:C_ForTypes_Check_Order = [ - \ 'char' , - \ 'int' , - \ 'long long int' , - \ 'long long' , - \ 'long int' , - \ 'long' , - \ 'short int' , - \ 'short' , - \ 'size_t' , - \ 'unsigned short int' , - \ 'unsigned short' , - \ 'unsigned long long int', - \ 'unsigned long long' , - \ 'unsigned long int' , - \ 'unsigned long' , - \ 'unsigned int' , - \ 'unsigned char' , - \ 'unsigned' , - \ ] - let s:MsgInsNotAvail = "insertion not available for a fold" -let s:MenuRun = s:C_Root.'&Run' - -"------------------------------------------------------------------------------ +let s:MenuRun = s:C_RootMenu.'&Run' +let s:Output = [ 'VIM->buffer->xterm', 'BUFFER->xterm->vim', 'XTERM->vim->buffer' ] +let s:C_saved_global_option = {} let s:C_SourceCodeExtensionsList = split( s:C_SourceCodeExtensions, '\s\+' ) - -"------------------------------------------------------------------------------ +" +let s:CppcheckSeverity = [ "all", "error", "warning", "style", "performance", "portability", "information" ] +" +"=== FUNCTION ================================================================ +" NAME: C_MenuTitle {{{1 +" DESCRIPTION: display warning +" PARAMETERS: - +" RETURNS: +"=============================================================================== +function! C_MenuTitle () + echohl WarningMsg | echo "This is a menu header." | echohl None +endfunction " ---------- end of function C_MenuTitle ---------- "------------------------------------------------------------------------------ " C : C_InitMenus {{{1 " Initialization of C support menus "------------------------------------------------------------------------------ " -function! C_InitMenus () -" -" the menu names -" - let MenuComments = s:C_Root.'&Comments' - let MenuStatements = s:C_Root.'&Statements' - let MenuIdioms = s:C_Root.'&Idioms' - let MenuPreprocessor = s:C_Root.'&Preprocessor' - let MenuSnippets = s:C_Root.'S&nippets' - let MenuCpp = s:C_Root.'C&++' +function! s:C_InitMenus () " - "=============================================================================================== - "----- Menu : C main menu entry ------------------------------------------- {{{2 - "=============================================================================================== + if ! has ( 'menu' ) + return + endif + " + " Preparation + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'do_reset' ) " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".s:C_Root.'-Sep00- ' - exe "amenu ".MenuComments.'.&CommentsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuComments.'.-Sep00- ' - exe "amenu ".MenuStatements.'.&StatementsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuStatements.'.-Sep00- ' - exe "amenu ".MenuIdioms.'.&IdiomsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuIdioms.'.-Sep00- ' - exe "amenu ".MenuPreprocessor.'.&PreprocessorC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuPreprocessor.'.-Sep00- ' - exe "amenu ".MenuPreprocessor.'.#include\ &Std\.Lib\.\\ps.Std\.Lib\.C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuPreprocessor.'.#include\ &Std\.Lib\.\\ps.-Sep0- ' - exe "amenu ".MenuPreprocessor.'.#include\ C&99\\pc.C99C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuPreprocessor.'.#include\ C&99\\pc.-Sep0- ' - exe "amenu ".MenuSnippets.'.S&nippetsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuSnippets.'.-Sep00- ' - exe "amenu ".MenuCpp.'.C&\+\+C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.-Sep00- ' - exe "amenu ".s:MenuRun.'.&RunC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".s:MenuRun.'.-Sep00- ' + " get the mapleader (correctly escaped) + let [ esc_mapl, err ] = mmtemplates#core#Resource ( g:C_Templates, 'escaped_mapleader' ) + " + exe 'amenu '.s:C_RootMenu.'C\/C\+\+ ' + exe 'amenu '.s:C_RootMenu.'-Sep00- ' + " + "------------------------------------------------------------------------------- + " menu headers + "------------------------------------------------------------------------------- + " + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', '&Comments', 'priority', 500 ) + " the other, automatically created menus go here; their priority is the standard priority 500 + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', 'S&nippets', 'priority', 600 ) + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', '&Run' , 'priority', 700 ) + if s:C_UseToolbox == 'yes' && mmtoolbox#tools#Property ( s:C_Toolbox, 'empty-menu' ) == 0 + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', '&Tool Box', 'priority', 800 ) endif + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', '&Help' , 'priority', 900 ) " "=============================================================================================== "----- Menu : C-Comments -------------------------------------------------- {{{2 "=============================================================================================== " - exe "amenu ".MenuComments.'.end-of-&line\ comment\\cl :call C_EndOfLineComment( )' - exe "vmenu ".MenuComments.'.end-of-&line\ comment\\cl :call C_EndOfLineComment( )' + let MenuComments = s:C_RootMenu.'&Comments' + " + exe "amenu ".MenuComments.'.end-of-&line\ comment'.esc_mapl.'cl :call C_EndOfLineComment( )' + exe "vmenu ".MenuComments.'.end-of-&line\ comment'.esc_mapl.'cl :call C_EndOfLineComment( )' - exe "amenu ".MenuComments.'.ad&just\ end-of-line\ com\.\\cj :call C_AdjustLineEndComm()' - exe "vmenu ".MenuComments.'.ad&just\ end-of-line\ com\.\\cj :call C_AdjustLineEndComm()' + exe "amenu ".MenuComments.'.ad&just\ end-of-line\ com\.'.esc_mapl.'cj :call C_AdjustLineEndComm()' + exe "vmenu ".MenuComments.'.ad&just\ end-of-line\ com\.'.esc_mapl.'cj :call C_AdjustLineEndComm()' - exe "amenu ".MenuComments.'.&set\ end-of-line\ com\.\ col\.\\cs :call C_GetLineEndCommCol()' + exe "amenu ".MenuComments.'.&set\ end-of-line\ com\.\ col\.'.esc_mapl.'cs :call C_GetLineEndCommCol()' exe "amenu ".MenuComments.'.-SEP10- :' - exe "amenu ".MenuComments.'.code\ ->\ comment\ \/&*\ *\/\\c* :call C_CodeToCommentC():nohlsearchj' - exe "vmenu ".MenuComments.'.code\ ->\ comment\ \/&*\ *\/\\c* :call C_CodeToCommentC():nohlsearchj' - exe "amenu ".MenuComments.'.code\ ->\ comment\ &\/\/\\cc :call C_CodeToCommentCpp():nohlsearchj' - exe "vmenu ".MenuComments.'.code\ ->\ comment\ &\/\/\\cc :call C_CodeToCommentCpp():nohlsearchj' - exe "amenu ".MenuComments.'.c&omment\ ->\ code\\co :call C_CommentToCode():nohlsearch' - exe "vmenu ".MenuComments.'.c&omment\ ->\ code\\co :call C_CommentToCode():nohlsearch' + exe "amenu ".MenuComments.'.code\ ->\ comment\ \/&*\ *\/'.esc_mapl.'c* :call C_CodeToCommentC():nohlsearchj' + exe "vmenu ".MenuComments.'.code\ ->\ comment\ \/&*\ *\/'.esc_mapl.'c* :call C_CodeToCommentC():nohlsearchj' + exe "imenu ".MenuComments.'.code\ ->\ comment\ \/&*\ *\/'.esc_mapl.'c* :call C_CodeToCommentC():nohlsearchj' + exe "amenu ".MenuComments.'.code\ ->\ comment\ &\/\/'.esc_mapl.'cc :call C_CodeToCommentCpp():nohlsearchj' + exe "vmenu ".MenuComments.'.code\ ->\ comment\ &\/\/'.esc_mapl.'cc :call C_CodeToCommentCpp():nohlsearchj' + exe "imenu ".MenuComments.'.code\ ->\ comment\ &\/\/'.esc_mapl.'cc :call C_CodeToCommentCpp():nohlsearchj' + exe "amenu ".MenuComments.'.c&omment\ ->\ code'.esc_mapl.'co :call C_CommentToCode():nohlsearch' + exe "vmenu ".MenuComments.'.c&omment\ ->\ code'.esc_mapl.'co :call C_CommentToCode():nohlsearch' + exe "imenu ".MenuComments.'.c&omment\ ->\ code'.esc_mapl.'co :call C_CommentToCode():nohlsearch' + " + exe "amenu ".MenuComments.'.toggle\ &non-C\ comment'.esc_mapl.'cn :call C_NonCCommentToggle()j' + exe "vmenu ".MenuComments.'.toggle\ &non-C\ comment'.esc_mapl.'cn :call C_NonCCommentToggle()j' + exe "imenu ".MenuComments.'.toggle\ &non-C\ comment'.esc_mapl.'cn :call C_NonCCommentToggle()j' exe "amenu ".MenuComments.'.-SEP0- :' - exe "amenu ".MenuComments.'.&frame\ comment\\cfr :call C_InsertTemplate("comment.frame")' - exe "amenu ".MenuComments.'.f&unction\ description\\cfu :call C_InsertTemplate("comment.function")' - exe "amenu ".MenuComments.'.-SEP1- :' - exe "amenu ".MenuComments.'.&method\ description\\cme :call C_InsertTemplate("comment.method")' - exe "amenu ".MenuComments.'.cl&ass\ description\\ccl :call C_InsertTemplate("comment.class")' - exe "amenu ".MenuComments.'.-SEP2- :' - exe "amenu ".MenuComments.'.file\ description\ \(impl\.\)\\cfdi :call C_InsertTemplate("comment.file-description")' - exe "amenu ".MenuComments.'.file\ description\ \(header\)\\cfdh :call C_InsertTemplate("comment.file-description-header")' - exe "amenu ".MenuComments.'.-SEP3- :' - " - "----- Submenu : C-Comments : file sections ------------------------------------------------------------- - " - if s:C_MenuHeader == 'yes' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.file\ sectionsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.-Sep0- ' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.H-file\ sectionsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.-Sep0- ' - exe "amenu ".MenuComments.'.-SEP4- :' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.keyw\.+comm\.C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.-Sep0- ' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.special\ comm\.C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.-Sep0- ' - exe "amenu ".MenuComments.'.ta&gs\ (plugin).tags\ (plugin)C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuComments.'.ta&gs\ (plugin).-Sep0- ' - endif - " - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.&Header\ File\ Includes :call C_InsertTemplate("comment.file-section-cpp-header-includes")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.Local\ &Macros :call C_InsertTemplate("comment.file-section-cpp-macros")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.Local\ &Type\ Def\. :call C_InsertTemplate("comment.file-section-cpp-typedefs")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.Local\ &Data\ Types :call C_InsertTemplate("comment.file-section-cpp-data-types")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.Local\ &Variables :call C_InsertTemplate("comment.file-section-cpp-local-variables")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.Local\ &Prototypes :call C_InsertTemplate("comment.file-section-cpp-prototypes")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.&Exp\.\ Function\ Def\. :call C_InsertTemplate("comment.file-section-cpp-function-defs-exported")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.&Local\ Function\ Def\. :call C_InsertTemplate("comment.file-section-cpp-function-defs-local")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.-SEP6- :' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.Local\ &Class\ Def\. :call C_InsertTemplate("comment.file-section-cpp-class-defs")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.E&xp\.\ Class\ Impl\. :call C_InsertTemplate("comment.file-section-cpp-class-implementations-exported")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.L&ocal\ Class\ Impl\. :call C_InsertTemplate("comment.file-section-cpp-class-implementations-local")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.-SEP7- :' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.&All\ sections,\ C :call C_Comment_C_SectionAll("c")' - exe "amenu ".MenuComments.'.&C\/C\+\+-file\ sections\\ccs.All\ §ions,\ C++ :call C_Comment_C_SectionAll("cpp")' - " - "----- Submenu : H-Comments : file sections ------------------------------------------------------------- - " - "' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.&Header\ File\ Includes :call C_InsertTemplate("comment.file-section-hpp-header-includes")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.Exported\ &Macros :call C_InsertTemplate("comment.file-section-hpp-macros")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.Exported\ &Type\ Def\. :call C_InsertTemplate("comment.file-section-hpp-exported-typedefs")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.Exported\ &Data\ Types :call C_InsertTemplate("comment.file-section-hpp-exported-data-types")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.Exported\ &Variables :call C_InsertTemplate("comment.file-section-hpp-exported-variables")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.Exported\ &Funct\.\ Decl\. :call C_InsertTemplate("comment.file-section-hpp-exported-function-declarations")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.-SEP4- :' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.E&xported\ Class\ Def\. :call C_InsertTemplate("comment.file-section-hpp-exported-class-defs")' - - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.-SEP5- :' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.&All\ sections,\ C :call C_Comment_H_SectionAll("c")' - exe "amenu ".MenuComments.'.&H-file\ sections\\chs.All\ §ions,\ C++ :call C_Comment_H_SectionAll("cpp")' - " - exe "amenu ".MenuComments.'.-SEP8- :' - " - "----- Submenu : C-Comments : keyword comments ---------------------------------------------------------- - " -" - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&BUG\: $:call C_InsertTemplate("comment.keyword-bug")' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&COMPILER\: $:call C_InsertTemplate("comment.keyword-compiler")' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&TODO\: $:call C_InsertTemplate("comment.keyword-todo")' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&WARNING\: $:call C_InsertTemplate("comment.keyword-warning")' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:W&ORKAROUND\: $:call C_InsertTemplate("comment.keyword-workaround")' - exe "amenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&new\ keyword\: $:call C_InsertTemplate("comment.keyword-keyword")' -" - exe "imenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&BUG\: $:call C_InsertTemplate("comment.keyword-bug")' - exe "imenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&COMPILER\: $:call C_InsertTemplate("comment.keyword-compiler")' - exe "imenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&TODO\: $:call C_InsertTemplate("comment.keyword-todo")' - exe "imenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&WARNING\: $:call C_InsertTemplate("comment.keyword-warning")' - exe "imenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:W&ORKAROUND\: $:call C_InsertTemplate("comment.keyword-workaround")' - exe "imenu ".MenuComments.'.&keyword\ comm\.\\ckc.\:&new\ keyword\: $:call C_InsertTemplate("comment.keyword-keyword")' - " - "----- Submenu : C-Comments : special comments ---------------------------------------------------------- - " - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.&EMPTY $:call C_InsertTemplate("comment.special-empty")' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.&FALL\ THROUGH $:call C_InsertTemplate("comment.special-fall-through") ' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.&IMPL\.\ TYPE\ CONV $:call C_InsertTemplate("comment.special-implicit-type-conversion") ' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.&NO\ RETURN $:call C_InsertTemplate("comment.special-no-return") ' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.NOT\ &REACHED $:call C_InsertTemplate("comment.special-not-reached") ' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.&TO\ BE\ IMPL\. $:call C_InsertTemplate("comment.special-remains-to-be-implemented")' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.-SEP81- :' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.constant\ type\ is\ &long\ (L) $:call C_InsertTemplate("comment.special-constant-type-is-long")' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.constant\ type\ is\ &unsigned\ (U) $:call C_InsertTemplate("comment.special-constant-type-is-unsigned")' - exe "amenu ".MenuComments.'.&special\ comm\.\\csc.constant\ type\ is\ unsigned\ l&ong\ (UL) $:call C_InsertTemplate("comment.special-constant-type-is-unsigned-long")' - " - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.&EMPTY $:call C_InsertTemplate("comment.special-empty")' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.&FALL\ THROUGH $:call C_InsertTemplate("comment.special-fall-through") ' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.&IMPL\.\ TYPE\ CONV $:call C_InsertTemplate("comment.special-implicit-type-conversion") ' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.&NO\ RETURN $:call C_InsertTemplate("comment.special-no-return") ' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.NOT\ &REACHED $:call C_InsertTemplate("comment.special-not-reached") ' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.&TO\ BE\ IMPL\. $:call C_InsertTemplate("comment.special-remains-to-be-implemented")' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.-SEP81- :' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.constant\ type\ is\ &long\ (L) $:call C_InsertTemplate("comment.special-constant-type-is-long")' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.constant\ type\ is\ &unsigned\ (U) $:call C_InsertTemplate("comment.special-constant-type-is-unsigned")' - exe "imenu ".MenuComments.'.&special\ comm\.\\csc.constant\ type\ is\ unsigned\ l&ong\ (UL) $:call C_InsertTemplate("comment.special-constant-type-is-unsigned-long")' - " - "----- Submenu : C-Comments : Tags ---------------------------------------------------------- - " - " - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&AUTHOR :call C_InsertMacroValue("AUTHOR")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&AUTHORREF :call C_InsertMacroValue("AUTHORREF")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&COMPANY :call C_InsertMacroValue("COMPANY")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).©RIGHTHOLDER :call C_InsertMacroValue("COPYRIGHTHOLDER")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&EMAIL :call C_InsertMacroValue("EMAIL")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&LICENSE :call C_InsertMacroValue("LICENSE")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&ORGANIZATION :call C_InsertMacroValue("ORGANIZATION")' - exe "anoremenu ".MenuComments.'.ta&gs\ (plugin).&PROJECT :call C_InsertMacroValue("PROJECT")' - " - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&AUTHOR :call C_InsertMacroValue("AUTHOR")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&AUTHORREF :call C_InsertMacroValue("AUTHORREF")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&COMPANY :call C_InsertMacroValue("COMPANY")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).©RIGHTHOLDER :call C_InsertMacroValue("COPYRIGHTHOLDER")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&EMAIL :call C_InsertMacroValue("EMAIL")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&LICENSE :call C_InsertMacroValue("LICENSE")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&ORGANIZATION :call C_InsertMacroValue("ORGANIZATION")a' - exe "inoremenu ".MenuComments.'.ta&gs\ (plugin).&PROJECT :call C_InsertMacroValue("PROJECT")a' - " - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&AUTHOR s:call C_InsertMacroValue("AUTHOR")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&AUTHORREF s:call C_InsertMacroValue("AUTHORREF")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&COMPANY s:call C_InsertMacroValue("COMPANY")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).©RIGHTHOLDER s:call C_InsertMacroValue("COPYRIGHTHOLDER")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&EMAIL s:call C_InsertMacroValue("EMAIL")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&LICENSE s:call C_InsertMacroValue("LICENSE")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&ORGANIZATION s:call C_InsertMacroValue("ORGANIZATION")a' - exe "vnoremenu ".MenuComments.'.ta&gs\ (plugin).&PROJECT s:call C_InsertMacroValue("PROJECT")a' - " - exe " menu ".MenuComments.'.&date\\cd :call C_InsertDateAndTime("d")' - exe "imenu ".MenuComments.'.&date\\cd :call C_InsertDateAndTime("d")a' - exe "vmenu ".MenuComments.'.&date\\cd s:call C_InsertDateAndTime("d")a' - exe " menu ".MenuComments.'.date\ &time\\ct :call C_InsertDateAndTime("dt")' - exe "imenu ".MenuComments.'.date\ &time\\ct :call C_InsertDateAndTime("dt")a' - exe "vmenu ".MenuComments.'.date\ &time\\ct s:call C_InsertDateAndTime("dt")a' - - exe "amenu ".MenuComments.'.-SEP12- :' - exe "amenu ".MenuComments.'.\/*\ &xxx\ *\/\ \ <->\ \ \/\/\ xxx\\cx :call C_CommentToggle()' - exe "vmenu ".MenuComments.'.\/*\ &xxx\ *\/\ \ <->\ \ \/\/\ xxx\\cx :call C_CommentToggle()' - " - "=============================================================================================== - "----- Menu : C-Statements------------------------------------------------- {{{2 - "=============================================================================================== - " - exe "amenu ".MenuStatements.'.&do\ \{\ \}\ while\\sd :call C_InsertTemplate("statements.do-while")' - exe "vmenu ".MenuStatements.'.&do\ \{\ \}\ while\\sd :call C_InsertTemplate("statements.do-while", "v")' - exe "imenu ".MenuStatements.'.&do\ \{\ \}\ while\\sd :call C_InsertTemplate("statements.do-while")' - " - exe "amenu ".MenuStatements.'.f&or\\sf :call C_InsertTemplate("statements.for")' - exe "imenu ".MenuStatements.'.f&or\\sf :call C_InsertTemplate("statements.for")' - " - exe "amenu ".MenuStatements.'.fo&r\ \{\ \}\\sfo :call C_InsertTemplate("statements.for-block")' - exe "vmenu ".MenuStatements.'.fo&r\ \{\ \}\\sfo :call C_InsertTemplate("statements.for-block", "v")' - exe "imenu ".MenuStatements.'.fo&r\ \{\ \}\\sfo :call C_InsertTemplate("statements.for-block")' - " - exe "amenu ".MenuStatements.'.&if\\si :call C_InsertTemplate("statements.if")' - exe "imenu ".MenuStatements.'.&if\\si :call C_InsertTemplate("statements.if")' - " - exe "amenu ".MenuStatements.'.i&f\ \{\ \}\\sif :call C_InsertTemplate("statements.if-block")' - exe "vmenu ".MenuStatements.'.i&f\ \{\ \}\\sif :call C_InsertTemplate("statements.if-block", "v")' - exe "imenu ".MenuStatements.'.i&f\ \{\ \}\\sif :call C_InsertTemplate("statements.if-block")' - - exe "amenu ".MenuStatements.'.if\ &else\\sie :call C_InsertTemplate("statements.if-else")' - exe "vmenu ".MenuStatements.'.if\ &else\\sie :call C_InsertTemplate("statements.if-else", "v")' - exe "imenu ".MenuStatements.'.if\ &else\\sie :call C_InsertTemplate("statements.if-else")' - " - exe "amenu ".MenuStatements.'.if\ \{\ \}\ e&lse\ \{\ \}\\sife :call C_InsertTemplate("statements.if-block-else")' - exe "vmenu ".MenuStatements.'.if\ \{\ \}\ e&lse\ \{\ \}\\sife :call C_InsertTemplate("statements.if-block-else", "v")' - exe "imenu ".MenuStatements.'.if\ \{\ \}\ e&lse\ \{\ \}\\sife :call C_InsertTemplate("statements.if-block-else")' - " - exe "amenu ".MenuStatements.'.&else\ \{\ \}\\se :call C_InsertTemplate("statements.else-block")' - exe "vmenu ".MenuStatements.'.&else\ \{\ \}\\se :call C_InsertTemplate("statements.else-block", "v")' - exe "imenu ".MenuStatements.'.&else\ \{\ \}\\se :call C_InsertTemplate("statements.else-block")' - " - exe "amenu ".MenuStatements.'.&while\\sw :call C_InsertTemplate("statements.while")' - exe "imenu ".MenuStatements.'.&while\\sw :call C_InsertTemplate("statements.while")' - " - exe "amenu ".MenuStatements.'.w&hile\ \{\ \}\\swh :call C_InsertTemplate("statements.while-block")' - exe "vmenu ".MenuStatements.'.w&hile\ \{\ \}\\swh :call C_InsertTemplate("statements.while-block", "v")' - exe "imenu ".MenuStatements.'.w&hile\ \{\ \}\\swh :call C_InsertTemplate("statements.while-block")' - " - exe "amenu ".MenuStatements.'.&switch\ \{\ \}\\ss :call C_InsertTemplate("statements.switch")' - exe "vmenu ".MenuStatements.'.&switch\ \{\ \}\\ss :call C_InsertTemplate("statements.switch", "v")' - exe "imenu ".MenuStatements.'.&switch\ \{\ \}\\ss :call C_InsertTemplate("statements.switch")' - " - exe "amenu ".MenuStatements.'.&case\ \.\.\.\ break\\sc :call C_InsertTemplate("statements.case")' - exe "imenu ".MenuStatements.'.&case\ \.\.\.\ break\\sc :call C_InsertTemplate("statements.case")' - " - " - exe "amenu ".MenuStatements.'.&\{\ \}\\sb :call C_InsertTemplate("statements.block")' - exe "vmenu ".MenuStatements.'.&\{\ \}\\sb :call C_InsertTemplate("statements.block", "v")' - exe "imenu ".MenuStatements.'.&\{\ \}\\sb :call C_InsertTemplate("statements.block")' - " " "=============================================================================================== - "----- Menu : C-Idioms ---------------------------------------------------- {{{2 + "----- Menu : GENERATE MENU ITEMS FROM THE TEMPLATES ---------------------- {{{2 "=============================================================================================== - " - exe "amenu ".MenuIdioms.'.&function\\if :call C_InsertTemplate("idioms.function")' - exe "vmenu ".MenuIdioms.'.&function\\if :call C_InsertTemplate("idioms.function", "v")' - exe "imenu ".MenuIdioms.'.&function\\if :call C_InsertTemplate("idioms.function")' - exe "amenu ".MenuIdioms.'.s&tatic\ function\\isf :call C_InsertTemplate("idioms.function-static")' - exe "vmenu ".MenuIdioms.'.s&tatic\ function\\isf :call C_InsertTemplate("idioms.function-static", "v")' - exe "imenu ".MenuIdioms.'.s&tatic\ function\\isf :call C_InsertTemplate("idioms.function-static")' - exe "amenu ".MenuIdioms.'.&main\\im :call C_InsertTemplate("idioms.main")' - exe "vmenu ".MenuIdioms.'.&main\\im :call C_InsertTemplate("idioms.main", "v")' - exe "imenu ".MenuIdioms.'.&main\\im :call C_InsertTemplate("idioms.main")' - - exe "amenu ".MenuIdioms.'.-SEP1- :' - exe "amenu ".MenuIdioms.'.for(x=&0;\ x\\i0 :call C_CodeFor("up" )' - exe "vmenu ".MenuIdioms.'.for(x=&0;\ x\\i0 :call C_CodeFor("up" )' - exe "imenu ".MenuIdioms.'.for(x=&0;\ x\\i0 :call C_CodeFor("up" )i' - exe "amenu ".MenuIdioms.'.for(x=&n-1;\ x>=0;\ x\-=1)\\in :call C_CodeFor("down")' - exe "vmenu ".MenuIdioms.'.for(x=&n-1;\ x>=0;\ x\-=1)\\in :call C_CodeFor("down")' - exe "imenu ".MenuIdioms.'.for(x=&n-1;\ x>=0;\ x\-=1)\\in :call C_CodeFor("down")i' - - exe "amenu ".MenuIdioms.'.-SEP2- :' - exe "amenu ".MenuIdioms.'.&enum\\ie :call C_InsertTemplate("idioms.enum")' - exe "vmenu ".MenuIdioms.'.&enum\\ie :call C_InsertTemplate("idioms.enum" , "v")' - exe "imenu ".MenuIdioms.'.&enum\\ie :call C_InsertTemplate("idioms.enum" )' - exe "amenu ".MenuIdioms.'.&struct\\is :call C_InsertTemplate("idioms.struct")' - exe "vmenu ".MenuIdioms.'.&struct\\is :call C_InsertTemplate("idioms.struct", "v")' - exe "imenu ".MenuIdioms.'.&struct\\is :call C_InsertTemplate("idioms.struct")' - exe "amenu ".MenuIdioms.'.&union\\iu :call C_InsertTemplate("idioms.union")' - exe "vmenu ".MenuIdioms.'.&union\\iu :call C_InsertTemplate("idioms.union" , "v")' - exe "imenu ".MenuIdioms.'.&union\\iu :call C_InsertTemplate("idioms.union" )' - exe "amenu ".MenuIdioms.'.-SEP3- :' - " - exe "amenu ".MenuIdioms.'.&scanf\\isc :call C_InsertTemplate("idioms.scanf")' - exe "imenu ".MenuIdioms.'.&scanf\\isc :call C_InsertTemplate("idioms.scanf")' - exe "amenu ".MenuIdioms.'.&printf\\ip :call C_InsertTemplate("idioms.printf")' - exe "imenu ".MenuIdioms.'.&printf\\ip :call C_InsertTemplate("idioms.printf")' - " - exe "amenu ".MenuIdioms.'.-SEP4- :' - exe "amenu ".MenuIdioms.'.p=&calloc\(n,sizeof(type)\)\\ica :call C_InsertTemplate("idioms.calloc")' - exe "imenu ".MenuIdioms.'.p=&calloc\(n,sizeof(type)\)\\ica :call C_InsertTemplate("idioms.calloc")' - exe "amenu ".MenuIdioms.'.p=&malloc\(sizeof(type)\)\\ima :call C_InsertTemplate("idioms.malloc")' - exe "imenu ".MenuIdioms.'.p=&malloc\(sizeof(type)\)\\ima :call C_InsertTemplate("idioms.malloc")' - exe "amenu ".MenuIdioms.'.p=&realloc\(p,sizeof(type)\)\\ire :call C_InsertTemplate("idioms.realloc")' - exe "imenu ".MenuIdioms.'.p=&realloc\(p,sizeof(type)\)\\ire :call C_InsertTemplate("idioms.realloc")' - " - exe "anoremenu ".MenuIdioms.'.&sizeof(\ \)\\isi :call C_InsertTemplate("idioms.sizeof")' - exe "inoremenu ".MenuIdioms.'.&sizeof(\ \)\\isi :call C_InsertTemplate("idioms.sizeof")' - exe "vnoremenu ".MenuIdioms.'.&sizeof(\ \)\\isi :call C_InsertTemplate("idioms.sizeof", "v")' - " - exe "anoremenu ".MenuIdioms.'.&assert(\ \)\\ias :call C_InsertTemplate("idioms.assert")' - exe "inoremenu ".MenuIdioms.'.&assert(\ \)\\ias :call C_InsertTemplate("idioms.assert")' - exe "vnoremenu ".MenuIdioms.'.&assert(\ \)\\ias :call C_InsertTemplate("idioms.assert", "v")' - - exe "amenu ".MenuIdioms.'.-SEP5- :' - exe "amenu ".MenuIdioms.'.open\ &input\ file\\ii :call C_InsertTemplate("idioms.open-input-file")' - exe "imenu ".MenuIdioms.'.open\ &input\ file\\ii :call C_InsertTemplate("idioms.open-input-file")' - exe "vmenu ".MenuIdioms.'.open\ &input\ file\\ii :call C_InsertTemplate("idioms.open-input-file", "v")' - exe "amenu ".MenuIdioms.'.open\ &output\ file\\io :call C_InsertTemplate("idioms.open-output-file")' - exe "imenu ".MenuIdioms.'.open\ &output\ file\\io :call C_InsertTemplate("idioms.open-output-file")' - exe "vmenu ".MenuIdioms.'.open\ &output\ file\\io :call C_InsertTemplate("idioms.open-output-file", "v")' - " - exe "amenu ".MenuIdioms.'.fscanf\\ifs :call C_InsertTemplate("idioms.fscanf")' - exe "imenu ".MenuIdioms.'.fscanf\\ifs :call C_InsertTemplate("idioms.fscanf")' - exe "amenu ".MenuIdioms.'.fprintf\\ifp :call C_InsertTemplate("idioms.fprintf")' - exe "imenu ".MenuIdioms.'.fprintf\\ifp :call C_InsertTemplate("idioms.fprintf")' - " + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'do_templates' ) "=============================================================================================== - "----- Menu : C-Preprocessor ---------------------------------------------- {{{2 "=============================================================================================== " - "----- Submenu : C-Idioms: standard library ------------------------------------------------------- - "' - call C_CIncludeMenus ( MenuPreprocessor.'.#include\ &Std\.Lib\.\\ps', s:C_StandardLibs ) - " - call C_CIncludeMenus ( MenuPreprocessor.'.#include\ C&99\\pc', s:C_C99Libs ) - " - exe "amenu ".MenuPreprocessor.'.-SEP2- :' - exe "anoremenu ".MenuPreprocessor.'.#include\ &\<\.\.\.\>\\p< :call C_InsertTemplate("preprocessor.include-global")' - exe "inoremenu ".MenuPreprocessor.'.#include\ &\<\.\.\.\>\\p< :call C_InsertTemplate("preprocessor.include-global")' - exe "anoremenu ".MenuPreprocessor.'.#include\ &\"\.\.\.\"\\p" :call C_InsertTemplate("preprocessor.include-local")' - exe "inoremenu ".MenuPreprocessor.'.#include\ &\"\.\.\.\"\\p" :call C_InsertTemplate("preprocessor.include-local")' - exe "amenu ".MenuPreprocessor.'.#&define\\pd :call C_InsertTemplate("preprocessor.define")' - exe "imenu ".MenuPreprocessor.'.#&define\\pd :call C_InsertTemplate("preprocessor.define")' - exe "amenu ".MenuPreprocessor.'.&#undef\\pu :call C_InsertTemplate("preprocessor.undefine")' - exe "imenu ".MenuPreprocessor.'.&#undef\\pu :call C_InsertTemplate("preprocessor.undefine")' - " - exe "amenu ".MenuPreprocessor.'.#&if\ #endif\\pif :call C_InsertTemplate("preprocessor.if-endif")' - exe "imenu ".MenuPreprocessor.'.#&if\ #endif\\pif :call C_InsertTemplate("preprocessor.if-endif")' - exe "vmenu ".MenuPreprocessor.'.#&if\ #endif\\pif :call C_InsertTemplate("preprocessor.if-endif", "v")' - exe "amenu ".MenuPreprocessor.'.#&if\ #else\ #endif\\pie :call C_InsertTemplate("preprocessor.if-else-endif")' - exe "imenu ".MenuPreprocessor.'.#&if\ #else\ #endif\\pie :call C_InsertTemplate("preprocessor.if-else-endif")' - exe "vmenu ".MenuPreprocessor.'.#&if\ #else\ #endif\\pie :call C_InsertTemplate("preprocessor.if-else-endif", "v")' - exe "amenu ".MenuPreprocessor.'.#i&fdef\ #else\ #endif\\pid :call C_InsertTemplate("preprocessor.ifdef-else-endif")' - exe "imenu ".MenuPreprocessor.'.#i&fdef\ #else\ #endif\\pid :call C_InsertTemplate("preprocessor.ifdef-else-endif")' - exe "vmenu ".MenuPreprocessor.'.#i&fdef\ #else\ #endif\\pid :call C_InsertTemplate("preprocessor.ifdef-else-endif", "v")' - exe "amenu ".MenuPreprocessor.'.#if&ndef\ #else\ #endif\\pin :call C_InsertTemplate("preprocessor.ifndef-else-endif")' - exe "imenu ".MenuPreprocessor.'.#if&ndef\ #else\ #endif\\pin :call C_InsertTemplate("preprocessor.ifndef-else-endif")' - exe "vmenu ".MenuPreprocessor.'.#if&ndef\ #else\ #endif\\pin :call C_InsertTemplate("preprocessor.ifndef-else-endif", "v")' - exe "amenu ".MenuPreprocessor.'.#ifnd&ef\ #def\ #endif\\pind :call C_InsertTemplate("preprocessor.ifndef-def-endif")' - exe "imenu ".MenuPreprocessor.'.#ifnd&ef\ #def\ #endif\\pind :call C_InsertTemplate("preprocessor.ifndef-def-endif")' - exe "vmenu ".MenuPreprocessor.'.#ifnd&ef\ #def\ #endif\\pind :call C_InsertTemplate("preprocessor.ifndef-def-endif", "v")' - - exe "amenu ".MenuPreprocessor.'.#if\ &0\ #endif\\pi0 :call C_PPIf0("a")2ji' - exe "imenu ".MenuPreprocessor.'.#if\ &0\ #endif\\pi0 :call C_PPIf0("a")2ji' - exe "vmenu ".MenuPreprocessor.'.#if\ &0\ #endif\\pi0 :call C_PPIf0("v")' - " - exe "amenu ".MenuPreprocessor.'.&remove\ #if\ 0\ #endif\\pr0 :call C_PPIf0Remove()' - exe "imenu ".MenuPreprocessor.'.&remove\ #if\ 0\ #endif\\pr0 :call C_PPIf0Remove()' - " - exe "amenu ".MenuPreprocessor.'.#err&or\\pe :call C_InsertTemplate("preprocessor.error")' - exe "imenu ".MenuPreprocessor.'.#err&or\\pe :call C_InsertTemplate("preprocessor.error")' - exe "amenu ".MenuPreprocessor.'.#&line\\pl :call C_InsertTemplate("preprocessor.line")' - exe "imenu ".MenuPreprocessor.'.#&line\\pl :call C_InsertTemplate("preprocessor.line")' - exe "amenu ".MenuPreprocessor.'.#&pragma\\pp :call C_InsertTemplate("preprocessor.pragma")' - exe "imenu ".MenuPreprocessor.'.#&pragma\\pp :call C_InsertTemplate("preprocessor.pragma")' - " "=============================================================================================== "----- Menu : Snippets ---------------------------------------------------- {{{2 "=============================================================================================== " - if !empty(s:C_CodeSnippets) - exe "amenu ".MenuSnippets.'.&read\ code\ snippet\\nr :call C_CodeSnippet("r")' - exe "imenu ".MenuSnippets.'.&read\ code\ snippet\\nr :call C_CodeSnippet("r")' - exe "amenu ".MenuSnippets.'.&write\ code\ snippet\\nw :call C_CodeSnippet("w")' - exe "vmenu ".MenuSnippets.'.&write\ code\ snippet\\nw :call C_CodeSnippet("wv")' - exe "imenu ".MenuSnippets.'.&write\ code\ snippet\\nw :call C_CodeSnippet("w")' - exe "amenu ".MenuSnippets.'.&edit\ code\ snippet\\ne :call C_CodeSnippet("e")' - exe "imenu ".MenuSnippets.'.&edit\ code\ snippet\\ne :call C_CodeSnippet("e")' - exe " menu ".MenuSnippets.'.-SEP1- :' - endif - exe " menu ".MenuSnippets.'.&pick\ up\ func\.\ prototype\\nf,\ \\np :call C_ProtoPick("function")' - exe "vmenu ".MenuSnippets.'.&pick\ up\ func\.\ prototype\\nf,\ \\np :call C_ProtoPick("function")' - exe "imenu ".MenuSnippets.'.&pick\ up\ func\.\ prototype\\nf,\ \\np :call C_ProtoPick("function")' - exe " menu ".MenuSnippets.'.&pick\ up\ method\ prototype\\nm :call C_ProtoPick("method")' - exe "vmenu ".MenuSnippets.'.&pick\ up\ method\ prototype\\nm :call C_ProtoPick("method")' - exe "imenu ".MenuSnippets.'.&pick\ up\ method\ prototype\\nm :call C_ProtoPick("method")' - exe " menu ".MenuSnippets.'.&insert\ prototype(s)\\ni :call C_ProtoInsert()' - exe "imenu ".MenuSnippets.'.&insert\ prototype(s)\\ni :call C_ProtoInsert()' - exe " menu ".MenuSnippets.'.&clear\ prototype(s)\\nc :call C_ProtoClear()' - exe "imenu ".MenuSnippets.'.&clear\ prototype(s)\\nc :call C_ProtoClear()' - exe " menu ".MenuSnippets.'.&show\ prototype(s)\\ns :call C_ProtoShow()' - exe "imenu ".MenuSnippets.'.&show\ prototype(s)\\ns :call C_ProtoShow()' - - exe " menu ".MenuSnippets.'.-SEP2- :' - exe "amenu ".MenuSnippets.'.edit\ &local\ templates\\ntl :call C_BrowseTemplateFiles("Local")' - exe "imenu ".MenuSnippets.'.edit\ &local\ templates\\ntl :call C_BrowseTemplateFiles("Local")' - if s:installation == 'system' - exe "amenu ".MenuSnippets.'.edit\ &global\ templates\\ntg :call C_BrowseTemplateFiles("Global")' - exe "imenu ".MenuSnippets.'.edit\ &global\ templates\\ntg :call C_BrowseTemplateFiles("Global")' - endif - exe "amenu ".MenuSnippets.'.reread\ &templates\\ntr :call C_RereadTemplates("yes")' - exe "imenu ".MenuSnippets.'.reread\ &templates\\ntr :call C_RereadTemplates("yes")' - exe "amenu ".MenuSnippets.'.switch\ template\ st&yle\\nts :CStyle' - exe "imenu ".MenuSnippets.'.switch\ template\ st&yle\\nts :CStyle' - " - "=============================================================================================== - "----- Menu : C++ --------------------------------------------------------- {{{2 - "=============================================================================================== - " - exe "anoremenu ".MenuCpp.'.c&in :call C_InsertTemplate("cpp.cin")' - exe "inoremenu ".MenuCpp.'.c&in :call C_InsertTemplate("cpp.cin")' - exe "anoremenu ".MenuCpp.'.c&out\\+co :call C_InsertTemplate("cpp.cout")' - exe "inoremenu ".MenuCpp.'.c&out\\+co :call C_InsertTemplate("cpp.cout")' - exe "anoremenu ".MenuCpp.'.<<\ &\"\"\\+" :call C_InsertTemplate("cpp.cout-operator")' - exe "inoremenu ".MenuCpp.'.<<\ &\"\"\\+" :call C_InsertTemplate("cpp.cout-operator")' - " - "----- Submenu : C++ : output manipulators ------------------------------------------------------- - " - if s:C_MenuHeader == 'yes' - exe "amenu ".MenuCpp.'.&output\ manipulators.output\ manip\.C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.&output\ manipulators.-Sep0- ' - exe "amenu ".MenuCpp.'.ios\ flag&bits.ios\ flagsC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.ios\ flag&bits.-Sep0- ' - exe "amenu ".MenuCpp.'.&#include\ \\+ps.alg\.\.vecC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.&#include\ \\+ps.-Sep0- ' - exe "amenu ".MenuCpp.'.&#include\ \\+pc.cXC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.&#include\ \\+pc.-Sep0- ' - endif - " - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &boolalpha :call C_InsertTemplate("cpp.output-manipulator-boolalpha")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &dec :call C_InsertTemplate("cpp.output-manipulator-dec")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &endl :call C_InsertTemplate("cpp.output-manipulator-endl")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &fixed :call C_InsertTemplate("cpp.output-manipulator-fixed")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ fl&ush :call C_InsertTemplate("cpp.output-manipulator-flush")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &hex :call C_InsertTemplate("cpp.output-manipulator-hex")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &internal :call C_InsertTemplate("cpp.output-manipulator-internal")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &left :call C_InsertTemplate("cpp.output-manipulator-left")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &oct :call C_InsertTemplate("cpp.output-manipulator-oct")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &right :call C_InsertTemplate("cpp.output-manipulator-right")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ s&cientific :call C_InsertTemplate("cpp.output-manipulator-scientific")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &setbase\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setbase")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ se&tfill\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setfill")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ setiosfla&g\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setiosflags")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ set&precision\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setprecision")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ set&w\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setw")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ showb&ase :call C_InsertTemplate("cpp.output-manipulator-showbase")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ showpoi&nt :call C_InsertTemplate("cpp.output-manipulator-showpoint")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ showpos\ \(&1\) :call C_InsertTemplate("cpp.output-manipulator-showpos")' - exe "anoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ uppercase\ \(&2\) :call C_InsertTemplate("cpp.output-manipulator-uppercase")' - " - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &boolalpha :call C_InsertTemplate("cpp.output-manipulator-boolalpha")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &dec :call C_InsertTemplate("cpp.output-manipulator-dec")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &endl :call C_InsertTemplate("cpp.output-manipulator-endl")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &fixed :call C_InsertTemplate("cpp.output-manipulator-fixed")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ fl&ush :call C_InsertTemplate("cpp.output-manipulator-flush")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &hex :call C_InsertTemplate("cpp.output-manipulator-hex")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &internal :call C_InsertTemplate("cpp.output-manipulator-internal")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &left :call C_InsertTemplate("cpp.output-manipulator-left")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &oct :call C_InsertTemplate("cpp.output-manipulator-oct")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &right :call C_InsertTemplate("cpp.output-manipulator-right")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ s&cientific :call C_InsertTemplate("cpp.output-manipulator-scientific")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ &setbase\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setbase")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ se&tfill\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setfill")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ setiosfla&g\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setiosflags")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ set&precision\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setprecision")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ set&w\(\ \) :call C_InsertTemplate("cpp.output-manipulator-setw")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ showb&ase :call C_InsertTemplate("cpp.output-manipulator-showbase")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ showpoi&nt :call C_InsertTemplate("cpp.output-manipulator-showpoint")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ showpos\ \(&1\) :call C_InsertTemplate("cpp.output-manipulator-showpos")' - exe "inoremenu ".MenuCpp.'.&output\ manipulators.\<\<\ uppercase\ \(&2\) :call C_InsertTemplate("cpp.output-manipulator-uppercase")' - " - "----- Submenu : C++ : ios flag bits ------------------------------------------------------------- - " - " - call C_CIosFlagMenus ( MenuCpp.'.ios\ flag&bits', s:Cpp_IosFlagBits ) - " - "----- Submenu : C++ library (algorithm - locale) ---------------------------------------------- - " - call C_CIncludeMenus ( MenuCpp.'.&#include\ \\+ps', s:Cpp_StandardLibs ) - " - "----- Submenu : C library (cassert - ctime) ------------------------------------------------- - " - call C_CIncludeMenus ( MenuCpp.'.&#include\ \\+pc', s:Cpp_CStandardLibs ) - " - "----- End Submenu : C library (cassert - ctime) --------------------------------------------- - " - exe "amenu ".MenuCpp.'.-SEP2- :' - - exe "amenu ".MenuCpp.'.&class\\+c :call C_InsertTemplate("cpp.class-definition")' - exe "imenu ".MenuCpp.'.&class\\+c :call C_InsertTemplate("cpp.class-definition")' - exe "amenu ".MenuCpp.'.class\ (w\.\ &new)\\+cn :call C_InsertTemplate("cpp.class-using-new-definition")' - exe "imenu ".MenuCpp.'.class\ (w\.\ &new)\\+cn :call C_InsertTemplate("cpp.class-using-new-definition")' - exe "amenu ".MenuCpp.'.&templ\.\ class\\+tc :call C_InsertTemplate("cpp.template-class-definition")' - exe "imenu ".MenuCpp.'.&templ\.\ class\\+tc :call C_InsertTemplate("cpp.template-class-definition")' - exe "amenu ".MenuCpp.'.templ\.\ class\ (w\.\ ne&w)\\+tcn :call C_InsertTemplate("cpp.template-class-using-new-definition")' - exe "imenu ".MenuCpp.'.templ\.\ class\ (w\.\ ne&w)\\+tcn :call C_InsertTemplate("cpp.template-class-using-new-definition")' - - " - "----- Submenu : C++ : IMPLEMENTATION ------------------------------------------------------- - " - if s:C_MenuHeader == 'yes' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.IMPLEMENT\.C\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.-Sep0- ' - endif - " - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.&class\\+ci :call C_InsertTemplate("cpp.class-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.&class\\+ci :call C_InsertTemplate("cpp.class-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.class\ (w\.\ &new)\\+cni :call C_InsertTemplate("cpp.class-using-new-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.class\ (w\.\ &new)\\+cni :call C_InsertTemplate("cpp.class-using-new-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.&method\\+mi :call C_InsertTemplate("cpp.method-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.&method\\+mi :call C_InsertTemplate("cpp.method-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.&accessor\\+ai :call C_InsertTemplate("cpp.accessor-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.&accessor\\+ai :call C_InsertTemplate("cpp.accessor-implementation")' - " - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.-SEP21- :' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.&templ\.\ class\\+tci :call C_InsertTemplate("cpp.template-class-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.&templ\.\ class\\+tci :call C_InsertTemplate("cpp.template-class-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.templ\.\ class\ (w\.\ ne&w)\\+tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.templ\.\ class\ (w\.\ ne&w)\\+tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.templ\.\ mðod\\+tmi :call C_InsertTemplate("cpp.template-method-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.templ\.\ mðod\\+tmi :call C_InsertTemplate("cpp.template-method-implementation")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.templ\.\ a&ccessor\\+tai :call C_InsertTemplate("cpp.template-accessor-implementation")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.templ\.\ a&ccessor\\+tai :call C_InsertTemplate("cpp.template-accessor-implementation")' - " - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.-SEP22- :' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.operator\ &<< :call C_InsertTemplate("cpp.operator-in")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.operator\ &<< :call C_InsertTemplate("cpp.operator-in")' - exe "amenu ".MenuCpp.'.IM&PLEMENTATION.operator\ &>> :call C_InsertTemplate("cpp.operator-out")' - exe "imenu ".MenuCpp.'.IM&PLEMENTATION.operator\ &>> :call C_InsertTemplate("cpp.operator-out")' - " - "----- End Submenu : C++ : IMPLEMENTATION ------------------------------------------------------- - " - exe "amenu ".MenuCpp.'.-SEP31- :' - exe "amenu ".MenuCpp.'.templ\.\ &function\\+tf :call C_InsertTemplate("cpp.template-function")' - exe "imenu ".MenuCpp.'.templ\.\ &function\\+tf :call C_InsertTemplate("cpp.template-function")' - exe "amenu ".MenuCpp.'.&error\ class\\+ec :call C_InsertTemplate("cpp.error-class")' - exe "imenu ".MenuCpp.'.&error\ class\\+ec :call C_InsertTemplate("cpp.error-class")' - - exe "amenu ".MenuCpp.'.-SEP5- :' - exe "amenu ".MenuCpp.'.tr&y\ \.\.\ catch\\+tr :call C_InsertTemplate("cpp.try-catch")' - exe "imenu ".MenuCpp.'.tr&y\ \.\.\ catch\\+tr :call C_InsertTemplate("cpp.try-catch")' - exe "vmenu ".MenuCpp.'.tr&y\ \.\.\ catch\\+tr :call C_InsertTemplate("cpp.try-catch", "v")' - exe "amenu ".MenuCpp.'.catc&h\\+ca :call C_InsertTemplate("cpp.catch")' - exe "imenu ".MenuCpp.'.catc&h\\+ca :call C_InsertTemplate("cpp.catch")' - exe "vmenu ".MenuCpp.'.catc&h\\+ca :call C_InsertTemplate("cpp.catch", "v")' - - exe "amenu ".MenuCpp.'.catch\(&\.\.\.\)\\+c\. :call C_InsertTemplate("cpp.catch-points")' - exe "imenu ".MenuCpp.'.catch\(&\.\.\.\)\\+c\. :call C_InsertTemplate("cpp.catch-points")' - exe "vmenu ".MenuCpp.'.catch\(&\.\.\.\)\\+c\. :call C_InsertTemplate("cpp.catch-points", "v")' - - exe "amenu ".MenuCpp.'.-SEP6- :' - exe "amenu ".MenuCpp.'.open\ input\ file\ \ \(&4\) :call C_InsertTemplate("cpp.open-input-file")' - exe "imenu ".MenuCpp.'.open\ input\ file\ \ \(&4\) :call C_InsertTemplate("cpp.open-input-file")' - exe "vmenu ".MenuCpp.'.open\ input\ file\ \ \(&4\) :call C_InsertTemplate("cpp.open-input-file", "v")' - exe "amenu ".MenuCpp.'.open\ output\ file\ \(&5\) :call C_InsertTemplate("cpp.open-output-file")' - exe "imenu ".MenuCpp.'.open\ output\ file\ \(&5\) :call C_InsertTemplate("cpp.open-output-file")' - exe "vmenu ".MenuCpp.'.open\ output\ file\ \(&5\) :call C_InsertTemplate("cpp.open-output-file", "v")' - exe "amenu ".MenuCpp.'.-SEP7- :' - - exe "amenu ".MenuCpp.'.&using\ namespace\ std; :call C_InsertTemplate("cpp.namespace-std")' - exe "imenu ".MenuCpp.'.&using\ namespace\ std; :call C_InsertTemplate("cpp.namespace-std")' - exe "amenu ".MenuCpp.'.u&sing\ namespace\ ???; :call C_InsertTemplate("cpp.namespace")' - exe "imenu ".MenuCpp.'.u&sing\ namespace\ ???; :call C_InsertTemplate("cpp.namespace")' - - exe "amenu ".MenuCpp.'.names&pace\ ???\ \{\ \} :call C_InsertTemplate("cpp.namespace-block")' - exe "imenu ".MenuCpp.'.names&pace\ ???\ \{\ \} :call C_InsertTemplate("cpp.namespace-block")' - exe "vmenu ".MenuCpp.'.names&pace\ ???\ \{\ \} :call C_InsertTemplate("cpp.namespace-block", "v")' - exe "amenu ".MenuCpp.'.namespace\ &alias\ =\ ??? :call C_InsertTemplate("cpp.namespace-alias")' - exe "imenu ".MenuCpp.'.namespace\ &alias\ =\ ??? :call C_InsertTemplate("cpp.namespace-alias")' - - exe "amenu ".MenuCpp.'.-SEP8- :' - " - "----- Submenu : RTTI ---------------------------------------------------------------------------- + let ahead = 'anoremenu '.s:C_RootMenu.'S&nippets.' + let vhead = 'vnoremenu '.s:C_RootMenu.'S&nippets.' + let ihead = 'inoremenu '.s:C_RootMenu.'S&nippets.' " - if s:C_MenuHeader == 'yes' - exe "amenu ".MenuCpp.'.&RTTI.RTTIC\/C\+\+ :call C_MenuTitle()' - exe "amenu ".MenuCpp.'.&RTTI.-Sep0- ' - endif - " - exe "anoremenu ".MenuCpp.'.&RTTI.&typeid :call C_InsertTemplate("cpp.rtti-typeid")' - exe "anoremenu ".MenuCpp.'.&RTTI.&static_cast :call C_InsertTemplate("cpp.rtti-static-cast")' - exe "anoremenu ".MenuCpp.'.&RTTI.&const_cast :call C_InsertTemplate("cpp.rtti-const-cast")' - exe "anoremenu ".MenuCpp.'.&RTTI.&reinterpret_cast :call C_InsertTemplate("cpp.rtti-reinterpret-cast")' - exe "anoremenu ".MenuCpp.'.&RTTI.&dynamic_cast :call C_InsertTemplate("cpp.rtti-dynamic-cast")' - " - exe "inoremenu ".MenuCpp.'.&RTTI.&typeid :call C_InsertTemplate("cpp.rtti-typeid")' - exe "inoremenu ".MenuCpp.'.&RTTI.&static_cast :call C_InsertTemplate("cpp.rtti-static-cast")' - exe "inoremenu ".MenuCpp.'.&RTTI.&const_cast :call C_InsertTemplate("cpp.rtti-const-cast")' - exe "inoremenu ".MenuCpp.'.&RTTI.&reinterpret_cast :call C_InsertTemplate("cpp.rtti-reinterpret-cast")' - exe "inoremenu ".MenuCpp.'.&RTTI.&dynamic_cast :call C_InsertTemplate("cpp.rtti-dynamic-cast")' - " - exe "vnoremenu ".MenuCpp.'.&RTTI.&typeid :call C_InsertTemplate("cpp.rtti-typeid", "v")' - exe "vnoremenu ".MenuCpp.'.&RTTI.&static_cast :call C_InsertTemplate("cpp.rtti-static-cast", "v")' - exe "vnoremenu ".MenuCpp.'.&RTTI.&const_cast :call C_InsertTemplate("cpp.rtti-const-cast", "v")' - exe "vnoremenu ".MenuCpp.'.&RTTI.&reinterpret_cast :call C_InsertTemplate("cpp.rtti-reinterpret-cast", "v")' - exe "vnoremenu ".MenuCpp.'.&RTTI.&dynamic_cast :call C_InsertTemplate("cpp.rtti-dynamic-cast", "v")' - " - "----- End Submenu : RTTI ------------------------------------------------------------------------ - " - exe "amenu ".MenuCpp.'.e&xtern\ \"C\"\ \{\ \} :call C_InsertTemplate("cpp.extern")' - exe "imenu ".MenuCpp.'.e&xtern\ \"C\"\ \{\ \} :call C_InsertTemplate("cpp.extern")' - exe "vmenu ".MenuCpp.'.e&xtern\ \"C\"\ \{\ \} :call C_InsertTemplate("cpp.extern", "v")' + if !empty(s:C_CodeSnippets) + exe ahead.'&read\ code\ snippet'.esc_mapl.'nr :call C_CodeSnippet("r")' + exe ihead.'&read\ code\ snippet'.esc_mapl.'nr :call C_CodeSnippet("r")' + exe ahead.'&view\ code\ snippet'.esc_mapl.'nv :call C_CodeSnippet("view")' + exe ihead.'&view\ code\ snippet'.esc_mapl.'nv :call C_CodeSnippet("view")' + exe ahead.'&write\ code\ snippet'.esc_mapl.'nw :call C_CodeSnippet("w")' + exe vhead.'&write\ code\ snippet'.esc_mapl.'nw :call C_CodeSnippet("wv")' + exe ihead.'&write\ code\ snippet'.esc_mapl.'nw :call C_CodeSnippet("w")' + exe ahead.'&edit\ code\ snippet'.esc_mapl.'ne :call C_CodeSnippet("e")' + exe ihead.'&edit\ code\ snippet'.esc_mapl.'ne :call C_CodeSnippet("e")' + exe ahead.'-SEP1- :' + endif + exe ahead.'&pick\ up\ func\.\ prototype'.esc_mapl.'nf,\ '.esc_mapl.'np :call C_ProtoPick("function")' + exe vhead.'&pick\ up\ func\.\ prototype'.esc_mapl.'nf,\ '.esc_mapl.'np :call C_ProtoPick("function")' + exe ihead.'&pick\ up\ func\.\ prototype'.esc_mapl.'nf,\ '.esc_mapl.'np :call C_ProtoPick("function")' + exe ahead.'&pick\ up\ method\ prototype'.esc_mapl.'nm :call C_ProtoPick("method")' + exe vhead.'&pick\ up\ method\ prototype'.esc_mapl.'nm :call C_ProtoPick("method")' + exe ihead.'&pick\ up\ method\ prototype'.esc_mapl.'nm :call C_ProtoPick("method")' + exe ahead.'&insert\ prototype(s)'.esc_mapl.'ni :call C_ProtoInsert()' + exe ihead.'&insert\ prototype(s)'.esc_mapl.'ni :call C_ProtoInsert()' + exe ahead.'&clear\ prototype(s)'.esc_mapl.'nc :call C_ProtoClear()' + exe ihead.'&clear\ prototype(s)'.esc_mapl.'nc :call C_ProtoClear()' + exe ahead.'&show\ prototype(s)'.esc_mapl.'ns :call C_ProtoShow()' + exe ihead.'&show\ prototype(s)'.esc_mapl.'ns :call C_ProtoShow()' + + exe ahead.'-SEP2- :' + " + exe ahead.'edit\ &local\ templates'.esc_mapl.'ntl :call mmtemplates#core#EditTemplateFiles(g:C_Templates,-1)' + exe ihead.'edit\ &local\ templates'.esc_mapl.'ntl :call mmtemplates#core#EditTemplateFiles(g:C_Templates,-1)' + if g:C_Installation == 'system' + exe ahead.'edit\ &global\ templates'.esc_mapl.'ntg :call mmtemplates#core#EditTemplateFiles(g:C_Templates,0)' + exe ihead.'edit\ &global\ templates'.esc_mapl.'ntg :call mmtemplates#core#EditTemplateFiles(g:C_Templates,0)' + endif + " + exe ahead.'reread\ &templates'.esc_mapl.'ntr :call mmtemplates#core#ReadTemplates(g:C_Templates,"reload","all")' + exe ihead.'reread\ &templates'.esc_mapl.'ntr :call mmtemplates#core#ReadTemplates(g:C_Templates,"reload","all")' + " + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'do_styles', 'specials_menu', 'Snippets' ) " "=============================================================================================== - "----- Menu : run ----- -------------------------------------------------- {{{2 + "----- Menu : Run --------------------------------------------------------- {{{2 "=============================================================================================== " - exe "amenu ".s:MenuRun.'.save\ and\ &compile\\rc\ \ \ :call C_Compile():call C_HlMessage()' - exe "imenu ".s:MenuRun.'.save\ and\ &compile\\rc\ \ \ :call C_Compile():call C_HlMessage()' - exe "amenu ".s:MenuRun.'.&link\\rl\ \ \ \ \ :call C_Link():call C_HlMessage()' - exe "imenu ".s:MenuRun.'.&link\\rl\ \ \ \ \ :call C_Link():call C_HlMessage()' - exe "amenu ".s:MenuRun.'.&run\\rr\ \ \ :call C_Run()' - exe "imenu ".s:MenuRun.'.&run\\rr\ \ \ :call C_Run()' - exe "amenu ".s:MenuRun.'.cmd\.\ line\ &arg\.\\ra\ \ \ :call C_Arguments()' - exe "imenu ".s:MenuRun.'.cmd\.\ line\ &arg\.\\ra\ \ \ :call C_Arguments()' - " - exe "amenu ".s:MenuRun.'.-SEP0- :' - exe "amenu ".s:MenuRun.'.&make\\rm :call C_Make()' - exe "imenu ".s:MenuRun.'.&make\\rm :call C_Make()' - exe "amenu ".s:MenuRun.'.&choose\ makefile\\rcm :call C_ChooseMakefile()' - exe "imenu ".s:MenuRun.'.&choose\ makefile\\rcm :call C_ChooseMakefile()' - exe "amenu ".s:MenuRun.'.executable\ to\ run\\rme :call C_MakeExeToRun()' - exe "imenu ".s:MenuRun.'.executable\ to\ run\\rme :call C_MakeExeToRun()' - exe "amenu ".s:MenuRun.'.&make\ clean\\rmc :call C_MakeClean()' - exe "imenu ".s:MenuRun.'.&make\ clean\\rmc :call C_MakeClean()' - exe "amenu ".s:MenuRun.'.cmd\.\ line\ ar&g\.\ for\ make\\rma :call C_MakeArguments()' - exe "imenu ".s:MenuRun.'.cmd\.\ line\ ar&g\.\ for\ make\\rma :call C_MakeArguments()' - " - exe "amenu ".s:MenuRun.'.-SEP1- :' + let ahead = 'anoremenu '.s:MenuRun.'.' + let vhead = 'vnoremenu '.s:MenuRun.'.' + let ihead = 'inoremenu '.s:MenuRun.'.' + " + exe ahead.'save\ and\ &compile'.esc_mapl.'rc\ \ \ :call C_Compile():call C_HlMessage()' + exe ihead.'save\ and\ &compile'.esc_mapl.'rc\ \ \ :call C_Compile():call C_HlMessage()' + exe ahead.'&link'.esc_mapl.'rl\ \ \ \ \ :call C_Link():call C_HlMessage()' + exe ihead.'&link'.esc_mapl.'rl\ \ \ \ \ :call C_Link():call C_HlMessage()' + exe ahead.'&run'.esc_mapl.'rr\ \ \ :call C_Run()' + exe ihead.'&run'.esc_mapl.'rr\ \ \ :call C_Run()' + exe ahead.'executable\ to\ run'.esc_mapl.'re :call C_ExeToRun()' + exe ihead.'executable\ to\ run'.esc_mapl.'re :call C_ExeToRun()' + exe 'anoremenu '.s:MenuRun.'.cmd\.\ line\ &arg\.'.esc_mapl.'ra\ \ \ :CCmdlineArgs' + exe 'inoremenu '.s:MenuRun.'.cmd\.\ line\ &arg\.'.esc_mapl.'ra\ \ \ :CCmdlineArgs' + exe ahead.'run\ &debugger'.esc_mapl.'rd :call C_Debugger()' + exe ihead.'run\ &debugger'.esc_mapl.'rd :call C_Debugger()' + " + exe ahead.'-SEP1- :' " if s:C_SplintIsExecutable==1 - exe "amenu ".s:MenuRun.'.s&plint\\rp :call C_SplintCheck():call C_HlMessage()' - exe "imenu ".s:MenuRun.'.s&plint\\rp :call C_SplintCheck():call C_HlMessage()' - exe "amenu ".s:MenuRun.'.cmd\.\ line\ arg\.\ for\ spl&int\\rpa :call C_SplintArguments()' - exe "imenu ".s:MenuRun.'.cmd\.\ line\ arg\.\ for\ spl&int\\rpa :call C_SplintArguments()' - exe "amenu ".s:MenuRun.'.-SEP2- :' + exe ahead.'s&plint'.esc_mapl.'rp :call C_SplintCheck():call C_HlMessage()' + exe ihead.'s&plint'.esc_mapl.'rp :call C_SplintCheck():call C_HlMessage()' + exe ahead.'cmd\.\ line\ arg\.\ for\ spl&int'.esc_mapl.'rpa :call C_SplintArguments()' + exe ihead.'cmd\.\ line\ arg\.\ for\ spl&int'.esc_mapl.'rpa :call C_SplintArguments()' + exe ahead.'-SEP2- :' + endif + " + if s:C_CppcheckIsExecutable==1 + exe ahead.'cppcheck'.esc_mapl.'rcc :call C_CppcheckCheck():call C_HlMessage()' + exe ihead.'cppcheck'.esc_mapl.'rcc :call C_CppcheckCheck():call C_HlMessage()' + " + if s:C_MenuHeader == 'yes' + exe ahead.'cppcheck\ severity'.esc_mapl.'rccs.cppcheck\ severity :call C_MenuTitle()' + exe ahead.'cppcheck\ severity'.esc_mapl.'rccs.-Sep5- :' + endif + + for level in s:CppcheckSeverity + exe ahead.'cppcheck\ severity'.esc_mapl.'rccs.&'.level.' :call C_GetCppcheckSeverity("'.level.'")' + endfor endif " if s:C_CodeCheckIsExecutable==1 - exe "amenu ".s:MenuRun.'.CodeChec&k\\rk :call C_CodeCheck():call C_HlMessage()' - exe "imenu ".s:MenuRun.'.CodeChec&k\\rk :call C_CodeCheck():call C_HlMessage()' - exe "amenu ".s:MenuRun.'.cmd\.\ line\ arg\.\ for\ Cod&eCheck\\rka :call C_CodeCheckArguments()' - exe "imenu ".s:MenuRun.'.cmd\.\ line\ arg\.\ for\ Cod&eCheck\\rka :call C_CodeCheckArguments()' - exe "amenu ".s:MenuRun.'.-SEP3- :' + exe ahead.'CodeChec&k'.esc_mapl.'rk :call C_CodeCheck():call C_HlMessage()' + exe ihead.'CodeChec&k'.esc_mapl.'rk :call C_CodeCheck():call C_HlMessage()' + exe ahead.'cmd\.\ line\ arg\.\ for\ Cod&eCheck'.esc_mapl.'rka :call C_CodeCheckArguments()' + exe ihead.'cmd\.\ line\ arg\.\ for\ Cod&eCheck'.esc_mapl.'rka :call C_CodeCheckArguments()' + exe ahead.'-SEP3- :' endif " - exe "amenu ".s:MenuRun.'.in&dent\\rd :call C_Indent()' - exe "imenu ".s:MenuRun.'.in&dent\\rd :call C_Indent()' + exe ahead.'in&dent'.esc_mapl.'ri :call C_Indent()' + exe ihead.'in&dent'.esc_mapl.'ri :call C_Indent()' if s:MSWIN - exe "amenu ".s:MenuRun.'.&hardcopy\ to\ printer\\rh :call C_Hardcopy()' - exe "imenu ".s:MenuRun.'.&hardcopy\ to\ printer\\rh :call C_Hardcopy()' - exe "vmenu ".s:MenuRun.'.&hardcopy\ to\ printer\\rh :call C_Hardcopy()' + exe ahead.'&hardcopy\ to\ printer'.esc_mapl.'rh :call C_Hardcopy()' + exe ihead.'&hardcopy\ to\ printer'.esc_mapl.'rh :call C_Hardcopy()' + exe vhead.'&hardcopy\ to\ printer'.esc_mapl.'rh :call C_Hardcopy()' else - exe "amenu ".s:MenuRun.'.&hardcopy\ to\ FILENAME\.ps\\rh :call C_Hardcopy()' - exe "imenu ".s:MenuRun.'.&hardcopy\ to\ FILENAME\.ps\\rh :call C_Hardcopy()' - exe "vmenu ".s:MenuRun.'.&hardcopy\ to\ FILENAME\.ps\\rh :call C_Hardcopy()' + exe ahead.'&hardcopy\ to\ FILENAME\.ps'.esc_mapl.'rh :call C_Hardcopy()' + exe ihead.'&hardcopy\ to\ FILENAME\.ps'.esc_mapl.'rh :call C_Hardcopy()' + exe vhead.'&hardcopy\ to\ FILENAME\.ps'.esc_mapl.'rh :call C_Hardcopy()' endif - exe "imenu ".s:MenuRun.'.-SEP4- :' + exe ihead.'-SEP4- :' - exe "amenu ".s:MenuRun.'.&settings\\rs :call C_Settings()' - exe "imenu ".s:MenuRun.'.&settings\\rs :call C_Settings()' - exe "imenu ".s:MenuRun.'.-SEP5- :' + exe ahead.'&settings'.esc_mapl.'rs :call C_Settings()' + exe ihead.'&settings'.esc_mapl.'rs :call C_Settings()' + exe ihead.'-SEP5- :' - if !s:MSWIN - exe "amenu ".s:MenuRun.'.&xterm\ size\\rx :call C_XtermSize()' - exe "imenu ".s:MenuRun.'.&xterm\ size\\rx :call C_XtermSize()' + if !s:MSWIN + exe ahead.'&xterm\ size'.esc_mapl.'rx :call C_XtermSize()' + exe ihead.'&xterm\ size'.esc_mapl.'rx :call C_XtermSize()' endif if s:C_OutputGvim == "vim" - exe "amenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm\\ro :call C_Toggle_Gvim_Xterm()' + exe ahead.'&output:\ '.s:Output[0].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + exe ihead.'&output:\ '.s:Output[0].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' else if s:C_OutputGvim == "buffer" - exe "amenu ".s:MenuRun.'.&output:\ BUFFER->xterm->vim\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ BUFFER->xterm->vim\\ro :call C_Toggle_Gvim_Xterm()' + exe ahead.'&output:\ '.s:Output[1].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + exe ihead.'&output:\ '.s:Output[1].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' else - exe "amenu ".s:MenuRun.'.&output:\ XTERM->vim->buffer\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ XTERM->vim->buffer\\ro :call C_Toggle_Gvim_Xterm()' + exe ahead.'&output:\ '.s:Output[2].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + exe ihead.'&output:\ '.s:Output[2].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' endif endif " "=============================================================================================== - "----- Menu : help ------------------------------------------------------- {{{2 + "----- Menu : Tools ----------------------------------------------------- {{{2 "=============================================================================================== " - exe " menu ".s:C_Root.'&help\ (C-Support)\\hp :call C_HelpCsupport()' - exe "imenu ".s:C_Root.'&help\ (C-Support)\\hp :call C_HelpCsupport()' - exe " menu ".s:C_Root.'show\ &manual\\hm :call C_Help("m")' - exe "imenu ".s:C_Root.'show\ &manual\\hm :call C_Help("m")' - -endfunction " ---------- end of function C_InitMenus ---------- -" -function! C_MenuTitle () - echohl WarningMsg | echo "This is a menu title." | echohl None -endfunction " ---------- end of function C_MenuTitle ---------- + if s:C_UseToolbox == 'yes' && mmtoolbox#tools#Property ( s:C_Toolbox, 'empty-menu' ) == 0 + call mmtoolbox#tools#AddMenus ( s:C_Toolbox, s:C_RootMenu.'&Tool\ Box' ) + endif + " + "=============================================================================================== + "----- Menu : Help -------------------------------------------------------- {{{2 + "=============================================================================================== + " + let ahead = 'anoremenu '.s:C_RootMenu.'Help.' + let vhead = 'vnoremenu '.s:C_RootMenu.'Help.' + let ihead = 'inoremenu '.s:C_RootMenu.'Help.' + " + exe ahead.'show\ &manual'.esc_mapl.'hm :call C_Help("m")' + exe ihead.'show\ &manual'.esc_mapl.'hm :call C_Help("m")' + exe ahead.'-SEP1- :' + exe ahead.'&help\ (C-Support)'.esc_mapl.'hp :call C_HelpCsupport()' + exe ihead.'&help\ (C-Support)'.esc_mapl.'hp :call C_HelpCsupport()' + " + "=============================================================================================== + "----- Menu : C-Comments -------------------------------------------------- {{{2 + "=============================================================================================== + " + exe "amenu ".MenuComments.'.-SEP12- :' + exe "amenu ".MenuComments.'.\/*\ &xxx\ *\/\ \ <->\ \ \/\/\ xxx'.esc_mapl.'cx :call C_CommentToggle()' + exe "vmenu ".MenuComments.'.\/*\ &xxx\ *\/\ \ <->\ \ \/\/\ xxx'.esc_mapl.'cx :call C_CommentToggle()' + " + "=============================================================================================== + "----- Menu : C-Doxygen --------------------------------------------------- {{{2 + "=============================================================================================== + " + let [ MenuDoxygen, err ] = mmtemplates#core#Resource ( g:C_Templates, 'get', 'property', 'Doxygen::BriefAM::Menu' ) + " + if err == '' && MenuDoxygen != '' + let MenuDoxygen = s:C_RootMenu.mmtemplates#core#EscapeMenu( MenuDoxygen, 'menu' ) + " + let [ bam_map, err ] = mmtemplates#core#Resource ( g:C_Templates, 'get', 'property', 'Doxygen::BriefAM::Map' ) + " + if err == '' && bam_map != '' + let bam_map = esc_mapl.mmtemplates#core#EscapeMenu( bam_map, 'right' ) + else + let bam_map = esc_mapl.'dba' + endif + " + exe "amenu ".MenuDoxygen.'.-SEP-brief- :' + exe "amenu ".MenuDoxygen.'.brief,\ &after\ member'.bam_map.' :call C_EndOfLineComment("doxygen")' + exe "vmenu ".MenuDoxygen.'.brief,\ &after\ member'.bam_map.' :call C_EndOfLineComment("doxygen")' + endif + " + "=============================================================================================== + "----- Menu : C-Idioms ---------------------------------------------------- {{{2 + "=============================================================================================== + " + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', '&Idioms' ) + let MenuIdioms = s:C_RootMenu.'&Idioms.' + " + exe "amenu ".MenuIdioms.'-SEP1- :' + exe "amenu ".MenuIdioms.'for(x=&0;\ x'.esc_mapl.'i0 :call C_CodeFor("up" )' + exe "vmenu ".MenuIdioms.'for(x=&0;\ x'.esc_mapl.'i0 :call C_CodeFor("up","v")' + exe "imenu ".MenuIdioms.'for(x=&0;\ x'.esc_mapl.'i0 :call C_CodeFor("up" )' + exe "amenu ".MenuIdioms.'for(x=&n-1;\ x>=0;\ x\-=1)'.esc_mapl.'in :call C_CodeFor("down" )' + exe "vmenu ".MenuIdioms.'for(x=&n-1;\ x>=0;\ x\-=1)'.esc_mapl.'in :call C_CodeFor("down","v")' + exe "imenu ".MenuIdioms.'for(x=&n-1;\ x>=0;\ x\-=1)'.esc_mapl.'in :call C_CodeFor("down" )' + " + "=============================================================================================== + "----- Menu : C-Preprocessor ---------------------------------------------- {{{2 + "=============================================================================================== + " + call mmtemplates#core#CreateMenus ( 'g:C_Templates', s:C_RootMenu, 'sub_menu', '&Preprocessor' ) + let MenuPreprocessor = s:C_RootMenu.'&Preprocessor.' + " + exe "amenu ".MenuPreprocessor.'-SEP2- :' + exe "amenu ".MenuPreprocessor.'#if\ &0\ #endif'.esc_mapl.'pi0 :call C_PPIf0("a")2ji' + exe "imenu ".MenuPreprocessor.'#if\ &0\ #endif'.esc_mapl.'pi0 :call C_PPIf0("a")2ji' + exe "vmenu ".MenuPreprocessor.'#if\ &0\ #endif'.esc_mapl.'pi0 :call C_PPIf0("v")' + exe "amenu ".MenuPreprocessor.'&remove\ #if\ 0\ #endif'.esc_mapl.'pr0 :call C_PPIf0Remove()' + exe "imenu ".MenuPreprocessor.'&remove\ #if\ 0\ #endif'.esc_mapl.'pr0 :call C_PPIf0Remove()' + " +endfunction " ---------- end of function s: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.' i#include<'.replacement.'>' - exe "inoremenu ".a:menupath.'.'.item.' #include<'.replacement.'>' - endfor - return -endfunction " ---------- end of function C_CIncludeMenus ---------- - "------------------------------------------------------------------------------ -" C_CIosFlagMenus: generate the C++ ios flags menu entries {{{1 +" C_SaveGlobalOption {{{1 +" param 1 : option name +" param 2 : characters to be escaped (optional) "------------------------------------------------------------------------------ -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 ---------- +function! s:C_SaveGlobalOption ( option, ... ) + exe 'let escaped =&'.a:option + if a:0 == 0 + let escaped = escape( escaped, ' |"\' ) + else + let escaped = escape( escaped, ' |"\'.a:1 ) + endif + let s:C_saved_global_option[a:option] = escaped +endfunction " ---------- end of function C_SaveGlobalOption ---------- +" +"------------------------------------------------------------------------------ +" C_RestoreGlobalOption {{{1 +"------------------------------------------------------------------------------ +function! s:C_RestoreGlobalOption ( option ) + exe ':set '.a:option.'='.s:C_saved_global_option[a:option] +endfunction " ---------- end of function C_RestoreGlobalOption ---------- " "------------------------------------------------------------------------------ " C_Input: Input after a highlighted prompt {{{1 @@ -1142,83 +660,98 @@ 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 ( ) range " - if !exists("b:C_LineEndCommentColumn") - let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault + " comment character (for use in regular expression) + let cc = '\%(/\*\|//\)' " start of C or C++ comment + " + " patterns to ignore when adjusting line-end comments (maybe incomplete): + " - double-quoted strings, includes \n \" \\ ... + let align_regex = '"\%(\\.\|[^"]\)*"' + " + " local position + if !exists( 'b:C_LineEndCommentColumn' ) + let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault endif - - let save_cursor = getpos(".") - - let save_expandtab = &expandtab - exe ":set expandtab" - - let linenumber = a:firstline - exe ":".a:firstline - - while linenumber <= a:lastline - let line= getline(".") - - " line is not a pure comment but contains one + let correct_idx = b:C_LineEndCommentColumn + " + " === plug-in specific code ends here === + " === the behavior is governed by the variables above === + " + " save the cursor position + let save_cursor = getpos('.') + " + for line in range( a:firstline, a:lastline ) + silent exe ':'.line " - 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 - + let linetxt = getline('.') + " + " "pure" comment line left unchanged + if match ( linetxt, '^\s*'.cc ) == 0 + "echo 'line '.line.': "pure" comment' + continue + endif + " + let b_idx1 = 1 + match ( linetxt, '\s*'.cc.'.*$', 0 ) + let b_idx2 = 1 + match ( linetxt, cc.'.*$', 0 ) + " + " not found? + if b_idx1 == 0 + "echo 'line '.line.': no end-of-line comment' + continue + endif + " + " walk through ignored patterns + let idx_start = 0 + " + while 1 + let this_start = match ( linetxt, align_regex, idx_start ) + " + if this_start == -1 + break + else + let idx_start = matchend ( linetxt, align_regex, idx_start ) + "echo 'line '.line.': ignoring >>>'.strpart(linetxt,this_start,idx_start-this_start).'<<<' endif + endwhile + " + let b_idx1 = 1 + match ( linetxt, '\s*'.cc.'.*$', idx_start ) + let b_idx2 = 1 + match ( linetxt, cc.'.*$', idx_start ) + " + " not found? + if b_idx1 == 0 + "echo 'line '.line.': no end-of-line comment' + continue endif - let linenumber=linenumber+1 - normal j - endwhile + " + call cursor ( line, b_idx2 ) + let v_idx2 = virtcol('.') + " + " do b_idx1 last, so the cursor is in the right position for substitute below + call cursor ( line, b_idx1 ) + let v_idx1 = virtcol('.') + " + " already at right position? + if ( v_idx2 == correct_idx ) + "echo 'line '.line.': already at right position' + continue + endif + " ... or line too long? + if ( v_idx1 > correct_idx ) + "echo 'line '.line.': line too long' + continue + endif + " + " substitute all whitespaces behind the cursor (regex '\%#') and the next character, + " to ensure the match is at least one character long + silent exe 'substitute/\%#\s*\(\S\)/'.repeat( ' ', correct_idx - v_idx1 ).'\1/' + "echo 'line '.line.': adjusted' + " + endfor + " + " restore the cursor position + call setpos ( '.', save_cursor ) " - " restore tab expansion settings and cursor position - let &expandtab = save_expandtab - call setpos('.', save_cursor) - endfunction " ---------- end of function C_AdjustLineEndComm ---------- " "------------------------------------------------------------------------------ @@ -1240,64 +773,37 @@ endfunction " ---------- end of function C_GetLineEndCommCol ---------- "------------------------------------------------------------------------------ " C_EndOfLineComment: single line-end comment {{{1 "------------------------------------------------------------------------------ -function! C_EndOfLineComment ( ) range +function! C_EndOfLineComment ( ... ) range + " if !exists("b:C_LineEndCommentColumn") let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault endif - " ----- trim whitespaces ----- + " + " which template? + let template = 'Comments.end-of-line-comment' + " + if a:0 > 0 && a:1 == 'doxygen' + let template = 'Doxygen.brief, after member' + endif + " + " trim whitespaces exe a:firstline.','.a:lastline.'s/\s*$//' - + " + " do lines for line in range( a:lastline, a:firstline, -1 ) - let linelength = virtcol( [line, "$"] ) - 1 - let diff = 1 - if linelength < b:C_LineEndCommentColumn - let diff = b:C_LineEndCommentColumn -1 -linelength - endif - exe "normal ".diff."A " - call C_InsertTemplate('comment.end-of-line-comment') - if line > a:firstline - normal k + silent exe ":".line + if getline(line) !~ '^\s*$' + let linelength = virtcol( [line, "$"] ) - 1 + let diff = 1 + if linelength < b:C_LineEndCommentColumn + let diff = b:C_LineEndCommentColumn -1 -linelength + endif + exe "normal! ".diff."A " + call mmtemplates#core#InsertTemplate(g:C_Templates, template) endif endfor endfunction " ---------- end of function C_EndOfLineComment ---------- " -"------------------------------------------------------------------------------ -" 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_CodeToCommentC : Code -> Comment {{{1 "---------------------------------------------------------------------- @@ -1405,6 +911,27 @@ function! C_CommentToggle () range endfor endfunction " ---------- end of function C_CommentToggle ---------- " +"=== FUNCTION ================================================================ +" NAME: C_NonCCommentToggle {{{1 +" DESCRIPTION: toggle comment +"=============================================================================== +function! C_NonCCommentToggle ( ) range + let comment=1 " + for line in range( a:firstline, a:lastline ) + if match( getline(line), '^\V'.s:C_NonCComment ) == -1 " no comment + let comment = 0 + break + endif + endfor + + if comment == 0 + exe a:firstline.','.a:lastline."s/^/".s:C_NonCComment."/" + else + exe a:firstline.','.a:lastline."s/^".s:C_NonCComment."//" + endif + +endfunction " ---------- end of function C_NonCCommentToggle ---------- +" "===================================================================================== "----- Menu : Statements ----------------------------------------------------------- "===================================================================================== @@ -1420,7 +947,7 @@ function! C_PPIf0 (mode) " " search for the maximum option number (if any) " - normal gg + 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\\+" ) @@ -1436,7 +963,7 @@ function! C_PPIf0 (mode) 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 + normal! 4k endif if a:mode=='v' @@ -1448,7 +975,7 @@ function! C_PPIf0 (mode) exe ":".pos1."put! =zz" " if &foldenable && foldclosed(".") - normal zv + normal! zv endif endif @@ -1461,7 +988,7 @@ function! C_PPIf0Remove () " " cursor on fold: open fold first if &foldenable && foldclosed(".") - normal zv + normal! zv endif " let frstline = searchpair( '^\s*#if\s\+0', '', '^\s*#endif\>.\+\ 0 let loopvar_type = item @@ -1646,7 +1181,9 @@ function! C_CodeFor( direction ) range if empty(startval) let startval = '0' endif - let zz= 'for ( '.loopvar_type.loopvar.' = '.startval.'; '.loopvar.' < '.endval.'; '.loopvar.' += '.incval." )" + let txt_init = loopvar_type.loopvar.' = '.startval + let txt_cond = loopvar.' < '.endval + let txt_incr = loopvar.' += '.incval else if empty(endval) let endval = '0' @@ -1654,45 +1191,21 @@ function! C_CodeFor( direction ) range if empty(startval) let startval = 'n-1' endif - let zz= 'for ( '.loopvar_type.loopvar.' = '.startval.'; '.loopvar.' >= '.endval.'; '.loopvar.' -= '.incval." )" + let txt_init = loopvar_type.loopvar.' = '.startval + let txt_cond = loopvar.' >= '.endval + let txt_incr = loopvar.' -= '.incval endif " - " use internal formatting to avoid conficts when using == below - let equalprg_save = &equalprg - set equalprg= - - " ----- normal mode ---------------- - if a:firstline == a:lastline - let zz = zz." {\n}" - put =zz - normal k - normal 2== - endif - " ----- visual mode ---------------- - if a:firstline < a:lastline - let zz = zz.' {' - let zz2= '}' - exe ":".a:lastline."put =zz2" - exe ":".a:firstline."put! =zz" - :exe 'normal ='.(a:lastline-a:firstline+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 + if a:0 == 0 + call mmtemplates#core#InsertTemplate ( g:C_Templates, 'Statements.for block', + \ '|INIT|', txt_init, '|CONDITION|', txt_cond, '|INCREMENT|', txt_incr, + \ 'range', a:firstline, a:lastline ) + elseif a:0 == 1 && a:1 == 'v' + call mmtemplates#core#InsertTemplate ( g:C_Templates, 'Statements.for block', + \ '|INIT|', txt_init, '|CONDITION|', txt_cond, '|INCREMENT|', txt_incr, + \ 'range', a:firstline, a:lastline, 'v' ) + else + echohl WarningMsg | echomsg "for loop construction : unknown argument ".a:1 | echohl None endif " endfunction " ---------- end of function C_CodeFor ---------- @@ -1735,7 +1248,9 @@ function! C_ProtoPick( type ) range " " remove template keyword " - let prototyp = substitute( prototyp, '^template\s*<\s*class \w\+\s*>\s*', "", "" ) + let template_param = '\s*\w\+\s\+\w\+\s*' + let template_params = template_param.'\(,'.template_param.'\)*' + let prototyp = substitute( prototyp, '^template\s*<'.template_params.'>\s*', "", "" ) " let idx = stridx( prototyp, '(' ) " start of the parameter list let head = strpart( prototyp, 0, idx ) @@ -1743,16 +1258,16 @@ function! C_ProtoPick( type ) range " " remove the scope resolution operator " - let template_id = '\h\w*\s*\(<[^>]\+>\)\?' - let rgx2 = '\('.template_id.'\s*::\s*\)*\([~]\?\h\w*\|operator.\+\)\s*$' + let template_id = '\h\w*\s*\(<[^>]\+>\)\?\s*::\s*' + let rgx2 = '\('.template_id.'\)*\([~]\?\h\w*\|operator.\+\)\s*$' let idx = match( head, rgx2 ) " start of the function name let returntype = strpart( head, 0, idx ) let fctname = strpart( head, idx ) - let resret = matchstr( returntype, '\('.template_id.'\s*::\s*\)*'.template_id ) + let resret = matchstr( returntype, '\('.template_id.'\)*'.template_id ) let resret = substitute( resret, '\s\+', '', 'g' ) - let resfct = matchstr( fctname , '\('.template_id.'\s*::\s*\)*'.template_id ) + let resfct = matchstr( fctname , '\('.template_id.'\)*'.template_id ) let resfct = substitute( resfct, '\s\+', '', 'g' ) if !empty(resret) && match( resfct, resret.'$' ) >= 0 @@ -1765,7 +1280,7 @@ function! C_ProtoPick( type ) range let returntype = substitute( returntype, '\', "", "g" ) + let fctname = substitute( fctname, '<[^>]\+>', '', 'g' ) let fctname = substitute( fctname, '\= getftime(Sou)) - let makeprg_saved='"'.&makeprg.'"' + call s:C_SaveGlobalOption('makeprg') if expand("%:e") == s:C_CExtension - exe "setlocal makeprg=".s:C_CCompiler + exe "setlocal makeprg=".g:C_CCompiler + let linkerflags = g:C_LFlags else - exe "setlocal makeprg=".s:C_CplusCompiler + exe "setlocal makeprg=".g:C_CplusCompiler + let linkerflags = g:C_CplusLFlags endif - exe ":compiler ".s:C_VimCompilerName let s:LastShellReturnCode = 0 let v:statusmsg = '' - silent exe "make ".s:C_LFlags." -o ".ExeEsc." ".ObjEsc." ".s:C_Libs + if &filetype == "c" + silent exe "make ".linkerflags." -o ".ExeEsc." ".ObjEsc." ".g:C_Libs + else + silent exe "make ".linkerflags." -o ".ExeEsc." ".ObjEsc." ".g:C_CplusLibs + endif if v:shell_error != 0 let s:LastShellReturnCode = v:shell_error endif - exe "setlocal makeprg=".makeprg_saved + call s:C_RestoreGlobalOption('makeprg') " if empty(v:statusmsg) let s:C_HlMessage = "'".Exe."' : linking successful" @@ -2041,9 +1564,9 @@ function! C_Run () "============================================================================== if s:C_OutputGvim == "vim" " - if s:C_MakeExecutableToRun !~ "^\s*$" - call C_HlMessage( "executable : '".s:C_MakeExecutableToRun."'" ) - exe '!'.Quote.s:C_MakeExecutableToRun.Quote.' '.l:arguments + if s:C_ExecutableToRun !~ "^\s*$" + call C_HlMessage( "executable : '".s:C_ExecutableToRun."'" ) + exe '!'.Quote.s:C_ExecutableToRun.Quote.' '.l:arguments else silent call C_Link() @@ -2068,7 +1591,7 @@ function! C_Run () if s:C_OutputGvim == "buffer" let l:currentbuffernr = bufnr("%") " - if s:C_MakeExecutableToRun =~ "^\s*$" + if s:C_ExecutableToRun =~ "^\s*$" call C_Link() endif if l:currentbuffer == bufname("%") @@ -2094,28 +1617,27 @@ function! C_Run () " run programm " setlocal modifiable - if s:C_MakeExecutableToRun !~ "^\s*$" - call C_HlMessage( "executable : '".s:C_MakeExecutableToRun."'" ) - exe '%!'.Quote.s:C_MakeExecutableToRun.Quote.' '.l:arguments - setlocal nomodifiable - " - if winheight(winnr()) >= line("$") - exe bufwinnr(l:currentbuffernr) . "wincmd w" - endif + + if s:C_ExecutableToRun !~ "^\s*$" + call C_HlMessage( "executable : '".s:C_ExecutableToRun."'" ) + let realexe = s:C_ExecutableToRun + elseif executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) + let realexe = ExeEsc else - " - if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) - exe "%!".Quote.ExeEsc.Quote." ".l:arguments - setlocal nomodifiable - " - if winheight(winnr()) >= line("$") - exe bufwinnr(l:currentbuffernr) . "wincmd w" - endif - else - setlocal nomodifiable - :close - echomsg "file '".Exe.s:C_RunMsg1 - endif + setlocal nomodifiable + :close + echomsg "file '".Exe.s:C_RunMsg1 + return + endif + + exe '%!'.s:stdbuf.Quote.realexe.Quote.' '.l:arguments + if v:shell_error + call append( line('$'), "program '".realexe."' terminated with error ".v:shell_error ) + endif + setlocal nomodifiable + " + if winheight(winnr()) >= line("$") + exe bufwinnr(l:currentbuffernr) . "wincmd w" endif " endif @@ -2126,13 +1648,13 @@ function! C_Run () "============================================================================== if s:C_OutputGvim == "xterm" " - if s:C_MakeExecutableToRun !~ "^\s*$" + if s:C_ExecutableToRun !~ "^\s*$" if s:MSWIN - exe '!'.Quote.s:C_MakeExecutableToRun.Quote.' '.l:arguments + exe '!'.Quote.s:C_ExecutableToRun.Quote.' '.l:arguments else - silent exe '!xterm -title '.s:C_MakeExecutableToRun.' '.s:C_XtermDefaults.' -e '.s:C_Wrapper.' '.s:C_MakeExecutableToRun.' '.l:arguments.' &' + silent exe '!xterm -title '.s:C_ExecutableToRun.' '.s:C_XtermDefaults.' -e '.s:C_Wrapper.' '.s:C_ExecutableToRun.' '.l:arguments.' &' :redraw! - call C_HlMessage( "executable : '".s:C_MakeExecutableToRun."'" ) + call C_HlMessage( "executable : '".s:C_ExecutableToRun."'" ) endif else @@ -2156,56 +1678,38 @@ endfunction " ---------- end of function C_Run ---------- "------------------------------------------------------------------------------ " C_Arguments : Arguments for the executable {{{1 "------------------------------------------------------------------------------ -function! C_Arguments () - let Exe = expand("%:r").s:C_ExeExtension - if empty(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 +function! C_Arguments ( ... ) + let b:C_CmdLineArgs= join( a:000 ) endfunction " ---------- end of function C_Arguments ---------- " "---------------------------------------------------------------------- " C_Toggle_Gvim_Xterm : change output destination {{{1 "---------------------------------------------------------------------- function! C_Toggle_Gvim_Xterm () - + " + " get the mapleader (correctly escaped) + let [ esc_mapl, err ] = mmtemplates#core#Resource ( g:C_Templates, 'escaped_mapleader' ) + " if s:C_OutputGvim == "vim" - exe "aunmenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm' - exe "amenu ".s:MenuRun.'.&output:\ BUFFER->xterm->vim\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ BUFFER->xterm->vim\\ro :call C_Toggle_Gvim_Xterm()' + exe "aunmenu ".s:MenuRun.'.&output:\ '.s:Output[0] + exe "amenu ".s:MenuRun.'.&output:\ '.s:Output[1].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + exe "imenu ".s:MenuRun.'.&output:\ '.s:Output[1].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' let s:C_OutputGvim = "buffer" else if s:C_OutputGvim == "buffer" - exe "aunmenu ".s:MenuRun.'.&output:\ BUFFER->xterm->vim' - if (!s:MSWIN) - exe "amenu ".s:MenuRun.'.&output:\ XTERM->vim->buffer\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ XTERM->vim->buffer\\ro :call C_Toggle_Gvim_Xterm()' - else - exe "amenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm\\ro :call C_Toggle_Gvim_Xterm()' - endif - if (!s:MSWIN) && (!empty($Display)) - let s:C_OutputGvim = "xterm" - else - let s:C_OutputGvim = "vim" - endif + exe "aunmenu ".s:MenuRun.'.&output:\ '.s:Output[1] + exe "amenu ".s:MenuRun.'.&output:\ '.s:Output[2].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + exe "imenu ".s:MenuRun.'.&output:\ '.s:Output[2].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + let s:C_OutputGvim = "xterm" else " ---------- output : xterm -> gvim - exe "aunmenu ".s:MenuRun.'.&output:\ XTERM->vim->buffer' - exe "amenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm\\ro :call C_Toggle_Gvim_Xterm()' - exe "imenu ".s:MenuRun.'.&output:\ VIM->buffer->xterm\\ro :call C_Toggle_Gvim_Xterm()' + exe "aunmenu ".s:MenuRun.'.&output:\ '.s:Output[2] + exe "amenu ".s:MenuRun.'.&output:\ '.s:Output[0].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' + exe "imenu ".s:MenuRun.'.&output:\ '.s:Output[0].''.esc_mapl.'ro :call C_Toggle_Gvim_Xterm()' let s:C_OutputGvim = "vim" endif endif echomsg "output destination is '".s:C_OutputGvim."'" - endfunction " ---------- end of function C_Toggle_Gvim_Xterm ---------- " "------------------------------------------------------------------------------ @@ -2225,84 +1729,81 @@ function! C_XtermSize () endfunction " ---------- end of function C_XtermSize ---------- " "------------------------------------------------------------------------------ -" run make(1) {{{1 +" C_ExeToRun : choose executable to run {{{1 "------------------------------------------------------------------------------ -let s:C_MakeCmdLineArgs = '' " command line arguments for Run-make; initially empty -let s:C_MakeExecutableToRun = '' -let s:C_Makefile = '' -" -"------------------------------------------------------------------------------ -" C_ChooseMakefile : choose a makefile {{{1 -"------------------------------------------------------------------------------ -function! C_ChooseMakefile () - let s:C_Makefile = '' - " the path will be escaped: - let s:C_Makefile = C_Input ( "choose a Makefile: ", getcwd(), "file" ) - if s:MSWIN - let s:C_Makefile = substitute( s:C_Makefile, '\\ ', ' ', 'g' ) - endif -endfunction " ---------- end of function C_ChooseMakefile ---------- -" -"------------------------------------------------------------------------------ -" C_Make : run make {{{1 -"------------------------------------------------------------------------------ -function! C_Make() - exe ":cclose" - " update : write source file if necessary - exe ":update" - " run make - if s:C_Makefile == '' - exe ":make ".s:C_MakeCmdLineArgs - else - exe ':lchdir '.fnamemodify( s:C_Makefile, ":p:h" ) - if s:MSWIN - exe ':make -f "'.s:C_Makefile.'" '.s:C_MakeCmdLineArgs - else - exe ':make -f '.s:C_Makefile.' '.s:C_MakeCmdLineArgs - endif - exe ":lchdir -" - endif - exe ":botright cwindow" - " -endfunction " ---------- end of function C_Make ---------- -" -"------------------------------------------------------------------------------ -" C_MakeClean : run 'make clean' {{{1 -"------------------------------------------------------------------------------ -function! C_MakeClean() - " run make clean - if s:C_Makefile == '' - exe ":make clean" - else - exe ':lchdir '.fnamemodify( s:C_Makefile, ":p:h" ) - if s:MSWIN - exe ':make -f "'.s:C_Makefile.'" clean' - else - exe ':make -f '.s:C_Makefile.' clean' - endif - exe ":lchdir -" - endif -endfunction " ---------- end of function C_MakeClean ---------- - -"------------------------------------------------------------------------------ -" C_MakeArguments : get make command line arguments {{{1 -"------------------------------------------------------------------------------ -function! C_MakeArguments () - let s:C_MakeCmdLineArgs= C_Input( 'make command line arguments : ', s:C_MakeCmdLineArgs, 'file' ) -endfunction " ---------- end of function C_MakeArguments ---------- - -"------------------------------------------------------------------------------ -" C_MakeExeToRun : choose executable to run {{{1 -"------------------------------------------------------------------------------ -function! C_MakeExeToRun () - let s:C_MakeExecutableToRun = C_Input( 'executable to run [tab compl.]: ', '', 'file' ) - if s:C_MakeExecutableToRun !~ "^\s*$" +function! C_ExeToRun () + let s:C_ExecutableToRun = C_Input( 'executable to run [tab compl.]: ', '', 'file' ) + if s:C_ExecutableToRun !~ "^\s*$" if s:MSWIN - let s:C_MakeExecutableToRun = substitute(s:C_MakeExecutableToRun, '\\ ', ' ', 'g' ) + let s:C_ExecutableToRun = substitute(s:C_ExecutableToRun, '\\ ', ' ', 'g' ) endif - let s:C_MakeExecutableToRun = escape( getcwd().'/', s:C_FilenameEscChar ).s:C_MakeExecutableToRun + let s:C_ExecutableToRun = escape( getcwd().'/'.s:C_ExecutableToRun, s:C_FilenameEscChar ) endif -endfunction " ---------- end of function C_MakeExeToRun ---------- +endfunction " ---------- end of function C_ExeToRun ---------- +" +" +"=== FUNCTION ================================================================ +" NAME: C_Debugger {{{1 +" DESCRIPTION: start debugger +" PARAMETERS: - +" RETURNS: +"=============================================================================== +function! C_Debugger () + " + silent exe ":update" + if s:C_ExecutableToRun == '' + call C_ExeToRun() + endif + let l:arguments = exists("b:C_CmdLineArgs") ? " ".b:C_CmdLineArgs : "" + " + if s:MSWIN + let l:arguments = substitute( l:arguments, '^\s\+', ' ', '' ) + let l:arguments = substitute( l:arguments, '\s\+', "\" \"", 'g') + endif + " + " debugger is 'gdb' + " + if g:C_Debugger == "gdb" + if s:MSWIN + exe '!gdb "'.s:C_ExecutableToRun.l:arguments.'"' + else + if has("gui_running") || &term == "xterm" + silent exe "!xterm ".s:C_XtermDefaults.' -e gdb ' . s:C_ExecutableToRun.l:arguments.' &' + else + silent exe '!clear; gdb ' . s:C_ExecutableToRun.l:arguments + endif + endif + endif + " + if v:windowid != 0 + " + " grapical debugger is 'kdbg', uses a PerlTk interface + " + if g:C_Debugger == "kdbg" + if s:MSWIN + exe '!kdbg "'.s:C_ExecutableToRun.l:arguments.'"' + else + silent exe '!kdbg '.s:C_ExecutableToRun.l:arguments.' &' + endif + endif + " + " debugger is 'ddd' (not available for MS Windows); graphical front-end for GDB + " + if g:C_Debugger == "ddd" && !s:MSWIN + if !executable("ddd") + echohl WarningMsg + echo 'ddd does not exist or is not executable!' + echohl None + return + else + silent exe '!ddd '.s:C_ExecutableToRun.l:arguments.' &' + endif + endif + " + endif + " + redraw! +endfunction " ---------- end of function C_Debugger ---------- " "------------------------------------------------------------------------------ " C_SplintArguments : splint command line arguments {{{1 @@ -2336,7 +1837,7 @@ function! C_SplintCheck () let s:C_HlMessage = "" exe ":cclose" silent exe ":update" - let makeprg_saved='"'.&makeprg.'"' + call s:C_SaveGlobalOption('makeprg') " Windows seems to need this: if s:MSWIN :compiler splint @@ -2345,7 +1846,7 @@ function! C_SplintCheck () " let l:arguments = exists("b:C_SplintCmdLineArgs") ? b:C_SplintCmdLineArgs : ' ' silent exe "make ".l:arguments." ".escape(l:currentbuffer,s:C_FilenameEscChar) - exe "setlocal makeprg=".makeprg_saved + call s:C_RestoreGlobalOption('makeprg') exe ":botright cwindow" " " message in case of success @@ -2356,6 +1857,89 @@ function! C_SplintCheck () endfunction " ---------- end of function C_SplintCheck ---------- " "------------------------------------------------------------------------------ +" C_CppcheckCheck : run cppcheck(1) {{{1 +"------------------------------------------------------------------------------ +function! C_CppcheckCheck () + if s:C_CppcheckIsExecutable==0 + let s:C_HlMessage = ' Cppcheck 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" + call s:C_SaveGlobalOption('makeprg') + " + call s:C_SaveGlobalOption('errorformat') + setlocal errorformat=[%f:%l]:%m + " Windows seems to need this: + if s:MSWIN + :compiler cppcheck + endif + :setlocal makeprg=cppcheck + " + silent exe "make --enable=".s:C_CppcheckSeverity.' '.escape(l:currentbuffer,s:C_FilenameEscChar) + call s:C_RestoreGlobalOption('makeprg') + exe ":botright cwindow" + " + " message in case of success + " + if l:currentbuffer == bufname("%") + let s:C_HlMessage = " Cppcheck --- no warnings for : ".l:currentbuffer + endif +endfunction " ---------- end of function C_CppcheckCheck ---------- + +"=== FUNCTION ================================================================ +" NAME: C_CppcheckSeverityList {{{1 +" DESCRIPTION: cppcheck severity : callback function for completion +" PARAMETERS: ArgLead - +" CmdLine - +" CursorPos - +" RETURNS: +"=============================================================================== +function! C_CppcheckSeverityList ( ArgLead, CmdLine, CursorPos ) + return filter( copy( s:CppcheckSeverity ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) +endfunction " ---------- end of function C_CppcheckSeverityList ---------- + +"=== FUNCTION ================================================================ +" NAME: C_GetCppcheckSeverity {{{1 +" DESCRIPTION: cppcheck severity : used in command definition +" PARAMETERS: severity - cppcheck severity +" RETURNS: +"=============================================================================== +function! C_GetCppcheckSeverity ( severity ) + let sev = a:severity + let sev = substitute( sev, '^\s\+', '', '' ) " remove leading whitespaces + let sev = substitute( sev, '\s\+$', '', '' ) " remove trailing whitespaces + " + if index( s:CppcheckSeverity, tolower(sev) ) >= 0 + let s:C_CppcheckSeverity = sev + echomsg "cppcheck severity is set to '".s:C_CppcheckSeverity."'" + else + let s:C_CppcheckSeverity = 'all' " the default + echomsg "wrong argument '".a:severity."' / severity is set to '".s:C_CppcheckSeverity."'" + endif + " +endfunction " ---------- end of function C_GetCppcheckSeverity ---------- +" +"=== FUNCTION ================================================================ +" NAME: C_CppcheckSeverityInput +" DESCRIPTION: read cppcheck severity from the command line +" PARAMETERS: - +" RETURNS: +"=============================================================================== +function! C_CppcheckSeverityInput () + let retval = input( "cppcheck severity (current = '".s:C_CppcheckSeverity."' / tab exp.): ", '', 'customlist,C_CppcheckSeverityList' ) + redraw! + call C_GetCppcheckSeverity( retval ) + return +endfunction " ---------- end of function C_CppcheckSeverityInput ---------- +" +"------------------------------------------------------------------------------ " C_CodeCheckArguments : CodeCheck command line arguments {{{1 "------------------------------------------------------------------------------ function! C_CodeCheckArguments () @@ -2387,21 +1971,22 @@ function! C_CodeCheck () let s:C_HlMessage = "" exe ":cclose" silent exe ":update" - let makeprg_saved='"'.&makeprg.'"' + call s:C_SaveGlobalOption('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 + call s:C_SaveGlobalOption('errorformat') + setlocal errorformat=%f(%l)%m " let l:arguments = exists("b:C_CodeCheckCmdLineArgs") ? b:C_CodeCheckCmdLineArgs : "" if empty( l:arguments ) let l:arguments = s:C_CodeCheckOptions endif exe ":make ".l:arguments." ".escape( l:currentbuffer, s:C_FilenameEscChar ) - exe ':setlocal errorformat=' - exe ":setlocal makeprg=".makeprg_saved + call s:C_RestoreGlobalOption('errorformat') + call s:C_RestoreGlobalOption('makeprg') exe ":botright cwindow" " " message in case of success @@ -2416,7 +2001,7 @@ endfunction " ---------- end of function C_CodeCheck ---------- "------------------------------------------------------------------------------ " function! C_Indent ( ) - if !executable("indent") + if s:C_IndentIsExecutable == 0 echomsg 'indent is not executable or not installed!' return endif @@ -2436,6 +2021,7 @@ function! C_Indent ( ) else silent exe ":%!indent 2> ".s:C_IndentErrorLog redraw! + call s:C_SaveGlobalOption('errorformat') if getfsize( s:C_IndentErrorLog ) > 0 exe ':edit! '.s:C_IndentErrorLog let errorlogbuffer = bufnr("%") @@ -2447,7 +2033,7 @@ function! C_Indent ( ) else echomsg 'File "'.l:currentbuffer.'" reformatted.' endif - setlocal errorformat= + call s:C_RestoreGlobalOption('errorformat') endif endfunction " ---------- end of function C_Indent ---------- @@ -2471,32 +2057,36 @@ endfunction " ---------- end of function C_HlMessage ---------- "------------------------------------------------------------------------------ function! C_Settings () let txt = " C/C++-Support settings\n\n" - let txt = txt.' author : "'.s:C_Macro['|AUTHOR|']."\"\n" - let txt = txt.' authorref : "'.s:C_Macro['|AUTHORREF|']."\"\n" - let txt = txt.' company : "'.s:C_Macro['|COMPANY|']."\"\n" - let txt = txt.' copyright holder : "'.s:C_Macro['|COPYRIGHTHOLDER|']."\"\n" - let txt = txt.' email : "'.s:C_Macro['|EMAIL|']."\"\n" - let txt = txt.' licence : "'.s:C_Macro['|LICENSE|']."\"\n" - let txt = txt.' organization : "'.s:C_Macro['|ORGANIZATION|']."\"\n" - let txt = txt.' project : "'.s:C_Macro['|PROJECT|']."\"\n" - let txt = txt.' C / C++ compiler : '.s:C_CCompiler.' / '.s:C_CplusCompiler."\n" + let txt = txt.' author : "'.mmtemplates#core#ExpandText( g:C_Templates, '|AUTHOR|' )."\"\n" + let txt = txt.' authorref : "'.mmtemplates#core#ExpandText( g:C_Templates, '|AUTHORREF|' )."\"\n" + let txt = txt.' company : "'.mmtemplates#core#ExpandText( g:C_Templates, '|COMPANY|' )."\"\n" + let txt = txt.' copyright holder : "'.mmtemplates#core#ExpandText( g:C_Templates, '|COPYRIGHT|' )."\"\n" + let txt = txt.' email : "'.mmtemplates#core#ExpandText( g:C_Templates, '|EMAIL|' )."\"\n" + let txt = txt.' licence : "'.mmtemplates#core#ExpandText( g:C_Templates, '|LICENSE|' )."\"\n" + let txt = txt.' organization : "'.mmtemplates#core#ExpandText( g:C_Templates, '|ORGANIZATION|')."\"\n" + let txt = txt.' project : "'.mmtemplates#core#ExpandText( g:C_Templates, '|PROJECT|' )."\"\n" + let txt = txt.' C / C++ compiler : '.g:C_CCompiler.' / '.g: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.' compiler flags (C) : "'.g:C_CFlags."\"\n" + let txt = txt.' linker flags (C) : "'.g:C_LFlags."\"\n" + let txt = txt.' libraries (C) : "'.g:C_Libs."\"\n" + let txt = txt.' compiler flags (C++) : "'.g:C_CplusCFlags."\"\n" + let txt = txt.' linker flags (C++) : "'.g:C_CplusLFlags."\"\n" + let txt = txt.' libraries (C++) : "'.g:C_CplusLibs."\"\n" + let txt = txt.' debugger : "'.g:C_Debugger."\"\n" let txt = txt.' code snippet directory : "'.s:C_CodeSnippets."\"\n" " ----- template files ------------------------ - let txt = txt.' template style : "'.s:C_ActualStyle."\"\n" - let txt = txt.' plugin installation : "'.s:installation."\"\n" - if s:installation == 'system' - let txt = txt.'global template directory : '.s:C_GlobalTemplateDir."\n" + let txt = txt.' template style : "'.mmtemplates#core#Resource ( g:C_Templates, "style" )[0]."\"\n" + let txt = txt.' plugin installation : "'.g:C_Installation."\"\n" + if g:C_Installation == 'system' + let txt = txt.' global template file : "'.s:C_GlobalTemplateFile."\"\n" if filereadable( s:C_LocalTemplateFile ) - let txt = txt.' local template directory : '.s:C_LocalTemplateDir."\n" + let txt = txt.' local template file : "'.s:C_LocalTemplateFile."\"\n" endif else - let txt = txt.' local template directory : '.s:C_LocalTemplateDir."\n" + let txt = txt.' local template file : "'.s:C_LocalTemplateFile."\"\n" endif if !s:MSWIN let txt = txt.' xterm defaults : '.s:C_XtermDefaults."\n" @@ -2517,6 +2107,10 @@ function! C_Settings () endif let txt = txt." splint options(s) : ".ausgabe."\n" endif + " ----- cppcheck ------------------------------ + if s:C_CppcheckIsExecutable==1 + let txt = txt." cppcheck severity : ".s:C_CppcheckSeverity."\n" + endif " ----- code check -------------------------- if s:C_CodeCheckIsExecutable==1 if exists("b:C_CodeCheckCmdLineArgs") @@ -2526,9 +2120,20 @@ function! C_Settings () endif let txt = txt."CodeCheck (TM) options(s) : ".ausgabe."\n" endif + " ----- toolbox ----------------------------- + if s:C_UseToolbox == 'yes' + let toollist = mmtoolbox#tools#GetList ( s:C_Toolbox ) + if empty ( toollist ) + let txt .= " toolbox : -no tools-\n" + else + let sep = "\n"." " + let txt .= " toolbox : " + \ .join ( toollist, sep )."\n" + endif + 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" + let txt = txt." C/C++-Support, Version ".g:C_Version." / Dr.-Ing. Fritz Mehner / mehner.fritz@fh-swf.de\n\n" echo txt endfunction " ---------- end of function C_Settings ---------- " @@ -2673,7 +2278,15 @@ function! C_Help( type ) endif set filetype=man - silent exe ":%!".s:C_Man." ".catalog." ".item + + " get the width of the newly opened window + " and set the width of man's output accordingly + let win_w = winwidth( winnr() ) + if s:UNIX && win_w > 0 + silent exe ":%! MANWIDTH=".win_w." ".s:C_Man." ".catalog." ".item + else + silent exe ":%!".s:C_Man." ".catalog." ".item + endif if s:MSWIN call s:C_RemoveSpecialCharacters() @@ -2700,19 +2313,8 @@ function! s:C_RemoveSpecialCharacters ( ) silent exe ':%s/'.patternbold.'//g' endif setlocal nomodifiable - silent normal gg + silent normal! gg endfunction " ---------- end of function s:C_RemoveSpecialCharacters ---------- - -"------------------------------------------------------------------------------ -" C_CreateMenusDelayed {{{1 -"------------------------------------------------------------------------------ -let s:C_MenusVisible = 'no' " state variable controlling the C-menus -" -function! C_CreateMenusDelayed () - if s:C_CreateMenusDelayed == 'yes' && s:C_MenusVisible == 'no' - call C_CreateGuiMenus() - endif -endfunction " ---------- end of function C_CreateMenusDelayed ---------- " "------------------------------------------------------------------------------ " C_CreateGuiMenus {{{1 @@ -2722,88 +2324,130 @@ function! C_CreateGuiMenus () aunmenu &Tools.Load\ C\ Support amenu 40.1000 &Tools.-SEP100- : amenu 40.1030 &Tools.Unload\ C\ Support :call C_RemoveGuiMenus() - call C_InitMenus() - let s:C_MenusVisible = 'yes' + call s:C_RereadTemplates('no') + call s:C_InitMenus() + let s:C_MenusVisible = 'yes' endif endfunction " ---------- end of function C_CreateGuiMenus ---------- - +" "------------------------------------------------------------------------------ -" C_ToolMenu {{{1 +" s:CheckAndRereadTemplates {{{1 "------------------------------------------------------------------------------ -function! C_ToolMenu () - amenu 40.1000 &Tools.-SEP100- : - amenu 40.1030 &Tools.Load\ C\ Support :call C_CreateGuiMenus() - imenu 40.1030 &Tools.Load\ C\ Support :call C_CreateGuiMenus() -endfunction " ---------- end of function C_ToolMenu ---------- - +function! s:CheckAndRereadTemplates () + if ! exists ( 'g:C_Templates' ) + call s:C_RereadTemplates('no') + endif +endfunction " ---------- end of function s:CheckAndRereadTemplates ---------- +" "------------------------------------------------------------------------------ -" C_RemoveGuiMenus {{{1 +" === Templates API === {{{1 "------------------------------------------------------------------------------ -function! C_RemoveGuiMenus () - if s:C_MenusVisible == 'yes' - exe "aunmenu ".s:C_Root - " - aunmenu &Tools.Unload\ C\ Support - call C_ToolMenu() - " - let s:C_MenusVisible = 'no' +" +"------------------------------------------------------------------------------ +" C_SetMapLeader {{{2 +"------------------------------------------------------------------------------ +function! C_SetMapLeader () + if exists ( 'g:C_MapLeader' ) + call mmtemplates#core#SetMapleader ( g:C_MapLeader ) endif -endfunction " ---------- end of function C_RemoveGuiMenus ---------- - +endfunction " ---------- end of function C_SetMapLeader ---------- +" "------------------------------------------------------------------------------ -" C_RereadTemplates {{{1 -" rebuild commands and the menu from the (changed) template file +" C_ResetMapLeader {{{2 "------------------------------------------------------------------------------ -function! C_RereadTemplates ( msg ) - let s:style = 'default' - let s:C_Template = { 'default' : {} } - let s:C_FileVisited = [] - let messsage = '' +function! C_ResetMapLeader () + if exists ( 'g:C_MapLeader' ) + call mmtemplates#core#ResetMapleader () + endif +endfunction " ---------- end of function C_ResetMapLeader ---------- +" }}}2 +" +"=== FUNCTION ================================================================ +" NAME: C_RereadTemplates {{{1 +" DESCRIPTION: rebuild commands and the menu from the (changed) template file +" PARAMETERS: displaymsg - yes / no +" RETURNS: +"=============================================================================== +function! s:C_RereadTemplates ( displaymsg ) + " + "------------------------------------------------------------------------------- + " SETUP TEMPLATE LIBRARY + "------------------------------------------------------------------------------- + let g:C_Templates = mmtemplates#core#NewLibrary () + " + " mapleader + if empty ( g:C_MapLeader ) + call mmtemplates#core#Resource ( g:C_Templates, 'set', 'property', 'Templates::Mapleader', '\' ) + else + call mmtemplates#core#Resource ( g:C_Templates, 'set', 'property', 'Templates::Mapleader', g:C_MapLeader ) + endif + " + " map: choose style + call mmtemplates#core#Resource ( g:C_Templates, 'set', 'property', 'Templates::ChooseStyle::Map', 'nts' ) + " + " syntax: comments + call mmtemplates#core#ChangeSyntax ( g:C_Templates, 'comment', '§' ) + let s:C_TemplateJumpTarget = mmtemplates#core#Resource ( g:C_Templates, "jumptag" )[0] " - if s:installation == 'system' + " property: Doxygen menu + call mmtemplates#core#Resource ( g:C_Templates, 'add', 'property', 'Doxygen::BriefAM::Menu', '' ) + call mmtemplates#core#Resource ( g:C_Templates, 'add', 'property', 'Doxygen::BriefAM::Map', '' ) + " + let messsage = '' + " + if g:C_Installation == 'system' "------------------------------------------------------------------------------- - " system installation + " SYSTEM INSTALLATION "------------------------------------------------------------------------------- if filereadable( s:C_GlobalTemplateFile ) - call C_ReadTemplates( s:C_GlobalTemplateFile ) + call mmtemplates#core#ReadTemplates ( g:C_Templates, 'load', s:C_GlobalTemplateFile ) else echomsg "Global template file '".s:C_GlobalTemplateFile."' not readable." return endif let messsage = "Templates read from '".s:C_GlobalTemplateFile."'" " + "------------------------------------------------------------------------------- + " handle local template files + "------------------------------------------------------------------------------- + let templ_dir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' + " + if finddir( templ_dir ) == '' + " try to create a local template directory + if exists("*mkdir") + try + call mkdir( templ_dir, "p" ) + catch /.*/ + endtry + endif + endif + + if isdirectory( templ_dir ) && !filereadable( s:C_LocalTemplateFile ) + " write a default local template file + let template = [ ] + let sample_template_file = s:plugin_dir.'/c-support/rc/sample_template_file' + if filereadable( sample_template_file ) + for line in readfile( sample_template_file ) + call add( template, line ) + endfor + call writefile( template, s:C_LocalTemplateFile ) + endif + endif + " if filereadable( s:C_LocalTemplateFile ) - call C_ReadTemplates( s:C_LocalTemplateFile ) + call mmtemplates#core#ReadTemplates ( g:C_Templates, 'load', s:C_LocalTemplateFile ) let messsage = messsage." and '".s:C_LocalTemplateFile."'" - if s:C_Macro['|AUTHOR|'] == 'YOUR NAME' + if mmtemplates#core#ExpandText( g:C_Templates, '|AUTHOR|' ) == 'YOUR NAME' echomsg "Please set your personal details in file '".s:C_LocalTemplateFile."'." endif - else - let template = [ '|AUTHOR| = YOUR NAME', - \ '|COPYRIGHT| = Copyright (c) |YEAR|, |AUTHOR|' - \ ] - if finddir( s:C_LocalTemplateDir ) == '' - " try to create a local template directory - if exists("*mkdir") - try - call mkdir( s:C_LocalTemplateDir, "p" ) - " write a default local template file - call writefile( template, s:C_LocalTemplateFile ) - catch /.*/ - endtry - endif - else - " write a default local template file - call writefile( template, s:C_LocalTemplateFile ) - endif endif " else "------------------------------------------------------------------------------- - " local installation + " LOCAL INSTALLATION "------------------------------------------------------------------------------- if filereadable( s:C_LocalTemplateFile ) - call C_ReadTemplates( s:C_LocalTemplateFile ) + call mmtemplates#core#ReadTemplates ( g:C_Templates, 'load', s:C_LocalTemplateFile ) let messsage = "Templates read from '".s:C_LocalTemplateFile."'" else echomsg "Local template file '".s:C_LocalTemplateFile."' not readable." @@ -2811,183 +2455,34 @@ function! C_RereadTemplates ( msg ) endif " endif - if a:msg == 'yes' + if a:displaymsg == 'yes' echomsg messsage.'.' endif -endfunction " ---------- end of function C_RereadTemplates ---------- -" -"------------------------------------------------------------------------------ -" C_BrowseTemplateFiles {{{1 -"------------------------------------------------------------------------------ -function! C_BrowseTemplateFiles ( type ) - let templatefile = eval( 's:C_'.a:type.'TemplateFile' ) - let templatedir = eval( 's:C_'.a:type.'TemplateDir' ) - if isdirectory( templatedir ) - if has("browse") && s:C_GuiTemplateBrowser == 'gui' - let l:templatefile = browse(0,"edit a template file", templatedir, "" ) - else - let l:templatefile = '' - if s:C_GuiTemplateBrowser == 'explorer' - exe ':Explore '.templatedir - endif - if s:C_GuiTemplateBrowser == 'commandline' - let l:templatefile = input("edit a template file", templatedir, "file" ) - endif - endif - if !empty(l:templatefile) - :execute "update! | split | edit ".l:templatefile - endif - else - echomsg "Template directory '".templatedir."' does not exist." - endif -endfunction " ---------- end of function C_BrowseTemplateFiles ---------- +endfunction " ---------- end of function s:C_RereadTemplates ---------- "------------------------------------------------------------------------------ -" C_ReadTemplates {{{1 -" read the template file(s), build the macro and the template dictionary -" +" C_ToolMenu {{{1 "------------------------------------------------------------------------------ -let s:style = 'default' - -function! C_CheckAndRereadTemplates () - if s:C_TemplatesLoaded == 'no' - call C_RereadTemplates('no') - let s:C_TemplatesLoaded = 'yes' - endif -endfunction " ---------- end of function C_CheckAndRereadTemplates ---------- - -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 !empty(name) - let part = split( name, '\s*==\s*') - let item = part[0] - if has_key( s:C_Template[s:style], item ) && s:C_TemplateOverriddenMsg == '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 !empty(item) - let s:C_Template[s:style][item] .= line."\n" - endif - endif - endif - " - endfor " --------- read line --------- - - let s:C_ActualStyle = 'default' - if !empty( 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 ---------- +function! C_ToolMenu () + amenu 40.1000 &Tools.-SEP100- : + amenu 40.1030 &Tools.Load\ C\ Support :call C_CreateGuiMenus() + imenu 40.1030 &Tools.Load\ C\ Support :call C_CreateGuiMenus() +endfunction " ---------- end of function C_ToolMenu ---------- "------------------------------------------------------------------------------ -" C_Style{{{1 -" ex-command CStyle : callback function +" C_RemoveGuiMenus {{{1 "------------------------------------------------------------------------------ -function! C_Style ( style ) - call C_CheckAndRereadTemplates() - 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" +function! C_RemoveGuiMenus () + if s:C_MenusVisible == 'yes' + exe "aunmenu ".s:C_RootMenu + " + aunmenu &Tools.Unload\ C\ Support + call C_ToolMenu() + " + let s:C_MenusVisible = 'no' 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 ---------- +endfunction " ---------- end of function C_RemoveGuiMenus ---------- "------------------------------------------------------------------------------ " C_OpenFold {{{1 @@ -2999,7 +2494,7 @@ function! C_OpenFold ( mode ) " last line of the previously closed fold let foldstart = foldclosed(".") let foldend = foldclosedend(".") - normal zv + normal! zv if a:mode == 'below' exe ":".foldend endif @@ -3009,217 +2504,6 @@ function! C_OpenFold ( mode ) 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 s:C_TemplatesLoaded == 'no' - call C_RereadTemplates('no') - let s:C_TemplatesLoaded = 'yes' - endif - - 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 and insert the complete macro - " - if a:0 == 0 - let val = C_ExpandUserMacros (a:key) - if empty(val) - return - endif - let val = C_ExpandSingleMacro( val, '', '' ) - - 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 "" : - exe 'normal! a'.val - " 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 empty(val) - return - endif - - if match( val, '\s*\n' ) >= 0 - let part = split( val, '\s*\n' ) - else - let part = split( val, '' ) - endif - - if len(part) < 2 - let part = [ "" ] + part - echomsg 'SPLIT missing in template '.a:key - endif - " - " 'visual' and mode 'insert': - " - " part0 and part1 can consist of several lines - " - if mode == 'insert' - let pos1 = line(".") - let pos2 = pos1 - " windows: recover area of the visual mode and yank, puts the selected area in the buffer - normal gvy - let string = eval('@"') - 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 and part1 can consist of several lines - " - if mode == 'below' - - :'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 "------------------------------------------------------------------------------ @@ -3242,147 +2526,10 @@ function! C_JumpCtrlJ () if match( getline(".")[col(".") - 1], "[\]})\"'`]" ) != 0 call search( "[\]})\"'`]", '', line(".") ) endif - normal l + 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 !empty( 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 empty(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 !empty( 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 replacement = escape( replacement, '&' ) - 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 @@ -3391,298 +2538,286 @@ 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 empty( 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 () " prevent insertion for a file generated from a link error: " - call C_CheckAndRereadTemplates() - if isdirectory(expand('%:p:h')) + call s:CheckAndRereadTemplates() + if isdirectory(expand('%:p:h')) && s:C_InsertFileHeader == 'yes' if index( s:C_SourceCodeExtensionsList, expand('%:e') ) >= 0 - call C_InsertTemplate("comment.file-description") + call mmtemplates#core#InsertTemplate(g:C_Templates, 'Comments.file description impl') else - call C_InsertTemplate("comment.file-description-header") + call mmtemplates#core#InsertTemplate(g:C_Templates, 'Comments.file description header') endif set modified 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 - exe 'normal a#include <'.a:arg.'>' - 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 ================================================================ +" NAME: CreateAdditionalMaps {{{1 +" DESCRIPTION: create additional maps +" PARAMETERS: - +" RETURNS: +"=============================================================================== +function! s:CreateAdditionalMaps () + " + "------------------------------------------------------------------------------- + " settings - local leader + "------------------------------------------------------------------------------- + if ! empty ( g:C_MapLeader ) + if exists ( 'g:maplocalleader' ) + let ll_save = g:maplocalleader + endif + let g:maplocalleader = g:C_MapLeader + endif + " + " ---------- C/C++ dictionary ----------------------------------- + " This will enable keyword completion for C and C++ + " using Vim's dictionary feature |i_CTRL-X_CTRL-K|. + " Set the new dictionaries in front of the existing ones + " + if exists("g:C_Dictionary_File") + silent! exe 'setlocal dictionary+='.g:C_Dictionary_File + endif + " + "------------------------------------------------------------------------------- + " USER DEFINED COMMANDS + "------------------------------------------------------------------------------- + " + command! -nargs=1 -complete=customlist,C_CppcheckSeverityList CppcheckSeverity call C_GetCppcheckSeverity () + " + " ---------- commands : run ------------------------------------- + command! -nargs=* -complete=file CCmdlineArgs call C_Arguments() + " + " ---------- F-key mappings ------------------------------------ + " + " Alt-F9 write buffer and compile + " F9 compile and link + " Ctrl-F9 run executable + " Shift-F9 command line arguments + " + noremap :call C_Compile():call C_HlMessage() + inoremap :call C_Compile():call C_HlMessage() + " + noremap :call C_Link():call C_HlMessage() + inoremap :call C_Link():call C_HlMessage() + " + noremap :call C_Run() + inoremap :call C_Run() + " + noremap :CCmdlineArgs + inoremap :CCmdlineArgs + " -function! C_CppCLibraryIncludesInsert ( arg ) - call C_IncludesInsert ( a:arg, s:Cpp_CStandardLibsClean ) -endfunction " ---------- end of function C_CppCLibraryIncludesInsert + " ---------- KEY MAPPINGS : MENU ENTRIES ------------------------------------- + " ---------- comments menu ------------------------------------------------ + " + noremap cl :call C_EndOfLineComment() + inoremap cl :call C_EndOfLineComment() + " + nnoremap cj :call C_AdjustLineEndComm() + vnoremap cj :call C_AdjustLineEndComm() + inoremap cj :call C_AdjustLineEndComm()a + " + noremap cs :call C_GetLineEndCommCol() -"------------------------------------------------------------------------------- -" callback functions used in the filetype plugin ftplugin/c.vim -" custom completion -"------------------------------------------------------------------------------- + noremap c* :call C_CodeToCommentC():nohlsearchj + vnoremap c* :call C_CodeToCommentC():nohlsearchj + inoremap c* :call C_CodeToCommentC():nohlsearchj -function! C_IncludesList ( ArgLead, CmdLine, CursorPos, List ) - " show all libs - if empty(a:ArgLead) - return a:List + noremap cc :call C_CodeToCommentCpp():nohlsearchj + vnoremap cc :call C_CodeToCommentCpp():nohlsearchj + inoremap cc :call C_CodeToCommentCpp():nohlsearchj + noremap co :call C_CommentToCode():nohlsearch + vnoremap co :call C_CommentToCode():nohlsearch + inoremap co :call C_CommentToCode():nohlsearch + " + noremap cn :call C_NonCCommentToggle( ) + vnoremap cn :call C_NonCCommentToggle( ) + inoremap cn :call C_NonCCommentToggle( ) + " + noremap cx :call C_CommentToggle( ) + vnoremap cx :call C_CommentToggle( ) + inoremap cx :call C_CommentToggle( ) + " + " ---------- Doxygen menu --------------------------------------------------- + " + let [ bam_map, err ] = mmtemplates#core#Resource ( g:C_Templates, 'get', 'property', 'Doxygen::BriefAM::Map' ) + " + if err == '' && bam_map != '' + silent exe ' noremap '.bam_map.' :call C_EndOfLineComment("doxygen")' + silent exe 'inoremap '.bam_map.' :call C_EndOfLineComment("doxygen")' + endif + " + " ---------- statements menu ------------------------------------------------ + " + " ---------- preprocessor menu ---------------------------------------------- + " + noremap pi0 :call C_PPIf0("a")2ji + inoremap pi0 :call C_PPIf0("a")2ji + vnoremap pi0 :call C_PPIf0("v") + + noremap pr0 :call C_PPIf0Remove() + inoremap pr0 :call C_PPIf0Remove() + " + " ---------- idioms menu ---------------------------------------------------- + " + noremap i0 :call C_CodeFor("up" ) + vnoremap i0 :call C_CodeFor("up","v") + inoremap i0 :call C_CodeFor("up" ) + noremap in :call C_CodeFor("down" ) + vnoremap in :call C_CodeFor("down","v") + inoremap in :call C_CodeFor("down" ) + " + " ---------- snippet menu : snippets ----------------------------------------- + " + noremap nr :call C_CodeSnippet("r") + noremap nv :call C_CodeSnippet("view") + noremap nw :call C_CodeSnippet("w") + vnoremap nw :call C_CodeSnippet("wv") + noremap ne :call C_CodeSnippet("e") + " + inoremap nr :call C_CodeSnippet("r") + inoremap nv :call C_CodeSnippet("view") + inoremap nw :call C_CodeSnippet("w") + inoremap ne :call C_CodeSnippet("e") + " + " ---------- snippet menu : prototypes --------------------------------------- + " + noremap np :call C_ProtoPick("function") + vnoremap np :call C_ProtoPick("function") + inoremap np :call C_ProtoPick("function") + " + noremap nf :call C_ProtoPick("function") + vnoremap nf :call C_ProtoPick("function") + inoremap nf :call C_ProtoPick("function") + " + noremap nm :call C_ProtoPick("method") + vnoremap nm :call C_ProtoPick("method") + inoremap nm :call C_ProtoPick("method") + " + noremap ni :call C_ProtoInsert() + inoremap ni :call C_ProtoInsert() + " + noremap nc :call C_ProtoClear() + inoremap nc :call C_ProtoClear() + " + noremap ns :call C_ProtoShow() + inoremap ns :call C_ProtoShow() + " + " ---------- snippet menu : templates ---------------------------------------- + " + nnoremap ntl :call mmtemplates#core#EditTemplateFiles(g:C_Templates,-1) + inoremap ntl :call mmtemplates#core#EditTemplateFiles(g:C_Templates,-1) + if g:C_Installation == 'system' + nnoremap ntg :call mmtemplates#core#EditTemplateFiles(g:C_Templates,0) + inoremap ntg :call mmtemplates#core#EditTemplateFiles(g:C_Templates,0) + endif + nnoremap ntr :call mmtemplates#core#ReadTemplates(g:C_Templates,"reload","all") + inoremap ntr :call mmtemplates#core#ReadTemplates(g:C_Templates,"reload","all") + nnoremap nts :call mmtemplates#core#ChooseStyle(g:C_Templates,"!pick") + inoremap nts :call mmtemplates#core#ChooseStyle(g:C_Templates,"!pick") + " + " ---------- C++ menu ---------------------------------------------------- + " + " ---------- run menu -------------------------------------------------------- + " + noremap rc :call C_Compile():call C_HlMessage() + inoremap rc :call C_Compile():call C_HlMessage() + noremap rl :call C_Link():call C_HlMessage() + inoremap rl :call C_Link():call C_HlMessage() + noremap rr :call C_Run() + inoremap rr :call C_Run() + noremap re :call C_ExeToRun() + inoremap re :call C_ExeToRun() + noremap ra :CCmdlineArgs + inoremap ra :CCmdlineArgs + noremap rd :call C_Debugger() + inoremap rd :call C_Debugger() + noremap rp :call C_SplintCheck():call C_HlMessage() + inoremap rp :call C_SplintCheck():call C_HlMessage() + noremap rpa :call C_SplintArguments() + inoremap rpa :call C_SplintArguments() + noremap rcc :call C_CppcheckCheck():call C_HlMessage() + inoremap rcc :call C_CppcheckCheck():call C_HlMessage() + noremap rccs :call C_CppcheckSeverityInput() + inoremap rccs :call C_CppcheckSeverityInput() + + noremap ri :call C_Indent() + inoremap ri :call C_Indent() + noremap rh :call C_Hardcopy() + inoremap rh :call C_Hardcopy() + vnoremap rh :call C_Hardcopy() + noremap rs :call C_Settings() + inoremap rs :call C_Settings() + " + if has("unix") + noremap rx :call C_XtermSize() + inoremap rx :call C_XtermSize() + endif + noremap ro :call C_Toggle_Gvim_Xterm() + inoremap ro :call C_Toggle_Gvim_Xterm() + " + " Abraxas CodeCheck (R) + " + if s:C_CodeCheckIsExecutable==1 + noremap rk :call C_CodeCheck():call C_HlMessage() + inoremap rk :call C_CodeCheck():call C_HlMessage() + noremap rka :call C_CodeCheckArguments() + inoremap rka :call C_CodeCheckArguments() 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 ) + " ---------- plugin help ----------------------------------------------------- + " + noremap hp :call C_HelpCsupport() + inoremap hp :call C_HelpCsupport() + noremap hm :call C_Help("m") + inoremap hm :call C_Help("m") + " + if !exists("g:C_Ctrl_j") || ( exists("g:C_Ctrl_j") && g:C_Ctrl_j != 'off' ) + nnoremap i=C_JumpCtrlJ() + inoremap =C_JumpCtrlJ() + endif + " + " ---------- tool box -------------------------------------------------------- + " + if s:C_UseToolbox == 'yes' + call mmtoolbox#tools#AddMaps ( s:C_Toolbox ) + endif + " + "------------------------------------------------------------------------------- + " settings - reset local leader + "------------------------------------------------------------------------------- + if ! empty ( g:C_MapLeader ) + if exists ( 'll_save' ) + let g:maplocalleader = ll_save + else + unlet g:maplocalleader endif - endfor - return expansions -endfunction " ---------- end of function C_IncludesList ---------- + endif + " +endfunction " ---------- end of function s:CreateAdditionalMaps ---------- +" +" Plug-in setup: {{{1 +" +"------------------------------------------------------------------------------ +" setup the toolbox +"------------------------------------------------------------------------------ +" +if s:C_UseToolbox == 'yes' + " + let s:C_Toolbox = mmtoolbox#tools#NewToolbox ( 'C' ) + call mmtoolbox#tools#Property ( s:C_Toolbox, 'mapleader', g:C_MapLeader ) + " + call mmtoolbox#tools#Load ( s:C_Toolbox, s:C_ToolboxDir ) + " + " debugging only: + "call mmtoolbox#tools#Info ( s:C_Toolbox ) + " +endif " -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) @@ -3702,7 +2837,6 @@ endif " so that the autocommands execute in the order in which " they were given. The order matters! "------------------------------------------------------------------------------ - if has("autocmd") " " *.h has filetype 'cpp' by default; this can be changed to 'c' : @@ -3716,13 +2850,18 @@ if has("autocmd") autocmd BufNewFile,BufRead *.i :set filetype=c autocmd BufNewFile,BufRead *.ii :set filetype=cpp " - " " DELAYED LOADING OF THE TEMPLATE DEFINITIONS " - autocmd BufNewFile,BufRead * - \ if (&filetype=='cpp' || &filetype=='c') | - \ call C_CreateMenusDelayed() | - \ endif + autocmd FileType * + \ if ( &filetype == 'cpp' || &filetype == 'c') | + \ if ! exists( 'g:C_Templates' ) | + \ if s:C_LoadMenus == 'yes' | call C_CreateGuiMenus () | + \ else | call s:C_RereadTemplates ('no') | + \ endif | + \ endif | + \ call s:CreateAdditionalMaps() | + \ call mmtemplates#core#CreateMaps ( 'g:C_Templates', g:C_MapLeader ) | + \ endif "------------------------------------------------------------------------------- " style switching :Automated header insertion (suffixes from the gcc manual) @@ -3739,7 +2878,7 @@ if has("autocmd") " 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,BufRead,BufEnter ".pattern." call mmtemplates#core#ChooseStyle ( g:C_Templates, '".stl."')" exe "autocmd BufNewFile ".pattern." call C_InsertTemplateWrapper()" endfor " @@ -3752,6 +2891,8 @@ if has("autocmd") exe 'autocmd BufRead *.'.join( s:C_SourceCodeExtensionsList, '\|*.' ) \ .' call C_HighlightJumpTargets()' " +" autocmd BufNewFile,BufRead * if &filetype =~ '^\(c\|cpp\)$' | +" \ call s:CreateAdditionalMaps() | endif endif " has("autocmd") " "===================================================================================== diff --git a/syntax/template.vim b/syntax/template.vim new file mode 100644 index 0000000..76ddc9d --- /dev/null +++ b/syntax/template.vim @@ -0,0 +1,94 @@ +" Vim syntax file +" Language: mm template engine : template library +" Maintainer: Wolfgang Mehner +" Last Change: 12.08.2013 +" Version: 0.9.1-2 + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +"------------------------------------------------------------------------------- +" Syntax +"------------------------------------------------------------------------------- + +" comment +syn match Comment "^§.*$" +syn match Comment "\%(==\)\@<=[^=]*$" + +" templates, lists, ... +syn match Structure "^==\s*\%(TEMPLATE:\)\?[a-zA-Z0-9\-+.,_ ]\+==\%(.\+==\)\?" +syn match Structure "^==\s*ENDTEMPLATE\s*==" + +syn match Structure "^==\s*HELP:[a-zA-Z0-9\-+.,_ ]\+==\%(.\+==\)\?" + +syn match Structure "^==\s*SEP:[a-zA-Z0-9\-+.,_ ]\+==" + +syn match Structure "^==\s*LIST:\s*[a-zA-Z0-9_]\+\s*==\%(.\+==\)\?" +syn match Structure "^==\s*ENDLIST\s*==" + +" style sections +syn match Statement "^==\s*IF\s\+|STYLE|\s\+IS\s\+[a-zA-Z0-9_]\+\s*==" +syn match Statement "^==\s*ENDIF\s*==" + +syn match Statement "^==\s*USE\s\+STYLES\s*:[a-zA-Z0-9_, ]\+==" +syn match Statement "^==\s*ENDSTYLES\s*==" + +" functions: command mode +syn match Function "IncludeFile\ze\s*(" +syn match Function "SetFormat\ze\s*(" +syn match Function "SetMacro\ze\s*(" +syn match Function "SetStyle\ze\s*(" +syn match Function "SetSyntax\ze\s*(" +syn match Function "SetPath\ze\s*(" + +syn match Function "MenuShortcut\ze\s*(" +syn match Function "SetProperty\ze\s*(" +syn match Function "SetMap\ze\s*(" +syn match Function "SetShortcut\ze\s*(" + +" functions: standard template +syn match Function "|\zsDefaultMacro\ze(" +syn match Function "|\zsPrompt\ze(" +syn match Function "|\zsPickFile\ze(" +syn match Function "|\zsPickList\ze(" +syn match Function "|\zsSurroundWith\ze(" +syn match Function "|\zsInsert\ze(" +syn match Function "|\zsInsertLine\ze(" + +syn match Comment "|C(.\{-})|" +syn match Comment "|Comment(.\{-})|" + +" functions: picker +syn match Function "|\zsPath\ze(" " file +syn match Function "|\zsGetPath\ze(" " file +syn match Function "|\zsKeepPath\ze(" " file +syn match Function "|\zsRemovePath\ze(" " file +syn match Function "|\zsList\ze(" " list +syn match Function "|\zsGetList\ze(" " list + +" functions: help +syn match Function "|\zsPrompt\ze(" +syn match Function "|\zsWord\ze(" +syn match Function "|\zsPattern\ze(" +syn match Function "|\zsDefault\ze(" +syn match Function "|\zsSubstitute\ze(" +syn match Function "|\zsLiteralSub\ze(" +syn match Function "|\zsSystem\ze(" +syn match Function "|\zsVim\ze(" + +" strings, macros, tags, jump targets +syn match String "'\%([^']\|''\)*'" +syn match String "\"\%([^\\]\|\\.\)*\"" + +syn match Tag "|?\?[a-zA-Z][a-zA-Z0-9_:]*|" +syn match Tag "\|{CURSOR}" +syn match Tag "" +syn match Tag "" + +syn match Search "<\([+-]\)\w*\1>" +syn match Search "{\([+-]\)\w*\1}" + +let b:current_syntax = "template"