aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/sonictemplate.vim8
-rw-r--r--doc/sonictemplate-vim.txt29
-rw-r--r--plugin/sonictemplate.vim30
3 files changed, 50 insertions, 17 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 38928a7..91f45df 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -317,7 +317,8 @@ endfunction
let s:pat = {}
-function! sonictemplate#pattern()
+function! sonictemplate#postfix()
+ call sonictemplate#load_postfix()
if !has_key(s:pat, &ft)
return ''
endif
@@ -356,8 +357,11 @@ function! sonictemplate#pattern()
return ''
endfunction
-function! sonictemplate#load_pattern()
+function! sonictemplate#load_postfix()
let ft = &ft
+ if has_key(s:pat, ft)
+ return
+ endif
let tmp = []
for tmpldir in s:tmpldir
let tmp += split(globpath(join([tmpldir, ft], '/'), 'pattern.stpl'), "\n")
diff --git a/doc/sonictemplate-vim.txt b/doc/sonictemplate-vim.txt
index 429ffa7..0cde2c0 100644
--- a/doc/sonictemplate-vim.txt
+++ b/doc/sonictemplate-vim.txt
@@ -16,6 +16,7 @@ CONTENTS *sonictemplate-vim-contents*
Introduction |sonictemplate-vim-introduction|
Install |sonictemplate-vim-install|
Tutorial |sonictemplate-vim-tutorial|
+Postfix Completion |sonictemplate-vim-postfix-completion|
Customize |sonictemplate-vim-customize|
Unite Source |sonictemplate-vim-unitesource|
Write Your Template |sonictemplate-vim-writetemplate|
@@ -106,6 +107,34 @@ For example, you are writing C++ file.
}
<
==============================================================================
+POSTFIX COMPLETION *sonictemplate-vim-postfix-completion*
+
+Sonictemplate provide postfix-completion. For example: >
+
+ name.var_
+<
+Typing "<c-y><c-y>" expand to: >
+
+ var name = _;
+<
+You can customize your own postfix patterns with putting file "pattern.stpl"
+in template directory. >
+
+ \(\S\+\)\.var$
+ var {{$1}} = {{_cursor_}};
+
+ ^\s*\zs\(\S.*\)\.throw$
+ throw {{$1}};
+
+ \(\S\+\)\.notif$
+ if ({{$1}} != null) {
+ {{_cursor_}}
+ }
+<
+The pattern must be located at leading of per lines. The texts should be
+expanded are following with tab characters prefixed.
+
+==============================================================================
CUSTOMIZE *sonictemplate-vim-customize*
You can modify template directory for your-self templates: >
diff --git a/plugin/sonictemplate.vim b/plugin/sonictemplate.vim
index 06f598a..6c8a6fa 100644
--- a/plugin/sonictemplate.vim
+++ b/plugin/sonictemplate.vim
@@ -22,34 +22,34 @@ set cpo&vim
exe "command!" "-nargs=1" "-complete=customlist,sonictemplate#complete" get(g:, 'sonictemplate_commandname', 'Template') "call sonictemplate#apply(<f-args>, 'n')"
+nnoremap <plug>(sonictemplate) :call sonictemplate#select('n')<cr>
+inoremap <plug>(sonictemplate) <c-r>=sonictemplate#select('i')<cr>
+
if get(g:, 'sonictemplate_key', '') == ''
- nnoremap <plug>(sonictemplate) :call sonictemplate#select('n')<cr>
- inoremap <plug>(sonictemplate) <c-r>=sonictemplate#select('i')<cr>
nmap <unique> <c-y>t <plug>(sonictemplate)
imap <unique> <c-y>t <plug>(sonictemplate)
nmap <unique> <c-y><c-t> <plug>(sonictemplate)
imap <unique> <c-y><c-t> <plug>(sonictemplate)
else
- exe "nnoremap" g:sonictemplate_key ":call sonictemplate#select('n')<cr>"
- exe "inoremap" g:sonictemplate_key "<c-r>=sonictemplate#select('i')<cr>"
+ exe "nnoremap" g:sonictemplate_key "<plug>(sonictemplate)"
+ exe "inoremap" g:sonictemplate_key "<plug>(sonictemplate)"
endif
+
+nnoremap <plug>(sonictemplate-intelligent) :call sonictemplate#select_intelligent('n')<cr>
+inoremap <plug>(sonictemplate-intelligent) <c-r>=sonictemplate#select_intelligent('i')<cr>
if get(g:, 'sonictemplate_intelligent_key', '') == ''
- nnoremap <plug>(sonictemplate-intelligent) :call sonictemplate#select_intelligent('n')<cr>
- inoremap <plug>(sonictemplate-intelligent) <c-r>=sonictemplate#select_intelligent('i')<cr>
nmap <unique> <c-y>T <plug>(sonictemplate-intelligent)
imap <unique> <c-y>T <plug>(sonictemplate-intelligent)
else
- exe "nnoremap" g:sonictemplate_intelligent_key ":call sonictemplate#select_intelligent('n')<cr>"
- exe "inoremap" g:sonictemplate_intelligent_key "<c-r>=sonictemplate#select_intelligent('i')<cr>"
+ exe "nnoremap" g:sonictemplate_intelligent_key "<plug>(sonictemplate-intelligent)"
+ exe "inoremap" g:sonictemplate_intelligent_key "<plug>(sonictemplate-intelligent)"
endif
-" TODO fix better name
-if get(g:, 'sonictemplate_enable_pattern', 0) != 0
- augroup sonictemplate
- au! filetype * silent! call sonictemplate#load_pattern()
- augroup END
- inoremap <plug>(sonictemplate-pattern) <c-r>=sonictemplate#pattern()<cr>
- imap <unique> <c-y><c-b> <plug>(sonictemplate-pattern)
+inoremap <plug>(sonictemplate-postfix) <c-r>=sonictemplate#postfix()<cr>
+if get(g:, 'sonictemplate_postfix_key', '') == ''
+ imap <unique> <c-y><c-b> <plug>(sonictemplate-postfix)
+else
+ exe "inoremap" g:sonictemplate_postfix_key "<plug>(sonictemplate-postfix)"
endif
let &cpo = s:save_cpo