aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/sonictemplate.vim26
-rw-r--r--autoload/sonictemplate/lang/html.vim2
-rw-r--r--autoload/sonictemplate/lang/perl.vim2
-rw-r--r--autoload/unite/kinds/sonictemplate.vim8
-rw-r--r--autoload/unite/sources/sonictemplate.vim12
-rw-r--r--template/go/base-package-cgo.go2
-rw-r--r--template/go/base-package.go2
7 files changed, 30 insertions, 24 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 31492fe..229d2cb 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -34,7 +34,7 @@ function! sonictemplate#select_intelligent(mode) abort
return ''
endfunction
-function! sonictemplate#get_filetype()
+function! sonictemplate#get_filetype() abort
let c = col('.')
if c == col('$')
let c -= 1
@@ -52,7 +52,7 @@ function! sonictemplate#get_filetype()
return ft
endfunction
-function! s:get_candidate(fts, lead)
+function! s:get_candidate(fts, lead) abort
let fts = a:fts
let filter = ''
if getcmdwintype() ==# ''
@@ -136,14 +136,14 @@ function! sonictemplate#complete_intelligent(lead, cmdline, curpos) abort
return s:get_candidate([sonictemplate#get_filetype(), s:get_raw_filetype(), s:get_filetype()], a:lead)
endfunction
-function! s:setopt(k, v)
+function! s:setopt(k, v) abort
if !exists('b:sonictemplate')
let b:sonictemplate = {}
endif
let b:sonictemplate[a:k] = a:v
endfunction
-function! s:getopt(k)
+function! s:getopt(k) abort
if !exists('b:sonictemplate') || !has_key(b:sonictemplate, a:k)
return ''
endif
@@ -152,15 +152,15 @@ endfunction
let s:vars = {}
-function! s:get_filetype()
+function! s:get_filetype() abort
return matchstr(s:get_raw_filetype(), '^\([^.]\)\+')
endfunction
-function! s:get_raw_filetype()
+function! s:get_raw_filetype() abort
return getcmdwintype() ==# '' ? &ft : getbufvar('#', '&ft')
endfunction
-function! sonictemplate#getvar(name)
+function! sonictemplate#getvar(name) abort
let ft = s:get_filetype()
let ft = ft != "" ? ft : "_"
if !has_key(s:vars, ft)
@@ -169,6 +169,11 @@ function! sonictemplate#getvar(name)
return has_key(s:vars[ft], a:name) ? s:vars[ft][a:name] : ''
endfunction
+function! s:name(default) abort
+ let l:name = expand('%:t:r:')
+ return empty(l:name) ? a:default : l:name
+endfunction
+
function! sonictemplate#apply(name, mode, ...) abort
let name = matchstr(a:name, '\S\+')
let buffer_is_not_empty = search('[^ \t]', 'wn')
@@ -218,7 +223,8 @@ function! sonictemplate#apply(name, mode, ...) abort
let ft = s:get_filetype()
let ft = ft != "" ? ft : "_"
let c = join(readfile(f), "\n")
- let c = substitute(c, '{{_name_}}', expand('%:t:r:'), 'g')
+ let c = substitute(c, '{{_name_}}', s:name('Main'), 'g')
+ let c = substitute(c, '{{_name_:\([^}]\+\)}}', '\=s:name(submatch(1))', 'g')
let tmp = c
let mx = '{{_input_:\(.\{-}\)}}'
if !has_key(s:vars, ft)
@@ -330,7 +336,7 @@ endfunction
let s:pat = {}
-function! sonictemplate#postfix()
+function! sonictemplate#postfix() abort
call sonictemplate#load_postfix()
if !has_key(s:pat, s:get_raw_filetype())
return ''
@@ -385,7 +391,7 @@ function! sonictemplate#postfix()
return ''
endfunction
-function! sonictemplate#load_postfix()
+function! sonictemplate#load_postfix() abort
let ft = s:get_raw_filetype()
if has_key(s:pat, ft)
return
diff --git a/autoload/sonictemplate/lang/html.vim b/autoload/sonictemplate/lang/html.vim
index 36d20c9..e8f22ae 100644
--- a/autoload/sonictemplate/lang/html.vim
+++ b/autoload/sonictemplate/lang/html.vim
@@ -1,4 +1,4 @@
-function! sonictemplate#lang#html#guess()
+function! sonictemplate#lang#html#guess() abort
let [m1, m2] = ['<\([^ >]\+\)[^>]*>', '</[^>]\+>\zs']
let area = [searchpairpos(m1, '\%#', m2, 'bnW'), searchpos(m2, 'nW')]
if area[0][0] == 0 || area[1][0] == 0
diff --git a/autoload/sonictemplate/lang/perl.vim b/autoload/sonictemplate/lang/perl.vim
index add3d12..c9e5a6d 100644
--- a/autoload/sonictemplate/lang/perl.vim
+++ b/autoload/sonictemplate/lang/perl.vim
@@ -1,4 +1,4 @@
-function! sonictemplate#lang#perl#guess()
+function! sonictemplate#lang#perl#guess() abort
if expand('%:t') ==# 'Makefile.PL'
return {
\ 'filter': 'make',
diff --git a/autoload/unite/kinds/sonictemplate.vim b/autoload/unite/kinds/sonictemplate.vim
index 2e61d9c..a42bced 100644
--- a/autoload/unite/kinds/sonictemplate.vim
+++ b/autoload/unite/kinds/sonictemplate.vim
@@ -6,9 +6,9 @@
let s:save_cpo = &cpo
set cpo&vim
-function! unite#kinds#sonictemplate#define()"{{{
+function! unite#kinds#sonictemplate#define() abort "{{{
return s:kind
-endfunction"}}}
+endfunction "}}}
let s:kind = {
\ 'name' : 'sonictemplate',
@@ -25,12 +25,12 @@ let s:kind.action_table.insert = {
\ 'is_invalidate_cache' : 0,
\ 'is_listed' : 1,
\}
-function! s:kind.action_table.insert.func(candidate)"{{{
+function! s:kind.action_table.insert.func(candidate) abort "{{{
call sonictemplate#apply(
\ a:candidate.word,
\ a:candidate.action__mode,
\ )
-endfunction"}}}
+endfunction "}}}
" local functions {{{
" }}}
diff --git a/autoload/unite/sources/sonictemplate.vim b/autoload/unite/sources/sonictemplate.vim
index 93578b7..894da2e 100644
--- a/autoload/unite/sources/sonictemplate.vim
+++ b/autoload/unite/sources/sonictemplate.vim
@@ -6,16 +6,16 @@
let s:save_cpo = &cpo
set cpo&vim
-function! unite#sources#sonictemplate#define()"{{{
+function! unite#sources#sonictemplate#define() abort "{{{
return s:source
-endfunction"}}}
+endfunction "}}}
let s:source = {
\ 'name' : 'sonictemplate',
\ 'description' : 'disp templates for sonictemplate',
\}
-function! s:source.gather_candidates(args, context)"{{{
+function! s:source.gather_candidates(args, context) abort "{{{
call unite#print_message('[sonictemplate]')
return s:uniq(map(
\ sonictemplate#complete("", "", 0), '{
@@ -27,10 +27,10 @@ function! s:source.gather_candidates(args, context)"{{{
\ "action__path" : v:val,
\ }'
\ ))
-endfunction"}}}
+endfunction "}}}
" local functions {{{
-function! s:uniq(candidates)
+function! s:uniq(candidates) abort
let has = {}
let uniq_list = []
for candidate in a:candidates
@@ -44,7 +44,7 @@ function! s:uniq(candidates)
return uniq_list
endfunction
-function! s:to_template_name(path)
+function! s:to_template_name(path) abort
return substitute(fnamemodify(a:path, ':t:r'), '^\%(base\|snip\)-', '', '')
endfunction
" }}}
diff --git a/template/go/base-package-cgo.go b/template/go/base-package-cgo.go
index 50dab19..86b7739 100644
--- a/template/go/base-package-cgo.go
+++ b/template/go/base-package-cgo.go
@@ -1,4 +1,4 @@
-package {{_name_}}
+package {{_name_:main}}
/*
#include {{_cursor_}}
diff --git a/template/go/base-package.go b/template/go/base-package.go
index 14586d8..4ab0650 100644
--- a/template/go/base-package.go
+++ b/template/go/base-package.go
@@ -1,3 +1,3 @@
-package {{_name_}}
+package {{_name_:main}}
{{_cursor_}}