Skip to content

Commit

Permalink
Be more careful about when to transmute re #48
Browse files Browse the repository at this point in the history
  • Loading branch information
andymass committed Jan 8, 2019
1 parent 6f57694 commit 46f411c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
9 changes: 8 additions & 1 deletion autoload/matchup/matchparen.vim
Expand Up @@ -43,6 +43,7 @@ function! matchup#matchparen#enable() " {{{1
if has('patch-8.0.1494')
autocmd TextChangedP * call s:matchparen.highlight_deferred()
endif
autocmd BufReadPost * call s:matchparen.transmute_reset()
autocmd WinLeave,BufLeave * call s:matchparen.clear()
autocmd InsertEnter,Insertchange * call s:matchparen.highlight(1, 1)
autocmd InsertLeave * call s:matchparen.highlight(1)
Expand Down Expand Up @@ -324,7 +325,7 @@ function! s:matchparen.highlight(...) abort dict " {{{1
endif

" if transmuted, highlight again (will reset timeout)
if matchup#transmute#tick(l:insertmode, 'unused')
if matchup#transmute#tick(l:insertmode)
" no force_update here because it would screw up prior
return s:matchparen.highlight(0, l:changing_insert)
endif
Expand Down Expand Up @@ -364,6 +365,12 @@ function! s:matchparen.highlight(...) abort dict " {{{1
call matchup#perf#toc('matchparen.highlight', 'end')
endfunction

function s:matchparen.transmute_reset() abort dict
if g:matchup_transmute_enabled
call matchup#transmute#reset()
endif
endfunction

" }}}1
function! s:do_offscreen(current) " {{{1
let l:offscreen = {}
Expand Down
12 changes: 11 additions & 1 deletion autoload/matchup/transmute.vim
Expand Up @@ -27,7 +27,7 @@ endfunction

" }}}1

function! matchup#transmute#tick(insertmode, entering_insert) " {{{1
function! matchup#transmute#tick(insertmode) " {{{1
if !g:matchup_transmute_enabled | return 0 | endif

if a:insertmode
Expand All @@ -47,6 +47,12 @@ function! matchup#transmute#tick(insertmode, entering_insert) " {{{1
return 0
endfunction

" }}}1
function! matchup#transmute#reset() " {{{1
if !g:matchup_transmute_enabled | return 0 | endif
let w:matchup_transmute_last_changenr = changenr()
endfunction

" }}}1
function! matchup#transmute#dochange(list, pri, cur) " {{{1
if empty(a:list) || empty(a:pri) || empty(a:cur) | return 0 | endif
Expand All @@ -64,6 +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]
return 0
endif

let l:num_changes = 0

Expand Down
20 changes: 20 additions & 0 deletions test/issues/48/minvimrc
@@ -0,0 +1,20 @@
set nocompatible

" load match-up
let s:path = simplify(expand('<sfile>:h').'/../../..')
let &rtp = s:path.',' . &rtp
let &rtp .= ','.s:path.'/after'

" rtp for testing files
let &rtp = s:path.'/test/rtp,' . &rtp

" load other plugins, if necessary
" let &rtp = '~/path/to/other/plugin,' . &rtp

filetype plugin indent on
syntax enable

" match-up options go here
hi MatchParen ctermfg=blue ctermbg=NONE
let g:matchup_transmute_enabled = 1

10 changes: 10 additions & 0 deletions test/issues/48/simple.xml
@@ -0,0 +1,10 @@
<root>
<blue>
</blue>
<red>
</red>

<green>
</green>
</root>

28 changes: 28 additions & 0 deletions test/issues/48/vim-matchup-20181230.xml
@@ -0,0 +1,28 @@
<window title="App" icon-name="app" resizable="false" window-position="1">
<vbox>
<text justify="0">
<label>" App not found TODO "</label>
</text>

<checkbox use-underline="true">
<label>"_Show this message at next start"</label>
<default>$CHECK_FZF</default>
<variable>CHECK_FZF</variable>
<action>awk $0~"^"N"="{$0=N"="V;f=1}{a[++n]=$0}END{if(!f)a[++n]=N"="V;++n;for(i=1;i!=n;i++)print a[i]>ARGV[ARGC-1]} N=CHECK_FZF V=\$CHECK_FZF /root/.apprc</action>
</checkbox>

<text><label>""</label></text>
<hbox>
<text space-fill="true" space-expand="true"><label>""</label></text>
<button yes>
<action>yad --text="INSTALL FZF TODO"</action>
</button>
<button no>
<action>closewindow:CHECK_FZF_WINDOW</action>
</button>
<text space-fill="true" space-expand="true"><label>""</label></text>
</hbox>
</vbox>
<variable>CHECK_FZF_WINDOW</variable>
<action signal="key-press-event" condition="command_is_true([ $KEY_SYM = Escape ] && echo true )">closewindow:CHECK_FZF_WINDOW</action>
</window>

0 comments on commit 46f411c

Please sign in to comment.