aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2016-07-04 09:49:41 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2016-07-04 09:49:41 +0900
commitffb805ca09df9530c806a25b86cadb48892fa40f (patch)
tree236e0a6a41de43e7662f424b33e459767b7ae5da
parent58b5595f88909e9d45eb338e31d2952a8e1d9c8f (diff)
downloadvim-sonictemplate-ffb805ca09df9530c806a25b86cadb48892fa40f.tar.gz
vim-sonictemplate-ffb805ca09df9530c806a25b86cadb48892fa40f.tar.bz2
vim-sonictemplate-ffb805ca09df9530c806a25b86cadb48892fa40f.zip
add postfix for go
-rw-r--r--autoload/sonictemplate.vim23
-rw-r--r--template/go/pattern.stpl18
2 files changed, 34 insertions, 7 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 91f45df..c543b20 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -333,19 +333,28 @@ function! sonictemplate#postfix()
let c = substitute(c, '{{$' . i . '}}', ml[i], 'g')
endfor
let indent = matchstr(line, '^\(\s*\)')
- if len(indent) && (&expandtab || (&shiftwidth && &tabstop != &shiftwidth) || indent =~ '^ \+$')
- let c = substitute(c, "\t", repeat(' ', min([len(indent), &shiftwidth])), 'g')
- elseif &expandtab || (&shiftwidth && &tabstop != &shiftwidth)
- let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g')
- endif
if line !~ '^\s*$'
let lhs = col('.') > 1 ? line[:col('.')-2] : ''
let rhs = line[len(lhs):]
let lhs = lhs[len(indent):]
let c = lhs . c . rhs
endif
- call setline('.', line)
- silent! exe "normal! a\<c-r>=c\<cr>"
+ if c =~ "\n"
+ let c = indent . substitute(substitute(c, "\n", "\n".indent, 'g'), "\n".indent."\n", "\n\n", 'g')
+ if len(indent) && (&expandtab || (&shiftwidth && &tabstop != &shiftwidth) || indent =~ '^ \+$')
+ let c = substitute(c, "\t", repeat(' ', min([len(indent), &shiftwidth])), 'g')
+ elseif &expandtab || (&shiftwidth && &tabstop != &shiftwidth)
+ let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g')
+ endif
+ call setline('.', line)
+ if line('.') < line('$')
+ silent! normal! dd
+ endif
+ silent! put! =c
+ else
+ call setline('.', line)
+ silent! exe "normal! a\<c-r>=c\<cr>"
+ endif
if stridx(c, '{{_cursor_}}') != -1
silent! call search('{{_cursor_}}\zs', 'w')
silent! foldopen
diff --git a/template/go/pattern.stpl b/template/go/pattern.stpl
new file mode 100644
index 0000000..45c3b02
--- /dev/null
+++ b/template/go/pattern.stpl
@@ -0,0 +1,18 @@
+\(\S\+\)\.var$
+ var {{$1}} = {{_cursor_}}
+
+\(\S\+\)\.iferr$
+ if {{$1}} != nil {
+ return err
+ }
+ {{_cursor_}}
+
+\(\S\+\)\.fatal$
+ if {{$1}} != nil {
+ log.Fatal(err)
+ }
+ {{_cursor_}}
+
+\(\S\+\)\.log$
+ log.Println({{$1}})
+ {{_cursor_}}