From fd2001cd614dfa0d55ec820b7c358a1795d3ea27 Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Tue, 14 Dec 2021 11:42:41 -0500 Subject: Simplify vim configuration --- dot_vim/plugin/SyntaxFolds.vim | 323 --- dot_vim/plugin/c.vim | 2678 ----------------------- dot_vim/plugin/filebrowser.vim | 251 --- dot_vim/plugin/gnupg.vim | 1226 ----------- dot_vim/plugin/imaps.vim | 831 -------- dot_vim/plugin/libList.vim | 249 --- dot_vim/plugin/minibufexpl.vim | 1838 ---------------- dot_vim/plugin/openssl.vim | 201 -- dot_vim/plugin/remoteOpen.vim | 163 -- dot_vim/plugin/taglist.vim | 4546 ---------------------------------------- 10 files changed, 12306 deletions(-) delete mode 100644 dot_vim/plugin/SyntaxFolds.vim delete mode 100644 dot_vim/plugin/c.vim delete mode 100644 dot_vim/plugin/filebrowser.vim delete mode 100644 dot_vim/plugin/gnupg.vim delete mode 100644 dot_vim/plugin/imaps.vim delete mode 100644 dot_vim/plugin/libList.vim delete mode 100644 dot_vim/plugin/minibufexpl.vim delete mode 100644 dot_vim/plugin/openssl.vim delete mode 100644 dot_vim/plugin/remoteOpen.vim delete mode 100644 dot_vim/plugin/taglist.vim (limited to 'dot_vim/plugin') diff --git a/dot_vim/plugin/SyntaxFolds.vim b/dot_vim/plugin/SyntaxFolds.vim deleted file mode 100644 index 27c622c..0000000 --- a/dot_vim/plugin/SyntaxFolds.vim +++ /dev/null @@ -1,323 +0,0 @@ -" ============================================================================== -" File: syntaxFolds.vim -" Author: Srinath Avadhanula -" ( srinath@fastmail.fm ) -" Last Change: Sun Oct 27 01:00 AM 2002 PST -" Description: Emulation of the syntax folding capability of vim using manual -" folding -" -" This script provides an emulation of the syntax folding of vim using manual -" folding. Just as in syntax folding, the folds are defined by regions. Each -" region is specified by a call to FoldRegions() which accepts 4 parameters: -" -" call FoldRegions(startpat, endpat, startoff, endoff) -" -" startpat: a line matching this pattern defines the beginning of a fold. -" endpat : a line matching this pattern defines the end of a fold. -" startoff: this is the offset from the starting line at which folding will -" actually start -" endoff : like startoff, but gives the offset of the actual fold end from -" the line satisfying endpat. -" startoff and endoff are necessary when the folding region does -" not have a specific end pattern corresponding to a start -" pattern. for example in latex, -" \begin{section} -" defines the beginning of a section, but its not necessary to -" have a corresponding -" \end{section} -" the section is assumed to end 1 line _before_ another section -" starts. -" startskip: a pattern which defines the beginning of a "skipped" region. -" -" For example, suppose we define a \itemize fold as follows: -" startpat = '^\s*\\item', -" endpat = '^\s*\\item\|^\s*\\end{\(enumerate\|itemize\|description\)}', -" startoff = 0, -" endoff = -1 -" -" This defines a fold which starts with a line beginning with an -" \item and ending one line before a line beginning with an -" \item or \end{enumerate} etc. -" -" Then, as long as \item's are not nested things are fine. -" However, once items begin to nest, the fold started by one -" \item can end because of an \item in an \itemize -" environment within this \item. i.e, the following can happen: -" -" \begin{itemize} -" \item Some text <------- fold will start here -" This item will contain a nested item -" \begin{itemize} <----- fold will end here because next line contains \item... -" \item Hello -" \end{itemize} <----- ... instead of here. -" \item Next item of the parent itemize -" \end{itemize} -" -" Therefore, in order to completely define a folding item which -" allows nesting, we need to also define a "skip" pattern. -" startskip and end skip do that. -" Leave '' when there is no nesting. -" endskip: the pattern which defines the end of the "skip" pattern for -" nested folds. -" -" Example: -" 1. A syntax fold region for a latex section is -" startpat = "\\section{" -" endpat = "\\section{" -" startoff = 0 -" endoff = -1 -" startskip = '' -" endskip = '' -" Note that the start and end patterns are thus the same and endoff has a -" negative value to capture the effect of a section ending one line before -" the next starts. -" 2. A syntax fold region for the \itemize environment is: -" startpat = '^\s*\\item', -" endpat = '^\s*\\item\|^\s*\\end{\(enumerate\|itemize\|description\)}', -" startoff = 0, -" endoff = -1, -" startskip = '^\s*\\begin{\(enumerate\|itemize\|description\)}', -" endskip = '^\s*\\end{\(enumerate\|itemize\|description\)}' -" Note the use of startskip and endskip to allow nesting. -" -" -" Each time a call is made to FoldRegions(), all the regions (which might be -" disjoint, but not nested) are folded up. -" Nested folds can be created by successive calls to FoldRegions(). The first -" call defines the region which is deepest in the folding. See MakeTexFolds() -" for an idea of how this works for latex files. - -" Function: AddSyntaxFoldItem (start, end, startoff, endoff [, skipStart, skipEnd]) {{{ -function! AddSyntaxFoldItem(start, end, startoff, endoff, ...) - if a:0 > 0 - let skipStart = a:1 - let skipEnd = a:2 - else - let skipStart = '' - let skipEnd = '' - end - if !exists('b:numFoldItems') - let b:numFoldItems = 0 - end - let b:numFoldItems = b:numFoldItems + 1 - - exe 'let b:startPat_'.b:numFoldItems.' = a:start' - exe 'let b:endPat_'.b:numFoldItems.' = a:end' - exe 'let b:startOff_'.b:numFoldItems.' = a:startoff' - exe 'let b:endOff_'.b:numFoldItems.' = a:endoff' - exe 'let b:skipStartPat_'.b:numFoldItems.' = skipStart' - exe 'let b:skipEndPat_'.b:numFoldItems.' = skipEnd' -endfunction - - -" }}} -" Function: MakeSyntaxFolds (force) {{{ -" Description: This function calls FoldRegions() several times with the -" parameters specifying various regions resulting in a nested fold -" structure for the file. -function! MakeSyntaxFolds(force, ...) - if exists('b:doneFolding') && a:force == 0 - return - end - - let skipEndPattern = '' - if a:0 > 0 - let line1 = a:1 - let skipEndPattern = '\|'.a:2 - else - let line1 = 1 - let r = line('.') - let c = virtcol('.') - - setlocal fdm=manual - normal! zE - end - if !exists('b:numFoldItems') - b:numFoldItems = 1000000 - end - - let i = 1 - - let maxline = line('.') - - while exists('b:startPat_'.i) && i <= b:numFoldItems - exe 'let startPat = b:startPat_'.i - exe 'let endPat = b:endPat_'.i - exe 'let startOff = b:startOff_'.i - exe 'let endOff = b:endOff_'.i - - let skipStart = '' - let skipEnd = '' - if exists('b:skipStartPat_'.i) - exe 'let skipStart = b:skipStartPat_'.i - exe 'let skipEnd = b:skipEndPat_'.i - end - exe line1 - let lastLoc = line1 - - if skipStart != '' - call InitStack('BeginSkipArray') - call FoldRegionsWithSkip(startPat, endPat, startOff, endOff, skipStart, skipEnd, 1, line('$')) - " call PrintError('done folding ['.startPat.']') - else - call FoldRegionsWithNoSkip(startPat, endPat, startOff, endOff, 1, line('$'), '') - end - - let i = i + 1 - endwhile - - exe maxline - - if a:0 == 0 - exe r - exe "normal! ".c."|" - if foldlevel(r) > 1 - exe "normal! ".(foldlevel(r) - 1)."zo" - end - let b:doneFolding = 0 - end -endfunction - - -" }}} -" FoldRegionsWithSkip: folding things such as \item's which can be nested. {{{ -function! FoldRegionsWithSkip(startpat, endpat, startoff, endoff, startskip, endskip, line1, line2) - exe a:line1 - " count the regions which have been skipped as we go along. do not want to - " create a fold which with a beginning or end line in one of the skipped - " regions. - let skippedRegions = '' - - " start searching for either the starting pattern or the end pattern. - while search(a:startskip.'\|'.a:endskip, 'W') - - if getline('.') =~ a:endskip - - let lastBegin = Pop('BeginSkipArray') - " call PrintError('popping '.lastBegin.' from stack and folding till '.line('.')) - call FoldRegionsWithNoSkip(a:startpat, a:endpat, a:startoff, a:endoff, lastBegin, line('.'), skippedRegions) - let skippedRegions = skippedRegions.lastBegin.','.line('.').'|' - - - " if this is the beginning of a skip region, then, push this line as - " the beginning of a skipped region. - elseif getline('.') =~ a:startskip - - " call PrintError('pushing '.line('.').' ['.getline('.').'] into stack') - call Push('BeginSkipArray', line('.')) - - end - endwhile - - " call PrintError('with skip starting at '.a:line1.' returning at line# '.line('.')) -endfunction - -" }}} -" FoldRegionsWithNoSkip: folding things such as \sections which do not nest. {{{ -function! FoldRegionsWithNoSkip(startpat, endpat, startoff, endoff, line1, line2, skippedRegions) - exe a:line1 - - " call PrintError('line1 = '.a:line1.', searching from '.line('.').'... for ['.a:startpat.'') - let lineBegin = s:MySearch(a:startpat, 'in') - " call PrintError('... and finding it at '.lineBegin) - - while lineBegin <= a:line2 - if IsInSkippedRegion(lineBegin, a:skippedRegions) - let lineBegin = s:MySearch(a:startpat, 'out') - " call PrintError(lineBegin.' is being skipped') - continue - end - let lineEnd = s:MySearch(a:endpat, 'out') - while IsInSkippedRegion(lineEnd, a:skippedRegions) && lineEnd <= a:line2 - let lineEnd = s:MySearch(a:endpat, 'out') - endwhile - if lineEnd > a:line2 - exe (lineBegin + a:startoff).','.a:line2.' fold' - break - else - " call PrintError ('for ['.a:startpat.'] '.(lineBegin + a:startoff).','.(lineEnd + a:endoff).' fold') - exe (lineBegin + a:startoff).','.(lineEnd + a:endoff).' fold' - end - - " call PrintError('line1 = '.a:line1.', searching from '.line('.').'... for ['.a:startpat.'') - let lineBegin = s:MySearch(a:startpat, 'in') - " call PrintError('... and finding it at '.lineBegin) - endwhile - - exe a:line2 - return -endfunction - -" }}} -" InitStack: initialize a stack {{{ -function! InitStack(name) - exe 'let s:'.a:name.'_numElems = 0' -endfunction -" }}} -" Push: push element into stack {{{ -function! Push(name, elem) - exe 'let numElems = s:'.a:name.'_numElems' - let numElems = numElems + 1 - exe 'let s:'.a:name.'_Element_'.numElems.' = a:elem' - exe 'let s:'.a:name.'_numElems = numElems' -endfunction -" }}} -" Pop: pops element off stack {{{ -function! Pop(name) - exe 'let numElems = s:'.a:name.'_numElems' - if numElems == 0 - return '' - else - exe 'let ret = s:'.a:name.'_Element_'.numElems - let numElems = numElems - 1 - exe 'let s:'.a:name.'_numElems = numElems' - return ret - end -endfunction -" }}} -" MySearch: just like search(), but returns large number on failure {{{ -function! MySearch(pat, opt) - if a:opt == 'in' - if getline('.') =~ a:pat - let ret = line('.') - else - let ret = search(a:pat, 'W') - end - else - normal! $ - let ret = search(a:pat, 'W') - end - - if ret == 0 - let ret = line('$') + 1 - end - return ret -endfunction -" }}} -" Function: IsInSkippedRegion (lnum, regions) {{{ -" Description: finds whether a given line number is within one of the regions -" skipped. -function! IsInSkippedRegion(lnum, regions) - let i = 1 - let subset = s:Strntok(a:regions, '|', i) - while subset != '' - let n1 = s:Strntok(subset, ',', 1) - let n2 = s:Strntok(subset, ',', 2) - if a:lnum >= n1 && a:lnum <= n2 - return 1 - end - - let subset = s:Strntok(a:regions, '|', i) - let i = i + 1 - endwhile - - return 0 -endfunction " }}} -" Function: Strntok (string, tok, n) {{{ -" extract the n^th token from s seperated by tok. -" example: Strntok('1,23,3', ',', 2) = 23 -fun! Strntok(s, tok, n) - return matchstr( a:s.a:tok[0], '\v(\zs([^'.a:tok.']*)\ze['.a:tok.']){'.a:n.'}') -endfun " }}} - -" vim600:fdm=marker diff --git a/dot_vim/plugin/c.vim b/dot_vim/plugin/c.vim deleted file mode 100644 index bb9390f..0000000 --- a/dot_vim/plugin/c.vim +++ /dev/null @@ -1,2678 +0,0 @@ -"############################################################################################### -" -" Filename: c.vim -" -" Description: C/C++-IDE. Write programs by inserting complete statements, -" comments, idioms, code snippets, templates and comments. -" Compile, link and run one-file-programs without a makefile. -" See also help file csupport.txt . -" -" GVIM Version: 7.0+ -" -" Configuration: There are some personal details which should be configured -" (see the files README.csupport and csupport.txt). -" -" Author: Dr.-Ing. Fritz Mehner, FH Südwestfalen, 58644 Iserlohn, Germany -" Email: mehner@fh-swf.de -" -" Version: see variable g:C_Version below -" Created: 04.11.2000 -" License: Copyright (c) 2000-2007, Fritz Mehner -" This program is free software; you can redistribute it and/or -" modify it under the terms of the GNU General Public License as -" published by the Free Software Foundation, version 2 of the -" License. -" This program is distributed in the hope that it will be -" useful, but WITHOUT ANY WARRANTY; without even the implied -" warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -" PURPOSE. -" See the GNU General Public License version 2 for more details. -" Revision: $Id: c.vim,v 1.35 2007/11/21 09:14:16 mehner Exp $ -" -"------------------------------------------------------------------------------ -" -if v:version < 700 - echohl WarningMsg | echo 'The plugin c-support.vim needs Vim version >= 7 .'| echohl None - finish -endif -" -" Prevent duplicate loading: -" -if exists("g:C_Version") || &cp - finish -endif -let g:C_Version= "5.0.5" " version number of this script; do not change -" -"############################################################################################### -" -" Global variables (with default values) which can be overridden. -" -" Platform specific items: {{{1 -" - root directory -" - characters that must be escaped for filenames -" -let s:MSWIN = has("win16") || has("win32") || has("win64") || - \ has("win95") || has("win32unix") -" -if s:MSWIN - " - let s:escfilename = '' - let s:plugin_dir = $VIM.'\vimfiles\' - let s:C_CodeSnippets = s:plugin_dir.'c-support/codesnippets/' - let s:C_IndentErrorLog = $HOME.'.indent.errorlog' - let s:installation = 'system' - " - let s:C_Display = '' - " -else - " - let s:escfilename = ' \%#[]' - let s:installation = 'local' - " - " user / system wide installation (Linux/Unix) - " - if match( expand(""), $VIM ) >= 0 - " system wide installation - let s:plugin_dir = $VIM.'/vimfiles/' - let s:installation = 'system' - else - " user installation assumed - let s:plugin_dir = $HOME.'/.vim/' - endif - " - let s:C_CodeSnippets = $HOME.'/.vim/c-support/codesnippets/' - let s:C_IndentErrorLog = $HOME.'/.indent.errorlog' - " - let s:C_Display = system("echo -n $DISPLAY") - " -endif -" Use of dictionaries {{{1 -" Key word completion is enabled by the filetype plugin 'c.vim' -" g:C_Dictionary_File must be global -" -if !exists("g:C_Dictionary_File") - let g:C_Dictionary_File = s:plugin_dir.'c-support/wordlists/c-c++-keywords.list,'. - \ s:plugin_dir.'c-support/wordlists/k+r.list,'. - \ s:plugin_dir.'c-support/wordlists/stl_index.list' -endif -" -" Modul global variables (with default values) which can be overridden. {{{1 -" -if s:MSWIN - let s:C_CCompiler = 'gcc.exe' " the C compiler - let s:C_CplusCompiler = 'g++.exe' " the C++ compiler - let s:C_ExeExtension = '.exe' " file extension for executables (leading point required) - let s:C_ObjExtension = '.obj' " file extension for objects (leading point required) -else - let s:C_CCompiler = 'gcc' " the C compiler - let s:C_CplusCompiler = 'g++' " the C++ compiler - let s:C_ExeExtension = '' " file extension for executables (leading point required) - let s:C_ObjExtension = '.o' " file extension for objects (leading point required) -endif -" -let s:C_CExtension = 'c' " C file extension; everything else is C++ -let s:C_CFlags = '-Wall -g -O0 -c' " compiler flags: compile, don't optimize -let s:C_CodeCheckExeName = 'check' -let s:C_CodeCheckOptions = '-K13' -let s:C_LFlags = '-Wall -g -O0' " compiler flags: link , don't optimize -let s:C_Libs = '-lm' " libraries to use -let s:C_LineEndCommColDefault = 49 -let s:C_LoadMenus = 'yes' -let s:C_MenuHeader = 'yes' -let s:C_OutputGvim = 'vim' -let s:C_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} Page %N" -let s:C_Root = '&C\/C\+\+.' " the name of the root menu of this plugin -let s:C_TypeOfH = 'cpp' -let s:C_Wrapper = s:plugin_dir.'c-support/scripts/wrapper.sh' -let s:C_XtermDefaults = '-fa courier -fs 12 -geometry 80x24' -" -let s:C_GlobalTemplateFile = s:plugin_dir.'c-support/templates/Templates' -let s:C_GlobalTemplateDir = fnamemodify( s:C_GlobalTemplateFile, ":p:h" ).'/' -let s:C_LocalTemplateFile = $HOME.'/.vim/c-support/templates/Templates' -let s:C_LocalTemplateDir = fnamemodify( s:C_LocalTemplateFile, ":p:h" ).'/' -let s:C_TemplateOverwrittenMsg= 'yes' -" -let s:C_FormatDate = '%x' -let s:C_FormatTime = '%X' -let s:C_FormatYear = '%Y' -" -"------------------------------------------------------------------------------ -" -" 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_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_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_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_TemplateOverwrittenMsg ') -call C_CheckGlobal('C_TypeOfH ') -call C_CheckGlobal('C_XtermDefaults ') -" -"----- some variables for internal use only ----------------------------------- -" -" -" set default geometry if not specified -" -if match( s:C_XtermDefaults, "-geometry\\s\\+\\d\\+x\\d\\+" ) < 0 - let s:C_XtermDefaults = s:C_XtermDefaults." -geometry 80x24" -endif -" -" escape the printheader -" -let s:C_Printheader = escape( s:C_Printheader, ' %' ) -" -let s:C_HlMessage = "" -" -" characters that must be escaped for filenames -" -let s:C_If0_Counter = 0 -let s:C_If0_Txt = "If0Label_" -" -let s:C_SplintIsExecutable = 0 -if executable( "splint" ) - let s:C_SplintIsExecutable = 1 -endif -" -let s:C_CodeCheckIsExecutable = 0 -if executable( s:C_CodeCheckExeName ) - let s:C_CodeCheckIsExecutable = 1 -endif -" -"------------------------------------------------------------------------------ -" Control variables (not user configurable) -"------------------------------------------------------------------------------ -let s:Attribute = { 'below':'', 'above':'', 'start':'', 'append':'', 'insert':'' } -let s:C_Attribute = {} -let s:C_ExpansionLimit = 10 -let s:C_FileVisited = [] -" -let s:C_MacroNameRegex = '\([a-zA-Z][a-zA-Z0-9_]*\)' -let s:C_MacroLineRegex = '^\s*|'.s:C_MacroNameRegex.'|\s*=\s*\(.*\)' -let s:C_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_ExpansionCounter = {} -let s:C_Template = {} -let s:C_Macro = {'|AUTHOR|' : 'first name surname', - \ '|AUTHORREF|' : '', - \ '|EMAIL|' : '', - \ '|COMPANY|' : '', - \ '|PROJECT|' : '', - \ '|COPYRIGHTHOLDER|': '' - \ } -let s:C_MacroFlag = { ':l' : 'lowercase' , - \ ':u' : 'uppercase' , - \ ':c' : 'capitalize' , - \ ':L' : 'legalize name' , - \ } - -"------------------------------------------------------------------------------ -" C : C_InitMenus {{{1 -" Initialization of C support menus -"------------------------------------------------------------------------------ -" -function! C_InitMenus () - " - "=============================================================================================== - "----- Menu : C main menu entry ------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_Root != "" - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'C\/C\+\+ ' - exe "amenu ".s:C_Root.'-Sep00- :' - endif - endif - " - "=============================================================================================== - "----- Menu : C-Comments -------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'&Comments.&CommentsC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Comments.-Sep00- :' - endif - exe "amenu ".s:C_Root.'&Comments.end-of-&line\ comment :call C_LineEndComment( )' - exe "vmenu ".s:C_Root.'&Comments.end-of-&line\ comment :call C_MultiLineEndComments( )' - - exe "amenu ".s:C_Root.'&Comments.ad&just\ end-of-line\ com\. :call C_AdjustLineEndComm("a")' - exe "vmenu ".s:C_Root.'&Comments.ad&just\ end-of-line\ com\. :call C_AdjustLineEndComm("v")' - - exe "amenu ".s:C_Root.'&Comments.&set\ end-of-line\ com\.\ col\. :call C_GetLineEndCommCol()' - - exe "amenu ".s:C_Root.'&Comments.-SEP10- :' - exe "amenu ".s:C_Root.'&Comments.code\ ->\ comment\ \/&*\ *\/ :call C_CodeComment("a","yes"):nohlsearchj' - exe "vmenu ".s:C_Root.'&Comments.code\ ->\ comment\ \/&*\ *\/ :call C_CodeComment("v","yes"):nohlsearchj' - exe "amenu ".s:C_Root.'&Comments.code\ ->\ comment\ &\/\/ :call C_CodeComment("a","no"):nohlsearchj' - exe "vmenu ".s:C_Root.'&Comments.code\ ->\ comment\ &\/\/ :call C_CodeComment("v","no"):nohlsearchj' - exe "amenu ".s:C_Root.'&Comments.c&omment\ ->\ code :call C_CommentCode("a"):nohlsearch' - exe "vmenu ".s:C_Root.'&Comments.c&omment\ ->\ code :call C_CommentCode("v"):nohlsearch' - - exe "amenu ".s:C_Root.'&Comments.-SEP0- :' - exe "amenu ".s:C_Root.'&Comments.&frame\ comment :call C_InsertTemplate("comment.frame")' - exe "amenu ".s:C_Root.'&Comments.f&unction\ description :call C_InsertTemplate("comment.function")' - exe "amenu ".s:C_Root.'&Comments.-SEP1- :' - exe "amenu ".s:C_Root.'&Comments.&method\ description :call C_InsertTemplate("comment.method")' - exe "amenu ".s:C_Root.'&Comments.cl&ass\ description :call C_InsertTemplate("comment.class")' - exe "amenu ".s:C_Root.'&Comments.-SEP2- :' - exe "amenu ".s:C_Root.'&Comments.file\ description :call C_InsertTemplate("comment.file-description")' - exe "amenu ".s:C_Root.'&Comments.-SEP3- :' - " - "----- Submenu : C-Comments : file sections ------------------------------------------------------------- - " - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.file\ sectionsC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.-Sep0- :' - " - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.&Header\ File\ Includes :call C_InsertTemplate("comment.file-section-cpp-header-includes")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.Local\ &Macros :call C_InsertTemplate("comment.file-section-cpp-macros")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.Local\ &Type\ Def\. :call C_InsertTemplate("comment.file-section-cpp-typedefs")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.Local\ &Data\ Types :call C_InsertTemplate("comment.file-section-cpp-data-types")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.Local\ &Variables :call C_InsertTemplate("comment.file-section-cpp-class-defs")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.Local\ &Prototypes :call C_InsertTemplate("comment.file-section-cpp-local-variables")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.&Exp\.\ Function\ Def\. :call C_InsertTemplate("comment.file-section-cpp-prototypes")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.&Local\ Function\ Def\. :call C_InsertTemplate("comment.file-section-cpp-function-defs-exported")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.-SEP6- :' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.Local\ &Class\ Def\. :call C_InsertTemplate("comment.file-section-cpp-function-defs-local")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.E&xp\.\ Class\ Impl\. :call C_InsertTemplate("comment.file-section-cpp-class-implementations-exported")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.L&ocal\ Class\ Impl\. :call C_InsertTemplate("comment.file-section-cpp-class-implementations-local")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.-SEP7- :' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.&All\ sections,\ C ' - \':call C_Comment_C_SectionAll("c")' - exe "amenu ".s:C_Root.'&Comments.&C\/C\+\+-file\ sections.All\ §ions,\ C++ ' - \':call C_Comment_C_SectionAll("cpp")' - " - " - "----- Submenu : H-Comments : file sections ------------------------------------------------------------- - " - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.H-file\ sectionsC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.-Sep0- :' - "' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.&Header\ File\ Includes :call C_InsertTemplate("comment.file-section-hpp-header-includes")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.Exported\ &Macros :call C_InsertTemplate("comment.file-section-hpp-macros")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.Exported\ &Type\ Def\. :call C_InsertTemplate("comment.file-section-hpp-exported-typedefs")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.Exported\ &Data\ Types :call C_InsertTemplate("comment.file-section-hpp-exported-data-types")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.Exported\ &Variables :call C_InsertTemplate("comment.file-section-hpp-exported-class-defs")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.Exported\ &Funct\.\ Decl\. :call C_InsertTemplate("comment.file-section-hpp-exported-variables")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.-SEP4- :' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.E&xported\ Class\ Def\. :call C_InsertTemplate("comment.file-section-hpp-exported-function-declarations")' - - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.-SEP5- :' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.&All\ sections,\ C ' - \':call C_Comment_H_SectionAll("c")' - exe "amenu ".s:C_Root.'&Comments.&H-file\ sections.All\ §ions,\ C++ ' - \':call C_Comment_H_SectionAll("cpp")' - " - exe "amenu ".s:C_Root.'&Comments.-SEP8- :' - " - "----- Submenu : C-Comments : keyword comments ---------------------------------------------------------- - " - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..keyw\.+comm\.C\/C\+\+ ' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..-Sep0- :' -" - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:&BUG\: $:call C_InsertTemplate("comment.keyword-bug")' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:&COMPILER\: $:call C_InsertTemplate("comment.keyword-compiler")' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:&TODO\: $:call C_InsertTemplate("comment.keyword-todo")' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:T&RICKY\: $:call C_InsertTemplate("comment.keyword-tricky")' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:&WARNING\: $:call C_InsertTemplate("comment.keyword-warning")' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:W&ORKAROUND\: $:call C_InsertTemplate("comment.keyword-workaround")' - exe "amenu ".s:C_Root.'&Comments.&KEYWORD+comm\..\:&new\ keyword\: $:call C_InsertTemplate("comment.keyword-keyword")' - " - "----- Submenu : C-Comments : special comments ---------------------------------------------------------- - " - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..special\ comm\.C\/C\+\+ ' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..-Sep0- :' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..&EMPTY $:call C_CommentSpecial("EMPTY") kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..&FALL\ THROUGH $:call C_CommentSpecial("FALL THROUGH") kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..&IMPL\.\ TYPE\ CONV $:call C_CommentSpecial("IMPLICIT TYPE CONVERSION") kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..&NO\ RETURN $:call C_CommentSpecial("NO RETURN") kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..NOT\ &REACHED $:call C_CommentSpecial("NOT REACHED") kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..&TO\ BE\ IMPL\. $:call C_CommentSpecial("REMAINS TO BE IMPLEMENTED")kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..-SEP81- :' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..constant\ type\ is\ &long\ (L) $:call C_CommentSpecial("constant type is long")kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..constant\ type\ is\ &unsigned\ (U) $:call C_CommentSpecial("constant type is unsigned")kgJA' - exe "amenu ".s:C_Root.'&Comments.&special\ comm\..constant\ type\ is\ unsigned\ l&ong\ (UL) $:call C_CommentSpecial("constant type is unsigned long")kgJA' - - " - "----- Submenu : C-Comments : Tags ---------------------------------------------------------- - " - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).tags\ (plugin)C\/C\+\+ ' - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).-Sep0- :' - " - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&AUTHOR :call C_InsertMacroValue("AUTHOR")' - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).AUTHOR&REF :call C_InsertMacroValue("AUTHORREF")' - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&COMPANY :call C_InsertMacroValue("COMPANY")' - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).C&OPYRIGHTHOLDER :call C_InsertMacroValue("COPYRIGHTHOLDER")' - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&EMAIL :call C_InsertMacroValue("EMAIL")' - exe "amenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&PROJECT :call C_InsertMacroValue("PROJECT")' - - exe "imenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&AUTHOR :call C_InsertMacroValue("AUTHOR")a' - exe "imenu ".s:C_Root.'&Comments.ta&gs\ (plugin).AUTHOR&REF :call C_InsertMacroValue("AUTHORREF")a' - exe "imenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&COMPANY :call C_InsertMacroValue("COMPANY")a' - exe "imenu ".s:C_Root.'&Comments.ta&gs\ (plugin).C&OPYRIGHTHOLDER :call C_InsertMacroValue("COPYRIGHTHOLDER")a' - exe "imenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&EMAIL :call C_InsertMacroValue("EMAIL")a' - exe "imenu ".s:C_Root.'&Comments.ta&gs\ (plugin).&PROJECT :call C_InsertMacroValue("PROJECT")a' - " - " - exe "amenu ".s:C_Root.'&Comments.-SEP9- :' - " - exe " menu ".s:C_Root.'&Comments.&date a=C_InsertDateAndTime("d")' - exe "imenu ".s:C_Root.'&Comments.&date =C_InsertDateAndTime("d")' - exe " menu ".s:C_Root.'&Comments.date\ &time a=C_InsertDateAndTime("dt")' - exe "imenu ".s:C_Root.'&Comments.date\ &time =C_InsertDateAndTime("dt")' - - exe "amenu ".s:C_Root.'&Comments.-SEP12- :' - exe "amenu ".s:C_Root.'&Comments.\/\/\ xxx\ \ \ \ \ &->\ \ \/*\ xxx\ *\/ :call C_CommentCppToC()' - exe "vmenu ".s:C_Root.'&Comments.\/\/\ xxx\ \ \ \ \ &->\ \ \/*\ xxx\ *\/ :'."'<,'>".'call C_CommentCppToC()' - exe "amenu ".s:C_Root.'&Comments.\/*\ xxx\ *\/\ \ -&>\ \ \/\/\ xxx :call C_CommentCToCpp()' - exe "vmenu ".s:C_Root.'&Comments.\/*\ xxx\ *\/\ \ -&>\ \ \/\/\ xxx :'."'<,'>".'call C_CommentCToCpp()' - " - "=============================================================================================== - "----- Menu : C-Statements------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'&Statements.&StatementsC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Statements.-Sep00- :' - endif - " - exe "amenu ".s:C_Root.'&Statements.&do\ \{\ \}\ while :call C_InsertTemplate("statements.do-while")' - exe "vmenu ".s:C_Root.'&Statements.&do\ \{\ \}\ while :call C_InsertTemplate("statements.do-while", "v")' - " - exe "amenu ".s:C_Root.'&Statements.f&or :call C_InsertTemplate("statements.for")' - " - exe "anoremenu ".s:C_Root.'&Statements.fo&r\ \{\ \} :call C_InsertTemplate("statements.for-block")' - exe "vnoremenu ".s:C_Root.'&Statements.fo&r\ \{\ \} :call C_InsertTemplate("statements.for-block", "v")' - " - exe "amenu ".s:C_Root.'&Statements.&if :call C_InsertTemplate("statements.if")' - " - exe "amenu ".s:C_Root.'&Statements.i&f\ \{\ \} :call C_InsertTemplate("statements.if-block")' - exe "vmenu ".s:C_Root.'&Statements.i&f\ \{\ \} :call C_InsertTemplate("statements.if-block", "v")' - - exe "amenu ".s:C_Root.'&Statements.if\ &else :call C_InsertTemplate("statements.if-else")' - exe "vmenu ".s:C_Root.'&Statements.if\ &else :call C_InsertTemplate("statements.if-else", "v")' - " - exe "amenu ".s:C_Root.'&Statements.if\ \{\ \}\ e&lse\ \{\ \} :call C_InsertTemplate("statements.if-block-else")' - exe "vmenu ".s:C_Root.'&Statements.if\ \{\ \}\ e&lse\ \{\ \} :call C_InsertTemplate("statements.if-block-else", "v")' - " - exe "amenu ".s:C_Root.'&Statements.&while :call C_InsertTemplate("statements.while")' - " - exe "amenu ".s:C_Root.'&Statements.w&hile\ \{\ \} :call C_InsertTemplate("statements.while-block")' - exe "vmenu ".s:C_Root.'&Statements.w&hile\ \{\ \} :call C_InsertTemplate("statements.while-block", "v")' - " - exe "amenu ".s:C_Root.'&Statements.&switch\ \{\ \} :call C_InsertTemplate("statements.switch")' - exe "vmenu ".s:C_Root.'&Statements.&switch\ \{\ \} :call C_InsertTemplate("statements.switch", "v")' - " - exe "amenu ".s:C_Root.'&Statements.&case\ \.\.\.\ break <:call C_InsertTemplate("statements.case")' - " - " - exe "amenu ".s:C_Root.'&Statements.&\{\ \} :call C_InsertTemplate("statements.block")' - exe "vmenu ".s:C_Root.'&Statements.&\{\ \} :call C_InsertTemplate("statements.block", "v")' - " - " - "=============================================================================================== - "----- Menu : C-Idioms ---------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'&Idioms.&IdiomsC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Idioms.-Sep00- :' - endif - exe "amenu ".s:C_Root.'&Idioms.&function :call C_InsertTemplate("idioms.function")' - exe "vmenu ".s:C_Root.'&Idioms.&function :call C_InsertTemplate("idioms.function", "v")' - exe "amenu ".s:C_Root.'&Idioms.s&tatic\ function :call C_InsertTemplate("idioms.function-static")' - exe "vmenu ".s:C_Root.'&Idioms.s&tatic\ function :call C_InsertTemplate("idioms.function-static", "v")' - exe "amenu ".s:C_Root.'&Idioms.&main :call C_InsertTemplate("idioms.main")' - exe "vmenu ".s:C_Root.'&Idioms.&main :call C_InsertTemplate("idioms.main", "v")' - - exe "amenu ".s:C_Root.'&Idioms.-SEP1- :' - exe "amenu ".s:C_Root.'&Idioms.for(x=&0;\ x:call C_CodeFor("up" , "a")a' - exe "amenu ".s:C_Root.'&Idioms.for(x=&n-1;\ x>=0;\ x\-=1) :call C_CodeFor("down", "a")a' - exe "vmenu ".s:C_Root.'&Idioms.for(x=&0;\ x:call C_CodeFor("up" , "v")' - exe "vmenu ".s:C_Root.'&Idioms.for(x=&n-1;\ x>=0;\ x\-=1) :call C_CodeFor("down", "v")' - - exe "amenu ".s:C_Root.'&Idioms.-SEP2- :' - exe "amenu ".s:C_Root.'&Idioms.&enum\+typedef :call C_InsertTemplate("idioms.enum")' - exe "amenu ".s:C_Root.'&Idioms.&struct\+typedef :call C_InsertTemplate("idioms.struct")' - exe "amenu ".s:C_Root.'&Idioms.&union\+typedef :call C_InsertTemplate("idioms.union")' - exe "vmenu ".s:C_Root.'&Idioms.&enum\+typedef :call C_InsertTemplate("idioms.enum" , "v")' - exe "vmenu ".s:C_Root.'&Idioms.&struct\+typedef :call C_InsertTemplate("idioms.struct", "v")' - exe "vmenu ".s:C_Root.'&Idioms.&union\+typedef :call C_InsertTemplate("idioms.union" , "v")' - exe "amenu ".s:C_Root.'&Idioms.-SEP3- :' - " - exe " noremenu ".s:C_Root.'&Idioms.&printf oprintf("\n");2F"a' - exe "inoremenu ".s:C_Root.'&Idioms.&printf printf("\n");2F"a' - - exe " noremenu ".s:C_Root.'&Idioms.s&canf oscanf("", & );F"i' - exe "inoremenu ".s:C_Root.'&Idioms.s&canf scanf("", & );F"i' - " - exe "amenu ".s:C_Root.'&Idioms.-SEP4- :' - exe "amenu ".s:C_Root.'&Idioms.p=ca&lloc\(n,sizeof(type)\) :call C_InsertTemplate("idioms.calloc")' - exe "amenu ".s:C_Root.'&Idioms.p=m&alloc\(sizeof(type)\) :call C_InsertTemplate("idioms.malloc")' - " - exe "anoremenu ".s:C_Root.'&Idioms.si&zeof(\ \) isizeof()' - exe "inoremenu ".s:C_Root.'&Idioms.si&zeof(\ \) sizeof()' - exe "vnoremenu ".s:C_Root.'&Idioms.si&zeof(\ \) ssizeof()P' - " - exe "anoremenu ".s:C_Root.'&Idioms.asse&rt(\ \) oassert();' - exe "vnoremenu ".s:C_Root.'&Idioms.asse&rt(\ \) sassert();F(p' - exe "amenu ".s:C_Root.'&Idioms.-SEP5- :' - exe "amenu ".s:C_Root.'&Idioms.open\ &input\ file :call C_InsertTemplate("idioms.open-input-file")' - exe "amenu ".s:C_Root.'&Idioms.open\ &output\ file :call C_InsertTemplate("idioms.open-output-file")' - exe "amenu ".s:C_Root.'&Idioms.fscanf :call C_InsertTemplate("idioms.fscanf")' - exe "amenu ".s:C_Root.'&Idioms.fprintf :call C_InsertTemplate("idioms.fprintf")' - " - "=============================================================================================== - "----- Menu : C-Preprocessor ---------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'&Preprocessor.&PreprocessorC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Preprocessor.-Sep00- :' - endif - " - "----- Submenu : C-Idioms: standard library ------------------------------------------------------- - "' - exe "amenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..Std\.Lib\.C\/C\+\+ ' - exe "amenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..-Sep0- :' - " - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&assert\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&ctype\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&errno\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&float\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&limits\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..l&ocale\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&math\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..set&jmp\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..s&ignal\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..stdar&g\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..st&ddef\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&stdio\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..stdli&b\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..st&ring\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &Std\.Lib\..&time\.h o#include' - " - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.C99C\/C\+\+ ' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.-Sep0- :' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.&complex\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.&fenv\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.&inttypes\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.is&o646\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.&stdbool\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.s&tdint\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.tg&math\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.&wchar\.h o#include' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ C&99.wct&ype\.h o#include' - " - exe "amenu ".s:C_Root.'&Preprocessor.-SEP2- :' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &\<\.\.\.\> o#include<>' - exe "anoremenu ".s:C_Root.'&Preprocessor.#include\ &\"\.\.\.\" o#include""' - exe "amenu ".s:C_Root.'&Preprocessor.#&define :call C_InsertTemplate("preprocessor.define")' - exe "amenu ".s:C_Root.'&Preprocessor.&#undef :call C_InsertTemplate("preprocessor.undefine")' - " - exe "amenu ".s:C_Root.'&Preprocessor.#&if\ #else\ #endif :call C_InsertTemplate("preprocessor.if-else-endif")' - exe "amenu ".s:C_Root.'&Preprocessor.#i&fdef\ #else\ #endif :call C_InsertTemplate("preprocessor.ifdef-else-endif")' - exe "amenu ".s:C_Root.'&Preprocessor.#if&ndef\ #else\ #endif :call C_InsertTemplate("preprocessor.ifndef-else-endif")' - exe "amenu ".s:C_Root.'&Preprocessor.#ifnd&ef\ #def\ #endif :call C_InsertTemplate("preprocessor.ifndef-def-endif")' - exe "amenu ".s:C_Root.'&Preprocessor.#if\ &0\ #endif :call C_PPIf0("a")2ji' - " - exe "vmenu ".s:C_Root.'&Preprocessor.#&if\ #else\ #endif :call C_InsertTemplate("preprocessor.if-else-endif", "v")' - exe "vmenu ".s:C_Root.'&Preprocessor.#i&fdef\ #else\ #endif :call C_InsertTemplate("preprocessor.ifdef-else-endif", "v")' - exe "vmenu ".s:C_Root.'&Preprocessor.#if&ndef\ #else\ #endif :call C_InsertTemplate("preprocessor.ifndef-else-endif", "v")' - exe "vmenu ".s:C_Root.'&Preprocessor.#ifnd&ef\ #def\ #endif :call C_InsertTemplate("preprocessor.ifndef-def-endif", "v")' - exe "vmenu ".s:C_Root.'&Preprocessor.#if\ &0\ #endif :call C_PPIf0("v")' - " - exe "amenu ".s:C_Root.'&Preprocessor.&remove\ #if\ 0\ #endif :call C_PPIf0Remove()' - " - "=============================================================================================== - "----- Menu : Snippets ---------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'S&nippets.S&nippetsC\/C\+\+ ' - exe "amenu ".s:C_Root.'S&nippets.-Sep00- :' - endif - if s:C_CodeSnippets != "" - exe "amenu ".s:C_Root.'S&nippets.&read\ code\ snippet :call C_CodeSnippet("r")' - exe "amenu ".s:C_Root.'S&nippets.&write\ code\ snippet :call C_CodeSnippet("w")' - exe "vmenu ".s:C_Root.'S&nippets.&write\ code\ snippet :call C_CodeSnippet("wv")' - exe "amenu ".s:C_Root.'S&nippets.&edit\ code\ snippet :call C_CodeSnippet("e")' - exe " menu ".s:C_Root.'S&nippets.-SEP1- :' - endif - exe " menu ".s:C_Root.'S&nippets.&pick\ up\ prototype :call C_ProtoPick("n")' - exe "vmenu ".s:C_Root.'S&nippets.&pick\ up\ prototype :call C_ProtoPick("v")' - exe " menu ".s:C_Root.'S&nippets.&insert\ prototype(s) :call C_ProtoInsert()' - exe " menu ".s:C_Root.'S&nippets.&clear\ prototype(s) :call C_ProtoClear()' - exe " menu ".s:C_Root.'S&nippets.&show\ prototype(s) :call C_ProtoShow()' - - " - "=============================================================================================== - "----- Menu : C++ --------------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'C&++.C&\+\+C\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.-Sep00- :' - endif - exe " noremenu ".s:C_Root.'C&++.c&in ocin>> ;i' - exe " noremenu ".s:C_Root.'C&++.cout\ &variable ocout<< << endl;2Focout<< "\n";2F"a' - exe " noremenu ".s:C_Root.'C&++.<<\ &\"\" i<< "" ' - " - exe "inoremenu ".s:C_Root.'C&++.c&in cin>> ;i' - exe "inoremenu ".s:C_Root.'C&++.cout\ &variable cout<< << endl;2F<< "\n";2F"a' - exe "inoremenu ".s:C_Root.'C&++.<<\ &\"\" << "" ' - " - "----- Submenu : C++ : output manipulators ------------------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.&output\ manipulators.output\ manip\.C\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.&output\ manipulators.-Sep0- :' - " - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &boolalpha i<< boolalpha' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &dec i<< dec' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &endl i<< endl' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &fixed i<< fixed' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ fl&ush i<< flush' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &hex i<< hex' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &internal i<< internal' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &left i<< left' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &oct i<< oct' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &right i<< right' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ s&cientific i<< scientific' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &setbase\(\ \) i<< setbase(10) ' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ se&tfill\(\ \) i<< setfill() ' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ setiosfla&g\(\ \) i<< setiosflags() ' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ set&precision\(\ \) i<< setprecision(6) ' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ set&w\(\ \) i<< setw(0) ' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ showb&ase i<< showbase' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ showpoi&nt i<< showpoint' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ showpos\ \(&1\) i<< showpos' - exe " noremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ uppercase\ \(&2\) i<< uppercase' - " - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &boolalpha << boolalpha' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &dec << dec' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &endl << endl' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &fixed << fixed' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ fl&ush << flush' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &hex << hex' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &internal << internal' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &left << left' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ o&ct << oct' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &right << right' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ s&cientific << scientific' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ &setbase\(\ \) << setbase(10) ' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ se&tfill\(\ \) << setfill() ' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ setiosfla&g\(\ \) << setiosflags() ' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ set&precision\(\ \) << setprecision(6) ' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ set&w\(\ \) << setw(0) ' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ showb&ase << showbase' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ showpoi&nt << showpoint' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ showpos\ \(&1\) << showpos' - exe "inoremenu ".s:C_Root.'C&++.&output\ manipulators.\<\<\ uppercase\ \(&2\) << uppercase' - " - "----- Submenu : C++ : ios flag bits ------------------------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.ios\ flag&bits.ios\ flagsC\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.ios\ flag&bits.-Sep0- :' - " - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&adjustfield iios::adjustfield' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::bas&efield iios::basefield' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&boolalpha iios::boolalpha' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&dec iios::dec' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&fixed iios::fixed' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::floa&tfield iios::floatfield' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&hex iios::hex' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&internal iios::internal' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&left iios::left' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&oct iios::oct' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&right iios::right' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::s&cientific iios::scientific' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::sho&wbase iios::showbase' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::showpoint\ \(&1\) iios::showpoint' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::show&pos iios::showpos' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&skipws iios::skipws' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::u&nitbuf iios::unitbuf' - exe " noremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&uppercase iios::uppercase' - " - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&adjustfield ios::adjustfield' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::bas&efield ios::basefield' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&boolalpha ios::boolalpha' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&dec ios::dec' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&fixed ios::fixed' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::floa&tfield ios::floatfield' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&hex ios::hex' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&internal ios::internal' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&left ios::left' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&oct ios::oct' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&right ios::right' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::s&cientific ios::scientific' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::sho&wbase ios::showbase' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::showpoint\ \(&1\) ios::showpoint' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::show&pos ios::showpos' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&skipws ios::skipws' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::u&nitbuf ios::unitbuf' - exe "inoremenu ".s:C_Root.'C&++.ios\ flag&bits.ios::&uppercase ios::uppercase' - " - "----- Submenu : C++ library (algorithm - locale) ---------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.#include\ \ \(&1\).alg\.\.locC\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.#include\ \ \(&1\).-Sep0- :' - " - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&algorithm o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&bitset o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&complex o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&deque o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&exception o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&fstream o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).f&unctional o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).iomani&p o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&ios o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).iosf&wd o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).io&stream o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).istrea&m o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).iterato&r o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).&limits o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).lis&t o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&1\).l&ocale o#include' - " - "----- Submenu : C++ library (map - vector) ---------------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.#include\ \ \(&2\).map\.\.vecC\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.#include\ \ \(&2\).-Sep0- :' - - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&map o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).memor&y o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&new o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).numeri&c o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&ostream o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&queue o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&set o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).sst&ream o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).st&ack o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).stde&xcept o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).stream&buf o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).str&ing o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&typeinfo o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&utility o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).&valarray o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&2\).v&ector o#include' - " - "----- Submenu : C library (cassert - ctime) ------------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.#include\ \ \(&3\).cXC\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.#include\ \ \(&3\).-Sep0- :' - " - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&assert o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&ctype o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&errno o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&float o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&limits o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cl&ocale o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&math o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cset&jmp o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cs&ignal o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cstdar&g o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cst&ddef o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&stdio o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cstdli&b o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).cst&ring o#include' - exe "anoremenu ".s:C_Root.'C&++.#include\ \ \(&3\).c&time o#include' - " - "----- End Submenu : C library (cassert - ctime) --------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.-SEP2- :' - exe "amenu ".s:C_Root.'C&++.&method\ implement\. :call C_InsertTemplate("cpp.method-implementation")' - - exe "amenu ".s:C_Root.'C&++.&class :call C_InsertTemplate("cpp.class")' - exe "amenu ".s:C_Root.'C&++.class\ (w\.\ &new) :call C_InsertTemplate("cpp.class-using-new")' - exe "amenu ".s:C_Root.'C&++.-SEP3- :' - exe "amenu ".s:C_Root.'C&++.tem&pl\.\ method\ impl\. :call C_InsertTemplate("cpp.template-method-implementation")' - exe "amenu ".s:C_Root.'C&++.&templ\.\ class :call C_InsertTemplate("cpp.template-class")' - exe "amenu ".s:C_Root.'C&++.templ\.\ class\ (w\.\ ne&w) :call C_InsertTemplate("cpp.template-class-using-new")' - - exe "amenu ".s:C_Root.'C&++.-SEP31- :' - exe "amenu ".s:C_Root.'C&++.templ\.\ &function :call C_InsertTemplate("cpp.template-function")' - exe "amenu ".s:C_Root.'C&++.&error\ class :call C_InsertTemplate("cpp.error-class")' - exe "amenu ".s:C_Root.'C&++.-SEP4- :' - exe "amenu ".s:C_Root.'C&++.operator\ &<< :call C_InsertTemplate("cpp.operator-in")' - exe "amenu ".s:C_Root.'C&++.operator\ &>> :call C_InsertTemplate("cpp.operator-out")' - exe "amenu ".s:C_Root.'C&++.-SEP5- :' - exe "amenu ".s:C_Root.'C&++.tr&y\ \.\.\ catch :call C_InsertTemplate("cpp.try-catch")' - exe "vmenu ".s:C_Root.'C&++.tr&y\ \.\.\ catch :call C_InsertTemplate("cpp.try-catch", "v")' - exe "amenu ".s:C_Root.'C&++.catc&h :call C_InsertTemplate("cpp.catch")' - exe "vmenu ".s:C_Root.'C&++.catc&h :call C_InsertTemplate("cpp.catch", "v")' - - exe "amenu ".s:C_Root.'C&++.catch\(&\.\.\.\) :call C_InsertTemplate("cpp.catch-points")' - exe "vmenu ".s:C_Root.'C&++.catch\(&\.\.\.\) :call C_InsertTemplate("cpp.catch-points", "v")' - - exe "amenu ".s:C_Root.'C&++.-SEP6- :' - exe "amenu ".s:C_Root.'C&++.open\ input\ file\ \ \(&4\) :call C_InsertTemplate("cpp.open-input-file")' - exe "amenu ".s:C_Root.'C&++.open\ output\ file\ \(&5\) :call C_InsertTemplate("cpp.open-output-file")' - exe "amenu ".s:C_Root.'C&++.-SEP7- :' - - exe " menu ".s:C_Root.'C&++.&using\ namespace\ std; ousing namespace std;' - exe " menu ".s:C_Root.'C&++.usin&g\ namespace\ ; ousing namespace ;$i' - exe "amenu ".s:C_Root.'C&++.namespace\ &\{\ \} :call C_InsertTemplate("cpp.namespace")' - - exe "imenu ".s:C_Root.'C&++.&using\ namespace\ std; using namespace std;' - exe "imenu ".s:C_Root.'C&++.usin&g\ namespace\ ; using namespace ;$i' - exe "vmenu ".s:C_Root.'C&++.namespace\ &\{\ \} :call C_InsertTemplate("cpp.namespace", "v")' - - exe "amenu ".s:C_Root.'C&++.-SEP8- :' - " - "----- Submenu : RTTI ---------------------------------------------------------------------------- - " - exe "amenu ".s:C_Root.'C&++.&RTTI.RTTIC\/C\+\+ ' - exe "amenu ".s:C_Root.'C&++.&RTTI.-Sep0- :' - " - exe " noremenu ".s:C_Root.'C&++.&RTTI.&typeid atypeid()hr(a' - exe " noremenu ".s:C_Root.'C&++.&RTTI.&static_cast astatic_cast<>()' - exe " noremenu ".s:C_Root.'C&++.&RTTI.&const_cast aconst_cast<>()' - exe " noremenu ".s:C_Root.'C&++.&RTTI.&reinterpret_cast areinterpret_cast<>()' - exe " noremenu ".s:C_Root.'C&++.&RTTI.&dynamic_cast adynamic_cast<>()' - " - exe "vnoremenu ".s:C_Root.'C&++.&RTTI.&typeid stypeid()hr(p' - exe "vnoremenu ".s:C_Root.'C&++.&RTTI.&static_cast sstatic_cast<>()P' - exe "vnoremenu ".s:C_Root.'C&++.&RTTI.&const_cast sconst_cast<>()P' - exe "vnoremenu ".s:C_Root.'C&++.&RTTI.&reinterpret_cast sreinterpret_cast<>()P' - exe "vnoremenu ".s:C_Root.'C&++.&RTTI.&dynamic_cast sdynamic_cast<>()P' - " - exe "inoremenu ".s:C_Root.'C&++.&RTTI.&typeid typeid()hr(a' - exe "inoremenu ".s:C_Root.'C&++.&RTTI.&static_cast static_cast<>()' - exe "inoremenu ".s:C_Root.'C&++.&RTTI.&const_cast const_cast<>()' - exe "inoremenu ".s:C_Root.'C&++.&RTTI.&reinterpret_cast reinterpret_cast<>()' - exe "inoremenu ".s:C_Root.'C&++.&RTTI.&dynamic_cast dynamic_cast<>()' - " - "----- End Submenu : RTTI ------------------------------------------------------------------------ - " - exe "amenu ".s:C_Root.'C&++.e&xtern\ \"C\"\ \{\ \} :call C_InsertTemplate("cpp.extern")' - exe "vmenu ".s:C_Root.'C&++.e&xtern\ \"C\"\ \{\ \} :call C_InsertTemplate("cpp.extern", "v")' - " - "=============================================================================================== - "----- Menu : run ----- -------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_MenuHeader == 'yes' - exe "amenu ".s:C_Root.'&Run.&RunC\/C\+\+ ' - exe "amenu ".s:C_Root.'&Run.-Sep00- :' - endif - " - exe "amenu ".s:C_Root.'&Run.save\ and\ &compile\ :call C_Compile():redraw:call C_HlMessage()' - exe "amenu ".s:C_Root.'&Run.&link\ :call C_Link():redraw:call C_HlMessage()' - exe "amenu ".s:C_Root.'&Run.&run\ :call C_Run()' - exe "amenu ".s:C_Root.'&Run.cmd\.\ line\ &arg\.\ :call C_Arguments()' - exe "amenu ".s:C_Root.'&Run.-SEP0- :' - exe "amenu ".s:C_Root.'&Run.&make :call C_Make()' - exe "amenu ".s:C_Root.'&Run.cmd\.\ line\ ar&g\.\ for\ make :call C_MakeArguments()' - exe "amenu ".s:C_Root.'&Run.-SEP1- :' - if s:C_SplintIsExecutable==1 - exe "amenu ".s:C_Root.'&Run.s&plint :call C_SplintCheck():redraw:call C_HlMessage()' - exe "amenu ".s:C_Root.'&Run.cmd\.\ line\ arg\.\ for\ spl&int :call C_SplintArguments()' - exe "amenu ".s:C_Root.'&Run.-SEP2- :' - endif - " - if s:C_CodeCheckIsExecutable==1 - exe "amenu ".s:C_Root.'&Run.CodeChec&k :call C_CodeCheck():redraw:call C_HlMessage()' - exe "amenu ".s:C_Root.'&Run.cmd\.\ line\ arg\.\ for\ Cod&eCheck :call C_CodeCheckArguments()' - exe "amenu ".s:C_Root.'&Run.-SEP3- :' - endif - " - exe "amenu ".s:C_Root.'&Run.in&dent :call C_Indent("a"):redraw:call C_HlMessage()' - exe "vmenu ".s:C_Root.'&Run.in&dent :call C_Indent("v"):redraw:call C_HlMessage()' - if s:MSWIN - exe "amenu ".s:C_Root.'&Run.&hardcopy\ to\ printer :call C_Hardcopy("n")' - exe "vmenu ".s:C_Root.'&Run.&hardcopy\ to\ printer :call C_Hardcopy("v")' - else - exe "amenu ".s:C_Root.'&Run.&hardcopy\ to\ FILENAME\.ps :call C_Hardcopy("n")' - exe "vmenu ".s:C_Root.'&Run.&hardcopy\ to\ FILENAME\.ps :call C_Hardcopy("v")' - endif - exe "imenu ".s:C_Root.'&Run.-SEP4- :' - - exe "amenu ".s:C_Root.'&Run.rebuild\ &templates :call C_RebuildTemplates()' - exe "amenu ".s:C_Root.'&Run.&settings :call C_Settings()' - exe "imenu ".s:C_Root.'&Run.-SEP5- :' - - if !s:MSWIN - exe "amenu ".s:C_Root.'&Run.&xterm\ size :call C_XtermSize()' - endif - if s:C_OutputGvim == "vim" - exe "amenu ".s:C_Root.'&Run.&output:\ VIM->buffer->xterm :call C_Toggle_Gvim_Xterm()' - else - if s:C_OutputGvim == "buffer" - exe "amenu ".s:C_Root.'&Run.&output:\ BUFFER->xterm->vim :call C_Toggle_Gvim_Xterm()' - else - exe "amenu ".s:C_Root.'&Run.&output:\ XTERM->vim->buffer :call C_Toggle_Gvim_Xterm()' - endif - endif - " - "=============================================================================================== - "----- Menu : help ------------------------------------------------------- {{{2 - "=============================================================================================== - " - if s:C_Root != "" - exe "menu ".s:C_Root.'&help\ \(plugin\) :call C_HelpCsupport()' - endif - -endfunction " ---------- end of function C_InitMenus ---------- -" -"=============================================================================================== -"----- Menu Functions -------------------------------------------------------------------------- -"=============================================================================================== -" -"------------------------------------------------------------------------------ -" C_Input: Input after a highlighted prompt {{{1 -"------------------------------------------------------------------------------ -function! C_Input ( promp, text ) - echohl Search " highlight prompt - call inputsave() " preserve typeahead - let retval=input( a:promp, a:text ) " read input - call inputrestore() " restore typeahead - echohl None " reset highlighting - let retval = substitute( retval, '^\s\+', "", "" ) " remove leading whitespaces - let retval = substitute( retval, '\s\+$', "", "" ) " remove trailing whitespaces - return retval -endfunction " ---------- end of function C_Input ---------- -" -"------------------------------------------------------------------------------ -" C_AdjustLineEndComm: adjust line-end comments {{{1 -"------------------------------------------------------------------------------ -function! C_AdjustLineEndComm ( mode ) range - " - if !exists("b:C_LineEndCommentColumn") - let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault - endif - - let save_cursor = getpos(".") - - let save_expandtab = &expandtab - exe ":set expandtab" - - if a:mode == 'v' - let pos0 = line("'<") - let pos1 = line("'>") - else - let pos0 = line(".") - let pos1 = pos0 - endif - - let linenumber = pos0 - exe ":".pos0 - - while linenumber <= pos1 - let line= getline(".") - " look for a C comment - let idx1 = 1 + match( line, '\s*\/\*.\{-}\*\/' ) - let idx2 = 1 + match( line, '\/\*.\{-}\*\/' ) - if idx2 == 0 - " look for a C++ comment - let idx1 = 1 + match( line, '\s*\/\/.*$' ) - let idx2 = 1 + match( line, '\/\/.*$' ) - endif - - let ln = line(".") - call setpos(".", [ 0, ln, idx1, 0 ] ) - let vpos1 = virtcol(".") - call setpos(".", [ 0, ln, 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, ln, 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, ln, b:C_LineEndCommentColumn, 0 ] ) - exe "normal ".diff."x" - endif - - endif - let linenumber=linenumber+1 - normal j - endwhile - " restore tab expansion settings and cursor position - let &expandtab = save_expandtab - call setpos('.', save_cursor) - -endfunction " ---------- end of function C_AdjustLineEndComm ---------- -" -"------------------------------------------------------------------------------ -" C_GetLineEndCommCol: get line-end comment position {{{1 -"------------------------------------------------------------------------------ -function! C_GetLineEndCommCol () - let actcol = virtcol(".") - if actcol+1 == virtcol("$") - let b:C_LineEndCommentColumn = C_Input( 'start line-end comment at virtual column : ', actcol ) - else - let b:C_LineEndCommentColumn = virtcol(".") - endif - echomsg "line end comments will start at column ".b:C_LineEndCommentColumn -endfunction " ---------- end of function C_GetLineEndCommCol ---------- -" -"------------------------------------------------------------------------------ -" C_LineEndComment: single line-end comment {{{1 -"------------------------------------------------------------------------------ -function! C_LineEndComment ( ) - if !exists("b:C_LineEndCommentColumn") - let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault - endif - " ----- trim whitespaces ----- - exe 's/\s*$//' - let linelength= virtcol("$") - 1 - if linelength < b:C_LineEndCommentColumn - let diff = b:C_LineEndCommentColumn -1 -linelength - exe "normal ".diff."A " - endif - " append at least one blank - if linelength >= b:C_LineEndCommentColumn - exe "normal A " - endif - call C_InsertTemplate('comment.end-of-line-comment') -endfunction " ---------- end of function C_LineEndComment ---------- -" -"------------------------------------------------------------------------------ -" C_MultiLineEndComments: multi line-end comments {{{1 -"------------------------------------------------------------------------------ -function! C_MultiLineEndComments ( ) - " - if !exists("b:C_LineEndCommentColumn") - let b:C_LineEndCommentColumn = s:C_LineEndCommColDefault - endif - " - let pos0 = line("'<") - let pos1 = line("'>") - " - " ----- trim whitespaces ----- - exe pos0.','.pos1.'s/\s*$//' - " - " ----- find the longest line ----- - let maxlength = 0 - let linenumber = pos0 - normal '< - while linenumber <= pos1 - if getline(".") !~ "^\\s*$" && maxlength 0 - exe "normal ".diff."k" - end -endfunction " ---------- end of function C_MultiLineEndComments ---------- -" -"------------------------------------------------------------------------------ -" C_CommentSpecial : special comments {{{1 -"------------------------------------------------------------------------------ -function! C_CommentSpecial (special) - put = ' '.s:C_Com1.' '.a:special.' '.s:C_Com2 -endfunction " ---------- end of function C_CommentSpecial ---------- -" -"------------------------------------------------------------------------------ -" C_Comment_C_SectionAll: Section Comments {{{1 -"------------------------------------------------------------------------------ -" -function! C_Comment_C_SectionAll ( type ) - - call C_InsertTemplate("comment.file-section-cpp-header-includes") - call C_InsertTemplate("comment.file-section-cpp-macros") - call C_InsertTemplate("comment.file-section-cpp-typedefs") - call C_InsertTemplate("comment.file-section-cpp-data-types") - if a:type=="cpp" - call C_InsertTemplate("comment.file-section-cpp-class-defs") - endif - call C_InsertTemplate("comment.file-section-cpp-local-variables") - call C_InsertTemplate("comment.file-section-cpp-prototypes") - call C_InsertTemplate("comment.file-section-cpp-function-defs-exported") - call C_InsertTemplate("comment.file-section-cpp-function-defs-local") - if a:type=="cpp" - call C_InsertTemplate("comment.file-section-cpp-class-implementations-exported") - call C_InsertTemplate("comment.file-section-cpp-class-implementations-local") - endif - -endfunction " ---------- end of function C_Comment_C_SectionAll ---------- -" -function! C_Comment_H_SectionAll ( type ) - - call C_InsertTemplate("comment.file-section-hpp-header-includes") - call C_InsertTemplate("comment.file-section-hpp-macros") - call C_InsertTemplate("comment.file-section-hpp-exported-typedefs") - call C_InsertTemplate("comment.file-section-hpp-exported-data-types") - if a:type=="cpp" - call C_InsertTemplate("comment.file-section-hpp-exported-class-defs") - endif - call C_InsertTemplate("comment.file-section-hpp-exported-variables") - call C_InsertTemplate("comment.file-section-hpp-exported-function-declarations") - -endfunction " ---------- end of function C_Comment_H_SectionAll ---------- -" -"---------------------------------------------------------------------- -" C_CodeComment : Code -> Comment {{{1 -"---------------------------------------------------------------------- -function! C_CodeComment( mode, style ) - - if a:mode=="a" - if a:style == 'yes' - silent exe ":s#^#/\* #" - silent put = ' */' - else - silent exe ":s#^#//#" - endif - endif - - if a:mode=="v" - if a:style == 'yes' - silent exe ":'<,'>s/^/ \* /" - silent exe ":'< s'^ '\/'" - silent exe ":'>" - silent put = ' */' - else - silent exe ":'<,'>s#^#//#" - endif - endif - -endfunction " ---------- end of function C_CodeComment ---------- -" -"---------------------------------------------------------------------- -" C_StartMultilineComment : Comment -> Code {{{1 -"---------------------------------------------------------------------- -let s:C_StartMultilineComment = '^\s*\/\*[\*! ]\=' - -function! C_RemoveCComment( start, end ) - - if a:end-a:start<1 - return 0 " lines removed - endif - " - " Is the C-comment complete ? Get length. - " - let check = getline( a:start ) =~ s:C_StartMultilineComment - let linenumber = a:start+1 - while linenumber < a:end && getline( linenumber ) !~ '^\s*\*\/' - let check = check && getline( linenumber ) =~ '^\s*\*[ ]\=' - let linenumber = linenumber+1 - endwhile - let check = check && getline( linenumber ) =~ '^\s*\*\/' - " - " remove a complete comment - " - if check - exe "silent :".a:start.' s/'.s:C_StartMultilineComment.'//' - let linenumber1 = a:start+1 - while linenumber1 < linenumber - exe "silent :".linenumber1.' s/^\s*\*[ ]\=//' - let linenumber1 = linenumber1+1 - endwhile - exe "silent :".linenumber1.' s/^\s*\*\///' - endif - - return linenumber-a:start+1 " lines removed -endfunction " ---------- end of function C_RemoveCComment ---------- -" -"---------------------------------------------------------------------- -" C_CommentCode : Comment -> Code {{{1 -"---------------------------------------------------------------------- -function! C_CommentCode(mode) - if a:mode=="a" - let pos1 = line(".") - let pos2 = pos1 - endif - if a:mode=="v" - let pos1 = line("'<") - let pos2 = line("'>") - endif - - let removed = 0 - " - let linenumber=pos1 - while linenumber <= pos2 - " Do we have a C++ comment ? - if getline( linenumber ) =~ '^\s*//' - exe "silent :".linenumber.' s#^\s*//##' - let removed = 1 - endif - " Do we have a C comment ? - if removed == 0 && getline( linenumber ) =~ s:C_StartMultilineComment - let removed = C_RemoveCComment(linenumber,pos2) - endif - - if removed!=0 - let linenumber = linenumber+removed - let removed = 0 - else - let linenumber = linenumber+1 - endif - endwhile -endfunction " ---------- end of function C_CommentCode ---------- -" -"---------------------------------------------------------------------- -" C_CommentCppToC : C++ Comment -> C Comment {{{1 -" Removes trailing whitespaces. -"---------------------------------------------------------------------- -function! C_CommentCppToC() - silent! exe ':s#\/\/\s*\(.*\)\s*$#/* \1 */#' -endfunction " ---------- end of function C_CommentCppToC ---------- -" -"---------------------------------------------------------------------- -" C_CommentCToCpp : C Comment -> C++ Comment {{{1 -" Changes the first comment in case of multiple comments: -" xxxx; /* */ /* */ -" xxxx; // /* */ -" Removes trailing whitespaces. -"---------------------------------------------------------------------- -function! C_CommentCToCpp() - silent! exe ':s!\/\*\s*\(.\{-}\)\*\/!\/\/ \1!' - silent! exe ':s!\s*$!!' -endfunction " ---------- end of function C_CommentCToCpp ---------- -" -"===================================================================================== -"----- Menu : Statements ----------------------------------------------------------- -"===================================================================================== -" -"------------------------------------------------------------------------------ -" C_PPIf0 : #if 0 .. #endif {{{1 -"------------------------------------------------------------------------------ -function! C_PPIf0 (mode) - " - let s:C_If0_Counter = 0 - let save_line = line(".") - let actual_line = 0 - " - " search for the maximum option number (if any) - " - normal gg - while actual_line < search( s:C_If0_Txt."\\d\\+" ) - let actual_line = line(".") - let actual_opt = matchstr( getline(actual_line), s:C_If0_Txt."\\d\\+" ) - let actual_opt = strpart( actual_opt, strlen(s:C_If0_Txt),strlen(actual_opt)-strlen(s:C_If0_Txt)) - if s:C_If0_Counter < actual_opt - let s:C_If0_Counter = actual_opt - endif - endwhile - let s:C_If0_Counter = s:C_If0_Counter+1 - silent exe ":".save_line - " - if a:mode=='a' - let zz= "\n#if 0 ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n" - let zz= zz."\n#endif ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n\n" - put =zz - if v:version >= 700 - normal 4k - endif - endif - - if a:mode=='v' - let zz= "\n#if 0 ".s:C_Com1." ----- #if 0 : ".s:C_If0_Txt.s:C_If0_Counter." ----- ".s:C_Com2."\n" - :'put =zz - :normal '< - endif - -endfunction " ---------- end of function C_PPIf0 ---------- -" -"------------------------------------------------------------------------------ -" C_PPIf0Remove : remove #if 0 .. #endif {{{1 -"------------------------------------------------------------------------------ -function! C_PPIf0Remove () - - let frstline = searchpair( '^\s*#if\s\+0', '', '^\s*#endif\>.\+\.\+\=0 && match( l:snippetfile, '\.\(ni\|noindent\)$' ) < 0 - endif - endif - if line(".")==2 && getline(1)=~"^$" - silent exe ":1,1d" - endif - endif - " - " update current buffer / split window / edit snippet file - " - if a:mode == "e" - if has("gui_running") - let l:snippetfile = browse(0,"edit a code snippet",s:C_CodeSnippets,"") - else - let l:snippetfile=input("edit snippet ", s:C_CodeSnippets, "file" ) - end - if l:snippetfile != "" - :execute "update! | split | edit ".l:snippetfile - endif - endif - " - " write whole buffer into snippet file - " - if a:mode == "w" || a:mode == "wv" - if has("gui_running") - let l:snippetfile = browse(0,"edit a code snippet",s:C_CodeSnippets,"") - else - let l:snippetfile=input("edit snippet ", s:C_CodeSnippets, "file" ) - end - if l:snippetfile != "" - if filereadable(l:snippetfile) - if confirm("File ".l:snippetfile." exists ! Overwrite ? ", "&Cancel\n&No\n&Yes") != 3 - return - endif - endif - if a:mode == "w" - :execute ":write! ".l:snippetfile - else - :execute ":*write! ".l:snippetfile - end - endif - endif - - else - echo "code snippet directory ".s:C_CodeSnippets." does not exist (please create it)" - endif -endfunction " ---------- end of function C_CodeSnippets ---------- -" -"------------------------------------------------------------------------------ -" C_CodeFor : for (idiom) {{{1 -"------------------------------------------------------------------------------ -function! C_CodeFor( direction, mode ) - if a:direction=="up" - let string = C_Input( " loop var. [ start [ end [ incr. ]]] : ", "" ) - else - let string = C_Input( " loop var. [ start [ end [ decr. ]]] : ", "" ) - endif - let pos = 0 - let jmp = 0 - if string != "" - " - " use internal formatting to avoid conficts when using == below - let equalprg_save = &equalprg - set equalprg= - " - " loop variable - let loopvar = matchstr( string, '\S\+\s*', pos ) - let pos = pos + strlen(loopvar) - let loopvar = substitute( loopvar, '\s*$', "", "" ) - " - " start value - let startval = matchstr( string, '\S\+\s*', pos ) - let pos = pos + strlen(startval) - let startval = substitute( startval, '\s*$', "", "" ) - - " end value - let endval = matchstr( string, '\S\+\s*', pos ) - let pos = pos + strlen(endval) - let endval = substitute( endval, '\s*$', "", "" ) - - " increment - let incval = matchstr( string, '\S\+\s*', pos ) - let pos = pos + strlen(incval) - let incval = substitute( incval, '\s*$', "", "" ) - - if incval=="" - let incval = '1' - let jmp = 10 - endif - - if a:direction=="up" - if endval=="" - let endval = 'n' - let jmp = 7 - endif - if startval=="" - let startval = '0' - let jmp = 4 - endif - let zz= "for ( ".loopvar." = ".startval."; ".loopvar." < ".endval."; ".loopvar." += ".incval." )" - else - if endval=="" - let endval = '0' - let jmp = 7 - endif - if startval=="" - let startval = 'n-1' - let jmp = 4 - endif - let zz= "for ( ".loopvar." = ".startval."; ".loopvar." >= ".endval."; ".loopvar." -= ".incval." )" - endif - - " ----- normal mode ---------------- - if a:mode=="a" - put =zz - normal 2== - if jmp!=0 - exe "normal ".jmp."Wh" - else - exe 'normal $' - endif - endif - - " ----- visual mode ---------------- - if a:mode=="v" - let zz = zz." {" - :'put =zz - :'<-1 - :exe "normal =".(line("'>")-line(".")+3)."+" - endif - " - " restore formatter programm - let &equalprg = equalprg_save - " - endif -endfunction " ---------- end of function C_CodeFor ---------- -" -"------------------------------------------------------------------------------ -" Handle prototypes {{{1 -"------------------------------------------------------------------------------ -" -let s:C_Prototype = [] -let s:C_PrototypeShow = [] -let s:C_PrototypeCounter = 0 -let s:C_CComment = '\/\*.\{-}\*\/\s*' " C comment with trailing whitespaces - " '.\{-}' any character, non-greedy -let s:C_CppComment = '\/\/.*$' " C++ comment -" -"------------------------------------------------------------------------------ -" C_ProtoPick : pick up (normal/visual) {{{1 -"------------------------------------------------------------------------------ -function! C_ProtoPick (mode) - if a:mode=="n" - " --- normal mode ------------------- - let pos1 = line(".") - let pos2 = pos1 - else - " --- visual mode ------------------- - let pos1 = line("'<") - let pos2 = line("'>") - endif - " - " remove C/C++-comments, leading and trailing whitespaces, squeeze whitespaces - " - let prototyp = '' - let linenumber = pos1 - while linenumber <= pos2 - let newline = getline(linenumber) - let newline = substitute( newline, s:C_CppComment, "", "" ) " remove C++ comment - let prototyp = prototyp." ".newline - let linenumber = linenumber+1 - endwhile - " - let prototyp = substitute( prototyp, '^\s\+', "", "" ) " remove leading whitespaces - let prototyp = substitute( prototyp, s:C_CComment, "", "g" ) " remove (multiline) C comments - let prototyp = substitute( prototyp, '\s\+', " ", "g" ) " squeeze whitespaces - let prototyp = substitute( prototyp, '\s\+$', "", "" ) " remove trailing whitespaces - " - " remove template keyword - " - let prototyp = substitute( prototyp, '^template\s*<\s*class \w\+\s*>\s*', "", "" ) - " - let parlist = stridx( prototyp, '(' ) " start of the parameter list - let part1 = strpart( prototyp, 0, parlist ) - let part2 = strpart( prototyp, parlist ) - " - " remove the scope res. operator - " - let part1 = substitute( part1, '<\s*\w\+\s*>', "", "g" ) - let part1 = substitute( part1, '\ 0 - for protytype in s:C_Prototype - put =protytype - endfor - let lines = s:C_PrototypeCounter - 1 - silent exe "normal =".lines."-" - call C_ProtoClear() - else - echo "currently no prototypes available" - endif - " - " restore formatter programm - let &equalprg = equalprg_save - " -endfunction " --------- end of function C_ProtoInsert ---------- -" -"------------------------------------------------------------------------------ -" C_ProtoClear : clear {{{1 -"------------------------------------------------------------------------------ -function! C_ProtoClear () - if s:C_PrototypeCounter > 0 - let s:C_Prototype = [] - let s:C_PrototypeShow = [] - let s:C_PrototypeCounter = 0 - echo 'prototypes deleted' - else - echo "currently no prototypes available" - endif -endfunction " --------- end of function C_ProtoClear ---------- -" -"------------------------------------------------------------------------------ -" C_ProtoShow : show {{{1 -"------------------------------------------------------------------------------ -function! C_ProtoShow () - if s:C_PrototypeCounter > 0 - for protytype in s:C_PrototypeShow - echo protytype - endfor - else - echo "currently no prototypes available" - endif -endfunction " --------- end of function C_ProtoShow ---------- -" -"------------------------------------------------------------------------------ -" C_EscapeBlanks : C_EscapeBlanks {{{1 -"------------------------------------------------------------------------------ -function! C_EscapeBlanks (arg) - return substitute( a:arg, " ", "\\ ", "g" ) -endfunction " --------- end of function C_EscapeBlanks ---------- -" -"------------------------------------------------------------------------------ -" C_Compile : C_Compile {{{1 -"------------------------------------------------------------------------------ -" The standard make program 'make' called by vim is set to the C or C++ compiler -" and reset after the compilation (set makeprg=... ). -" The errorfile created by the compiler will now be read by gvim and -" the commands cl, cp, cn, ... can be used. -"------------------------------------------------------------------------------ -function! C_Compile () - - let l:currentbuffer = bufname("%") - let s:C_HlMessage = "" - exe ":cclose" - let Sou = expand("%:p") " name of the file in the current buffer - let Obj = expand("%:p:r").s:C_ObjExtension " name of the object - let SouEsc= escape( Sou, s:escfilename ) - let ObjEsc= escape( Obj, s:escfilename ) - - " update : write source file if necessary - exe ":update" - - " compilation if object does not exist or object exists and is older then the source - if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou))) - " &makeprg can be a string containing blanks - let makeprg_saved='"'.&makeprg.'"' - if expand("%:e") == s:C_CExtension - exe "set makeprg=".s:C_CCompiler - else - exe "set makeprg=".s:C_CplusCompiler - endif - " - " COMPILATION - " - if s:MSWIN - exe "make ".s:C_CFlags." \"".SouEsc."\" -o \"".ObjEsc."\"" - else - exe "make ".s:C_CFlags." ".SouEsc." -o ".ObjEsc - endif - exe "set makeprg=".makeprg_saved - " - " open error window if necessary - exe ":botright cwindow" - else - let s:C_HlMessage = " '".Obj."' is up to date " - endif - -endfunction " ---------- end of function C_Compile ---------- -" -"------------------------------------------------------------------------------ -" C_Link : C_Link {{{1 -"------------------------------------------------------------------------------ -" The standard make program which is used by gvim is set to the compiler -" (for linking) and reset after linking. -" -" calls: C_Compile -"------------------------------------------------------------------------------ -function! C_Link () - - call C_Compile() - - let s:C_HlMessage = "" - let Sou = expand("%:p") " name of the file in the current buffer - let Obj = expand("%:p:r").s:C_ObjExtension " name of the object file - let Exe = expand("%:p:r").s:C_ExeExtension " name of the executable - let ObjEsc= escape( Obj, s:escfilename ) - let ExeEsc= escape( Exe, s:escfilename ) - - " no linkage if: - " executable exists - " object exists - " source exists - " executable newer then object - " object newer then source - - if filereadable(Exe) && - \ filereadable(Obj) && - \ filereadable(Sou) && - \ (getftime(Exe) >= getftime(Obj)) && - \ (getftime(Obj) >= getftime(Sou)) - let s:C_HlMessage = " '".Exe."' is up to date " - return - endif - - " linkage if: - " object exists - " source exists - " object newer then source - - if filereadable(Obj) && (getftime(Obj) >= getftime(Sou)) - let makeprg_saved='"'.&makeprg.'"' - if expand("%:e") == s:C_CExtension - exe "set makeprg=".s:C_CCompiler - else - exe "set makeprg=".s:C_CplusCompiler - endif - let v:statusmsg="" - if s:MSWIN - silent exe "make ".s:C_LFlags." ".s:C_Libs." -o \"".ExeEsc."\" \"".ObjEsc."\"" - else - silent exe "make ".s:C_LFlags." ".s:C_Libs." -o ".ExeEsc." ".ObjEsc - endif - if v:statusmsg != "" - let s:C_HlMessage = v:statusmsg - endif - exe "set makeprg=".makeprg_saved - endif -endfunction " ---------- end of function C_Link ---------- -" -"------------------------------------------------------------------------------ -" C_Run : C_Run {{{1 -" calls: C_Link -"------------------------------------------------------------------------------ -" -let s:C_OutputBufferName = "C-Output" -let s:C_OutputBufferNumber = -1 -" -function! C_Run () -" - let Sou = expand("%:p") " name of the source file - let Obj = expand("%:p:r").s:C_ObjExtension " name of the object file - let Exe = expand("%:p:r").s:C_ExeExtension " name of the executable - let ExeEsc = escape( Exe, s:escfilename ) " name of the executable, escaped - " - let l:arguments = exists("b:C_CmdLineArgs") ? b:C_CmdLineArgs : '' - " - let l:currentbuffer = bufname("%") - " - "============================================================================== - " run : run from the vim command line - "============================================================================== - if s:C_OutputGvim == "vim" - " - silent call C_Link() - " - if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) - if s:MSWIN - exe "!\"".ExeEsc."\" ".l:arguments - else - exe "!".ExeEsc." ".l:arguments - endif - else - echomsg "file ".Exe." does not exist / is not executable" - endif - - endif - " - "============================================================================== - " run : redirect output to an output buffer - "============================================================================== - if s:C_OutputGvim == "buffer" - let l:currentbuffernr = bufnr("%") - " - silent call C_Link() - " - if l:currentbuffer == bufname("%") - " - " - if bufloaded(s:C_OutputBufferName) != 0 && bufwinnr(s:C_OutputBufferNumber)!=-1 - exe bufwinnr(s:C_OutputBufferNumber) . "wincmd w" - " buffer number may have changed, e.g. after a 'save as' - if bufnr("%") != s:C_OutputBufferNumber - let s:C_OutputBufferNumber = bufnr(s:C_OutputBufferName) - exe ":bn ".s:C_OutputBufferNumber - endif - else - silent exe ":new ".s:C_OutputBufferName - let s:C_OutputBufferNumber=bufnr("%") - setlocal buftype=nofile - setlocal noswapfile - setlocal syntax=none - setlocal bufhidden=delete - setlocal tabstop=8 - endif - " - " run programm - " - setlocal modifiable - if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) - if s:MSWIN - exe "%!\"".ExeEsc."\" ".l:arguments - else - exe "%!".ExeEsc." ".l:arguments - endif - endif - setlocal nomodifiable - " - if winheight(winnr()) >= line("$") - exe bufwinnr(l:currentbuffernr) . "wincmd w" - endif - " - endif - endif - " - "============================================================================== - " run : run in a detached xterm (not available for MS Windows) - "============================================================================== - if s:C_OutputGvim == "xterm" - " - silent call C_Link() - " - if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) - if s:MSWIN - exe "!\"".ExeEsc."\" ".l:arguments - else - silent exe '!xterm -title '.ExeEsc.' '.s:C_XtermDefaults.' -e '.s:C_Wrapper.' '.ExeEsc.' '.l:arguments.' &' - :redraw! - endif - endif - endif - -endfunction " ---------- end of function C_Run ---------- -" -"------------------------------------------------------------------------------ -" C_Arguments : Arguments for the executable {{{1 -"------------------------------------------------------------------------------ -function! C_Arguments () - let Exe = expand("%:r").s:C_ExeExtension - if Exe == "" - redraw - echohl WarningMsg | echo " no file name " | echohl None - return - endif - let prompt = 'command line arguments for "'.Exe.'" : ' - if exists("b:C_CmdLineArgs") - let b:C_CmdLineArgs= C_Input( prompt, b:C_CmdLineArgs ) - else - let b:C_CmdLineArgs= C_Input( prompt , "" ) - endif -endfunction " ---------- end of function C_Arguments ---------- -" -"---------------------------------------------------------------------- -" C_Toggle_Gvim_Xterm : change output destination {{{1 -"---------------------------------------------------------------------- -function! C_Toggle_Gvim_Xterm () - - if s:C_OutputGvim == "vim" - if has("gui_running") - exe "aunmenu ".s:C_Root.'&Run.&output:\ VIM->buffer->xterm' - exe "amenu ".s:C_Root.'&Run.&output:\ BUFFER->xterm->vim :call C_Toggle_Gvim_Xterm()' - endif - let s:C_OutputGvim = "buffer" - else - if s:C_OutputGvim == "buffer" - if has("gui_running") - exe "aunmenu ".s:C_Root.'&Run.&output:\ BUFFER->xterm->vim' - if (!s:MSWIN) - exe "amenu ".s:C_Root.'&Run.&output:\ XTERM->vim->buffer :call C_Toggle_Gvim_Xterm()' - else - exe "amenu ".s:C_Root.'&Run.&output:\ VIM->buffer->xterm :call C_Toggle_Gvim_Xterm()' - endif - endif - if (!s:MSWIN) && (s:C_Display != '') - let s:C_OutputGvim = "xterm" - else - let s:C_OutputGvim = "vim" - end - else - " ---------- output : xterm -> gvim - if has("gui_running") - exe "aunmenu ".s:C_Root.'&Run.&output:\ XTERM->vim->buffer' - exe "amenu ".s:C_Root.'&Run.&output:\ VIM->buffer->xterm :call C_Toggle_Gvim_Xterm()' - endif - let s:C_OutputGvim = "vim" - endif - endif - echomsg "output destination is '".s:C_OutputGvim."'" - -endfunction " ---------- end of function C_Toggle_Gvim_Xterm ---------- -" -"------------------------------------------------------------------------------ -" C_XtermSize : xterm geometry {{{1 -"------------------------------------------------------------------------------ -function! C_XtermSize () - let regex = '-geometry\s\+\d\+x\d\+' - let geom = matchstr( s:C_XtermDefaults, regex ) - let geom = matchstr( geom, '\d\+x\d\+' ) - let geom = substitute( geom, 'x', ' ', "" ) - let answer= C_Input(" xterm size (COLUMNS LINES) : ", geom ) - while match(answer, '^\s*\d\+\s\+\d\+\s*$' ) < 0 - let answer= C_Input(" + xterm size (COLUMNS LINES) : ", geom ) - endwhile - let answer = substitute( answer, '\s\+', "x", "" ) " replace inner whitespaces - let s:C_XtermDefaults = substitute( s:C_XtermDefaults, regex, "-geometry ".answer , "" ) -endfunction " ---------- end of function C_XtermSize ---------- -" -"------------------------------------------------------------------------------ -" C_MakeArguments : run make(1) {{{1 -"------------------------------------------------------------------------------ - -let s:C_MakeCmdLineArgs = "" " command line arguments for Run-make; initially empty - -function! C_MakeArguments () - let s:C_MakeCmdLineArgs= C_Input("make command line arguments : ",s:C_MakeCmdLineArgs) -endfunction " ---------- end of function C_MakeArguments ---------- -" -function! C_Make() - " update : write source file if necessary - exe ":update" - " run make - exe ":!make ".s:C_MakeCmdLineArgs -endfunction " ---------- end of function C_Make ---------- -" -"------------------------------------------------------------------------------ -" C_SplintArguments : splint command line arguments {{{1 -"------------------------------------------------------------------------------ -function! C_SplintArguments () - if s:C_SplintIsExecutable==0 - let s:C_HlMessage = ' Splint is not executable or not installed! ' - else - let prompt = 'Splint command line arguments for "'.expand("%").'" : ' - if exists("b:C_SplintCmdLineArgs") - let b:C_SplintCmdLineArgs= C_Input( prompt, b:C_SplintCmdLineArgs ) - else - let b:C_SplintCmdLineArgs= C_Input( prompt , "" ) - endif - endif -endfunction " ---------- end of function C_SplintArguments ---------- -" -"------------------------------------------------------------------------------ -" C_SplintCheck : run splint(1) {{{1 -"------------------------------------------------------------------------------ -function! C_SplintCheck () - if s:C_SplintIsExecutable==0 - let s:C_HlMessage = ' Splint is not executable or not installed! ' - return - endif - let l:currentbuffer=bufname("%") - if &filetype != "c" && &filetype != "cpp" - let s:C_HlMessage = ' "'.l:currentbuffer.'" seems not to be a C/C++ file ' - return - endif - let s:C_HlMessage = "" - exe ":cclose" - silent exe ":update" - let makeprg_saved='"'.&makeprg.'"' - " Windows seems to need this: - if s:MSWIN - :compiler splint - endif - :set makeprg=splint - " - let l:arguments = exists("b:C_SplintCmdLineArgs") ? b:C_SplintCmdLineArgs : ' ' - silent exe "make ".l:arguments." ".escape(l:currentbuffer,s:escfilename) - exe "set makeprg=".makeprg_saved - exe ":botright cwindow" - " - " message in case of success - " - if l:currentbuffer == bufname("%") - let s:C_HlMessage = " Splint --- no warnings for : ".l:currentbuffer - endif -endfunction " ---------- end of function C_SplintCheck ---------- -" -"------------------------------------------------------------------------------ -" C_CodeCheckArguments : CodeCheck command line arguments {{{1 -"------------------------------------------------------------------------------ -function! C_CodeCheckArguments () - if s:C_CodeCheckIsExecutable==0 - let s:C_HlMessage = ' CodeCheck is not executable or not installed! ' - else - let prompt = 'CodeCheck command line arguments for "'.expand("%").'" : ' - if exists("b:C_CodeCheckCmdLineArgs") - let b:C_CodeCheckCmdLineArgs= C_Input( prompt, b:C_CodeCheckCmdLineArgs ) - else - let b:C_CodeCheckCmdLineArgs= C_Input( prompt , s:C_CodeCheckOptions ) - endif - endif -endfunction " ---------- end of function C_CodeCheckArguments ---------- -" -"------------------------------------------------------------------------------ -" C_CodeCheck : run CodeCheck {{{1 -"------------------------------------------------------------------------------ -function! C_CodeCheck () - if s:C_CodeCheckIsExecutable==0 - let s:C_HlMessage = ' CodeCheck is not executable or not installed! ' - return - endif - let l:currentbuffer=bufname("%") - if &filetype != "c" && &filetype != "cpp" - let s:C_HlMessage = ' "'.l:currentbuffer.'" seems not to be a C/C++ file ' - return - endif - let s:C_HlMessage = "" - exe ":cclose" - silent exe ":update" - let makeprg_saved='"'.&makeprg.'"' - exe "set makeprg=".s:C_CodeCheckExeName - " - " match the splint error messages (quickfix commands) - " ignore any lines that didn't match one of the patterns - " - :setlocal errorformat=%f(%l)%m - " - let l:arguments = exists("b:C_CodeCheckCmdLineArgs") ? b:C_CodeCheckCmdLineArgs : "" - if l:arguments == "" - let l:arguments = s:C_CodeCheckOptions - endif - exe ":make ".l:arguments." ".escape( l:currentbuffer, s:escfilename ) - exe ':setlocal errorformat=' - exe "set makeprg=".makeprg_saved - exe ":botright cwindow" - " - " message in case of success - " - if l:currentbuffer == bufname("%") - let s:C_HlMessage = " CodeCheck --- no warnings for : ".l:currentbuffer - endif -endfunction " ---------- end of function C_CodeCheck ---------- -" -"------------------------------------------------------------------------------ -" C_Indent : run indent(1) {{{1 -"------------------------------------------------------------------------------ -" -function! C_Indent ( mode ) - if !executable("indent") - let s:C_HlMessage = ' indent 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 = "" - - if a:mode=="a" - if C_Input("indent whole file [y/n/Esc] : ", "y" ) != "y" - return - endif - exe ":update" - if has("MSWIN") - silent exe ":%!indent" - else - silent exe ":%!indent 2> ".s:C_IndentErrorLog - endif - let s:C_HlMessage = ' File "'.l:currentbuffer.'" reformatted.' - endif - - if a:mode=="v" - if has("MSWIN") - silent exe ":'<,'>!indent" - else - silent exe ":'<,'>!indent 2> ".s:C_IndentErrorLog - endif - let s:C_HlMessage = ' File "'.l:currentbuffer.'" (lines '.line("'<").'-'.line("'>").') reformatted. ' - endif - - if v:shell_error != 0 - let s:C_HlMessage = ' Indent reported an error when processing file "'.l:currentbuffer.'". ' - endif - -endfunction " ---------- end of function C_Indent ---------- -" -"------------------------------------------------------------------------------ -" C_HlMessage : indent message {{{1 -"------------------------------------------------------------------------------ -function! C_HlMessage () - echohl Search - echo s:C_HlMessage - echohl None -endfunction " ---------- end of function C_HlMessage ---------- -" -"------------------------------------------------------------------------------ -" C_Settings : settings {{{1 -"------------------------------------------------------------------------------ -function! C_Settings () - let txt = " C/C++-Support settings\n\n" - let txt = txt.' author : "'.s:C_Macro['|AUTHOR|']."\"\n" - let txt = txt.' initials : "'.s:C_Macro['|AUTHORREF|']."\"\n" - let txt = txt.' email : "'.s:C_Macro['|EMAIL|']."\"\n" - let txt = txt.' company : "'.s:C_Macro['|COMPANY|']."\"\n" - let txt = txt.' project : "'.s:C_Macro['|PROJECT|']."\"\n" - let txt = txt.' copyright holder : "'.s:C_Macro['|COPYRIGHTHOLDER|']."\"\n" - let txt = txt.' C / C++ compiler : '.s:C_CCompiler.' / '.s:C_CplusCompiler."\n" - let txt = txt.' C file extension : "'.s:C_CExtension.'" (everything else is C++)'."\n" - let txt = txt.' extension for objects : "'.s:C_ObjExtension."\"\n" - let txt = txt.'extension for executables : "'.s:C_ExeExtension."\"\n" - let txt = txt.' compiler flags : "'.s:C_CFlags."\"\n" - let txt = txt.' linker flags : "'.s:C_LFlags."\"\n" - let txt = txt.' libraries : "'.s:C_Libs."\"\n" - let txt = txt.' code snippet directory : '.s:C_CodeSnippets."\n" - if s:installation == 'system' - let txt = txt.'global template directory : '.s:C_GlobalTemplateDir."\n" - if filereadable( s:C_LocalTemplateFile ) - let txt = txt.' local template directory : '.s:C_LocalTemplateDir."\n" - endif - else - let txt = txt.' local template directory : '.s:C_GlobalTemplateDir."\n" - endif - if !s:MSWIN - let txt = txt.' xterm defaults : '.s:C_XtermDefaults."\n" - endif - " ----- dictionaries ------------------------ - if g:C_Dictionary_File != "" - let ausgabe= substitute( g:C_Dictionary_File, ",", ",\n + ", "g" ) - let txt = txt." dictionary file(s) : ".ausgabe."\n" - endif - let txt = txt.' current output dest. : '.s:C_OutputGvim."\n" - " ----- splint ------------------------------ - if s:C_SplintIsExecutable==1 - if exists("b:C_SplintCmdLineArgs") - let ausgabe = b:C_SplintCmdLineArgs - else - let ausgabe = "" - endif - let txt = txt." splint options(s) : ".ausgabe."\n" - endif - " ----- code check -------------------------- - if s:C_CodeCheckIsExecutable==1 - if exists("b:C_CodeCheckCmdLineArgs") - let ausgabe = b:C_CodeCheckCmdLineArgs - else - let ausgabe = s:C_CodeCheckOptions - endif - let txt = txt."CodeCheck (TM) options(s) : ".ausgabe."\n" - endif - let txt = txt."\n" - let txt = txt."__________________________________________________________________________\n" - let txt = txt." C/C++-Support, Version ".g:C_Version." / Dr.-Ing. Fritz Mehner / mehner@fh-swf.de\n\n" - echo txt -endfunction " ---------- end of function C_Settings ---------- -" -"------------------------------------------------------------------------------ -" C_Hardcopy : hardcopy {{{1 -" MSWIN : a printer dialog is displayed -" other : print PostScript to file -"------------------------------------------------------------------------------ -function! C_Hardcopy (arg1) - let Sou = expand("%") - if Sou == "" - redraw - echohl WarningMsg | echo " no file name " | echohl None - return - endif - let Sou = escape(Sou,s:escfilename) " name of the file in the current buffer - let old_printheader=&printheader - exe ':set printheader='.s:C_Printheader - " ----- normal mode ---------------- - if a:arg1=="n" - silent exe "hardcopy > ".Sou.".ps" - if !s:MSWIN - echo "file \"".Sou."\" printed to \"".Sou.".ps\"" - endif - endif - " ----- visual mode ---------------- - if a:arg1=="v" - silent exe "*hardcopy > ".Sou.".ps" - if !s:MSWIN - echo "file \"".Sou."\" (lines ".line("'<")."-".line("'>").") printed to \"".Sou.".ps\"" - endif - endif - exe ':set printheader='.escape( old_printheader, ' %' ) -endfunction " ---------- end of function C_Hardcopy ---------- -" -"------------------------------------------------------------------------------ -" C_HelpCsupport : help csupport {{{1 -"------------------------------------------------------------------------------ -function! C_HelpCsupport () - try - :help csupport - catch - exe ':helptags '.s:plugin_dir.'doc' - :help csupport - endtry -endfunction " ---------- end of function C_HelpCsupport ---------- - -"------------------------------------------------------------------------------ -" C_CreateGuiMenus {{{1 -"------------------------------------------------------------------------------ -let s:C_MenuVisible = 0 " state variable controlling the C-menus -" -function! C_CreateGuiMenus () - if s:C_MenuVisible != 1 - 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_MenuVisible = 1 - endif -endfunction " ---------- end of function C_CreateGuiMenus ---------- - -"------------------------------------------------------------------------------ -" C_ToolMenu {{{1 -"------------------------------------------------------------------------------ -function! C_ToolMenu () - amenu 40.1000 &Tools.-SEP100- : - amenu 40.1030 &Tools.Load\ C\ Support :call C_CreateGuiMenus() -endfunction " ---------- end of function C_ToolMenu ---------- - -"------------------------------------------------------------------------------ -" C_RemoveGuiMenus {{{1 -"------------------------------------------------------------------------------ -function! C_RemoveGuiMenus () - if s:C_MenuVisible == 1 - if s:C_Root == "" - aunmenu Comments - aunmenu Statements - aunmenu Preprocessor - aunmenu Idioms - aunmenu Snippets - aunmenu C++ - aunmenu Run - else - exe "aunmenu ".s:C_Root - endif - " - aunmenu &Tools.Unload\ C\ Support - call C_ToolMenu() - " - let s:C_MenuVisible = 0 - endif -endfunction " ---------- end of function C_RemoveGuiMenus ---------- - -"------------------------------------------------------------------------------ -" C_RebuildTemplates -" rebuild commands and the menu from the (changed) template file -"------------------------------------------------------------------------------ -function! C_RebuildTemplates () - let s:C_Template = {} - let s:C_FileVisited = [] - call C_ReadTemplates(s:C_GlobalTemplateFile) - echomsg "templates rebuilt from '".s:C_GlobalTemplateFile."'" - " - if s:installation == 'system' && filereadable( s:C_LocalTemplateFile ) - call C_ReadTemplates( s:C_LocalTemplateFile ) - echomsg " and from '".s:C_LocalTemplateFile."'" - endif -endfunction " ---------- end of function C_RebuildTemplates ---------- - -"------------------------------------------------------------------------------ -" C_ReadTemplates -" read the template file(s), build the macro and the template dictionary -" -"------------------------------------------------------------------------------ -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 = '' - for line in readfile( a:templatefile ) - " if not a comment : - if line !~ '^\$' - " - " 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] = val - endif - continue " next line - endif - " - " template header - " - let name = matchstr( line, s:C_TemplateLineRegex ) - " - if name != '' - let part = split( name, '\s*==\s*') - let item = part[0] - if has_key( s:C_Template, item ) && s:C_TemplateOverwrittenMsg == 'yes' - echomsg "existing C/C++ template '".item."' overwritten" - endif - let s:C_Template[item] = '' - let skipmacros = 1 - " - let s:C_Attribute[item] = 'below' - if has_key( s:Attribute, get( part, 1, 'NONE' ) ) - let s:C_Attribute[item] = part[1] - endif - else - if item != '' - let s:C_Template[item] = s:C_Template[item].line."\n" - endif - endif - endif - endfor - - call C_SetSmallCommentStyle() -endfunction " ---------- end of function C_ReadTemplates ---------- - -"------------------------------------------------------------------------------ -" C_InsertTemplate -" insert a template from the template dictionary -" do macro expansion -"------------------------------------------------------------------------------ -function! C_InsertTemplate ( key, ... ) - - if !has_key( s:C_Template, a:key ) - echomsg "Template '".a:key."' not found. Please check your template file in '".s:C_GlobalTemplateDir."'" - return - 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 val == "" - return - endif - let val = C_ExpandSingleMacro( val, '', '' ) - - if mode == 'below' - let pos1 = line(".")+1 - put =val - let pos2 = line(".") - " proper indenting - exe ":".pos1 - let ins = pos2-pos1+1 - exe "normal ".ins."==" - endif - - if mode == 'above' - let pos1 = line(".") - put! =val - let pos2 = line(".") - " proper indenting - exe ":".pos1 - let ins = pos2-pos1+1 - exe "normal ".ins."==" - endif - - if mode == 'start' - normal gg - let pos1 = 1 - put! =val - let pos2 = line(".") - " proper indenting - exe ":".pos1 - let ins = pos2-pos1+1 - exe "normal ".ins."==" - endif - - if mode == 'append' - let pos1 = line(".") - put =val - let pos2 = line(".")-1 - exe ":".pos1 - :join! - endif - - if mode == 'insert' - let val = substitute( val, '\n$', '', '' ) - let pos1 = line(".") - let pos2 = pos1 + count( split(val,'\zs'), "\n" ) - exe "normal a".val - endif - " - else - " - " ===== visual mode =============================== - " - if a:1 == 'v' - let val = C_ExpandUserMacros (a:key) - if val == "" - return - endif - - let part = split( val, '' ) - if len(part) < 2 - let part = [ "" ] + part - echomsg 'SPLIT missing in template '.a:key - endif - - 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 - endif - - " restore formatter programm - let &equalprg = equalprg_save - - "------------------------------------------------------------------------------ - " position the cursor - "------------------------------------------------------------------------------ - exe ":".pos1 - let mtch = search( '', "c", pos2 ) - if mtch != 0 - if matchend( getline(mtch) ,'') == match( getline(mtch) ,"$" ) - normal 8x - :startinsert! - else - normal 8x - :startinsert - endif - else - " to the end of the block; needed for repeated inserts - if mode == 'below' - exe ":".pos2 - endif - endif - -endfunction " ---------- end of function C_InsertTemplate ---------- - -"------------------------------------------------------------------------------ -" C_ExpandUserMacros -"------------------------------------------------------------------------------ -function! C_ExpandUserMacros ( key ) - - let template = s:C_Template[ a:key ] - 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_InsertDateAndTime('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_InsertDateAndTime('t') - let s:C_Macro['|YEAR|'] = C_InsertDateAndTime('y') - - "------------------------------------------------------------------------------ - " look for replacements - "------------------------------------------------------------------------------ - while match( template, s:C_ExpansionRegex ) != -1 - let macro = matchstr( template, s:C_ExpansionRegex ) - let replacement = substitute( macro, '?', '', '' ) - let template = substitute( template, macro, replacement, "g" ) - - let match = matchlist( macro, s:C_ExpansionRegex ) - - if match[1] != '' - let macroname = '|'.match[1].'|' - " - " notify flag action, if any - let flagaction = '' - if has_key( s:C_MacroFlag, match[2] ) - let flagaction = ' (-> '.s:C_MacroFlag[ match[2] ].')' - endif - " - " ask for a replacement - if has_key( s:C_Macro, macroname ) - let name = C_Input( match[1].flagaction.' : ', C_ApplyFlag( s:C_Macro[macroname], match[2] ) ) - else - let name = C_Input( match[1].flagaction.' : ', '' ) - endif - if name == "" - return "" - endif - " - " keep the modified name - let s:C_Macro[macroname] = C_ApplyFlag( name, match[2] ) - endif - endwhile - - "------------------------------------------------------------------------------ - " do the actual macro expansion - " loop over the macros found in the template - "------------------------------------------------------------------------------ - while match( template, s:C_NonExpansionRegex ) != -1 - - let macro = matchstr( template, s:C_NonExpansionRegex ) - let match = matchlist( macro, s:C_NonExpansionRegex ) - - if match[1] != '' - let macroname = '|'.match[1].'|' - - if has_key( s:C_Macro, macroname ) - "------------------------------------------------------------------------------- - " check for recursion - "------------------------------------------------------------------------------- - if has_key( s:C_ExpansionCounter, macroname ) - let s:C_ExpansionCounter[macroname] += 1 - else - let s:C_ExpansionCounter[macroname] = 0 - endif - if s:C_ExpansionCounter[macroname] >= s:C_ExpansionLimit - echomsg " recursion terminated for recursive macro ".macroname - return template - endif - "------------------------------------------------------------------------------- - " replace - "------------------------------------------------------------------------------- - let replacement = C_ApplyFlag( s:C_Macro[macroname], match[2] ) - let template = substitute( template, macro, replacement, "g" ) - else - " - " macro not yet defined - let s:C_Macro['|'.match[1].'|'] = '' - endif - endif - - endwhile - - return template -endfunction " ---------- end of function C_ExpandUserMacros ---------- - -"------------------------------------------------------------------------------ -" C_ApplyFlag -"------------------------------------------------------------------------------ -function! C_ApplyFlag ( val, flag ) - " - " l : lowercase - if a:flag == ':l' - return tolower(a:val) - end - " - " u : uppercase - if a:flag == ':u' - return toupper(a:val) - end - " - " c : capitalize - if a:flag == ':c' - return toupper(a:val[0]).a:val[1:] - end - " - " L : legalized name - if a:flag == ':L' - return C_LegalizeName(a:val) - end - " - " flag not valid - return a:val -endfunction " ---------- end of function C_ApplyFlag ---------- -" -"------------------------------------------------------------------------------ -" C_ExpandSingleMacro -"------------------------------------------------------------------------------ -function! C_ExpandSingleMacro ( val, macroname, replacement ) - return substitute( a:val, escape(a:macroname, '$' ), a:replacement, "g" ) -endfunction " ---------- end of function C_ExpandSingleMacro ---------- - -"------------------------------------------------------------------------------ -" C_SetSmallCommentStyle -"------------------------------------------------------------------------------ -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 -"------------------------------------------------------------------------------ -function! C_InsertMacroValue ( key ) - if col(".") > 1 - exe 'normal a'.s:C_Macro['|'.a:key.'|'] - else - exe 'normal i'.s:C_Macro['|'.a:key.'|'] - end -endfunction " ---------- end of function C_InsertMacroValue ---------- - -"------------------------------------------------------------------------------ -" date and time -"------------------------------------------------------------------------------ -function! C_InsertDateAndTime ( format ) - if a:format == 'd' - return strftime( s:C_FormatDate ) - end - if a:format == 't' - return strftime( s:C_FormatTime ) - end - if a:format == 'dt' - return strftime( s:C_FormatDate ).' '.strftime( s:C_FormatTime ) - end - if a:format == 'y' - return strftime( s:C_FormatYear ) - end -endfunction " ---------- end of function C_InsertDateAndTime ---------- - -"------------------------------------------------------------------------------ -" show / hide the c-support menus -" define key mappings (gVim only) -"------------------------------------------------------------------------------ -" -if has("gui_running") - " - call C_ToolMenu() - " - if s:C_LoadMenus == 'yes' - call C_CreateGuiMenus() - endif - " - nmap lcs :call C_CreateGuiMenus() - nmap ucs :call C_RemoveGuiMenus() - " -endif - -"------------------------------------------------------------------------------ -" Automated header insertion -" Local settings for the quickfix window -"------------------------------------------------------------------------------ -if has("autocmd") - " - " Automated header insertion (suffixes from the gcc manual) - " - autocmd BufNewFile * if (&filetype=='cpp' || &filetype=='c') | - \ call C_InsertTemplate("comment.file-description") | endif - " - " *.h has filetype 'cpp' by default; this can be changed to 'c' : - " - if s:C_TypeOfH=='c' - autocmd BufNewFile,BufEnter *.h :set filetype=c - endif - " - " C/C++ source code files which should not be preprocessed. - " - autocmd BufNewFile,BufRead *.i :set filetype=c - autocmd BufNewFile,BufRead *.ii :set filetype=cpp - " - " Wrap error descriptions in the quickfix window. - " - autocmd BufReadPost quickfix setlocal wrap | setlocal linebreak - " -endif " has("autocmd") -" -"------------------------------------------------------------------------------ -" READ THE TEMPLATE FILES -"------------------------------------------------------------------------------ -call C_ReadTemplates(s:C_GlobalTemplateFile) -if s:installation == 'system' && filereadable( s:C_LocalTemplateFile ) - call C_ReadTemplates( s:C_LocalTemplateFile ) -endif - -" -"===================================================================================== -" vim: tabstop=2 shiftwidth=2 foldmethod=marker diff --git a/dot_vim/plugin/filebrowser.vim b/dot_vim/plugin/filebrowser.vim deleted file mode 100644 index e9de049..0000000 --- a/dot_vim/plugin/filebrowser.vim +++ /dev/null @@ -1,251 +0,0 @@ -" filebrowser.vim: utility file for vim 6.2+ -" -" Copyright: Srinath Avadhanula -" Parts of this file are taken from explorer.vim which is a plugin file -" distributed with vim under the Vim charityware license. -" License: distributed under the Vim charityware license. -" -" Settings: -" FB_CallBackFunction: the function name which gets called when the user -" presses on a file-name in the file browser. -" FB_AllowRegexp: A filename has to match this regexp to be displayed. -" FB_RejectRegexp: If a filename matches this regexp, then its not displayed. -" (Both these regexps are '' by default which means no filtering is -" done). - -" line continuation used here. -let s:save_cpo = &cpo -set cpo&vim - -"====================================================================== -" Globally visible functions (API) -"====================================================================== -" FB_OpenFileBrowser: opens a new buffer and displays the file list {{{ -" Description: -function! FB_OpenFileBrowser(dir) - if !isdirectory(a:dir) - return - endif - if exists('s:FB_BufferNumber') - if bufwinnr(s:FB_BufferNumber) != -1 - execute bufwinnr(s:FB_BufferNumber).' wincmd w' - return - endif - execute 'aboveleft split #'.s:FB_BufferNumber - else - aboveleft split __Choose_File__ - let s:FB_BufferNumber = bufnr('%') - endif - call FB_DisplayFiles(a:dir) -endfunction " }}} -" FB_DisplayFiles: displays the files in a given directory {{{ -" Description: -" Call this function only when the cursor is in a temporary buffer -function! FB_DisplayFiles(dir) - if !isdirectory(a:dir) - return - endif - call s:FB_SetSilentSettings() - " make this a "scratch" buffer - call s:FB_SetScratchSettings() - - let allowRegexp = s:FB_GetVar('FB_AllowRegexp', '') - let rejectRegexp = s:FB_GetVar('FB_RejectRegexp', '') - - " change to the directory to make processing simpler. - execute "lcd ".a:dir - " delete everything in the buffer. - " IMPORTANT: we need to be in a scratch buffer - 0,$ d_ - - let allFilenames = glob('*') - let dispFiles = "" - let subDirs = "../\n" - - let i = 1 - while 1 - let filename = s:FB_Strntok(allFilenames, "\n", i) - if filename == '' - break - endif - if isdirectory(filename) - let subDirs = subDirs.filename."/\n" - else - if allowRegexp != '' && filename !~ allowRegexp - elseif rejectRegexp != '' && filename =~ rejectRegexp - else - let dispFiles = dispFiles.filename."\n" - endif - endif - let i = i + 1 - endwhile - 0put!=dispFiles - 0put!=subDirs - " delte the last empty line resulting from the put - $ d_ - - call s:FB_SetHighlighting() - call s:FB_DisplayHelp() - call s:FB_SetMaps() - - " goto the first file/directory - 0 - call search('^"=', 'w') - normal! j: - - set nomodified nomodifiable - - call s:FB_ResetSilentSettings() -endfunction " }}} -" FB_SetVar: sets script local variables from outside this script {{{ -" Description: -function! FB_SetVar(varname, value) - let s:{a:varname} = a:value -endfunction " }}} - -" FB_SetHighlighting: sets syntax highlighting for the buffer {{{ -" Description: -" Origin: from explorer.vim in vim -function! FB_SetHighlighting() - " Set up syntax highlighting - " Something wrong with the evaluation of the conditional though... - if has("syntax") && exists("g:syntax_on") && !has("syntax_items") - syn match browseSynopsis "^\"[ -].*" - syn match browseDirectory "[^\"].*/ " - syn match browseDirectory "[^\"].*/$" - syn match browseCurDir "^\"= .*$" - syn match browseSortBy "^\" Sorted by .*$" contains=browseSuffixInfo - syn match browseSuffixInfo "(.*)$" contained - syn match browseFilter "^\" Not Showing:.*$" - syn match browseFiletime "\d\+$" - - "hi def link browseSynopsis PreProc - hi def link browseSynopsis Special - hi def link browseDirectory Directory - hi def link browseCurDir Statement - hi def link browseSortBy String - hi def link browseSuffixInfo Type - hi def link browseFilter String - hi def link browseFiletime Ignore - hi def link browseSuffixes Type - endif -endfunction " }}} -" FB_SetMaps: sets buffer local maps {{{ -" Description: -function! FB_SetMaps() - nnoremap q :bdelete - nnoremap C :call FB_DisplayFiles(getcwd()) - nnoremap :bdelete - nnoremap :call FB_EditEntry() - nnoremap ? :call FB_ToggleHelp() - - " lock the user in this window - nnoremap -endfunction " }}} -" FB_SetSilentSettings: some settings which make things silent {{{ -" Description: -" Origin: from explorer.vim distributed with vim. -function! FB_SetSilentSettings() - let s:save_report=&report - let s:save_showcmd = &sc - set report=10000 noshowcmd -endfunction -" FB_ResetSilentSettings: reset settings set by FB_SetSilentSettings -" Description: -function! FB_ResetSilentSettings() - let &report=s:save_report - let &showcmd = s:save_showcmd -endfunction " }}} -" FB_SetScratchSettings: makes the present buffer a scratch buffer {{{ -" Description: -function! FB_SetScratchSettings() - " Turn off the swapfile, set the buffer type so that it won't get - " written, and so that it will get deleted when it gets hidden. - setlocal noreadonly modifiable - setlocal noswapfile - setlocal buftype=nowrite - setlocal bufhidden=delete - " Don't wrap around long lines - setlocal nowrap -endfunction - -" }}} -" FB_ToggleHelp: toggles verbosity of help {{{ -" Description: -function! FB_ToggleHelp() - let s:FB_VerboseHelp = 1 - s:FB_GetVar('FB_VerboseHelp', 0) - - call FB_DisplayFiles('.') -endfunction " }}} -" FB_DisplayHelp: displays a helpful header {{{ -" Description: -function! FB_DisplayHelp() - let verboseHelp = s:FB_GetVar('FB_VerboseHelp', 0) - if verboseHelp - let txt = - \ "\" : on file, choose the file and quit\n" - \ ."\" on dir, enter directory\n" - \ ."\" q/: quit without choosing\n" - \ ."\" C: change directory to getcwd()\n" - \ ."\" ?: toggle help verbosity\n" - \ ."\"= ".getcwd() - else - let txt = "\" ?: toggle help verbosity\n" - \ ."\"= ".getcwd() - endif - 0put!=txt -endfunction " }}} - -" Handles various actions in the file-browser -" FB_EditEntry: handles the user pressing on a line {{{ -" Description: -function! FB_EditEntry() - let line = getline('.') - - if isdirectory(line) - call FB_DisplayFiles(line) - endif - - " If the user has a call back function defined on choosing a file, handle - " it. - let cbf = s:FB_GetVar('FB_CallBackFunction', '') - if cbf != '' && line !~ '^" ' && filereadable(line) - let fname = fnamemodify(line, ':p') - bdelete - - let arguments = s:FB_GetVar('FB_CallBackFunctionArgs', '') - if arguments != '' - let arguments = ','.arguments - endif - call Tex_Debug('arguments = '.arguments, 'fb') - call Tex_Debug("call ".cbf."('".fname."'".arguments.')', 'fb') - exec "call ".cbf."('".fname."'".arguments.')' - endif -endfunction " }}} - -" FB_Strntok (string, tok, n) {{{ -" extract the n^th token from s seperated by tok. -" example: FB_Strntok('1,23,3', ',', 2) = 23 -fun! FB_Strntok(s, tok, n) - return matchstr( a:s.a:tok[0], '\v(\zs([^'.a:tok.']*)\ze['.a:tok.']){'.a:n.'}') -endfun " }}} -" FB_GetVar: gets the most local value of a variable {{{ -function! FB_GetVar(name, default) - if exists('s:'.a:name) - return s:{a:name} - elseif exists('w:'.a:name) - return w:{a:name} - elseif exists('b:'.a:name) - return b:{a:name} - elseif exists('g:'.a:name) - return g:{a:name} - else - return a:default - endif -endfunction - -" }}} - -let &cpo = s:save_cpo - -" vim:fdm=marker:ff=unix:noet:ts=4:sw=4:nowrap diff --git a/dot_vim/plugin/gnupg.vim b/dot_vim/plugin/gnupg.vim deleted file mode 100644 index e2e7665..0000000 --- a/dot_vim/plugin/gnupg.vim +++ /dev/null @@ -1,1226 +0,0 @@ -" Name: gnupg.vim -" Last Change: 2011 Nov 23 -" Maintainer: James McCoy -" Original Author: Markus Braun -" Summary: Vim plugin for transparent editing of gpg encrypted files. -" License: This program is free software; you can redistribute it and/or -" modify it under the terms of the GNU General Public License -" as published by the Free Software Foundation; either version -" 2 of the License, or (at your option) any later version. -" See http://www.gnu.org/copyleft/gpl-2.0.txt -" -" Section: Documentation {{{1 -" -" Description: {{{2 -" -" This script implements transparent editing of gpg encrypted files. The -" filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such -" a file the content is decrypted, when opening a new file the script will -" ask for the recipients of the encrypted file. The file content will be -" encrypted to all recipients before it is written. The script turns off -" viminfo and swapfile to increase security. -" -" Installation: {{{2 -" -" Copy the gnupg.vim file to the $HOME/.vim/plugin directory. -" Refer to ':help add-plugin', ':help add-global-plugin' and ':help -" runtimepath' for more details about Vim plugins. -" -" From "man 1 gpg-agent": -" -" ... -" You should always add the following lines to your .bashrc or whatever -" initialization file is used for all shell invocations: -" -" GPG_TTY=`tty` -" export GPG_TTY -" -" It is important that this environment variable always reflects the out‐ -" put of the tty command. For W32 systems this option is not required. -" ... -" -" Most distributions provide software to ease handling of gpg and gpg-agent. -" Examples are keychain or seahorse. -" -" Commands: {{{2 -" -" :GPGEditRecipients -" Opens a scratch buffer to change the list of recipients. Recipients that -" are unknown (not in your public key) are highlighted and have -" a prepended "!". Closing the buffer makes the changes permanent. -" -" :GPGViewRecipients -" Prints the list of recipients. -" -" :GPGEditOptions -" Opens a scratch buffer to change the options for encryption (symmetric, -" asymmetric, signing). Closing the buffer makes the changes permanent. -" WARNING: There is no check of the entered options, so you need to know -" what you are doing. -" -" :GPGViewOptions -" Prints the list of options. -" -" Variables: {{{2 -" -" g:GPGExecutable -" If set used as gpg executable, otherwise the system chooses what is run -" when "gpg" is called. Defaults to "gpg". -" -" g:GPGUseAgent -" If set to 0 a possible available gpg-agent won't be used. Defaults to 1. -" -" g:GPGPreferSymmetric -" If set to 1 symmetric encryption is preferred for new files. Defaults to 0. -" -" g:GPGPreferArmor -" If set to 1 armored data is preferred for new files. Defaults to 0 -" unless a "*.asc" file is being edited. -" -" g:GPGPreferSign -" If set to 1 signed data is preferred for new files. Defaults to 0. -" -" g:GPGDefaultRecipients -" If set, these recipients are used as defaults when no other recipient is -" defined. This variable is a Vim list. Default is unset. -" -" g:GPGUsePipes -" If set to 1, use pipes instead of temporary files when interacting with -" gnupg. When set to 1, this can cause terminal-based gpg agents to not -" display correctly when prompting for passwords. Defaults to 0. -" -" Known Issues: {{{2 -" -" In some cases gvim can't decrypt files - -" This is caused by the fact that a running gvim has no TTY and thus gpg is -" not able to ask for the passphrase by itself. This is a problem for Windows -" and Linux versions of gvim and could not be solved unless a "terminal -" emulation" is implemented for gvim. To circumvent this you have to use any -" combination of gpg-agent and a graphical pinentry program: -" -" - gpg-agent only: -" you need to provide the passphrase for the needed key to gpg-agent -" in a terminal before you open files with gvim which require this key. -" -" - pinentry only: -" you will get a popup window every time you open a file that needs to -" be decrypted. -" -" - gpgagent and pinentry: -" you will get a popup window the first time you open a file that -" needs to be decrypted. -" -" Credits: {{{2 -" -" - Mathieu Clabaut for inspirations through his vimspell.vim script. -" - Richard Bronosky for patch to enable ".pgp" suffix. -" - Erik Remmelzwaal for patch to enable windows support and patient beta -" testing. -" - Lars Becker for patch to make gpg2 working. -" - Thomas Arendsen Hein for patch to convert encoding of gpg output. -" - Karl-Heinz Ruskowski for patch to fix unknown recipients and trust model -" and patient beta testing. -" - Giel van Schijndel for patch to get GPG_TTY dynamically. -" - Sebastian Luettich for patch to fix issue with symmetric encryption an set -" recipients. -" - Tim Swast for patch to generate signed files. -" - James Vega for patches for better '*.asc' handling, better filename -" escaping and better handling of multiple keyrings. -" -" Section: Plugin header {{{1 - -" guard against multiple loads {{{2 -if (exists("g:loaded_gnupg") || &cp || exists("#BufReadCmd*.\(gpg\|asc\|pgp\)")) - finish -endif -let g:loaded_gnupg = '2.3' -let s:GPGInitRun = 0 - -" check for correct vim version {{{2 -if (v:version < 702) - echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.2' | echohl None - finish -endif - -" Section: Autocmd setup {{{1 - -augroup GnuPG - autocmd! - - " do the decryption - autocmd BufReadCmd,FileReadCmd *.\(gpg\|asc\|pgp\) call s:GPGInit() - autocmd BufReadCmd,FileReadCmd *.\(gpg\|asc\|pgp\) call s:GPGDecrypt() - autocmd BufReadCmd *.\(gpg\|asc\|pgp\) call s:GPGBufReadPost() - - " convert all text to encrypted text before writing - autocmd BufWriteCmd,FileWriteCmd *.\(gpg\|asc\|pgp\) call s:GPGInit() - autocmd BufWriteCmd,FileWriteCmd *.\(gpg\|asc\|pgp\) call s:GPGEncrypt() - - " cleanup on leaving vim - autocmd VimLeave *.\(gpg\|asc\|pgp\) call s:GPGCleanup() -augroup END - -" Section: Constants {{{1 - -let s:GPGMagicString = "\t \t" - -" Section: Highlight setup {{{1 - -highlight default link GPGWarning WarningMsg -highlight default link GPGError ErrorMsg -highlight default link GPGHighlightUnknownRecipient ErrorMsg - -" Section: Functions {{{1 - -" Function: s:GPGInit() {{{2 -" -" initialize the plugin -" -function s:GPGInit() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGInit()") - - " we don't want a swap file, as it writes unencrypted data to disk - setl noswapfile - - " if persistent undo is present, disable it for this buffer - if exists('+undofile') - setl noundofile - endif - - " the rest only has to be run once - if s:GPGInitRun - return - endif - - " first make sure nothing is written to ~/.viminfo while editing - " an encrypted file. - set viminfo= - - " check what gpg command to use - if (!exists("g:GPGExecutable")) - let g:GPGExecutable = "gpg --trust-model always" - endif - - " check if gpg-agent is allowed - if (!exists("g:GPGUseAgent")) - let g:GPGUseAgent = 1 - endif - - " check if symmetric encryption is preferred - if (!exists("g:GPGPreferSymmetric")) - let g:GPGPreferSymmetric = 0 - endif - - " check if armored files are preferred - if (!exists("g:GPGPreferArmor")) - " .asc files should be armored as that's what the extension is used for - if expand('') =~ '\.asc$' - let g:GPGPreferArmor = 1 - else - let g:GPGPreferArmor = 0 - endif - endif - - " check if signed files are preferred - if (!exists("g:GPGPreferSign")) - let g:GPGPreferSign = 0 - endif - - " start with empty default recipients if none is defined so far - if (!exists("g:GPGDefaultRecipients")) - let g:GPGDefaultRecipients = [] - endif - - " prefer not to use pipes since it can garble gpg agent display - if (!exists("g:GPGUsePipes")) - let g:GPGUsePipes = 0 - endif - - " allow alternate gnupg homedir - if (!exists('g:GPGHomedir')) - let g:GPGHomedir = '' - endif - - " print version - call s:GPGDebug(1, "gnupg.vim ". g:loaded_gnupg) - - " determine if gnupg can use the gpg-agent - if (exists("$GPG_AGENT_INFO") && g:GPGUseAgent == 1) - if (!exists("$GPG_TTY") && !has("gui_running")) - let $GPG_TTY = system("tty") - if (v:shell_error) - let $GPG_TTY = "" - echohl GPGError - echom "The GPG_TTY is not set and no TTY could be found using the `tty` command!" - echom "gpg-agent might not work." - echohl None - endif - endif - let s:GPGCommand = g:GPGExecutable . " --use-agent" - else - let s:GPGCommand = g:GPGExecutable . " --no-use-agent" - endif - - " don't use tty in gvim except for windows: we get their a tty for free. - " FIXME find a better way to avoid an error. - " with this solution only --use-agent will work - if (has("gui_running") && !has("gui_win32")) - let s:GPGCommand = s:GPGCommand . " --no-tty" - endif - - " setup shell environment for unix and windows - let s:shellredirsave = &shellredir - let s:shellsave = &shell - let s:shelltempsave = &shelltemp - " noshelltemp isn't currently supported on Windows, but it doesn't cause any - " errors and this future proofs us against requiring changes if Windows - " gains noshelltemp functionality - let s:shelltemp = !g:GPGUsePipes - if (has("unix")) - " unix specific settings - let s:shellredir = ">%s 2>&1" - let s:shell = '/bin/sh' - let s:stderrredirnull = '2>/dev/null' - let s:GPGCommand = "LANG=C LC_ALL=C " . s:GPGCommand - else - " windows specific settings - let s:shellredir = '>%s' - let s:shell = &shell - let s:stderrredirnull = '2>nul' - endif - - call s:GPGDebug(3, "shellredirsave: " . s:shellredirsave) - call s:GPGDebug(3, "shellsave: " . s:shellsave) - call s:GPGDebug(3, "shelltempsave: " . s:shelltempsave) - - call s:GPGDebug(3, "shell: " . s:shell) - call s:GPGDebug(3, "shellcmdflag: " . &shellcmdflag) - call s:GPGDebug(3, "shellxquote: " . &shellxquote) - call s:GPGDebug(3, "shellredir: " . s:shellredir) - call s:GPGDebug(3, "stderrredirnull: " . s:stderrredirnull) - - call s:GPGDebug(3, "shell implementation: " . resolve(s:shell)) - - " find the supported algorithms - let output = s:GPGSystem({ 'level': 2, 'args': '--version' }) - - let s:GPGPubkey = substitute(output, ".*Pubkey: \\(.\\{-}\\)\n.*", "\\1", "") - let s:GPGCipher = substitute(output, ".*Cipher: \\(.\\{-}\\)\n.*", "\\1", "") - let s:GPGHash = substitute(output, ".*Hash: \\(.\\{-}\\)\n.*", "\\1", "") - let s:GPGCompress = substitute(output, ".*Compress.\\{-}: \\(.\\{-}\\)\n.*", "\\1", "") - - call s:GPGDebug(2, "public key algorithms: " . s:GPGPubkey) - call s:GPGDebug(2, "cipher algorithms: " . s:GPGCipher) - call s:GPGDebug(2, "hashing algorithms: " . s:GPGHash) - call s:GPGDebug(2, "compression algorithms: " . s:GPGCompress) - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGInit()") - let s:GPGInitRun = 1 -endfunction - -" Function: s:GPGCleanup() {{{2 -" -" cleanup on leaving vim -" -function s:GPGCleanup() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGCleanup()") - - " wipe out screen - new +only - redraw! - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGCleanup()") -endfunction - -" Function: s:GPGDecrypt() {{{2 -" -" decrypt the buffer and find all recipients of the encrypted file -" -function s:GPGDecrypt() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGDecrypt()") - - " get the filename of the current buffer - let filename = expand(":p") - - " clear GPGRecipients and GPGOptions - let b:GPGRecipients = g:GPGDefaultRecipients - let b:GPGOptions = [] - - " File doesn't exist yet, so nothing to decrypt - if empty(glob(filename)) - return - endif - - " Only let this if the file actually exists, otherwise GPG functionality - " will be disabled when editing a buffer that doesn't yet have a backing - " file - let b:GPGEncrypted = 0 - - " find the recipients of the file - let cmd = { 'level': 3 } - let cmd.args = '--verbose --decrypt --list-only --dry-run --batch --no-use-agent --logger-fd 1 ' . shellescape(filename) - let output = s:GPGSystem(cmd) - - let asymmPattern = 'gpg: public key is \%(0x\)\=[[:xdigit:]]\{8,16}' - " check if the file is symmetric/asymmetric encrypted - if (match(output, "gpg: encrypted with [[:digit:]]\\+ passphrase") >= 0) - " file is symmetric encrypted - let b:GPGEncrypted = 1 - call s:GPGDebug(1, "this file is symmetric encrypted") - - let b:GPGOptions += ["symmetric"] - - " find the used cipher algorithm - let cipher = substitute(output, ".*gpg: \\([^ ]\\+\\) encrypted data.*", "\\1", "") - if (match(s:GPGCipher, "\\<" . cipher . "\\>") >= 0) - let b:GPGOptions += ["cipher-algo " . cipher] - call s:GPGDebug(1, "cipher-algo is " . cipher) - else - echohl GPGWarning - echom "The cipher " . cipher . " is not known by the local gpg command. Using default!" - echo - echohl None - endif - elseif (match(output, asymmPattern) >= 0) - " file is asymmetric encrypted - let b:GPGEncrypted = 1 - call s:GPGDebug(1, "this file is asymmetric encrypted") - - let b:GPGOptions += ["encrypt"] - - " find the used public keys - let start = match(output, asymmPattern) - while (start >= 0) - let start = start + strlen("gpg: public key is ") - let recipient = matchstr(output, '[[:xdigit:]]\{8,16}', start) - call s:GPGDebug(1, "recipient is " . recipient) - let name = s:GPGNameToID(recipient) - if (strlen(name) > 0) - let b:GPGRecipients += [name] - call s:GPGDebug(1, "name of recipient is " . name) - else - let b:GPGRecipients += [recipient] - echohl GPGWarning - echom "The recipient \"" . recipient . "\" is not in your public keyring!" - echohl None - end - let start = match(output, asymmPattern, start) - endwhile - else - " file is not encrypted - let b:GPGEncrypted = 0 - call s:GPGDebug(1, "this file is not encrypted") - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - silent exe '.r ' . fnameescape(filename) - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()") - return - endif - - " check if the message is armored - if (match(output, "gpg: armor header") >= 0) - call s:GPGDebug(1, "this file is armored") - let b:GPGOptions += ["armor"] - endif - - " finally decrypt the buffer content - " since even with the --quiet option passphrase typos will be reported, - " we must redirect stderr (using shell temporarily) - call s:GPGDebug(1, "decrypting file") - let cmd = { 'level': 1, 'ex': 'r !' } - let cmd.args = '--quiet --decrypt ' . shellescape(filename, 1) - call s:GPGExecute(cmd) - - if (v:shell_error) " message could not be decrypted - echohl GPGError - let blackhole = input("Message could not be decrypted! (Press ENTER)") - echohl None - silent bwipeout! - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()") - return - endif - - " refresh screen - redraw! - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()") -endfunction - -function s:GPGBufReadPost() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGBufReadPost()") - silent 1delete - " call the autocommand for the file minus .gpg$ - execute ':doautocmd BufReadPost ' . fnameescape(expand(':r')) - call s:GPGDebug(2, 'called autocommand for ' . fnameescape(expand(':r'))) - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGBufReadPost()") -endfunction - -" Function: s:GPGEncrypt() {{{2 -" -" encrypts the buffer to all previous recipients -" -function s:GPGEncrypt() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGEncrypt()") - - " store encoding and switch to a safe one - if (&fileencoding != &encoding) - let s:GPGEncoding = &encoding - let &encoding = &fileencoding - call s:GPGDebug(2, "encoding was \"" . s:GPGEncoding . "\", switched to \"" . &encoding . "\"") - else - let s:GPGEncoding = "" - call s:GPGDebug(2, "encoding and fileencoding are the same (\"" . &encoding . "\"), not switching") - endif - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGError - let blackhole = input("Message could not be encrypted! (Press ENTER)") - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()") - return - endif - - " initialize GPGOptions if not happened before - if (!exists("b:GPGOptions") || len(b:GPGOptions) == 0) - let b:GPGOptions = [] - if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 1) - let b:GPGOptions += ["symmetric"] - let b:GPGRecipients = [] - else - let b:GPGOptions += ["encrypt"] - endif - if (exists("g:GPGPreferArmor") && g:GPGPreferArmor == 1) - let b:GPGOptions += ["armor"] - endif - if (exists("g:GPGPreferSign") && g:GPGPreferSign == 1) - let b:GPGOptions += ["sign"] - endif - call s:GPGDebug(1, "no options set, so using default options: " . string(b:GPGOptions)) - endif - - " built list of options - let options = "" - for option in b:GPGOptions - let options = options . " --" . option . " " - endfor - - if (!exists('b:GPGRecipients')) - let b:GPGRecipients = [] - endif - - " check here again if all recipients are available in the keyring - let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(b:GPGRecipients) - - " check if there are unknown recipients and warn - if (len(unknownrecipients) > 0) - echohl GPGWarning - echom "Please use GPGEditRecipients to correct!!" - echo - echohl None - - " Let user know whats happend and copy known_recipients back to buffer - let dummy = input("Press ENTER to quit") - endif - - " built list of recipients - if (len(recipients) > 0) - for gpgid in recipients - let options = options . " -r " . gpgid - endfor - endif - - " encrypt the buffer - let destfile = tempname() - let cmd = { 'level': 1, 'ex': "'[,']w !" } - let cmd.args = '--quiet --no-encrypt-to ' . options - let cmd.redirect = '>' . shellescape(destfile, 1) - call s:GPGExecute(cmd) - - " restore encoding - if (s:GPGEncoding != "") - let &encoding = s:GPGEncoding - call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"") - endif - - if (v:shell_error) " message could not be encrypted - " Command failed, so clean up the tempfile - call delete(destfile) - echohl GPGError - let blackhole = input("Message could not be encrypted! (Press ENTER)") - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()") - return - endif - - call rename(destfile, resolve(expand(''))) - setl nomodified - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()") -endfunction - -" Function: s:GPGViewRecipients() {{{2 -" -" echo the recipients -" -function s:GPGViewRecipients() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGViewRecipients()") - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGViewRecipients()") - return - endif - - let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(b:GPGRecipients) - - echo 'This file has following recipients (Unknown recipients have a prepended "!"):' - " echo the recipients - for name in recipients - let name = s:GPGIDToName(name) - echo name - endfor - - " echo the unknown recipients - echohl GPGWarning - for name in unknownrecipients - let name = "!" . name - echo name - endfor - echohl None - - " check if there is any known recipient - if (len(recipients) == 0) - echohl GPGError - echom 'There are no known recipients!' - echohl None - endif - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGViewRecipients()") -endfunction - -" Function: s:GPGEditRecipients() {{{2 -" -" create a scratch buffer with all recipients to add/remove recipients -" -function s:GPGEditRecipients() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGEditRecipients()") - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEditRecipients()") - return - endif - - " only do this if it isn't already a GPGRecipients_* buffer - if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0) - - " save buffer name - let buffername = bufname("%") - let editbuffername = "GPGRecipients_" . buffername - - " check if this buffer exists - if (!bufexists(editbuffername)) - " create scratch buffer - execute 'silent! split ' . fnameescape(editbuffername) - - " add a autocommand to regenerate the recipients after a write - autocmd BufHidden,BufUnload,BufWriteCmd call s:GPGFinishRecipientsBuffer() - else - if (bufwinnr(editbuffername) >= 0) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(editbuffername) . "wincmd w" - else - " split scratch buffer window - execute 'silent! sbuffer ' . fnameescape(editbuffername) - - " add a autocommand to regenerate the recipients after a write - autocmd BufHidden,BufUnload,BufWriteCmd call s:GPGFinishRecipientsBuffer() - endif - - " empty the buffer - silent %delete - endif - - " Mark the buffer as a scratch buffer - setlocal buftype=acwrite - setlocal bufhidden=hide - setlocal noswapfile - setlocal nowrap - setlocal nobuflisted - setlocal nonumber - - " so we know for which other buffer this edit buffer is - let b:GPGCorrespondingTo = buffername - - " put some comments to the scratch buffer - silent put ='GPG: ----------------------------------------------------------------------' - silent put ='GPG: Please edit the list of recipients, one recipient per line.' - silent put ='GPG: Unknown recipients have a prepended \"!\".' - silent put ='GPG: Lines beginning with \"GPG:\" are removed automatically.' - silent put ='GPG: Data after recipients between and including \"(\" and \")\" is ignored.' - silent put ='GPG: Closing this buffer commits changes.' - silent put ='GPG: ----------------------------------------------------------------------' - - " get the recipients - let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(getbufvar(b:GPGCorrespondingTo, "GPGRecipients")) - - " if there are no known or unknown recipients, use the default ones - if (len(recipients) == 0 && len(unknownrecipients) == 0) - if (type(g:GPGDefaultRecipients) == type([])) - let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(g:GPGDefaultRecipients) - else - echohl GPGWarning - echom "g:GPGDefaultRecipients is not a Vim list, please correct this in your vimrc!" - echohl None - endif - endif - - " put the recipients in the scratch buffer - for name in recipients - let name = s:GPGIDToName(name) - silent put =name - endfor - - " put the unknown recipients in the scratch buffer - let syntaxPattern = "\\(nonexxistinwordinthisbuffer" - for name in unknownrecipients - let name = "!" . name - let syntaxPattern = syntaxPattern . "\\|" . fnameescape(name) - silent put =name - endfor - let syntaxPattern = syntaxPattern . "\\)" - - " define highlight - if (has("syntax") && exists("g:syntax_on")) - execute 'syntax match GPGUnknownRecipient "' . syntaxPattern . '"' - highlight clear GPGUnknownRecipient - highlight link GPGUnknownRecipient GPGHighlightUnknownRecipient - - syntax match GPGComment "^GPG:.*$" - execute 'syntax match GPGComment "' . s:GPGMagicString . '.*$"' - highlight clear GPGComment - highlight link GPGComment Comment - endif - - " delete the empty first line - silent 1delete - - " jump to the first recipient - silent $ - - endif - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEditRecipients()") -endfunction - -" Function: s:GPGFinishRecipientsBuffer() {{{2 -" -" create a new recipient list from RecipientsBuffer -" -function s:GPGFinishRecipientsBuffer() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGFinishRecipientsBuffer()") - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGFinishRecipientsBuffer()") - return - endif - - " go to buffer before doing work - if (bufnr("%") != expand("")) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(expand("")) . "wincmd w" - endif - - " delete the autocommand - autocmd! * - - - " get the recipients from the scratch buffer - let recipients = [] - let lines = getline(1,"$") - for recipient in lines - " delete all text after magic string - let recipient = substitute(recipient, s:GPGMagicString . ".*$", "", "") - - " delete all spaces at beginning and end of the recipient - " also delete a '!' at the beginning of the recipient - let recipient = substitute(recipient, "^[[:space:]!]*\\(.\\{-}\\)[[:space:]]*$", "\\1", "") - - " delete comment lines - let recipient = substitute(recipient, "^GPG:.*$", "", "") - - " only do this if the line is not empty - if (strlen(recipient) > 0) - let gpgid = s:GPGNameToID(recipient) - if (strlen(gpgid) > 0) - if (match(recipients, gpgid) < 0) - let recipients += [gpgid] - endif - else - if (match(recipients, recipient) < 0) - let recipients += [recipient] - echohl GPGWarning - echom "The recipient \"" . recipient . "\" is not in your public keyring!" - echohl None - endif - endif - endif - endfor - - " write back the new recipient list to the corresponding buffer and mark it - " as modified. Buffer is now for sure a encrypted buffer. - call setbufvar(b:GPGCorrespondingTo, "GPGRecipients", recipients) - call setbufvar(b:GPGCorrespondingTo, "&mod", 1) - call setbufvar(b:GPGCorrespondingTo, "GPGEncrypted", 1) - - " check if there is any known recipient - if (len(recipients) == 0) - echohl GPGError - echom 'There are no known recipients!' - echohl None - endif - - " reset modified flag - setl nomodified - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGFinishRecipientsBuffer()") -endfunction - -" Function: s:GPGViewOptions() {{{2 -" -" echo the recipients -" -function s:GPGViewOptions() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGViewOptions()") - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGViewOptions()") - return - endif - - if (exists("b:GPGOptions")) - echo 'This file has following options:' - " echo the options - for option in b:GPGOptions - echo option - endfor - endif - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGViewOptions()") -endfunction - -" Function: s:GPGEditOptions() {{{2 -" -" create a scratch buffer with all recipients to add/remove recipients -" -function s:GPGEditOptions() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGEditOptions()") - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEditOptions()") - return - endif - - " only do this if it isn't already a GPGOptions_* buffer - if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0) - - " save buffer name - let buffername = bufname("%") - let editbuffername = "GPGOptions_" . buffername - - " check if this buffer exists - if (!bufexists(editbuffername)) - " create scratch buffer - execute 'silent! split ' . fnameescape(editbuffername) - - " add a autocommand to regenerate the options after a write - autocmd BufHidden,BufUnload,BufWriteCmd call s:GPGFinishOptionsBuffer() - else - if (bufwinnr(editbuffername) >= 0) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(editbuffername) . "wincmd w" - else - " split scratch buffer window - execute 'silent! sbuffer ' . fnameescape(editbuffername) - - " add a autocommand to regenerate the options after a write - autocmd BufHidden,BufUnload,BufWriteCmd call s:GPGFinishOptionsBuffer() - endif - - " empty the buffer - silent %delete - endif - - " Mark the buffer as a scratch buffer - setlocal buftype=nofile - setlocal noswapfile - setlocal nowrap - setlocal nobuflisted - setlocal nonumber - - " so we know for which other buffer this edit buffer is - let b:GPGCorrespondingTo = buffername - - " put some comments to the scratch buffer - silent put ='GPG: ----------------------------------------------------------------------' - silent put ='GPG: THERE IS NO CHECK OF THE ENTERED OPTIONS!' - silent put ='GPG: YOU NEED TO KNOW WHAT YOU ARE DOING!' - silent put ='GPG: IF IN DOUBT, QUICKLY EXIT USING :x OR :bd.' - silent put ='GPG: Please edit the list of options, one option per line.' - silent put ='GPG: Please refer to the gpg documentation for valid options.' - silent put ='GPG: Lines beginning with \"GPG:\" are removed automatically.' - silent put ='GPG: Closing this buffer commits changes.' - silent put ='GPG: ----------------------------------------------------------------------' - - " put the options in the scratch buffer - let options = getbufvar(b:GPGCorrespondingTo, "GPGOptions") - - for option in options - silent put =option - endfor - - " delete the empty first line - silent 1delete - - " jump to the first option - silent $ - - " define highlight - if (has("syntax") && exists("g:syntax_on")) - syntax match GPGComment "^GPG:.*$" - highlight clear GPGComment - highlight link GPGComment Comment - endif - endif - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEditOptions()") -endfunction - -" Function: s:GPGFinishOptionsBuffer() {{{2 -" -" create a new option list from OptionsBuffer -" -function s:GPGFinishOptionsBuffer() - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGFinishOptionsBuffer()") - - " guard for unencrypted files - if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) - echohl GPGWarning - echom "File is not encrypted, all GPG functions disabled!" - echohl None - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGFinishOptionsBuffer()") - return - endif - - " go to buffer before doing work - if (bufnr("%") != expand("")) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(expand("")) . "wincmd w" - endif - - " clear options and unknownOptions - let options = [] - let unknownOptions = [] - - " delete the autocommand - autocmd! * - - " get the options from the scratch buffer - let lines = getline(1, "$") - for option in lines - " delete all spaces at beginning and end of the option - " also delete a '!' at the beginning of the option - let option = substitute(option, "^[[:space:]!]*\\(.\\{-}\\)[[:space:]]*$", "\\1", "") - " delete comment lines - let option = substitute(option, "^GPG:.*$", "", "") - - " only do this if the line is not empty - if (strlen(option) > 0 && match(options, option) < 0) - let options += [option] - endif - endfor - - " write back the new option list to the corresponding buffer and mark it - " as modified - call setbufvar(b:GPGCorrespondingTo, "GPGOptions", options) - call setbufvar(b:GPGCorrespondingTo, "&mod", 1) - - " reset modified flag - setl nomodified - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGFinishOptionsBuffer()") -endfunction - -" Function: s:GPGCheckRecipients(tocheck) {{{2 -" -" check if recipients are known -" Returns: two lists recipients and unknownrecipients -" -function s:GPGCheckRecipients(tocheck) - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGCheckRecipients()") - - let recipients = [] - let unknownrecipients = [] - - if (type(a:tocheck) == type([])) - for recipient in a:tocheck - let gpgid = s:GPGNameToID(recipient) - if (strlen(gpgid) > 0) - if (match(recipients, gpgid) < 0) - let recipients += [gpgid] - endif - else - if (match(unknownrecipients, recipient) < 0) - let unknownrecipients += [recipient] - echohl GPGWarning - echom "The recipient \"" . recipient . "\" is not in your public keyring!" - echohl None - endif - end - endfor - endif - - call s:GPGDebug(2, "recipients are: " . string(recipients)) - call s:GPGDebug(2, "unknown recipients are: " . string(unknownrecipients)) - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGCheckRecipients()") - return [ recipients, unknownrecipients ] -endfunction - -" Function: s:GPGNameToID(name) {{{2 -" -" find GPG key ID corresponding to a name -" Returns: ID for the given name -" -function s:GPGNameToID(name) - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGNameToID()") - - " ask gpg for the id for a name - let cmd = { 'level': 2 } - let cmd.args = '--quiet --with-colons --fixed-list-mode --list-keys ' . shellescape(a:name) - let output = s:GPGSystem(cmd) - - " when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8, - " so convert it, if necessary - if (&encoding != "utf-8") - let output = iconv(output, "utf-8", &encoding) - endif - let lines = split(output, "\n") - - " parse the output of gpg - let pubseen = 0 - let counter = 0 - let gpgids = [] - let duplicates = {} - let choices = "The name \"" . a:name . "\" is ambiguous. Please select the correct key:\n" - for line in lines - - " check if this line has already been processed - if !has_key(duplicates, line) - let duplicates[line] = 1 - - let fields = split(line, ":") - " search for the next uid - if (pubseen == 1) - if (fields[0] == "uid") - let choices = choices . " " . fields[9] . "\n" - else - let pubseen = 0 - endif - endif - - " search for the next pub - if (pubseen == 0) - if (fields[0] == "pub") - let identity = fields[4] - let gpgids += [identity] - if exists("*strftime") - let choices = choices . counter . ": ID: 0x" . identity . " created at " . strftime("%c", fields[5]) . "\n" - else - let choices = choices . counter . ": ID: 0x" . identity . "\n" - endif - let counter = counter+1 - let pubseen = 1 - endif - endif - endif - - endfor - - " counter > 1 means we have more than one results - let answer = 0 - if (counter > 1) - let choices = choices . "Enter number: " - let answer = input(choices, "0") - while (answer == "") - let answer = input("Enter number: ", "0") - endwhile - endif - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGNameToID()") - return get(gpgids, answer, "") -endfunction - -" Function: s:GPGIDToName(identity) {{{2 -" -" find name corresponding to a GPG key ID -" Returns: Name for the given ID -" -function s:GPGIDToName(identity) - call s:GPGDebug(3, ">>>>>>>> Entering s:GPGIDToName()") - - " TODO is the encryption subkey really unique? - - " ask gpg for the id for a name - let cmd = { 'level': 2 } - let cmd.args = '--quiet --with-colons --fixed-list-mode --list-keys ' . a:identity - let output = s:GPGSystem(cmd) - - " when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8, - " so convert it, if necessary - if (&encoding != "utf-8") - let output = iconv(output, "utf-8", &encoding) - endif - let lines = split(output, "\n") - - " parse the output of gpg - let pubseen = 0 - let uid = "" - for line in lines - let fields = split(line, ":") - if (pubseen == 0) " search for the next pub - if (fields[0] == "pub") - let pubseen = 1 - endif - else " search for the next uid - if (fields[0] == "uid") - let pubseen = 0 - if exists("*strftime") - let uid = fields[9] . s:GPGMagicString . "(ID: 0x" . a:identity . " created at " . strftime("%c", fields[5]) . ")" - else - let uid = fields[9] . s:GPGMagicString . "(ID: 0x" . a:identity . ")" - endif - break - endif - endif - endfor - - call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGIDToName()") - return uid -endfunction - -function s:GPGPreCmd() - let &shellredir = s:shellredir - let &shell = s:shell - let &shelltemp = s:shelltemp -endfunction - -function s:GPGPostCmd() - let &shellredir = s:shellredirsave - let &shell = s:shellsave - let &shelltemp = s:shelltempsave -endfunction - -" Function: s:GPGSystem(dict) {{{2 -" -" run g:GPGCommand using system(), logging the commandline and output -" Recognized keys are: -" level - Debug level at which the commandline and output will be logged -" args - Arguments to be given to g:GPGCommand -" -" Returns: command output -" -function s:GPGSystem(dict) - let commandline = printf('%s %s', s:GPGCommand, a:dict.args) - if (!empty(g:GPGHomedir)) - let commandline .= ' --homedir ' . shellescape(g:GPGHomedir) - endif - let commandline .= ' ' . s:stderrredirnull - call s:GPGDebug(a:dict.level, "command: ". commandline) - - call s:GPGPreCmd() - let output = system(commandline) - call s:GPGPostCmd() - - call s:GPGDebug(a:dict.level, "output: ". output) - return output -endfunction - -" Function: s:GPGExecute(dict) {{{2 -" -" run g:GPGCommand using :execute, logging the commandline -" Recognized keys are: -" level - Debug level at which the commandline will be logged -" args - Arguments to be given to g:GPGCommand -" ex - Ex command which will be :executed -" redirect - Shell redirect to use, if needed -" -function s:GPGExecute(dict) - let commandline = printf('%s%s %s', a:dict.ex, s:GPGCommand, a:dict.args) - if (!empty(g:GPGHomedir)) - let commandline .= ' --homedir ' . shellescape(g:GPGHomedir, 1) - endif - if (has_key(a:dict, 'redirect')) - let commandline .= ' ' . a:dict.redirect - endif - let commandline .= ' ' . s:stderrredirnull - call s:GPGDebug(a:dict.level, "command: " . commandline) - - call s:GPGPreCmd() - execute commandline - call s:GPGPostCmd() -endfunction - -" Function: s:GPGDebug(level, text) {{{2 -" -" output debug message, if this message has high enough importance -" only define function if GPGDebugLevel set at all -" -function s:GPGDebug(level, text) - if exists("g:GPGDebugLevel") && g:GPGDebugLevel >= a:level - if exists("g:GPGDebugLog") - execute "redir >> " . g:GPGDebugLog - echom "GnuPG: " . a:text - redir END - else - echom "GnuPG: " . a:text - endif - endif -endfunction - -" Section: Commands {{{1 - -command! GPGViewRecipients call s:GPGViewRecipients() -command! GPGEditRecipients call s:GPGEditRecipients() -command! GPGViewOptions call s:GPGViewOptions() -command! GPGEditOptions call s:GPGEditOptions() - -" Section: Menu {{{1 - -if (has("menu")) - amenu Plugin.GnuPG.View\ Recipients :GPGViewRecipients - amenu Plugin.GnuPG.Edit\ Recipients :GPGEditRecipients - amenu Plugin.GnuPG.View\ Options :GPGViewOptions - amenu Plugin.GnuPG.Edit\ Options :GPGEditOptions -endif - -" vim600: set foldmethod=marker foldlevel=0 : diff --git a/dot_vim/plugin/imaps.vim b/dot_vim/plugin/imaps.vim deleted file mode 100644 index d871aa1..0000000 --- a/dot_vim/plugin/imaps.vim +++ /dev/null @@ -1,831 +0,0 @@ -" File: imaps.vim -" Authors: Srinath Avadhanula -" Benji Fisher -" -" WWW: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/vim-latex/vimfiles/plugin/imaps.vim?only_with_tag=MAIN -" -" Description: insert mode template expander with cursor placement -" while preserving filetype indentation. -" -" $Id: imaps.vim 997 2006-03-20 09:45:45Z srinathava $ -" -" Documentation: {{{ -" -" Motivation: -" this script provides a way to generate insert mode mappings which do not -" suffer from some of the problem of mappings and abbreviations while allowing -" cursor placement after the expansion. It can alternatively be thought of as -" a template expander. -" -" Consider an example. If you do -" -" imap lhs something -" -" then a mapping is set up. However, there will be the following problems: -" 1. the 'ttimeout' option will generally limit how easily you can type the -" lhs. if you type the left hand side too slowly, then the mapping will not -" be activated. -" 2. if you mistype one of the letters of the lhs, then the mapping is -" deactivated as soon as you backspace to correct the mistake. -" -" If, in order to take care of the above problems, you do instead -" -" iab lhs something -" -" then the timeout problem is solved and so is the problem of mistyping. -" however, abbreviations are only expanded after typing a non-word character. -" which causes problems of cursor placement after the expansion and invariably -" spurious spaces are inserted. -" -" Usage Example: -" this script attempts to solve all these problems by providing an emulation -" of imaps wchich does not suffer from its attendant problems. Because maps -" are activated without having to press additional characters, therefore -" cursor placement is possible. furthermore, file-type specific indentation is -" preserved, because the rhs is expanded as if the rhs is typed in literally -" by the user. -" -" The script already provides some default mappings. each "mapping" is of the -" form: -" -" call IMAP (lhs, rhs, ft) -" -" Some characters in the RHS have special meaning which help in cursor -" placement. -" -" Example One: -" -" call IMAP ("bit`", "\\begin{itemize}\\\item <++>\\\end{itemize}<++>", "tex") -" -" This effectively sets up the map for "bit`" whenever you edit a latex file. -" When you type in this sequence of letters, the following text is inserted: -" -" \begin{itemize} -" \item * -" \end{itemize}<++> -" -" where * shows the cursor position. The cursor position after inserting the -" text is decided by the position of the first "place-holder". Place holders -" are special characters which decide cursor placement and movement. In the -" example above, the place holder characters are <+ and +>. After you have typed -" in the item, press and you will be taken to the next set of <++>'s. -" Therefore by placing the <++> characters appropriately, you can minimize the -" use of movement keys. -" -" NOTE: Set g:Imap_UsePlaceHolders to 0 to disable placeholders altogether. -" Set -" g:Imap_PlaceHolderStart and g:Imap_PlaceHolderEnd -" to something else if you want different place holder characters. -" Also, b:Imap_PlaceHolderStart and b:Imap_PlaceHolderEnd override the values -" of g:Imap_PlaceHolderStart and g:Imap_PlaceHolderEnd respectively. This is -" useful for setting buffer specific place hoders. -" -" Example Two: -" You can use the command to insert dynamic elements such as dates. -" call IMAP ('date`', "\=strftime('%b %d %Y')\", '') -" -" sets up the map for date` to insert the current date. -" -"--------------------------------------%<-------------------------------------- -" Bonus: This script also provides a command Snip which puts tearoff strings, -" '----%<----' above and below the visually selected range of lines. The -" length of the string is chosen to be equal to the longest line in the range. -" Recommended Usage: -" '<,'>Snip -"--------------------------------------%<-------------------------------------- -" }}} - -" line continuation used here. -let s:save_cpo = &cpo -set cpo&vim - -" ============================================================================== -" Script Options / Variables -" ============================================================================== -" Options {{{ -if !exists('g:Imap_StickyPlaceHolders') - let g:Imap_StickyPlaceHolders = 1 -endif -if !exists('g:Imap_DeleteEmptyPlaceHolders') - let g:Imap_DeleteEmptyPlaceHolders = 1 -endif -" }}} -" Variables {{{ -" s:LHS_{ft}_{char} will be generated automatically. It will look like -" s:LHS_tex_o = 'fo\|foo\|boo' and contain all mapped sequences ending in "o". -" s:Map_{ft}_{lhs} will be generated automatically. It will look like -" s:Map_c_foo = 'for(<++>; <++>; <++>)', the mapping for "foo". -" -" }}} - -" ============================================================================== -" functions for easy insert mode mappings. -" ============================================================================== -" IMAP: Adds a "fake" insert mode mapping. {{{ -" For example, doing -" IMAP('abc', 'def' ft) -" will mean that if the letters abc are pressed in insert mode, then -" they will be replaced by def. If ft != '', then the "mapping" will be -" specific to the files of type ft. -" -" Using IMAP has a few advantages over simply doing: -" imap abc def -" 1. with imap, if you begin typing abc, the cursor will not advance and -" long as there is a possible completion, the letters a, b, c will be -" displayed on on top of the other. using this function avoids that. -" 2. with imap, if a backspace or arrow key is pressed before completing -" the word, then the mapping is lost. this function allows movement. -" (this ofcourse means that this function is only limited to -" left-hand-sides which do not have movement keys or unprintable -" characters) -" It works by only mapping the last character of the left-hand side. -" when this character is typed in, then a reverse lookup is done and if -" the previous characters consititute the left hand side of the mapping, -" the previously typed characters and erased and the right hand side is -" inserted - -" IMAP: set up a filetype specific mapping. -" Description: -" "maps" the lhs to rhs in files of type 'ft'. If supplied with 2 -" additional arguments, then those are assumed to be the placeholder -" characters in rhs. If unspecified, then the placeholder characters -" are assumed to be '<+' and '+>' These placeholder characters in -" a:rhs are replaced with the users setting of -" [bg]:Imap_PlaceHolderStart and [bg]:Imap_PlaceHolderEnd settings. -" -function! IMAP(lhs, rhs, ft, ...) - - " Find the place holders to save for IMAP_PutTextWithMovement() . - if a:0 < 2 - let phs = '<+' - let phe = '+>' - else - let phs = a:1 - let phe = a:2 - endif - - let hash = s:Hash(a:lhs) - let s:Map_{a:ft}_{hash} = a:rhs - let s:phs_{a:ft}_{hash} = phs - let s:phe_{a:ft}_{hash} = phe - - " Add a:lhs to the list of left-hand sides that end with lastLHSChar: - let lastLHSChar = a:lhs[strlen(a:lhs)-1] - let hash = s:Hash(lastLHSChar) - if !exists("s:LHS_" . a:ft . "_" . hash) - let s:LHS_{a:ft}_{hash} = escape(a:lhs, '\') - else - let s:LHS_{a:ft}_{hash} = escape(a:lhs, '\') .'\|'. s:LHS_{a:ft}_{hash} - endif - - " map only the last character of the left-hand side. - if lastLHSChar == ' ' - let lastLHSChar = '' - end - exe 'inoremap ' - \ escape(lastLHSChar, '|') - \ '=LookupCharacter("' . - \ escape(lastLHSChar, '\|"') . - \ '")' -endfunction - -" }}} -" IMAP_list: list the rhs and place holders corresponding to a:lhs {{{ -" -" Added mainly for debugging purposes, but maybe worth keeping. -function! IMAP_list(lhs) - let char = a:lhs[strlen(a:lhs)-1] - let charHash = s:Hash(char) - if exists("s:LHS_" . &ft ."_". charHash) && a:lhs =~ s:LHS_{&ft}_{charHash} - let ft = &ft - elseif exists("s:LHS__" . charHash) && a:lhs =~ s:LHS__{charHash} - let ft = "" - else - return "" - endif - let hash = s:Hash(a:lhs) - return "rhs = " . s:Map_{ft}_{hash} . " place holders = " . - \ s:phs_{ft}_{hash} . " and " . s:phe_{ft}_{hash} -endfunction -" }}} -" LookupCharacter: inserts mapping corresponding to this character {{{ -" -" This function extracts from s:LHS_{&ft}_{a:char} or s:LHS__{a:char} -" the longest lhs matching the current text. Then it replaces lhs with the -" corresponding rhs saved in s:Map_{ft}_{lhs} . -" The place-holder variables are passed to IMAP_PutTextWithMovement() . -function! s:LookupCharacter(char) - if IMAP_GetVal('Imap_FreezeImap', 0) == 1 - return a:char - endif - let charHash = s:Hash(a:char) - - " The line so far, including the character that triggered this function: - let text = strpart(getline("."), 0, col(".")-1) . a:char - " Prefer a local map to a global one, even if the local map is shorter. - " Is this what we want? Do we care? - " Use '\V' (very no-magic) so that only '\' is special, and it was already - " escaped when building up s:LHS_{&ft}_{charHash} . - if exists("s:LHS_" . &ft . "_" . charHash) - \ && text =~ "\\C\\V\\(" . s:LHS_{&ft}_{charHash} . "\\)\\$" - let ft = &ft - elseif exists("s:LHS__" . charHash) - \ && text =~ "\\C\\V\\(" . s:LHS__{charHash} . "\\)\\$" - let ft = "" - else - " If this is a character which could have been used to trigger an - " abbreviation, check if an abbreviation exists. - if a:char !~ '\k' - let lastword = matchstr(getline('.'), '\k\+$', '') - call IMAP_Debug('getting lastword = ['.lastword.']', 'imap') - if lastword != '' - " An extremeley wierd way to get around the fact that vim - " doesn't have the equivalent of the :mapcheck() function for - " abbreviations. - let _a = @a - exec "redir @a | silent! iab ".lastword." | redir END" - let abbreviationRHS = matchstr(@a."\n", "\n".'i\s\+'.lastword.'\s\+@\?\zs.*\ze'."\n") - - call IMAP_Debug('getting abbreviationRHS = ['.abbreviationRHS.']', 'imap') - - if @a =~ "No abbreviation found" || abbreviationRHS == "" - let @a = _a - return a:char - endif - - let @a = _a - let abbreviationRHS = escape(abbreviationRHS, '\<"') - exec 'let abbreviationRHS = "'.abbreviationRHS.'"' - - let lhs = lastword.a:char - let rhs = abbreviationRHS.a:char - let phs = IMAP_GetPlaceHolderStart() - let phe = IMAP_GetPlaceHolderEnd() - else - return a:char - endif - else - return a:char - endif - endif - " Find the longest left-hand side that matches the line so far. - " matchstr() returns the match that starts first. This automatically - " ensures that the longest LHS is used for the mapping. - if !exists('lhs') || !exists('rhs') - let lhs = matchstr(text, "\\C\\V\\(" . s:LHS_{ft}_{charHash} . "\\)\\$") - let hash = s:Hash(lhs) - let rhs = s:Map_{ft}_{hash} - let phs = s:phs_{ft}_{hash} - let phe = s:phe_{ft}_{hash} - endif - - if strlen(lhs) == 0 - return a:char - endif - " enough back-spaces to erase the left-hand side; -1 for the last - " character typed: - let bs = substitute(strpart(lhs, 1), ".", "\", "g") - return bs . IMAP_PutTextWithMovement(rhs, phs, phe) -endfunction - -" }}} -" IMAP_PutTextWithMovement: returns the string with movement appended {{{ -" Description: -" If a:str contains "placeholders", then appends movement commands to -" str in a way that the user moves to the first placeholder and enters -" insert or select mode. If supplied with 2 additional arguments, then -" they are assumed to be the placeholder specs. Otherwise, they are -" assumed to be '<+' and '+>'. These placeholder chars are replaced -" with the users settings of [bg]:Imap_PlaceHolderStart and -" [bg]:Imap_PlaceHolderEnd. -function! IMAP_PutTextWithMovement(str, ...) - - " The placeholders used in the particular input string. These can be - " different from what the user wants to use. - if a:0 < 2 - let phs = '<+' - let phe = '+>' - else - let phs = escape(a:1, '\') - let phe = escape(a:2, '\') - endif - - let text = a:str - - " The user's placeholder settings. - let phsUser = IMAP_GetPlaceHolderStart() - let pheUser = IMAP_GetPlaceHolderEnd() - - " Problem: depending on the setting of the 'encoding' option, a character - " such as "\xab" may not match itself. We try to get around this by - " changing the encoding of all our strings. At the end, we have to - " convert text back. - let phsEnc = s:Iconv(phs, "encode") - let pheEnc = s:Iconv(phe, "encode") - let phsUserEnc = s:Iconv(phsUser, "encode") - let pheUserEnc = s:Iconv(pheUser, "encode") - let textEnc = s:Iconv(text, "encode") - if textEnc != text - let textEncoded = 1 - else - let textEncoded = 0 - endif - - let pattern = '\V\(\.\{-}\)' .phs. '\(\.\{-}\)' .phe. '\(\.\*\)' - " If there are no placeholders, just return the text. - if textEnc !~ pattern - call IMAP_Debug('Not getting '.phs.' and '.phe.' in '.textEnc, 'imap') - return text - endif - " Break text up into "initial <+template+> final"; any piece may be empty. - let initialEnc = substitute(textEnc, pattern, '\1', '') - let templateEnc = substitute(textEnc, pattern, '\2', '') - let finalEnc = substitute(textEnc, pattern, '\3', '') - - " If the user does not want to use placeholders, then remove all but the - " first placeholder. - " Otherwise, replace all occurences of the placeholders here with the - " user's choice of placeholder settings. - if exists('g:Imap_UsePlaceHolders') && !g:Imap_UsePlaceHolders - let finalEnc = substitute(finalEnc, '\V'.phs.'\.\{-}'.phe, '', 'g') - else - let finalEnc = substitute(finalEnc, '\V'.phs.'\(\.\{-}\)'.phe, - \ phsUserEnc.'\1'.pheUserEnc, 'g') - endif - - " The substitutions are done, so convert back, if necessary. - if textEncoded - let initial = s:Iconv(initialEnc, "decode") - let template = s:Iconv(templateEnc, "decode") - let final = s:Iconv(finalEnc, "decode") - else - let initial = initialEnc - let template = templateEnc - let final = finalEnc - endif - - " Build up the text to insert: - " 1. the initial text plus an extra character; - " 2. go to Normal mode with , so it works even if 'insertmode' - " is set, and mark the position; - " 3. replace the extra character with tamplate and final; - " 4. back to Normal mode and restore the cursor position; - " 5. call IMAP_Jumpfunc(). - let template = phsUser . template . pheUser - " Old trick: insert and delete a character to get the same behavior at - " start, middle, or end of line and on empty lines. - let text = initial . "X\\:call IMAP_Mark('set')\\"_s" - let text = text . template . final - let text = text . "\\:call IMAP_Mark('go')\" - let text = text . "i\=IMAP_Jumpfunc('', 1)\" - - call IMAP_Debug('IMAP_PutTextWithMovement: text = ['.text.']', 'imap') - return text -endfunction - -" }}} -" IMAP_Jumpfunc: takes user to next <+place-holder+> {{{ -" Author: Luc Hermitte -" Arguments: -" direction: flag for the search() function. If set to '', search forwards, -" if 'b', then search backwards. See the {flags} argument of the -" |search()| function for valid values. -" inclusive: In vim, the search() function is 'exclusive', i.e we always goto -" next cursor match even if there is a match starting from the -" current cursor position. Setting this argument to 1 makes -" IMAP_Jumpfunc() also respect a match at the current cursor -" position. 'inclusive'ness is necessary for IMAP() because a -" placeholder string can occur at the very beginning of a map which -" we want to select. -" We use a non-zero value only in special conditions. Most mappings -" should use a zero value. -function! IMAP_Jumpfunc(direction, inclusive) - - " The user's placeholder settings. - let phsUser = IMAP_GetPlaceHolderStart() - let pheUser = IMAP_GetPlaceHolderEnd() - - let searchString = '' - " If this is not an inclusive search or if it is inclusive, but the - " current cursor position does not contain a placeholder character, then - " search for the placeholder characters. - if !a:inclusive || strpart(getline('.'), col('.')-1) !~ '\V\^'.phsUser - let searchString = '\V'.phsUser.'\_.\{-}'.pheUser - endif - - " If we didn't find any placeholders return quietly. - if searchString != '' && !search(searchString, a:direction) - return '' - endif - - " Open any closed folds and make this part of the text visible. - silent! foldopen! - - " Calculate if we have an empty placeholder or if it contains some - " description. - let template = - \ matchstr(strpart(getline('.'), col('.')-1), - \ '\V\^'.phsUser.'\zs\.\{-}\ze\('.pheUser.'\|\$\)') - let placeHolderEmpty = !strlen(template) - - " If we are selecting in exclusive mode, then we need to move one step to - " the right - let extramove = '' - if &selection == 'exclusive' - let extramove = 'l' - endif - - " Select till the end placeholder character. - let movement = "\v/\\V".pheUser."/e\".extramove - - " First remember what the search pattern was. s:RemoveLastHistoryItem will - " reset @/ to this pattern so we do not create new highlighting. - let g:Tex_LastSearchPattern = @/ - - " Now either goto insert mode or select mode. - if placeHolderEmpty && g:Imap_DeleteEmptyPlaceHolders - " delete the empty placeholder into the blackhole. - return movement."\"_c\:".s:RemoveLastHistoryItem."\" - else - return movement."\\:".s:RemoveLastHistoryItem."\gv\" - endif - -endfunction - -" }}} -" Maps for IMAP_Jumpfunc {{{ -" -" These mappings use and thus provide for easy user customization. When -" the user wants to map some other key to jump forward, he can do for -" instance: -" nmap ,f IMAP_JumpForward -" etc. - -" jumping forward and back in insert mode. -imap IMAP_JumpForward =IMAP_Jumpfunc('', 0) -imap IMAP_JumpBack =IMAP_Jumpfunc('b', 0) - -" jumping in normal mode -nmap IMAP_JumpForward i=IMAP_Jumpfunc('', 0) -nmap IMAP_JumpBack i=IMAP_Jumpfunc('b', 0) - -" deleting the present selection and then jumping forward. -vmap IMAP_DeleteAndJumpForward "_i=IMAP_Jumpfunc('', 0) -vmap IMAP_DeleteAndJumpBack "_i=IMAP_Jumpfunc('b', 0) - -" jumping forward without deleting present selection. -vmap IMAP_JumpForward i=IMAP_Jumpfunc('', 0) -vmap IMAP_JumpBack `=IMAP_Jumpfunc('b', 0) - -" }}} -" Default maps for IMAP_Jumpfunc {{{ -" map only if there is no mapping already. allows for user customization. -" NOTE: Default mappings for jumping to the previous placeholder are not -" provided. It is assumed that if the user will create such mappings -" hself if e so desires. -if !hasmapto('IMAP_JumpForward', 'i') - imap IMAP_JumpForward -endif -if !hasmapto('IMAP_JumpForward', 'n') - nmap IMAP_JumpForward -endif -if exists('g:Imap_StickyPlaceHolders') && g:Imap_StickyPlaceHolders - if !hasmapto('IMAP_JumpForward', 'v') - vmap IMAP_JumpForward - endif -else - if !hasmapto('IMAP_DeleteAndJumpForward', 'v') - vmap IMAP_DeleteAndJumpForward - endif -endif -" }}} - -nmap