mirror of
https://github.com/Raimondi/delimitMate.git
synced 2026-02-27 03:52:30 +08:00
Implement autoclosingpairs.
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
|
||||
set bs=2
|
||||
set hidden
|
||||
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
|
||||
let g:delimitMate_quotes = '" '' ` « |'
|
||||
let g:delimitMate_pairs = ['()','{}','[]','<>','¿?','¡!',',:']
|
||||
let g:delimitMate_quotes = ['"', "'", '`', '«', '|']
|
||||
ru plugin/delimitMate.vim
|
||||
let runVimTests = expand('<sfile>:p:h').'/build/runVimTests'
|
||||
if isdirectory(runVimTests)
|
||||
@@ -30,7 +30,7 @@ function! s:setup_buffer(buf_content)
|
||||
silent %d_
|
||||
if !empty(a:buf_content)
|
||||
call setline(1, a:buf_content)
|
||||
call feedkeys("\<Esc>gg0", 'ntx')
|
||||
call feedkeys("gg0", 'ntx')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -55,10 +55,15 @@ function! DMTest_single(setup, typed, expected, ...)
|
||||
call vimtap#Todo(1)
|
||||
endif
|
||||
call s:setup_buffer(setup)
|
||||
call feedkeys('i', 'nt')
|
||||
call feedkeys(a:typed, 'mt')
|
||||
call feedkeys('', 'ntx')
|
||||
call vimtap#Is(getline(1,'$'), expected, strtrans(a:typed))
|
||||
for cmd in a:typed
|
||||
echom strtrans(cmd)
|
||||
call feedkeys(cmd, 'mt')
|
||||
call feedkeys('', 'x')
|
||||
doau delimitMate CursorMovedI
|
||||
doau delimitMate TextChangedI
|
||||
call feedkeys('', 'x')
|
||||
endfor
|
||||
call vimtap#Is(getline(1,'$'), expected, string(map(copy(a:typed), 'strtrans(v:val)')))
|
||||
endfunction
|
||||
|
||||
function! s:do_set(pat, sub, set, setup, typed, expected, ...)
|
||||
@@ -76,15 +81,17 @@ function! s:do_set(pat, sub, set, setup, typed, expected, ...)
|
||||
else
|
||||
let expected = [a:expected]
|
||||
endif
|
||||
if len(split(elem, '\zs')) > 1
|
||||
let [left, right] = map(split(elem, '\zs'), 'escape(v:val, escaped)')
|
||||
if strchars(elem) > 1
|
||||
"let [left, right] = map(split(elem, '\zs'), 'escape(v:val, escaped)')
|
||||
let left = escape(strcharpart(elem, 0, 1), escaped)
|
||||
let right = escape(strcharpart(elem, 1, 1), escaped)
|
||||
let sub = a:sub
|
||||
else
|
||||
let quote = escape(elem, escaped)
|
||||
let sub = eval(a:sub)
|
||||
endif
|
||||
call map(setup, "substitute(v:val, a:pat, sub, 'g')")
|
||||
let typed = substitute(a:typed, a:pat, sub, 'g')
|
||||
let typed = map(copy(a:typed), "substitute(v:val, a:pat, sub, 'g')")
|
||||
call map(expected, "substitute(v:val, a:pat, sub, 'g')")
|
||||
call DMTest_single(setup, typed, expected, skip_expr, todo_expr)
|
||||
endfor
|
||||
|
||||
@@ -11,68 +11,69 @@
|
||||
" - Add 5 to vimtap#Plan().
|
||||
|
||||
call vimtest#StartTap()
|
||||
call vimtap#Plan(217)
|
||||
call vimtap#Plan(224)
|
||||
|
||||
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "(x", "(x)")
|
||||
call DMTest_pairs('', "(\<BS>x", "x")
|
||||
call DMTest_pairs('', "()x", "()x")
|
||||
call DMTest_pairs('', "((\<C-G>gx", "(())x")
|
||||
call DMTest_pairs('', "(x\<Esc>u", "")
|
||||
call DMTest_pairs('', "@(x", "@(x)")
|
||||
call DMTest_pairs('', "@#\<Left>(x", "@(x)#")
|
||||
call DMTest_pairs('', "(\<S-Tab>x", "()x")
|
||||
call DMTest_pairs('', ["i("], "()")
|
||||
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('@#', ["a(","ax"], "@(x)#")
|
||||
call DMTest_pairs('\', ["a(","ax"], '\(x')
|
||||
call DMTest_pairs('', ["a(",'a\', 'a)', "ax"], '(\)x)')
|
||||
"call DMTest_pairs('', "(\<S-Tab>x", "()x")
|
||||
let g:delimitMate_autoclose = 0
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "(x", "(x")
|
||||
call DMTest_pairs('', "()x", "(x)")
|
||||
call DMTest_pairs('', "())x", "()x")
|
||||
call DMTest_pairs('', "()\<BS>x", "x")
|
||||
call DMTest_pairs('', "@()x", "@(x)")
|
||||
call DMTest_pairs('', "@#\<Left>()x", "@(x)#")
|
||||
call DMTest_pairs('', ["i(", "ax"], "(x")
|
||||
call DMTest_pairs('', ["i(", "a)", "ax"], "(x)")
|
||||
call DMTest_pairs('', ["i(", "a)", "a)", "ax"], "()x")
|
||||
call DMTest_pairs('', ["i(", "a)", "a\<BS>", "ax"], "x")
|
||||
call DMTest_pairs('', ["i@(", "a)", "ax"], "@(x)")
|
||||
call DMTest_pairs('@#', ["a(", "a)", "ax"], "@(x)#")
|
||||
let g:delimitMate_expand_space = 1
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "(\<Space>x", "( x )")
|
||||
call DMTest_pairs('', "(\<Space>\<BS>x", "(x)")
|
||||
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)")
|
||||
let g:delimitMate_autoclose = 0
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "()\<Space>\<BS>x", "(x)")
|
||||
call DMTest_pairs('', ["i(", "a)", "a\<Space>", "a\<BS>\<Right>", "ix"], "(x)")
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
" Handle backspace gracefully.
|
||||
set backspace=
|
||||
call DMTest_pairs('', "(\<Esc>a\<BS>x", "(x)")
|
||||
set bs=2
|
||||
call DMTest_pairs('', ["i(", "a\<BS>\<Right>", "ix"], "(x)")
|
||||
set backspace=2
|
||||
" closing parens removes characters. #133
|
||||
call DMTest_pairs('', "(a\<Esc>i)", "()a)")
|
||||
call DMTest_pairs('', ["i(", "aa", "i)"], "()a)")
|
||||
|
||||
" Add semicolon next to the closing paren. Issue #77.
|
||||
new
|
||||
let b:delimitMate_eol_marker = ';'
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "abc(x", "abc(x);")
|
||||
" BS should behave accordingly.
|
||||
call DMTest_pairs('', "abc(\<BS>", "abc;")
|
||||
"new
|
||||
"let b:delimitMate_eol_marker = ';'
|
||||
"call DMTest_pairs('', "abc(x", "abc(x);")
|
||||
"" BS should behave accordingly.
|
||||
"call DMTest_pairs('', "abc(\<BS>", "abc;")
|
||||
"unlet b:delimitMate_eol_marker
|
||||
" Expand iabbreviations
|
||||
unlet b:delimitMate_eol_marker
|
||||
DelimitMateReload
|
||||
iabb def ghi
|
||||
call DMTest_pairs('', "def(", "ghi()")
|
||||
call DMTest_pairs('', ["idef("], "ghi()")
|
||||
iunabb def
|
||||
|
||||
call DMTest_pairs('', "abc а\<Left>(", "abc (а")
|
||||
call DMTest_pairs('', "abc ñ\<Left>(", "abc (ñ")
|
||||
call DMTest_pairs('', "abc $\<Left>(", "abc ($")
|
||||
call DMTest_pairs('', "abc £\<Left>(", "abc (£")
|
||||
call DMTest_pairs('', "abc d\<Left>(", "abc (d")
|
||||
call DMTest_pairs('', "abc \<C-V>(\<Left>(", "abc ((")
|
||||
call DMTest_pairs('', "abc .\<Left>(", "abc ().")
|
||||
call DMTest_pairs('', "abc \<Left>(", "abc () ")
|
||||
|
||||
" Play nice with undo.
|
||||
call DMTest_pairs('', "a\<C-G>u(c)b\<C-O>u", "a")
|
||||
"
|
||||
"call DMTest_pairs('', "abc а\<Left>(", "abc (а")
|
||||
"call DMTest_pairs('', "abc ñ\<Left>(", "abc (ñ")
|
||||
"call DMTest_pairs('', "abc $\<Left>(", "abc ($")
|
||||
"call DMTest_pairs('', "abc £\<Left>(", "abc (£")
|
||||
"call DMTest_pairs('', "abc d\<Left>(", "abc (d")
|
||||
"call DMTest_pairs('', "abc \<C-V>(\<Left>(", "abc ((")
|
||||
"call DMTest_pairs('', "abc .\<Left>(", "abc ().")
|
||||
"call DMTest_pairs('', "abc \<Left>(", "abc () ")
|
||||
"
|
||||
"" Play nice with undo.
|
||||
"call DMTest_pairs('', "a\<C-G>u(c)b\<C-O>u", "a")
|
||||
"
|
||||
"let g:delimitMate_autoclose = 1
|
||||
"let g:delimitMate_balance_matchpairs = 1
|
||||
"call DMTest_pairs('', ")\<Left>(x", '(x)')
|
||||
|
||||
call vimtest#Quit()
|
||||
|
||||
Reference in New Issue
Block a user