Add map-<expr> support in neosnippet#anonymous()
This commit is contained in:
parent
6ce1d55242
commit
625382fab1
@ -52,8 +52,8 @@ endfunction"}}}
|
||||
function! neosnippet#jumpable() "{{{
|
||||
return neosnippet#mappings#jumpable()
|
||||
endfunction"}}}
|
||||
function! neosnippet#anonymous(snippet, ...) "{{{
|
||||
return neosnippet#mappings#_anonymous(a:snippet, get(a:000, 0, {}))
|
||||
function! neosnippet#anonymous(snippet) "{{{
|
||||
return neosnippet#mappings#_anonymous(a:snippet)
|
||||
endfunction"}}}
|
||||
function! neosnippet#expand(trigger) "{{{
|
||||
return neosnippet#mappings#_expand(a:trigger)
|
||||
|
@ -136,34 +136,17 @@ function! neosnippet#mappings#_expand_target_trigger(trigger) "{{{
|
||||
endif
|
||||
endfunction"}}}
|
||||
|
||||
function! neosnippet#mappings#_anonymous(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 ''
|
||||
function! neosnippet#mappings#_anonymous(snippet) "{{{
|
||||
let [cur_text, col, expr] = s:pre_trigger()
|
||||
let expr .= printf("\<ESC>:call neosnippet#view#_insert(%s, {}, %s, %d)\<CR>",
|
||||
\ string(a:snippet), string(cur_text), col)
|
||||
|
||||
return expr
|
||||
endfunction"}}}
|
||||
function! neosnippet#mappings#_expand(trigger) "{{{
|
||||
call neosnippet#init#check()
|
||||
let [cur_text, col, expr] = s:pre_trigger()
|
||||
|
||||
let cur_text = neosnippet#util#get_cur_text()
|
||||
|
||||
let col = col('.')
|
||||
if mode() !=# 'i'
|
||||
" Fix column.
|
||||
let col += 2
|
||||
endif
|
||||
|
||||
" Get selected text.
|
||||
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||
let neosnippet.trigger = 1
|
||||
let expr = ''
|
||||
if mode() ==# 's' && neosnippet.optional_tabstop
|
||||
let expr .= "\<C-o>\"_d"
|
||||
endif
|
||||
|
||||
let expr .= printf("\<ESC>:call neosnippet#view#_expand(%s,%d, %s)\<CR>",
|
||||
let expr .= printf("\<ESC>:call neosnippet#view#_expand(%s, %d, %s)\<CR>",
|
||||
\ string(cur_text), col, string(a:trigger))
|
||||
|
||||
return expr
|
||||
@ -208,6 +191,15 @@ function! s:SID_PREFIX() "{{{
|
||||
endfunction"}}}
|
||||
|
||||
function! neosnippet#mappings#_trigger(function) "{{{
|
||||
let [cur_text, col, expr] = s:pre_trigger()
|
||||
|
||||
let expr .= printf("\<ESC>:call %s(%s,%d)\<CR>",
|
||||
\ a:function, string(cur_text), col)
|
||||
|
||||
return expr
|
||||
endfunction"}}}
|
||||
|
||||
function! s:pre_trigger() "{{{
|
||||
call neosnippet#init#check()
|
||||
|
||||
let cur_text = neosnippet#util#get_cur_text()
|
||||
@ -226,10 +218,7 @@ function! neosnippet#mappings#_trigger(function) "{{{
|
||||
let expr .= "\<C-o>\"_d"
|
||||
endif
|
||||
|
||||
let expr .= printf("\<ESC>:call %s(%s,%d)\<CR>",
|
||||
\ a:function, string(cur_text), col)
|
||||
|
||||
return expr
|
||||
return [cur_text, col, expr]
|
||||
endfunction"}}}
|
||||
|
||||
" Plugin key-mappings.
|
||||
|
@ -51,6 +51,10 @@ function! neosnippet#view#_expand(cur_text, col, trigger_name) "{{{
|
||||
call neosnippet#view#_insert(snippet.snip, snippet.options, cur_text, a:col)
|
||||
endfunction"}}}
|
||||
function! neosnippet#view#_insert(snippet, options, cur_text, col) "{{{
|
||||
let options = extend(
|
||||
\ neosnippet#parser#_initialize_snippet_options(),
|
||||
\ a:options)
|
||||
|
||||
let snip_word = a:snippet
|
||||
if snip_word =~ '\\\@<!`.*\\\@<!`'
|
||||
let snip_word = s:eval_snippet(snip_word)
|
||||
@ -100,7 +104,7 @@ function! neosnippet#view#_insert(snippet, options, cur_text, col) "{{{
|
||||
endif
|
||||
call setline('.', snippet_lines[0])
|
||||
|
||||
if begin_line != end_line || a:options.indent
|
||||
if begin_line != end_line || options.indent
|
||||
call s:indent_snippet(begin_line, end_line)
|
||||
endif
|
||||
|
||||
|
@ -320,17 +320,19 @@ neosnippet#expandable_or_jumpable()
|
||||
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<C-n>"
|
||||
<
|
||||
*neosnippet#anonymous()*
|
||||
neosnippet#anonymous({snippet}, [{options}])
|
||||
neosnippet#anonymous({snippet})
|
||||
It defines anonymous snippet.
|
||||
{snippet} is snippet definition.
|
||||
{options} is snippet option.
|
||||
You can expand snippet definition without defining snippet
|
||||
trigger.
|
||||
Note: You cannot use it in |map-<expr>|. It changes the
|
||||
buffer text.
|
||||
Note: You can use this function with |map-<expr>|.
|
||||
>
|
||||
inoremap <silent> ((
|
||||
\ <C-r>=neosnippet#anonymous('\left(${1}\right)${0}')<CR>
|
||||
" OR
|
||||
inoremap <expr><silent> ((
|
||||
\ neosnippet#anonymous('\left(${1}\right)${0}')
|
||||
<
|
||||
*neosnippet#expand()*
|
||||
neosnippet#expand({trigger})
|
||||
|
Loading…
Reference in New Issue
Block a user