[vim/vim] runtime(shaderslang): fix b:match_words breaking % on braces (PR #21064)
Matthias Bruns (Vim Github Repository) <[email protected]>
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/pull/[email protected]> |
In `ftplugin/shaderslang.vim`, `b:match_words` puts `{` in the same *open* half as `if`/`for`/`while`/`switch`/`struct`/`class`, and `}` in the same *close* half as `break`.
matchit counts every alternative in a group instead of pairing them with each other, so `for (...) {` counts as two openers and a brace can pair with a `break`.
With `vim --clean -c 'packadd matchit' -c 'edit x.slang'` (in Nvim `nvim --clean x.slang` is enough, it enables matchit by default):
```slang
void f() { // % -> line 7 (should be 13)
switch (mode) { // % -> line 4 (should be 7)
case 1:
break;
default:
break;
} // % -> line 1 (should be 2)
for (int i = 0; i < 4; ++i) { // % -> line 12 (correct)
if (i == 2)
break;
total += i;
}
} // % -> line 8 (should be 1)
```
With one more keyword line in the mix (e.g. an `if` above the `break` in `case 1`) the surplus stops balancing altogether and `%` on the function's opening brace finds no match at all, leaving the cursor where it is.
### Fix
Drop the brace/keyword group and `\[:\]` — matchit appends `'matchpairs'` by itself.
The preprocessor group is left unchanged: Slang has no `#elifdef`/`#elifndef` (`kDirectives` in `slang-preprocessor.cpp`), so it should not follow `ftplugin/c.vim` there. `b:match_skip` is untouched.
Trade-offs: braces match correctly again, brackets and parens are unaffected, and `%` on `if`/`for`/`while` now goes to the header's closing paren as in C files - but `%` on a `break;` no longer jumps back to the enclosing opener.
Keeping that would need a group of its own (e.g. `^\s*\<\(do\|for\|switch\|while\)\>:^\s*\<break\>`), which in turn leaves `%` dead on any `for`/`while` without a `break` in it.
### Tests
`Test_shaderslang_matchit_switch_break` and `Test_shaderslang_matchit_loop_break` in `src/testdir/test_plugin_matchit.vim` fail before this change and pass after it.
cc @mTvare6 as the file's maintainer.
Prepared with AI assistance (Claude Opus 5) per CONTRIBUTING.md, recorded in the commit's `Co-Authored-By` trailer.
Mainly, I wanted to report this - the patch is a suggestion, written with AI assistance and reviewed as far as my understanding goes. So, please change or replace it as you see fit. If I can help with anything, let me know :)
You can view, comment on, or merge this pull request online at:
https://github.com/vim/vim/pull/21064
-- Commit Summary --
* runtime(shaderslang): fix b:match_words breaking % on braces
* Merge branch 'vim:master' into shaderslang-match-words
-- File Changes --
M runtime/ftplugin/shaderslang.vim (9)
M src/testdir/test_plugin_matchit.vim (18)
-- Patch Links --
https://github.com/vim/vim/pull/21064.patch
https://github.com/vim/vim/pull/21064.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/21064
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/pull/[email protected]>
--
--
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/vim/vim/pull/21064%40github.com.