]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1336: comment plugin does not support case-insensitive 'commentstring' v9.1.1336
authorMaxim Kim <habamax@gmail.com>
Tue, 22 Apr 2025 18:11:05 +0000 (20:11 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 22 Apr 2025 18:14:30 +0000 (20:14 +0200)
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>
runtime/pack/dist/opt/comment/autoload/comment.vim
src/testdir/test_plugin_comment.vim
src/version.c

index a0ee7a72fb0f07dad16a21652bd9d5182afc458a..ffe5a1516194ffd0cb6c5844e1bd0b4efcede006 100644 (file)
@@ -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 @@ export def Toggle(...args: list<string>): string
     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 @@ export def Toggle(...args: list<string>): string
         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 @@ export def Toggle(...args: list<string>): string
                     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
index d4718bc520d703f0443d3671367dc2803b40a3d6..800c2751b7193e2010e216152033ba42c30d25fe 100644 (file)
@@ -59,6 +59,29 @@ func Test_basic_uncomment()
   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 @@ func Test_textobj_last_line_empty_comment()
 
   call assert_equal([], result)
 endfunc
+
 func Test_textobj_cursor_on_leading_space_comment()
   CheckScreendump
   let lines =<< trim END
index 2d36034abdc12dda5f84280c0181be0b61c9d7c7..6d3a2953606f14c0c9d1357248bfcaa536fa8372 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1336,
 /**/
     1335,
 /**/