Allow abbreviations to expand.

This commit is contained in:
Israel Chauca Fuentes
2017-02-05 01:28:35 -05:00
parent 2335c4ae27
commit c4b5877958
2 changed files with 21 additions and 15 deletions

View File

@@ -53,10 +53,15 @@ function! delimitMate#ex_cmd(global, action)
endfunction
function! delimitMate#InsertCharPre(str)
if s:option('disabled')
if s:info.skip_icp
echom 11
return 0
endif
let s:info.skip_icp = 1
if s:option('disabled')
echom 12
return 0
endif
return map(split(a:str, '\zs'), 's:handle_vchar(v:val)')
endfunction
@@ -69,8 +74,7 @@ function! s:handle_vchar(str)
return
elseif a:str == ' '
echom 13
let [keys, append2vchar] = s:keys4space(s:info, opts)
let v:char .= append2vchar
let keys = s:keys4space(s:info, opts)
elseif a:str == "\<C-]>"
echom 14
return 0
@@ -80,8 +84,7 @@ function! s:handle_vchar(str)
elseif !empty(filter(copy(opts.pairs), 'strcharpart(v:val, 0, 1) ==# a:str'))
echom 16
let pair = get(filter(copy(opts.pairs), 'strcharpart(v:val, 0, 1) ==# a:str'), 0, '')
let [keys, append2vchar] = s:keys4left(a:str, pair, s:info, opts)
let v:char .= append2vchar
let keys = s:keys4left(a:str, pair, s:info, opts)
"echom strtrans(keys)
"echom string(pair)
elseif !empty(filter(copy(opts.pairs), 'strcharpart(v:val, 1, 1) ==# a:str'))
@@ -97,18 +100,17 @@ function! s:handle_vchar(str)
endfunction
function! s:keys4space(info, opts)
if !a:opts.expand_space && !empty(filter(copy(a:opts.pairs), 'v:val ==# a:info.cur.around'))
return ['', '']
if !a:opts.expand_space || empty(filter(copy(a:opts.pairs), 'v:val ==# a:info.cur.around'))
return ''
endif
if a:opts.expand_space
return ["\<C-G>U\<Left>", ' ']
return " \<C-G>U\<Left>"
endfunction
function! s:keys4left(char, pair, info, opts)
if a:opts.autoclose
return [strcharpart(a:pair, 1, 1) . "\<C-G>U\<Left>", '']
return strcharpart(a:pair, 1, 1) . "\<C-G>U\<Left>"
endif
return ['', '']
return ''
endfunction
function! s:keys4right(char, pair, info, opts)
@@ -149,6 +151,7 @@ endfunction
function! delimitMate#CursorMovedI(...)
let s:info.prev = s:info.cur
let s:info.cur = call('s:get_info', a:000)
let s:info.skip_icp = 0
echom 'INFO: ' . string(s:info)
echom 'CMI: ' . s:info.prev.text
endfunction
@@ -156,6 +159,7 @@ endfunction
function! delimitMate#InsertEnter(...)
let s:info.cur = call('s:get_info', a:000)
let s:info.prev = {}
let s:info.skip_icp = 0
echom 'IE: ' . s:info.cur.text
endfunction

View File

@@ -20,7 +20,7 @@ call DMTest_pairs('()', ["a\<BS>"], "")
call DMTest_pairs('()', ["a)", 'ax'], "()x")
"call DMTest_pairs('', "((\<C-G>gx", "(())x")
call DMTest_pairs('', ["i(x\<Esc>u"], "")
call DMTest_pairs('', ["i@(","ax"], "@(x)")
call DMTest_pairs('', ["i@", "a(","ax"], "@(x)")
call DMTest_pairs('@#', ["a(","ax"], "@(x)#")
call DMTest_pairs('\', ["a(","ax"], '\(x')
call DMTest_pairs('', ["a(",'a\', 'a)', "ax"], '(\)x)')
@@ -36,8 +36,9 @@ let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
call DMTest_pairs('', ['i(', "a\<Space>", 'ax'], "( x )")
" <Right> needs to be after <BS> so the cursor stays in the expected place for when
" the doau commands fire.
call DMTest_pairs('( )', ["2|a\<BS>\<Right>"], 'ix'], "(x)")
" the :doau commands fire.
call DMTest_pairs('( )', ["2|a\<BS>\<Right>", 'ix'], "(x)")
call DMTest_pairs('', ["iabc ", 'ax'], "abc x")
let g:delimitMate_autoclose = 0
call DMTest_pairs('', ["i(", "a)", "a\<Space>", "a\<BS>\<Right>", "ix"], "(x)")
let g:delimitMate_autoclose = 1
@@ -57,7 +58,8 @@ call DMTest_pairs('', ["i(", "aa", "i)"], "()a)")
"unlet b:delimitMate_eol_marker
" Expand iabbreviations
iabb def ghi
call DMTest_pairs('', ["idef("], "ghi()")
" TODO not sure how to make this test work
call DMTest_pairs('', ["idef("], "ghi()", '', 1)
iunabb def
"
"call DMTest_pairs('', "abc а\<Left>(", "abc (а")