aboutsummaryrefslogtreecommitdiff
path: root/runtime/plugin/matchparen.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/plugin/matchparen.vim')
-rw-r--r--runtime/plugin/matchparen.vim31
1 files changed, 19 insertions, 12 deletions
diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim
index 65b9fe57bf..cc4f38f669 100644
--- a/runtime/plugin/matchparen.vim
+++ b/runtime/plugin/matchparen.vim
@@ -1,6 +1,6 @@
" Vim plugin for showing matching parens
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2018 Jul 3
+" Last Change: 2021 Apr 08
" Exit quickly when:
" - this plugin was already loaded (or disabled)
@@ -21,6 +21,7 @@ endif
augroup matchparen
" Replace all matchparen autocommands
autocmd! CursorMoved,CursorMovedI,WinEnter * call s:Highlight_Matching_Pair()
+ autocmd! WinLeave * call s:Remove_Matches()
if exists('##TextChanged')
autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair()
endif
@@ -36,12 +37,9 @@ set cpo-=C
" The function that is invoked (very often) to define a ":match" highlighting
" for any matching paren.
-function! s:Highlight_Matching_Pair()
+func s:Highlight_Matching_Pair()
" Remove any previous match.
- if exists('w:paren_hl_on') && w:paren_hl_on
- silent! call matchdelete(3)
- let w:paren_hl_on = 0
- endif
+ call s:Remove_Matches()
" Avoid that we remove the popup menu.
" Return when there are no colors (looks like the cursor jumps).
@@ -109,9 +107,10 @@ function! s:Highlight_Matching_Pair()
" Build an expression that detects whether the current cursor position is
" in certain syntax types (string, comment, etc.), for use as
" searchpairpos()'s skip argument.
- " We match "escape" for special items, such as lispEscapeSpecial.
+ " 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\\|comment"''))'
+ \ '''v:val =~? "string\\|character\\|singlequote\\|escape\\|symbol\\|comment"''))'
" 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
@@ -195,11 +194,19 @@ function! s:Highlight_Matching_Pair()
endif
endfunction
+func s:Remove_Matches()
+ if exists('w:paren_hl_on') && w:paren_hl_on
+ silent! call matchdelete(3)
+ 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()
+command DoMatchParen call s:DoMatchParen()
+command NoMatchParen call s:NoMatchParen()
-func! s:NoMatchParen()
+func s:NoMatchParen()
let w = winnr()
noau windo silent! call matchdelete(3)
unlet! g:loaded_matchparen
@@ -207,7 +214,7 @@ func! s:NoMatchParen()
au! matchparen
endfunc
-func! s:DoMatchParen()
+func s:DoMatchParen()
runtime plugin/matchparen.vim
let w = winnr()
silent windo doau CursorMoved