From 775254651599148dc829d29e4c2a9fcc74d5cce3 Mon Sep 17 00:00:00 2001 From: Israel Chauca Fuentes Date: Sat, 11 Feb 2017 17:55:03 -0500 Subject: [PATCH] Add jump_expansion --- autoload/delimitMate.vim | 17 +++++++++++++++-- test/_setup.vim | 1 + test/expand_cr.vim | 36 +++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index c7a8816..fcbb77b 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -186,7 +186,8 @@ function! delimitMate#TextChangedI(...) "{{{1 echom 23 if s:option('expand_cr') && !empty(pair) echom "23.1" - return feedkeys("\") + let spaces = strchars(s:info.cur.next_line, '^\s*') + return feedkeys(repeat("\", spaces), 'nti') endif let quote = filter(s:option('quotes'), 's:info.cur.p_char . matchstr(s:info.cur.next_line, "^\\s*\\zs\\S") ==# v:val.v:val') if s:option('expand_cr') && s:option('expand_inside_quotes') && !empty(quote) @@ -322,6 +323,15 @@ function! s:keys4left(char, pair, info, opts) "{{{1 endfunction function! s:keys4right(char, pair, info, opts) "{{{1 + if a:opts.jump_expansion + echom 40 + let around = matchstr(a:info.cur.prev_line, "\\S$") . matchstr(a:info.cur.next_line, "^\\s*\zs\\S") + if empty(a:info.cur.ahead) && a:char ==# matchstr(a:info.cur.next_line, "^\\s*\\zs\\S") + let rights = strchars(matchstr(a:info.cur.next_line, '^\s*')) + 2 + echom "40.1" + return "\s" . repeat("\", rights) + endif + endif if !a:opts.autoclose if s:info.cur.around == a:pair echom 41 @@ -383,9 +393,12 @@ endfunction function! s:keys4cr(info, opts) "{{{1 if a:opts.expand_cr \&& !empty(filter(copy(a:opts.pairs), 'v:val ==# a:info.prev.around')) + \|| (a:opts.expand_cr == 2 && !empty(filter(copy(a:opts.pairs), 'strcharpart(v:val, 1, 1) == a:info.cur.n_char'))) " Empty pair echom 71 - return "\\\" + let right = a:info.cur.line + let rm_spaces = empty(a:info.cur.behind) ? '' : "\" + return rm_spaces . "\x\U\\\" . a:info.cur.n_char . "\\\\" endif if a:opts.expand_cr && a:opts.expand_inside_quotes \&& !empty(filter(copy(a:opts.quotes), 'v:val.v:val ==# a:info.prev.around')) diff --git a/test/_setup.vim b/test/_setup.vim index e67cff1..6ac9f7b 100644 --- a/test/_setup.vim +++ b/test/_setup.vim @@ -13,6 +13,7 @@ let &rtp = expand(':p:h:h') . ',' . &rtp . ',' . expand(':p:h:h') . '/after' set bs=2 set hidden +set whichwrap=[] let g:delimitMate_pairs = ['()','{}','[]','<>','¿?','¡!',',:'] let g:delimitMate_quotes = ['"', "'", '`', '«', '|'] ru plugin/delimitMate.vim diff --git a/test/expand_cr.vim b/test/expand_cr.vim index 2c3c0d4..6f8114b 100644 --- a/test/expand_cr.vim +++ b/test/expand_cr.vim @@ -11,7 +11,8 @@ " - Add 5 to vimtap#Plan(). call vimtest#StartTap() -call vimtap#Plan(25) +call vimtap#Plan(26) + let g:delimitMate_expand_cr = 1 "let g:delimitMate_eol_marker = ';' @@ -36,26 +37,37 @@ call DMTest_single('', "i( \\\x", '(x)') " Conflict with indentation settings (cindent). Issue #95 se cindent + call DMTest_single( \ ['sub foo {', \ ' while (1) {', - \ ' ', + \ '', \ ' }', \ '}'], - \ "i\3G8|a}x", + \ "3Gi\x", + \ ['sub foo {', + \ ' while (1) {x}', + \ '}']) + +call DMTest_single( \ ['sub foo {', \ ' while (1) {', - \ ' ', + \ ' bar', + \ ' }', + \ '}'], + \ "3GA}x", + \ ['sub foo {', + \ ' while (1) {', + \ ' bar', \ ' }x', \ '}']) call DMTest_single('"{bracketed}', "\A\"x", '"{bracketed}"x') -" Syntax folding enabled by autocmd breaks expansion. But ti can't be tested -" with :normal +" Syntax folding enabled by autocmd breaks expansion. new -autocmd InsertEnter * let w:fdm=&foldmethod | setl foldmethod=manual -autocmd InsertLeave * let &foldmethod = w:fdm +autocmd InsertEnter let w:fdm=&foldmethod | setl foldmethod=manual +autocmd InsertLeave let &foldmethod = w:fdm set foldmethod=marker set foldmarker={,} set foldlevel=0 @@ -64,7 +76,7 @@ call DMTest_single('', "iabc {\x", \['abc {', \ ' x', \ '}']) - +:bp " expand_cr != 2 call DMTest_single('abc(def)', "i\$i\x", \ ['abc(def', @@ -72,12 +84,14 @@ call DMTest_single('abc(def)', "i\$i\x", " expand_cr == 2 let delimitMate_expand_cr = 2 -call DMTest_single('abc(def)', "i\$i\x", ['abc(def', ' x', ' )']) +call DMTest_single('abc(def)', "$i\x", ['abc(def', ' x', ' )']) " Play nice with smartindent set all& +set whichwrap=[] +set bs=2 set smartindent -call DMTest_single('', "i\$i{\x", ['{', ' x', '}']) +call DMTest_single('', "i{\x", ['{', ' x', '}']) call DMTest_quotes('', "i' x", "' x'")