From 55cff877492c8501be73fe03e5aeeffb8d911477 Mon Sep 17 00:00:00 2001 From: "Andy K. Massimino" Date: Thu, 20 Dec 2018 08:06:57 -0500 Subject: [PATCH] Allow hotfix for dotted &filetype, fixes #46 --- autoload/matchup/loader.vim | 6 ++++-- doc/matchup.txt | 4 ++-- test/issues/46/Sample.jsx | 5 +++++ test/issues/46/minvimrc1 | 26 ++++++++++++++++++++++++++ test/issues/46/minvimrc2 | 26 ++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 test/issues/46/Sample.jsx create mode 100644 test/issues/46/minvimrc1 create mode 100644 test/issues/46/minvimrc2 diff --git a/autoload/matchup/loader.vim b/autoload/matchup/loader.vim index f332884..25400a0 100644 --- a/autoload/matchup/loader.vim +++ b/autoload/matchup/loader.vim @@ -47,7 +47,7 @@ function! matchup#loader#bufwinenter() abort " {{{1 endfunction " }}}1 -function! matchup#loader#refresh_match_words() " {{{1 +function! matchup#loader#refresh_match_words() abort " {{{1 if get(b:, 'match_words', ':') !~# ':' call matchup#perf#tic('refresh') @@ -96,7 +96,9 @@ function! s:init_delim_lists(...) abort " {{{1 " we don't explicitly check this, but the behavior might " be unpredictable if such groups are encountered.. (ref-1) - if exists('g:matchup_hotfix_'.&filetype) + if exists('g:matchup_hotfix') && has_key(g:matchup_hotfix, &filetype) + call call(g:matchup_hotfix[&filetype], []) + elseif exists('g:matchup_hotfix_'.&filetype) call call(g:matchup_hotfix_{&filetype}, []) elseif exists('b:matchup_hotfix') call call(b:matchup_hotfix, []) diff --git a/doc/matchup.txt b/doc/matchup.txt index 3518b76..a4b9712 100644 --- a/doc/matchup.txt +++ b/doc/matchup.txt @@ -769,7 +769,7 @@ HTML Customization~ -*g:matchup_hotfix_{&filetype}* *matchup-hotfix* +*g:matchup_hotfix[&filetype]* *matchup-hotfix* For each file type, this option can be set to the string name of a function which will be called when loading files, prior to checking |b:match_words| @@ -779,7 +779,7 @@ Customization~ function! VimHotfix() " customization endfunction - let g:matchup_hotfix_vim = 'VimHotfix' + let g:matchup_hotfix['vim'] = 'VimHotfix' *b:matchup_hotfix* diff --git a/test/issues/46/Sample.jsx b/test/issues/46/Sample.jsx new file mode 100644 index 0000000..cf82673 --- /dev/null +++ b/test/issues/46/Sample.jsx @@ -0,0 +1,5 @@ + +const Sample = + some body +; + diff --git a/test/issues/46/minvimrc1 b/test/issues/46/minvimrc1 new file mode 100644 index 0000000..1ef19d7 --- /dev/null +++ b/test/issues/46/minvimrc1 @@ -0,0 +1,26 @@ +set nocompatible + +" load match-up +let s:path = simplify(expand(':h').'/../../..') +let &rtp = s:path.',' . &rtp +let &rtp .= ','.s:path.'/after' + +autocmd FileType * echo &ft | sleep 1 + +call plug#begin('~/.vim/plugged') +Plug 'mxw/vim-jsx' +Plug 'othree/yajs.vim' +Plug 'othree/es.next.syntax.vim' +call plug#end() + +filetype plugin indent on +syntax enable + +" match-up options go here +function! JsxHotfix() + echo 'JsxHotfix' + setlocal matchpairs=(:),{:},[:],<:> + let b:match_words = '<\@<=\([^/][^ \t>]*\)\g{hlend}[^>]*\%(/\@\|$\):<\@<=/\1>' +endfunction +let g:matchup_hotfix = { 'javascript.jsx': 'JsxHotfix' } + diff --git a/test/issues/46/minvimrc2 b/test/issues/46/minvimrc2 new file mode 100644 index 0000000..2481959 --- /dev/null +++ b/test/issues/46/minvimrc2 @@ -0,0 +1,26 @@ +set nocompatible + +" load match-up +let s:path = simplify(expand(':h').'/../../..') +let &rtp = s:path.',' . &rtp +let &rtp .= ','.s:path.'/after' + +autocmd FileType * echo &ft | sleep 1 + +call plug#begin('~/.vim/plugged') +Plug 'mxw/vim-jsx' +Plug 'othree/yajs.vim' +Plug 'othree/es.next.syntax.vim' +call plug#end() + +filetype plugin indent on +syntax enable + +" match-up options go here +function! JsxHotfix() + echo 'JsxHotfix' + setlocal matchpairs=(:),{:},[:],<:> + let b:match_words = '<\@<=\([^/][^ \t>]*\)\g{hlend}[^>]*\%(/\@\|$\):<\@<=/\1>' +endfunction +autocmd FileType javascript.jsx let b:matchup_hotfix = 'JsxHotfix' +