diff options
author | mattn <mattn.jp@gmail.com> | 2011-10-25 10:23:00 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2011-10-25 10:23:00 +0900 |
commit | 2c81841396b1505461775c3ba65f7880a57bb7b1 (patch) | |
tree | c1a220f4ce8c5583f08103dfcc7d3c5745664561 | |
download | vim-sonictemplate-2c81841396b1505461775c3ba65f7880a57bb7b1.tar.gz vim-sonictemplate-2c81841396b1505461775c3ba65f7880a57bb7b1.tar.bz2 vim-sonictemplate-2c81841396b1505461775c3ba65f7880a57bb7b1.zip |
first import.
-rw-r--r-- | plugin/template.vim | 49 | ||||
-rw-r--r-- | template/main.c | 7 | ||||
-rw-r--r-- | template/main.cpp | 8 | ||||
-rw-r--r-- | template/main.go | 5 | ||||
-rw-r--r-- | template/package.go | 3 | ||||
-rw-r--r-- | template/package.perl | 9 | ||||
-rw-r--r-- | template/script.perl | 5 | ||||
-rw-r--r-- | template/test.perl | 6 |
8 files changed, 92 insertions, 0 deletions
diff --git a/plugin/template.vim b/plugin/template.vim new file mode 100644 index 0000000..de6c001 --- /dev/null +++ b/plugin/template.vim @@ -0,0 +1,49 @@ +" template.vim: Vim commands to load template. +" +" This filetype plugin adds one command for the buffers: +" +" :Template {name} +" +" Load template named as {name} in the current buffer. +" Template file is stored in ~/.vim/template. +" If you are using pathogen.vim, template folder is located at following. +" +" ~/.vim/bundle/template-vim +" plugin +" template.vim # This file. +" template +" main.go +" package.go +" package.perl +" script.perl +" + +command! -buffer -nargs=1 -complete=customlist,TemplateComplete Template call s:Template(<f-args>) + +let s:tmpldir = expand('<sfile>:p:h:h') . '/template/' + +function! TemplateComplete(lead, cmdline, curpos) + return map(split(globpath(s:tmpldir, '*.'.&ft), "\n"), 'fnamemodify(v:val, ":t:r")') +endfunction + +function! s:Template(name) + if search('[^ \t]', 'w') != 0 + echomsg 'This buffer is already modified.' + return + endif + let f = s:tmpldir . a:name . '.' . &ft + if !filereadable(f) + echomsg 'Template '.a:name.' is not exists.' . f + return + endif + let c = join(readfile(f, "b"), "\n") + let c = substitute(c, '{{_name_}}', expand('%:t:r:'), 'g') + let c = substitute(c, '{{_expr_:\(.\{-}\)}}', '\=eval(submatch(1))', 'g') + silent! %d _ + silent! put = c + silent! normal! ggdd + silent! call search('{{_cursor_}}', 'w') + silent! %s/{{_cursor_}}//g +endfunction + +" vim:ts=4:sw=4:et diff --git a/template/main.c b/template/main.c new file mode 100644 index 0000000..f2a929b --- /dev/null +++ b/template/main.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int +main(int argc, char* argv[]) { + {{_cursor_}} + return 0; +} diff --git a/template/main.cpp b/template/main.cpp new file mode 100644 index 0000000..c413be8 --- /dev/null +++ b/template/main.cpp @@ -0,0 +1,8 @@ +#include <iostream> +#include <string> + +int +main(int argc, char* argv[]) { + {{_cursor_}} + return 0; +} diff --git a/template/main.go b/template/main.go new file mode 100644 index 0000000..fb96c46 --- /dev/null +++ b/template/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + {{_cursor_}} +} diff --git a/template/package.go b/template/package.go new file mode 100644 index 0000000..14586d8 --- /dev/null +++ b/template/package.go @@ -0,0 +1,3 @@ +package {{_name_}} + +{{_cursor_}} diff --git a/template/package.perl b/template/package.perl new file mode 100644 index 0000000..b4fa22c --- /dev/null +++ b/template/package.perl @@ -0,0 +1,9 @@ +package {{_expr_:substitute(substitute(substitute(expand('%'), '.*lib[\\/]', '', 'g'), '[\\/]', '::', 'g'), '\.pm$', '', 'g')}}; + +use strict; +use warnings; +use utf8; + +{{_cursor_}} + +1 diff --git a/template/script.perl b/template/script.perl new file mode 100644 index 0000000..01e3ce9 --- /dev/null +++ b/template/script.perl @@ -0,0 +1,5 @@ +use strict; +use warnings; +use utf8; + +{{_cursor_}} diff --git a/template/test.perl b/template/test.perl new file mode 100644 index 0000000..3971050 --- /dev/null +++ b/template/test.perl @@ -0,0 +1,6 @@ +use strict; +use warnings; +use utf8; +use Test::More; + +{{_cursor_}} |