diff options
-rw-r--r-- | runtime/plugin/matchparen.vim | 13 | ||||
-rw-r--r-- | test/functional/legacy/matchparen_spec.lua | 44 | ||||
-rw-r--r-- | test/old/testdir/test_plugin_matchparen.vim | 32 |
3 files changed, 88 insertions, 1 deletions
diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim index 13d1b6824f..079cc668f0 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: 2024 May 18 +" Last Change: 2025 Mar 08 " Former Maintainer: Bram Moolenaar <Bram@vim.org> " Exit quickly when: @@ -114,6 +114,17 @@ func s:Highlight_Matching_Pair() \ .. 'string\|character\|singlequote\|escape\|symbol\|comment' \ .. "') != -1" else + " do not attempt to match when the syntax item where the cursor is + " indicates there does not exist a matching parenthesis, e.g. for shells + " case statement: "case $var in foobar)" + " + " add the check behind a filetype check, so it only needs to be + " evaluated for certain filetypes + if ['sh']->index(&filetype) >= 0 && + \ synstack(".", col("."))->indexof({_, id -> synIDattr(id, "name") + \ =~? "shSnglCase"}) >= 0 + return + endif " 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. diff --git a/test/functional/legacy/matchparen_spec.lua b/test/functional/legacy/matchparen_spec.lua index d992420c30..367830b564 100644 --- a/test/functional/legacy/matchparen_spec.lua +++ b/test/functional/legacy/matchparen_spec.lua @@ -195,4 +195,48 @@ describe('matchparen', function() {5:-- INSERT --} | ]]) end) + + -- oldtest: Test_matchparen_ignore_sh_case() + it('ignores shell case statements', function() + local screen = Screen.new(40, 15) + exec([[ + syntax on + source $VIMRUNTIME/plugin/matchparen.vim + set ft=sh + call setline(1, [ + \ '#!/bin/sh', + \ 'SUSUWU_PRINT() (', + \ ' case "${LEVEL}" in', + \ ' "$SUSUWU_SH_NOTICE")', + \ ' ${SUSUWU_S} && return 1', + \ ' ;;', + \ ' "$SUSUWU_SH_DEBUG")', + \ ' (! ${SUSUWU_VERBOSE}) && return 1', + \ ' ;;', + \ ' esac', + \ ' # snip', + \ ')' + \ ]) + call cursor(4, 26) + ]]) + screen:add_extra_attr_ids({ + [100] = { foreground = tonumber('0x6a0dad') }, + }) + screen:expect([[ + {18:#!/bin/sh} | + {25:SUSUWU_PRINT() (} | + {15:case} {15:"}{100:${LEVEL}}{15:"} {15:in} | + {15:"}{100:$SUSUWU_SH_NOTICE}{15:"^)} | + {100:${SUSUWU_S}} {15:&&} {15:return} {26:1} | + {15:;;} | + {15:"}{100:$SUSUWU_SH_DEBUG}{15:")} | + {100:(}{15:!} {100:${SUSUWU_VERBOSE})} {15:&&} {15:return} {26:1} | + {15:;;} | + {15:esac} | + {18:# snip} | + {25:)} | + {1:~ }|*2 + | + ]]) + end) end) diff --git a/test/old/testdir/test_plugin_matchparen.vim b/test/old/testdir/test_plugin_matchparen.vim index 7d80e43046..0739906a42 100644 --- a/test/old/testdir/test_plugin_matchparen.vim +++ b/test/old/testdir/test_plugin_matchparen.vim @@ -139,4 +139,36 @@ func Test_matchparen_mbyte() call StopVimInTerminal(buf) endfunc +" Test for ignoring certain parenthesis +func Test_matchparen_ignore_sh_case() + CheckScreendump + + let lines =<< trim END + source $VIMRUNTIME/plugin/matchparen.vim + set ft=sh + call setline(1, [ + \ '#!/bin/sh', + \ 'SUSUWU_PRINT() (', + \ ' case "${LEVEL}" in', + \ ' "$SUSUWU_SH_NOTICE")', + \ ' ${SUSUWU_S} && return 1', + \ ' ;;', + \ ' "$SUSUWU_SH_DEBUG")', + \ ' (! ${SUSUWU_VERBOSE}) && return 1', + \ ' ;;', + \ ' esac', + \ ' # snip', + \ ')' + \ ]) + call cursor(4, 26) + END + + let filename = 'Xmatchparen_sh' + call writefile(lines, filename, 'D') + + let buf = RunVimInTerminal('-S '.filename, #{rows: 10}) + call VerifyScreenDump(buf, 'Test_matchparen_sh_case_1', {}) + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab |