Add map-<expr> support in neosnippet#anonymous()
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user