diff options
author | mattn <mattn.jp@gmail.com> | 2011-10-28 09:42:05 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2011-10-28 09:42:05 +0900 |
commit | 50270c6dd21fb071fdb19e37f8dc95f4d6dff616 (patch) | |
tree | 72bd93193a30943fa6db98cd94f9be54c160a0b8 | |
parent | 6bf642f27e160a9218fc839c22627e4c515efa15 (diff) | |
download | vim-sonictemplate-50270c6dd21fb071fdb19e37f8dc95f4d6dff616.tar.gz vim-sonictemplate-50270c6dd21fb071fdb19e37f8dc95f4d6dff616.tar.bz2 vim-sonictemplate-50270c6dd21fb071fdb19e37f8dc95f4d6dff616.zip |
BIG CHANGE: changed directory structure.
-rw-r--r-- | plugin/template.vim | 69 | ||||
-rw-r--r-- | template/c/base-main.c (renamed from template/main.c) | 0 | ||||
-rw-r--r-- | template/c/snip-comment-block.c (renamed from template/comment-block.c) | 0 | ||||
-rw-r--r-- | template/c/snip-for.c (renamed from template/for.c) | 0 | ||||
-rw-r--r-- | template/cpp/base-boost-main.cpp (renamed from template/boost-main.cpp) | 0 | ||||
-rw-r--r-- | template/cpp/base-main.cpp (renamed from template/main.cpp) | 0 | ||||
-rw-r--r-- | template/cpp/snip-boost-foreach.cpp (renamed from template/boost-foreach.cpp) | 0 | ||||
-rw-r--r-- | template/cpp/snip-comment-block.cpp (renamed from template/comment-block.cpp) | 0 | ||||
-rw-r--r-- | template/cpp/snip-cout.cpp (renamed from template/cout.cpp) | 0 | ||||
-rw-r--r-- | template/cpp/snip-for.cpp (renamed from template/for.cpp) | 0 | ||||
-rw-r--r-- | template/go/base-main.go (renamed from template/main.go) | 0 | ||||
-rw-r--r-- | template/go/base-package.go (renamed from template/package.go) | 0 | ||||
-rw-r--r-- | template/go/snip-goroutine.go (renamed from template/goroutine.go) | 0 | ||||
-rw-r--r-- | template/go/snip-recover.go (renamed from template/recover.go) | 0 | ||||
-rw-r--r-- | template/html/base-page.html (renamed from template/page.html) | 0 | ||||
-rw-r--r-- | template/javascript/anon-call.js (renamed from template/anonymous-call.javascript) | 0 | ||||
-rw-r--r-- | template/javascript/anon-function.js (renamed from template/anonymous-function.javascript) | 0 | ||||
-rw-r--r-- | template/javascript/jquery-each.js (renamed from template/jquery-each.javascript) | 0 | ||||
-rw-r--r-- | template/javascript/jquery-getjson.js (renamed from template/jquery-getJSON.javascript) | 0 | ||||
-rw-r--r-- | template/javascript/jquery-ready.js (renamed from template/jquery-ready.javascript) | 0 | ||||
-rw-r--r-- | template/markdown/base-readme.mkd (renamed from template/readme.markdown) | 0 | ||||
-rw-r--r-- | template/perl/base-package.pl (renamed from template/package.perl) | 0 | ||||
-rw-r--r-- | template/perl/base-scraping.pl (renamed from template/scraping.perl) | 0 | ||||
-rw-r--r-- | template/perl/base-script.pl (renamed from template/script.perl) | 0 | ||||
-rw-r--r-- | template/perl/base-test.pl (renamed from template/test.perl) | 0 | ||||
-rw-r--r-- | template/perl/snip-dbi-connect-sqlite.pl (renamed from template/dbi-connect-sqlite.perl) | 0 | ||||
-rw-r--r-- | template/perl/snip-dbi-prepare.pl (renamed from template/dbi-prepare.perl) | 2 | ||||
-rw-r--r-- | template/perl/snip-file-read.pl (renamed from template/read-file.perl) | 0 | ||||
-rw-r--r-- | template/perl/snip-pit.pl (renamed from template/pit.perl) | 0 | ||||
-rw-r--r-- | template/perl/snip-sub.pl (renamed from template/sub.perl) | 0 | ||||
-rw-r--r-- | template/python/base-main.py (renamed from template/main.python) | 0 | ||||
-rw-r--r-- | template/ruby/snip-pit.rb (renamed from template/pit.ruby) | 0 |
32 files changed, 35 insertions, 36 deletions
diff --git a/plugin/template.vim b/plugin/template.vim index b1d2a12..a6cbc59 100644 --- a/plugin/template.vim +++ b/plugin/template.vim @@ -26,21 +26,28 @@ else let s:tmpldir = expand('<sfile>:p:h:h') . '/template/' endif -function! TemplateComplete(lead, cmdline, curpos) - return map(split(globpath(s:tmpldir, a:lead.'*.'.&ft), "\n"), 'fnamemodify(v:val, ":t:r")') +function! TemplateComplete(lead, cmdline, curpos) abort + if search('[^ \t]', 'wn') + return map(split(globpath(join([s:tmpldir, &ft], '/'), 'snip-' . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') + else + return map(split(globpath(join([s:tmpldir, &ft], '/'), 'base-' . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') + endif endfunction -function! s:Template(name) +function! s:Template(name) abort let buffer_is_not_empty = search('[^ \t]', 'wn') - if exists('g:template_vim_only_first') && g:template_vim_only_first == 1 - if buffer_is_not_empty - echomsg 'This buffer is already modified.' - return - endif + if search('[^ \t]', 'wn') + let fs = split(globpath(join([s:tmpldir, &ft], '/'), 'snip-' . a:name . '.*'), "\n") + else + let fs = split(globpath(join([s:tmpldir, &ft], '/'), 'base-' . a:name . '.*'), "\n") + endif + if len(fs) == 0 + echomsg 'Template '.a:name.' is not exists.' + return endif - let f = s:tmpldir . a:name . '.' . &ft + let f = fs[0] if !filereadable(f) - echomsg 'Template '.a:name.' is not exists.' . f + echomsg 'Template '.a:name.' is not exists.' return endif let c = join(readfile(f, "b"), "\n") @@ -67,37 +74,29 @@ function! s:Template(name) if len(c) == 0 return endif - if exists('g:template_vim_only_first') && g:template_vim_only_first == 1 + if !buffer_is_not_empty silent! %d _ silent! put = c silent! normal! ggdd - silent! call search('{{_cursor_}}', 'w') - silent! %s/{{_cursor_}}//g else - if !buffer_is_not_empty - silent! %d _ - silent! put = c - silent! normal! ggdd - else - if c[len(c)-1] == "\n" - let c = c[:-2] - endif - let line = getline('.') - let indent = matchstr(line, '^\(\s*\)') - if line =~ '^\s*$' && line('.') != line('$') - silent! normal dd - endif - let c = indent . substitute(c, "\n", "\n".indent, 'g') - if len(indent) && (&expandtab || indent =~ '^ \+$') - let c = substitute(c, "\t", repeat(' ', min([len(indent), &tabstop])), 'g') - endif - silent! put! = c + if c[len(c)-1] == "\n" + let c = c[:-2] + endif + let line = getline('.') + let indent = matchstr(line, '^\(\s*\)') + if line =~ '^\s*$' && line('.') != line('$') + silent! normal dd endif - if stridx(c, '{{_cursor_}}') - silent! call search('{{_cursor_}}', 'w') - silent! s/{{_cursor_}}//g - silent! exe "normal! \<c-o>" + let c = indent . substitute(c, "\n", "\n".indent, 'g') + if len(indent) && (&expandtab || indent =~ '^ \+$') + let c = substitute(c, "\t", repeat(' ', min([len(indent), &tabstop])), 'g') endif + silent! put! = c + endif + if stridx(c, '{{_cursor_}}') + silent! call search('{{_cursor_}}', 'w') + silent! s/{{_cursor_}}//g + silent! exe "normal! \<c-o>" endif endfunction diff --git a/template/main.c b/template/c/base-main.c index 794d581..794d581 100644 --- a/template/main.c +++ b/template/c/base-main.c diff --git a/template/comment-block.c b/template/c/snip-comment-block.c index 5d93c0d..5d93c0d 100644 --- a/template/comment-block.c +++ b/template/c/snip-comment-block.c diff --git a/template/for.c b/template/c/snip-for.c index 210541e..210541e 100644 --- a/template/for.c +++ b/template/c/snip-for.c diff --git a/template/boost-main.cpp b/template/cpp/base-boost-main.cpp index dab2cde..dab2cde 100644 --- a/template/boost-main.cpp +++ b/template/cpp/base-boost-main.cpp diff --git a/template/main.cpp b/template/cpp/base-main.cpp index 1a92edb..1a92edb 100644 --- a/template/main.cpp +++ b/template/cpp/base-main.cpp diff --git a/template/boost-foreach.cpp b/template/cpp/snip-boost-foreach.cpp index 411e066..411e066 100644 --- a/template/boost-foreach.cpp +++ b/template/cpp/snip-boost-foreach.cpp diff --git a/template/comment-block.cpp b/template/cpp/snip-comment-block.cpp index 5d93c0d..5d93c0d 100644 --- a/template/comment-block.cpp +++ b/template/cpp/snip-comment-block.cpp diff --git a/template/cout.cpp b/template/cpp/snip-cout.cpp index cf75f01..cf75f01 100644 --- a/template/cout.cpp +++ b/template/cpp/snip-cout.cpp diff --git a/template/for.cpp b/template/cpp/snip-for.cpp index 210541e..210541e 100644 --- a/template/for.cpp +++ b/template/cpp/snip-for.cpp diff --git a/template/main.go b/template/go/base-main.go index fb96c46..fb96c46 100644 --- a/template/main.go +++ b/template/go/base-main.go diff --git a/template/package.go b/template/go/base-package.go index 14586d8..14586d8 100644 --- a/template/package.go +++ b/template/go/base-package.go diff --git a/template/goroutine.go b/template/go/snip-goroutine.go index 6fc6038..6fc6038 100644 --- a/template/goroutine.go +++ b/template/go/snip-goroutine.go diff --git a/template/recover.go b/template/go/snip-recover.go index 593d853..593d853 100644 --- a/template/recover.go +++ b/template/go/snip-recover.go diff --git a/template/page.html b/template/html/base-page.html index fbc6486..fbc6486 100644 --- a/template/page.html +++ b/template/html/base-page.html diff --git a/template/anonymous-call.javascript b/template/javascript/anon-call.js index b9873d9..b9873d9 100644 --- a/template/anonymous-call.javascript +++ b/template/javascript/anon-call.js diff --git a/template/anonymous-function.javascript b/template/javascript/anon-function.js index ec979d5..ec979d5 100644 --- a/template/anonymous-function.javascript +++ b/template/javascript/anon-function.js diff --git a/template/jquery-each.javascript b/template/javascript/jquery-each.js index 77ef854..77ef854 100644 --- a/template/jquery-each.javascript +++ b/template/javascript/jquery-each.js diff --git a/template/jquery-getJSON.javascript b/template/javascript/jquery-getjson.js index 037e726..037e726 100644 --- a/template/jquery-getJSON.javascript +++ b/template/javascript/jquery-getjson.js diff --git a/template/jquery-ready.javascript b/template/javascript/jquery-ready.js index 27bc0d2..27bc0d2 100644 --- a/template/jquery-ready.javascript +++ b/template/javascript/jquery-ready.js diff --git a/template/readme.markdown b/template/markdown/base-readme.mkd index a4b3246..a4b3246 100644 --- a/template/readme.markdown +++ b/template/markdown/base-readme.mkd diff --git a/template/package.perl b/template/perl/base-package.pl index b4fa22c..b4fa22c 100644 --- a/template/package.perl +++ b/template/perl/base-package.pl diff --git a/template/scraping.perl b/template/perl/base-scraping.pl index ffb696d..ffb696d 100644 --- a/template/scraping.perl +++ b/template/perl/base-scraping.pl diff --git a/template/script.perl b/template/perl/base-script.pl index 01e3ce9..01e3ce9 100644 --- a/template/script.perl +++ b/template/perl/base-script.pl diff --git a/template/test.perl b/template/perl/base-test.pl index 3971050..3971050 100644 --- a/template/test.perl +++ b/template/perl/base-test.pl diff --git a/template/dbi-connect-sqlite.perl b/template/perl/snip-dbi-connect-sqlite.pl index 9366290..9366290 100644 --- a/template/dbi-connect-sqlite.perl +++ b/template/perl/snip-dbi-connect-sqlite.pl diff --git a/template/dbi-prepare.perl b/template/perl/snip-dbi-prepare.pl index b242b82..5424219 100644 --- a/template/dbi-prepare.perl +++ b/template/perl/snip-dbi-prepare.pl @@ -1,5 +1,5 @@ my $sth = $dbh->prepare("{{_cursor_}}"); $sth->execute; while (my @row = $sth->fetchrow_array) { - # print join(', ', @row), "\n"; + #print join(', ', @row), "\n"; } diff --git a/template/read-file.perl b/template/perl/snip-file-read.pl index 53138a4..53138a4 100644 --- a/template/read-file.perl +++ b/template/perl/snip-file-read.pl diff --git a/template/pit.perl b/template/perl/snip-pit.pl index 710aa50..710aa50 100644 --- a/template/pit.perl +++ b/template/perl/snip-pit.pl diff --git a/template/sub.perl b/template/perl/snip-sub.pl index 32f0e6d..32f0e6d 100644 --- a/template/sub.perl +++ b/template/perl/snip-sub.pl diff --git a/template/main.python b/template/python/base-main.py index e40b7ba..e40b7ba 100644 --- a/template/main.python +++ b/template/python/base-main.py diff --git a/template/pit.ruby b/template/ruby/snip-pit.rb index d8682d5..d8682d5 100644 --- a/template/pit.ruby +++ b/template/ruby/snip-pit.rb |