summaryrefslogtreecommitdiffstats
path: root/runtime/plugin
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2023-10-21 11:06:50 +0200
committerGitHub <noreply@github.com>2023-10-21 11:06:50 +0200
commitd3e277f279ed628809eb6857ea3ebcfca566ca2a (patch)
treeb478c1a9efc785bd1e2ebcabdab0d9a173f0d1be /runtime/plugin
parent47416d1a7441f8c815438903e78ba0a2d877699e (diff)
matchparen: do not use hard-coded match id (#13393)
* matchparen: do not use hard-coded match id Instead of using the hard-coded match id 3, which may also be used by other plugins, let the matchparen plugin use whatever ids are automatically returned when calling matchaddpos(). For backwards-compatibility, keep the `:3match` call, which will still use the hard-coded id 3 (as mentioned in :h :3match). closes: #13381 Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'runtime/plugin')
-rw-r--r--runtime/plugin/matchparen.vim17
1 files changed, 12 insertions, 5 deletions
diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim
index b33ecd557c..9d57545ee8 100644
--- a/runtime/plugin/matchparen.vim
+++ b/runtime/plugin/matchparen.vim
@@ -1,6 +1,6 @@
" Vim plugin for showing matching parens
" Maintainer: The Vim Project <https://github.com/vim/vim>
-" Last Change: 2023 Aug 10
+" Last Change: 2023 Oct 20
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" Exit quickly when:
@@ -18,6 +18,8 @@ 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()
@@ -38,6 +40,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()
@@ -185,11 +190,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
@@ -197,12 +203,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()