From a743362f150067c8891ae4421421613593646073 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Wed, 14 Nov 2012 09:14:13 -0500 Subject: [PATCH] Added support for templates --- templates/hdr.m4 | 17 +++++++++++++++++ templates/src.m4 | 14 ++++++++++++++ templates/test.m4 | 23 +++++++++++++++++++++++ templates/ut.m4 | 16 ++++++++++++++++ vimrc | 45 +++++++++++++++++++++++++++++---------------- 5 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 templates/hdr.m4 create mode 100644 templates/src.m4 create mode 100644 templates/test.m4 create mode 100644 templates/ut.m4 diff --git a/templates/hdr.m4 b/templates/hdr.m4 new file mode 100644 index 0000000..db7fa7a --- /dev/null +++ b/templates/hdr.m4 @@ -0,0 +1,17 @@ +define(SEP_IDX, regexp(ARGS,` '))dnl +define(NAME, substr(ARGS,0,SEP_IDX))dnl +define(FNAME, patsubst(substr(ARGS,eval(SEP_IDX+1)),` ',`_'))dnl +define(GUARD, translit(format(`%s_H', FNAME), `a-z', `A-Z'))dnl +dnl +/** + @file "format(`%s.h',FNAME)" + @brief TODO: Describe this file + $Revision$ + $HeadURL$ +*/ +`#'define GUARD +`#'ifndef GUARD + + + +`#'endif /* GUARD */ diff --git a/templates/src.m4 b/templates/src.m4 new file mode 100644 index 0000000..e34e682 --- /dev/null +++ b/templates/src.m4 @@ -0,0 +1,14 @@ +define(SEP_IDX, regexp(ARGS,` '))dnl +define(NAME, substr(ARGS,0,SEP_IDX))dnl +define(FNAME, patsubst(substr(ARGS,eval(SEP_IDX+1)),` ',`_'))dnl +dnl +/** + @file "format(`%s.c',FNAME)" + @brief TODO: Describe this file + $Revision$ + $HeadURL$ +*/ +`#'include "format(`%s.h',FNAME)" + + + diff --git a/templates/test.m4 b/templates/test.m4 new file mode 100644 index 0000000..ba028ff --- /dev/null +++ b/templates/test.m4 @@ -0,0 +1,23 @@ +#include "unity.h" + +// File to Test +`#'include "format(`%s',ARGS).h" + +// Real Includes + +// Mock Includes + +// Globals + +// Helper Functions +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +//----------------------------------------------------------------------------- + + diff --git a/templates/ut.m4 b/templates/ut.m4 new file mode 100644 index 0000000..e9b36f5 --- /dev/null +++ b/templates/ut.m4 @@ -0,0 +1,16 @@ +define(SEP_IDX, regexp(ARGS,` '))dnl +define(FNNAME, substr(ARGS,0,SEP_IDX))dnl +define(FNDESC, patsubst(substr(ARGS,eval(SEP_IDX+1)),` ',`_'))dnl +dnl +format(`void test_%s_%s',FNNAME,FNDESC)(void) // Requirements: +{ + // Setup + + // Expected Function Calls + + // Function to Test + + // Asserts + +} + diff --git a/vimrc b/vimrc index 6fcdaa0..0f062ae 100644 --- a/vimrc +++ b/vimrc @@ -53,9 +53,10 @@ set completeopt=menu,longest " Show a popup menu with the longest common "============================================================================== " Global Variables "============================================================================== -let g:BufsLeft = "" " Buffers to the left of our current buffer -let g:CurBuffer = "" " Name of our current buffer -let g:BufsRight = "" " Buffers to the right of the current buffer +let g:TemplateDir = $VIMHOME . "/templates" " Directory to search for templates +let g:BufsLeft = "" " Buffers to the left of our current buffer +let g:CurBuffer = "" " Name of our current buffer +let g:BufsRight = "" " Buffers to the right of the current buffer "============================================================================== " Function and Command Definitions @@ -70,6 +71,11 @@ set statusline+=%<%=[%l][%c][%P][%L]%< "============================================================================== " Function and Command Definitions "============================================================================== + +" ToFn - Converts a group of C function prototypes to definitions ---- +command! -range=% -nargs=0 ToFn execute ",s/;/\r{\r\r}\r/" + +" LoadProject - Searches for and loads project specific settings function! LoadProject() let proj = findfile("project.vim", ".;") let path = strpart(proj, 0, match(proj, "[\\\/]project.vim$")) @@ -83,6 +89,7 @@ function! LoadProject() endif endfunction +" ReformatWhiteSpace - Convert tabs to spaces and remove trailing whitespace function! ReformatWhiteSpace() if &modifiable retab @@ -90,6 +97,19 @@ function! ReformatWhiteSpace() endif endfunction +" Template - Finds and inserts the text of the given template +function! Template(input) + let tdir = g:TemplateDir + let tname = substitute(split(a:input,' ')[0], '\r', '', '') . '.m4' + let targs = strpart(a:input,stridx(a:input,' ')+1) + if filereadable( tdir . '/' . tname ) + execute(".-1read !m4 -DARGS='" . targs . "' -I" . tdir . " " . tname) + else + echoerr "No template found: " . tname + endif +endfunction + +" UpdateStatus - Updates the status bar to display a list of buffers function! UpdateStatus(lmarg,rmarg) " Reset our Globals let g:CurBuffer = '[' . bufnr('%') . ' ' . expand('%:t') . ((&modified) ? ' +]' : ']') @@ -131,9 +151,6 @@ function! UpdateStatus(lmarg,rmarg) endif endfunction -" ---- ToFn - Converts a group of C function prototypes to definitions ---- -command! -range=% -nargs=0 ToFn execute ",s/;/\r{\r\r}\r/" - "============================================================================== " Keyboard Mappings "============================================================================== @@ -145,9 +162,6 @@ let g:mapleader = ";" map j gj map k gk -" ---- Quick Save ---- -map w :w - " ---- Toggle Fold ---- map zz za @@ -161,6 +175,9 @@ map h :nohl " ---- Omni Complete ---- inoremap +" ---- Template Replacement ---- +map ;t :call Template(getline("."))jdd + " ---- Buffer Management ---- map :bp imap :bp @@ -206,7 +223,6 @@ map :e %:p:s,.h$,.X123X,:s,.c$,.h,:s,.X123X$,.c, " Command mode abbreviations cnoreabbrev format =gg cnoreabbrev trim %s/\s\+$// -cnoreabbrev print hardcopy cnoreabbrev tofn ToFn cnoreabbrev fn ToFn cnoreabbrev ff @@ -224,9 +240,6 @@ autocmd BufWritePre * call ReformatWhiteSpace() " Update the buffer list in the status line autocmd VimEnter,BufNew,BufEnter,BufWritePost,VimResized,FocusLost,FocusGained,InsertLeave * call UpdateStatus(0,20) -" Set filetypes -autocmd BufRead,BufNewFile *.md set filetype=markdown - "============================================================================== " Doxygen Comment Configuration "============================================================================== @@ -237,9 +250,9 @@ let g:DoxygenToolkit_authorName = "Michael D. Lowis" " GVim "============================================================================== if has('gui_running') - set guioptions-=T " no toolbar - set guioptions-=m " no menubar - set guifont=Monaco:h10 " use 10 point Monaco font in gui mode + set guioptions-=T " no toolbar + set guioptions-=m " no menubar + set guifont=Monaco:h10 " use 10 point Monaco font in gui mode " GVim resets this for some stupid reason so disable visual bell ... again autocmd GUIEnter * set visualbell t_vb= -- 2.55.0