From 3657056cc302efd98056fd2349776781759b1229 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 28 Jan 2008 09:29:22 +0100 Subject: * tools/vim: - added APBTeam vim setup and tools. --- tools/vim/plugin/apbteam.vim | 71 ++++++++++++++++++++++ tools/vim/plugin/template.vim | 136 ++++++++++++++++++++++++++++++++++++++++++ tools/vim/plugin/utils.vim | 25 ++++++++ 3 files changed, 232 insertions(+) create mode 100644 tools/vim/plugin/apbteam.vim create mode 100644 tools/vim/plugin/template.vim create mode 100644 tools/vim/plugin/utils.vim (limited to 'tools/vim/plugin') diff --git a/tools/vim/plugin/apbteam.vim b/tools/vim/plugin/apbteam.vim new file mode 100644 index 00000000..fa320567 --- /dev/null +++ b/tools/vim/plugin/apbteam.vim @@ -0,0 +1,71 @@ +" Name: apbteam +" Author: Nicolas Schodet +" Last Update: 2008-01-28 +" Description: Vim setup for APBTeam. +" License: Public domain. +" Installation: Put it in &runtimepath/plugin. + +if exists('g:apbteam_plugin') | finish | endif +let g:apbteam_plugin = 1 + +" APBTeam setup. +function! APBTeam() + set nocompatible + set backspace=2 + " Formatting. + set autoindent + set textwidth=78 + set formatoptions=tcqnl + set nocindent + set smartindent + set smarttab + set nojoinspaces + " Quickfix. + set errorformat= + \%*[^\"]\"%f\"%*\\D%l:\ %m, + \\"%f\"%*\\D%l:\ %m, + \%-G%f:%l:\ error:\ (Each\ undeclared\ identifier%.%#, + \%-G%f:%l:\ error:\ for\ each\ function\ it\ appears\ in.), + \%f:%l:%m, + \\"%f\"\\, + \\ line\ %l%*\\D%c%*[^\ ]\ %m, + \%D%*\\a:\ Entering\ directory\ `%f', + \%X%*\\a:\ Leaving\ directory\ `%f', + \%DMaking\ %*\\a\ in\ %f + " .h are for C. + let g:c_syntax_for_h = 1 + " Format options. + set cinoptions={.5s:.5sg.5sh.5st0(0=.5s + " Syntax highlighting & file types. + filetype plugin indent on + syn on + " Plugins. + let g:template_variant = "apbteam" + let g:ghph_GrabComments = 1 + let g:ghph_Reformat = 1 + let g:ghph_PutAfter = 1 + let g:ghph_SplitReturn = 1 +endfunction + +function! APBTeamProg() + " Programming options. + setlocal formatoptions+=rt + setlocal shortmess-=T + setlocal shiftwidth=4 + setlocal cindent + setlocal fo-=o fo-=r + setlocal com-=:// com+=:///,:// + " Call GHPH + nmap g :GHPH g + nmap h :GHPH p +endfunction + +" If you do not want automatic execution. +if exists('g:no_apbteam') | finish | endif + +call APBTeam() + +au FileType c call APBTeamProg() +au FileType cpp call APBTeamProg() +au BufNewFile README Template README +au BufNewFile *.c,*.cc,*.tcc,*.icc,*.h,*.hh,*.hpp,*.C,*.cxx TemplateHeader diff --git a/tools/vim/plugin/template.vim b/tools/vim/plugin/template.vim new file mode 100644 index 00000000..811ebaa0 --- /dev/null +++ b/tools/vim/plugin/template.vim @@ -0,0 +1,136 @@ +" Name: ni-template +" Author: Nicolas Schodet +" Last Update: 2007-03-29 +" Version: 0.84 +" Description: Chargeur de templates. +" License: Domaine public. +" Installation: Mettre le script dans &runtimepath/plugin, et les templates +" dans &runtimepath/templates. +" +" Appeler la commande :Template [filetype] pour charger un +" template. filetype est optionnel, il est detecté sinon. +" +" La commande :TemplateHeader essaye de détecter si le fichier +" est un en-tête (h au lieu de c, hpp au lieu de cpp). +" +" Exemple : Mettre le script dans ~/.vim/plugin, et les +" templates dans ~/.vim/templates. Mettre une autocommande : +" au BufNewFile * TemplateHeader +" +" Usage: Les fichiers de templates peuvent contenir des expressions +" remplacées par le script : +" @DATE@ : Tue Jan 28 00:42:47 2003 +" @ISODATE@ : 2003-01-28 +" @YEAR@ : 2003 +" @FILE@ : template.vim +" @FILEBASE@ : template +" @FILECAP@ : TEMPLATE_VIM +" @FILEDEF@ : template_vim +" @PATH@ : path/to/template.vim +" @PATHBASE@ : path/to/template +" @PATHCAP@ : PATH_TO_TEMPLATE_VIM +" @PATHDEF@ : path_to_template_vim +" @AUTHOR@ : valeur de g:fullname +" @EMAIL@ : valeur de g:email +" @NICK@ : valeur de g:nick +" @WEB@ : valeur de g:web +" @COPYRIGHT@ : valeur de g:copyright +" @%...@ : utilise expand pour construire un nom de fichier +" @!...@ : evalue une expression VIM +" @=...@ : evalue une expression VIM et remplace par le +" résultat. + +if exists('g:ni_template_plugin') | finish | endif +let g:ni_template_plugin = 1 + +function! s:Eval(expr) + exe 'return' a:expr +endf + +function! s:Exec(expr) + exe a:expr + return '' +endf + +" Find a template file for a given filetype. +function! s:Template_find_file(ft) + if exists ('b:template_variant') + let template_file = globpath (&runtimepath, 'templates/' . b:template_variant . '.' . a:ft) + if filereadable (template_file) + return template_file + endif + endif + if exists ('g:template_variant') + let template_file = globpath (&runtimepath, 'templates/' . g:template_variant . '.' . a:ft) + if filereadable (template_file) + return template_file + endif + endif + let template_file = globpath (&runtimepath, 'templates/default.' . a:ft) + return template_file +endf + +" Insert template. +function! s:Template(...) + let dellast = line ('$') == 1 && getline ('$') == '' + let ft = (a:0) ? (a:1) : (strlen (&ft) ? &ft : 'default') + let template_file = s:Template_find_file (ft) + if filereadable (template_file) + silent exe '0r ' . template_file + keepjumps silent %s/@=\([^@]*\)@/\=s:Eval(submatch(1))/ge + keepjumps silent %s/@!\([^@]*\)@/\=s:Exec(submatch(1))/ge + keepjumps silent %s/@\(%[^@]*\)@/\=expand(submatch(1))/ge + silent exe 'keepjumps %s/@DATE@/' . strftime ('%c') . '/ge' + silent exe 'keepjumps %s/@ISODATE@/' . strftime ('%Y-%m-%d') . '/ge' + silent exe 'keepjumps %s/@YEAR@/' . strftime ('%Y') . '/ge' + let file = expand ('%:t') + silent exe 'keepjumps %s/@FILE@/' . file . '/ge' + silent exe 'keepjumps %s/@FILEBASE@/' . expand ('%:t:r') . '/ge' + silent exe 'keepjumps %s/@FILECAP@/' . toupper (substitute (file, '\.', '_', 'g')) . '/ge' + silent exe 'keepjumps %s/@FILEDEF@/' . substitute (file, '\.', '_', 'g') . '/ge' + let path = expand ('%') + silent exe 'keepjumps %s:@PATH@:' . path . ':ge' + silent exe 'keepjumps %s:@PATHBASE@:' . expand ('%:r') . ':ge' + silent exe 'keepjumps %s:@PATHCAP@:' . toupper (substitute (path, '[/\.]', '_', 'g')) . ':ge' + silent exe 'keepjumps %s:@PATHDEF@:' . substitute (path, '[/\.]', '_', 'g') . ':ge' + if exists ('g:fullname') + silent exe 'keepjumps %s/@AUTHOR@/' . g:fullname . '/ge' + endif + if exists ('g:email') + silent exe 'keepjumps %s/@EMAIL@/' . g:email . '/ge' + endif + if exists ('g:nick') + silent exe 'keepjumps %s/@NICK@/' . g:nick . '/ge' + endif + if exists ('g:web') + silent exe 'keepjumps %s/@WEB@/' . g:web . '/ge' + endif + if exists ('g:copyright') + silent exe 'keepjumps %s/@COPYRIGHT@/' . g:copyright . '/ge' + endif + if dellast + keepjumps $d _ + endif + keepjumps 0 + endif +endf + +" Detect headers files, then call Template(). +function! s:TemplateHeader() + if &filetype == 'c' && expand ('%') =~ '\.h$' + call s:Template ('h') + elseif &filetype == 'cpp' && expand ('%') =~ '\.\(h\|H\|hh\|hxx\|hpp\|tcc\|inl\)$' + call s:Template ('hpp') + else + call s:Template () + endif +endfunction + +if !exists(':Template') + command -nargs=? Template :call s:Template () +endif + +if !exists(':TemplateHeader') + command -nargs=0 TemplateHeader :call s:TemplateHeader () +endif + diff --git a/tools/vim/plugin/utils.vim b/tools/vim/plugin/utils.vim new file mode 100644 index 00000000..be99551b --- /dev/null +++ b/tools/vim/plugin/utils.vim @@ -0,0 +1,25 @@ +" Name: ni-utils +" Author: Nicolas Schodet +" Last Update: 2008-01-28 +" Description: Misc utils. +" License: Public domain. +" Installation: Put it in &runtimepath/plugin. + +if exists('g:ni_utils_plugin') | finish | endif +let g:ni_utils_plugin = 1 + +" Look up README file in '.' and '..' to find a program description. +function! GetReadme() + if filereadable ('README') + let readme = 'README' + elseif filereadable ('../README') + let readme = '../README' + endif + if exists ('readme') + let progname = substitute (system ('head -1 ' . readme), "\n", '', '') + else + let progname = '' + endif + return progname +endfunction + -- cgit v1.2.3