Be even more careful about transmuting #48

This commit is contained in:
Andy K. Massimino
2019-01-10 09:47:19 -05:00
parent 62b3db9684
commit ef17dcb4c2
3 changed files with 17 additions and 6 deletions

View File

@@ -51,6 +51,7 @@ function! s:init_options()
call s:init_option('matchup_text_obj_linewise_operators', ['d', 'y'])
call s:init_option('matchup_transmute_enabled', 0)
call s:init_option('matchup_transmute_breakundo', 0)
call s:init_option('matchup_mouse_enabled', 1)

View File

@@ -70,8 +70,10 @@ function! matchup#transmute#dochange(list, pri, cur) " {{{1
if a:pri.class[0] != l:cur.class[0]
return 0
endif
if (a:pri.class[1] == 0 || a:pri.class[1] == 1)
\ && a:pri.class[1] isnot l:cur.class[1]
if a:pri.side =~# '^open\|close$' && a:pri.side isnot l:cur.side
return 0
endif
if !matchup#pos#equal(a:pri, l:cur)
return 0
endif
@@ -106,7 +108,7 @@ function! matchup#transmute#dochange(list, pri, cur) " {{{1
for l:dummy in range(len(l:count))
" create a pattern which isolates the old group text
let l:prevtext = escape(l:groups[l:grp], '\''')
let l:prevtext = s:qescape(l:groups[l:grp])
let l:pattern = substitute(l:re_anchored,
\ g:matchup#re#not_bslash.'\\'.l:grp,
\ '\=''\zs\V'.l:prevtext.'\m\ze''', '')
@@ -114,15 +116,16 @@ function! matchup#transmute#dochange(list, pri, cur) " {{{1
\ l:groups, 0)
let l:string = l:cur.groups[l:grp]
let l:line = substitute(l:line, l:pattern,
\ '\='''.escape(l:string, '\''')."'", '')
\ '\='''.s:qescape(l:string)."'", '')
endfor
let l:groups[l:grp] = l:cur.groups[l:grp]
endfor
if getline(l:corr.lnum) !=# l:line
" TODO break undo option
" exe "normal! a\<c-g>u"
if g:matchup_transmute_breakundo && l:num_changes == 0
execute "normal! a\<c-g>u"
endif
call setline(l:corr.lnum, l:line)
let l:num_changes += 1
endif
@@ -131,6 +134,10 @@ function! matchup#transmute#dochange(list, pri, cur) " {{{1
return l:num_changes
endfunction
function s:qescape(str)
return escape(substitute(a:str, "'", "''", 'g'), '\')
endfunction
" }}}1
let &cpo = s:save_cpo

3
test/issues/48/new.xml Normal file
View File

@@ -0,0 +1,3 @@
<variable>x</variable>
<action>a ''</action>