andymass / vim-matchup

vim match-up: even better % :facepunch: navigate and highlight matching words :facepunch: modern matchit and matchparen. Supports both vim and neovim + tree-sitter.
https://www.vim.org/scripts/script.php?script_id=5624
MIT License
1.7k stars 71 forks source link

Hotfix for combined filetype #46

Closed bootleq closed 5 years ago

bootleq commented 5 years ago

Hi, similar to issue 42, I'm try to highlight only tagname in JSX file follow the g:matchup_hotfix_javascript solution https://github.com/andymass/vim-matchup/issues/42#issuecomment-437415565.

I can confirm it works except that my &:filetype is javascript.jsx (contains a dot .). Read Vim help that 'filetype' can contain dots, which means several separated types, could we add support for this? Maybe detect dots and try each filetype's hotfix. Thank you very much.

andymass commented 5 years ago

Can you tell me which plugins you use for JavaScript and jsx? And an example document?

bootleq commented 5 years ago

I can see the filetype was latestly set by mxw/vim-jsx, besides, othree/yajs and othree/es.next.syntax.vim are enabled for JavaScript.

Reproduced document named Sample.jsx

const Sample = <Sample prop='highlight test'>                                      │                                             // vim: filetype=javascript
  some body                                                                        │
</Sample>;

The hotfix snippet is identical to issue 42 comment, except of g:matchup_hotfix_javascript variable name (since my &filetype is not javascript).

andymass commented 5 years ago

The simplest fix is to allow the syntax g:matchup_hotfix['javascript.jsx'].

This allows the following:

function! JsxHotfix()
    echo 'JsxHotfix'
    setlocal matchpairs=(:),{:},[:],<:>
    let b:match_words = '<\@<=\([^/][^ \t>]*\)\g{hlend}[^>]*\%(/\@<!>\|$\):<\@<=/\1>'
endfunction
let g:matchup_hotfix = { 'javascript.jsx': 'JsxHotfix' }

Note that this should also work:

autocmd FileType javascript.jsx let b:matchup_hotfix = 'JsxHotfix'
bootleq commented 5 years ago

Thanks very much for your great work! Just confirmed both solution works.