Fix #293 add neosnippet#annonymous()

This commit is contained in:
Shougo Matsushita 2015-10-21 21:13:14 +09:00
parent 7c07c4d8a2
commit bf4d2fdd31
4 changed files with 29 additions and 3 deletions

View File

@ -52,6 +52,9 @@ endfunction"}}}
function! neosnippet#jumpable() "{{{ function! neosnippet#jumpable() "{{{
return neosnippet#mappings#jumpable() return neosnippet#mappings#jumpable()
endfunction"}}} endfunction"}}}
function! neosnippet#annonymous(snippet, ...) "{{{
return neosnippet#mappings#_annonymous(a:snippet, get(a:000, 0, {}))
endfunction"}}}
function! neosnippet#get_snippets_directory() "{{{ function! neosnippet#get_snippets_directory() "{{{
return neosnippet#helpers#get_snippets_directory() return neosnippet#helpers#get_snippets_directory()

View File

@ -136,6 +136,15 @@ function! neosnippet#mappings#_expand_target_trigger(trigger) "{{{
endif endif
endfunction"}}} endfunction"}}}
function! neosnippet#mappings#_annonymous(snippet, options) "{{{
let cur_text = neosnippet#util#get_cur_text()
let options = extend(
\ neosnippet#parser#_initialize_snippet_options(),
\ a:options)
call neosnippet#view#_insert(a:snippet, options, cur_text, col('.'))
return ''
endfunction"}}}
function! s:snippets_expand(cur_text, col) "{{{ function! s:snippets_expand(cur_text, col) "{{{
let cur_word = neosnippet#helpers#get_cursor_snippet( let cur_word = neosnippet#helpers#get_cursor_snippet(
\ neosnippet#helpers#get_snippets(), \ neosnippet#helpers#get_snippets(),

View File

@ -48,7 +48,10 @@ function! neosnippet#view#_expand(cur_text, col, trigger_name) "{{{
let snippet = snippets[a:trigger_name] let snippet = snippets[a:trigger_name]
let cur_text = a:cur_text[: -1-len(a:trigger_name)] let cur_text = a:cur_text[: -1-len(a:trigger_name)]
let snip_word = snippet.snip call neosnippet#view#_insert(snippet.snip, snippet.options, cur_text, a:col)
endfunction"}}}
function! neosnippet#view#_insert(snippet, options, cur_text, col) "{{{
let snip_word = a:snippet
if snip_word =~ '\\\@<!`.*\\\@<!`' if snip_word =~ '\\\@<!`.*\\\@<!`'
let snip_word = s:eval_snippet(snip_word) let snip_word = s:eval_snippet(snip_word)
endif endif
@ -78,7 +81,7 @@ function! neosnippet#view#_expand(cur_text, col, trigger_name) "{{{
let begin_line = line('.') let begin_line = line('.')
let end_line = line('.') + len(snippet_lines) - 1 let end_line = line('.') + len(snippet_lines) - 1
let snippet_lines[0] = cur_text . snippet_lines[0] let snippet_lines[0] = a:cur_text . snippet_lines[0]
let snippet_lines[-1] = snippet_lines[-1] . next_line let snippet_lines[-1] = snippet_lines[-1] . next_line
let foldmethod_save = '' let foldmethod_save = ''
@ -97,7 +100,7 @@ function! neosnippet#view#_expand(cur_text, col, trigger_name) "{{{
endif endif
call setline('.', snippet_lines[0]) call setline('.', snippet_lines[0])
if begin_line != end_line || snippet.options.indent if begin_line != end_line || a:options.indent
call s:indent_snippet(begin_line, end_line) call s:indent_snippet(begin_line, end_line)
endif endif

View File

@ -316,6 +316,17 @@ neosnippet#expandable_or_jumpable()
\ neosnippet#expandable_or_jumpable() ? \ neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<C-n>" \ "\<Plug>(neosnippet_expand_or_jump)" : "\<C-n>"
< <
*neosnippet#annonymous()*
neosnippet#annonymous({snippet}, [{options}])
It defines anonymous snippet.
{snippet} is snippet definition.
{options} is snippet option.
You can expand snippet definition without defining snippet
trigger. >
inoremap <silent> ((
\ ((<C-r>=neosnippet#annonymous('\left(${1}\right)${0}')<CR>
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
FUNCTIONS *neosnippet-functions* FUNCTIONS *neosnippet-functions*