diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /runtime/plugin/matchparen.vim | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'runtime/plugin/matchparen.vim')
-rw-r--r-- | runtime/plugin/matchparen.vim | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim index 3982489b92..4235a0d39b 100644 --- a/runtime/plugin/matchparen.vim +++ b/runtime/plugin/matchparen.vim @@ -1,6 +1,7 @@ " Vim plugin for showing matching parens -" Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2022 Dec 01 +" Maintainer: The Vim Project <https://github.com/vim/vim> +" Last Change: 2023 Oct 20 +" Former Maintainer: Bram Moolenaar <Bram@vim.org> " Exit quickly when: " - this plugin was already loaded (or disabled) @@ -17,12 +18,15 @@ if !exists("g:matchparen_insert_timeout") let g:matchparen_insert_timeout = 60 endif +let s:has_matchaddpos = exists('*matchaddpos') + augroup matchparen " Replace all matchparen autocommands autocmd! CursorMoved,CursorMovedI,WinEnter,BufWinEnter,WinScrolled * call s:Highlight_Matching_Pair() autocmd! WinLeave,BufLeave * call s:Remove_Matches() if exists('##TextChanged') autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair() + autocmd! TextChangedP * call s:Remove_Matches() endif augroup END @@ -37,6 +41,9 @@ set cpo-=C " The function that is invoked (very often) to define a ":match" highlighting " for any matching paren. func s:Highlight_Matching_Pair() + if !exists("w:matchparen_ids") + let w:matchparen_ids = [] + endif " Remove any previous match. call s:Remove_Matches() @@ -108,8 +115,9 @@ func s:Highlight_Matching_Pair() " searchpairpos()'s skip argument. " We match "escape" for special items, such as lispEscapeSpecial, and " match "symbol" for lispBarSymbol. - let s_skip = '!empty(filter(map(synstack(line("."), col(".")), ''synIDattr(v:val, "name")''), ' . - \ '''v:val =~? "string\\|character\\|singlequote\\|escape\\|symbol\\|comment"''))' + let s_skip = 'synstack(".", col("."))' + \ . '->indexof({_, id -> synIDattr(id, "name") =~? ' + \ . '"string\\|character\\|singlequote\\|escape\\|symbol\\|comment"}) >= 0' " If executing the expression determines that the cursor is currently in " one of the syntax types, then we want searchpairpos() to find the pair " within those syntax types (i.e., not skip). Otherwise, the cursor is @@ -183,11 +191,12 @@ func s:Highlight_Matching_Pair() " If a match is found setup match highlighting. if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom - if exists('*matchaddpos') - call matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10, 3) + if s:has_matchaddpos + call add(w:matchparen_ids, matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10)) else exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) . \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/' + call add(w:matchparen_ids, 3) endif let w:paren_hl_on = 1 endif @@ -195,12 +204,13 @@ endfunction func s:Remove_Matches() if exists('w:paren_hl_on') && w:paren_hl_on - silent! call matchdelete(3) + while !empty(w:matchparen_ids) + silent! call remove(w:matchparen_ids, 0)->matchdelete() + endwhile let w:paren_hl_on = 0 endif endfunc - " Define commands that will disable and enable the plugin. command DoMatchParen call s:DoMatchParen() command NoMatchParen call s:NoMatchParen() |