patch 9.1.1336: comment plugin does not support case-insensitive 'commentstring'
Problem: comment plugin does not support case-insensitive
'commentstring' (char101)
Solution: Use pattern '\c' to make the regex case-insensitive
(Maxim Kim)
fixes: #17184
closes: #17186
Signed-off-by: Maxim Kim <habamax@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/pack/dist/opt/comment/autoload/comment.vim b/runtime/pack/dist/opt/comment/autoload/comment.vim
index a0ee7a7..ffe5a15 100644
--- a/runtime/pack/dist/opt/comment/autoload/comment.vim
+++ b/runtime/pack/dist/opt/comment/autoload/comment.vim
@@ -1,7 +1,7 @@
vim9script
# Maintainer: Maxim Kim <habamax@gmail.com>
-# Last Update: 2025-03-30
+# Last Update: 2025-04-22
#
# Toggle comments
# Usage:
@@ -26,8 +26,8 @@
if len(cms_l) == 1 && lnum1 == lnum2 && first_col < start_col
var line_start = getline(lnum1)[0 : start_col - 1]
var line_end = getline(lnum1)[start_col : -1]
- line_end = line_end =~ $'^\s*{cms_l[0]}' ?
- \ substitute(line_end, $'^\s*\zs{cms_l[0]}\s\ze\s*', line_end =~ '^\s' ? ' ' : '', '') :
+ line_end = line_end =~ $'\c^\s*{cms_l[0]}' ?
+ \ substitute(line_end, $'\c^\s*\zs{cms_l[0]}\s\ze\s*', line_end =~ '^\s' ? ' ' : '', '') :
\ printf(substitute(cms, '%s\@!', '%%', ''), line_end)
setline(lnum1, line_start .. line_end)
return ''
@@ -49,7 +49,7 @@
endif
indent_spaces = indent_spaces || (stridx(indent_str, ' ') != -1)
indent_tabs = indent_tabs || (stridx(indent_str, "\t") != -1)
- if getline(lnum) !~ $'^\s*{cms_l[0]}.*{cms_l[1]}$'
+ if getline(lnum) !~ $'\c^\s*{cms_l[0]}.*{cms_l[1]}$'
comment = true
endif
endfor
@@ -69,7 +69,7 @@
strpart(getline(lnum), strlen(indent_current)))
endif
else
- line = substitute(getline(lnum), $'^\s*\zs{cms_l[0]} \?\| \?{cms_l[1]}$', '', 'g')
+ line = substitute(getline(lnum), $'\c^\s*\zs{cms_l[0]} \?\| \?{cms_l[1]}$', '', 'g')
endif
add(lines, line)
endfor
diff --git a/src/testdir/test_plugin_comment.vim b/src/testdir/test_plugin_comment.vim
index d4718bc..800c275 100644
--- a/src/testdir/test_plugin_comment.vim
+++ b/src/testdir/test_plugin_comment.vim
@@ -59,6 +59,29 @@
call assert_equal(["# vim9script", "", "def Hello()", ' echo "Hello"', "enddef"], result)
endfunc
+func Test_caseinsensitive_uncomment()
+ CheckScreendump
+ let lines =<< trim END
+ rem echo "Hello"
+ END
+
+ let input_file = "test_caseinsensitive_uncomment_input.bat"
+ call writefile(lines, input_file, "D")
+
+ let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
+
+ call term_sendkeys(buf, "gcc")
+ let output_file = "comment_testinsensitive_uncomment_test.bat"
+ call term_sendkeys(buf, $":w {output_file}\<CR>")
+ defer delete(output_file)
+
+ call StopVimInTerminal(buf)
+
+ let result = readfile(output_file)
+
+ call assert_equal(['echo "Hello"'], result)
+endfunc
+
func Test_bothends_comment()
CheckScreendump
let lines =<< trim END
@@ -551,6 +574,7 @@
call assert_equal([], result)
endfunc
+
func Test_textobj_cursor_on_leading_space_comment()
CheckScreendump
let lines =<< trim END
diff --git a/src/version.c b/src/version.c
index 2d36034..6d3a295 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1336,
+/**/
1335,
/**/
1334,