Commit: patch 9.2.0969: runtime(shaderslang): matchit % breaks on braces

Christian Brabandt <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0969: runtime(shaderslang): matchit % breaks on braces

Commit: https://github.com/vim/vim/commit/08c74ce09a9269b93b01ff2289683ad63f396fba
Author: Matthias Bruns <[email protected]>
Date:   Tue Aug 18 18:27:16 2026 +0000

    patch 9.2.0969: runtime(shaderslang): matchit % breaks on braces
    
    Problem:  b:match_words groups "{" with the if/for/while/switch keywords
              and "}" with "break" which breaks % matching on braces
    Solution: Drop the brace and bracket groups, matchit appends
              'matchpairs' by itself (Matthias Bruns).
    
    matchit counts every alternative in a group instead of pairing the
    alternatives with each other.  Listing `{` alongside the if, for,
    while, switch, struct and class keywords therefore makes a line such
    as `for (...) {` count as two openers, and listing `break` alongside
    `}` lets a brace pair with a break statement.  As a result % on the
    opening brace of a function does not move at all, and % on
    `switch (x) {` jumps to `break;` instead of the closing brace.
    
    Braces and brackets do not need to be listed: matchit appends
    'matchpairs' to b:match_words by itself.  Drop them and leave the
    preprocessor group unchanged.
    
    closes: #21064
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    Signed-off-by: Matthias Bruns <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/ftplugin/shaderslang.vim b/runtime/ftplugin/shaderslang.vim
index f3d1ab8c1..900bc6dd9 100644
--- a/runtime/ftplugin/shaderslang.vim
+++ b/runtime/ftplugin/shaderslang.vim
@@ -1,7 +1,7 @@
 " Vim filetype plugin file
 " Language:	Slang
 " Maintainer:	Austin Shijo <[email protected]>
-" Last Change:	2025 Jan 05
+" Last Change:	2026 Aug 16
 
 " Only do this when not done yet for this buffer
 if exists("b:did_ftplugin")
@@ -28,12 +28,9 @@ setlocal commentstring=//\ %s
 setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
 
 " When the matchit plugin is loaded, this makes the % command skip parens and
-" braces in comments properly, and adds support for shader-specific keywords
+" braces in comments properly
 if exists("loaded_matchit")
-  " Add common shader control structures
-  let b:match_words = '{\|^\s*\<\(if\|for\|while\|switch\|struct\|class\)\>:}\|^\s*\<break\>,' ..
-        \ '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>,' ..
-        \ '\[:\]'
+  let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'
   let b:match_skip = 's:comment\|string\|character\|special'
   let b:match_ignorecase = 0
   let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words b:match_ignorecase"
diff --git a/src/testdir/test_plugin_matchit.vim b/src/testdir/test_plugin_matchit.vim
index 1c8144278..cbff2a6da 100644
--- a/src/testdir/test_plugin_matchit.vim
+++ b/src/testdir/test_plugin_matchit.vim
@@ -55,4 +55,22 @@ func Test_html_matchit_tag_multiline_attributes()
   bwipe!
 endfunc
 
+func Test_shaderslang_matchit_switch_break()
+  call s:Setup(['void main() {', '  switch (x) {', '    case 1:',
+        \ '      break;', '  }', '}'], 'shaderslang')
+  call assert_equal(5, s:PercentTo([2, 14]))
+  call assert_equal(2, s:PercentTo([5, 3]))
+  bwipe!
+endfunc
+
+func Test_shaderslang_matchit_loop_break()
+  call s:Setup(['void f() {', '  for (int i = 0; i < 4; ++i) {',
+        \ '    if (i == 2)', '      break;', '    total += i;', '  }',
+        \ '  int after = 1;', '}'], 'shaderslang')
+  call assert_equal(8, s:PercentTo([1, 10]))
+  call assert_equal(6, s:PercentTo([2, 31]))
+  call assert_equal(2, s:PercentTo([6, 3]))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 0115e9423..7f82d187b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    969,
 /**/
     968,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wwP2Z-00Aavs-SC%40256bit.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.