]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1456: comment plugin fails toggling if 'cms' contains \ v9.1.1456
authorMaxim Kim <habamax@gmail.com>
Thu, 12 Jun 2025 19:31:00 +0000 (21:31 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 12 Jun 2025 19:31:00 +0000 (21:31 +0200)
Problem:  comment plugin fails toggling if 'cms' contains \
Solution: escape backslash (Maxim Kim)

groff could be commented using \" or \# and comment plugin fails to
uncomment such things.

NOTE: if newstyle comment would be introduced, e.g. .\#
for groff test would need to be adjusted.

closes: #17530

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 ffe5a1516194ffd0cb6c5844e1bd0b4efcede006..f678a98fac19b0ef6c614946da17a8289990b29c 100644 (file)
@@ -1,7 +1,7 @@
 vim9script
 
 # Maintainer: Maxim Kim <habamax@gmail.com>
-# Last Update: 2025-04-22
+# Last Update: 2025-06-12
 #
 # Toggle comments
 # Usage:
@@ -19,7 +19,7 @@ export def Toggle(...args: list<string>): string
     if empty(&cms) || !&ma | return '' | endif
     var cms = substitute(substitute(&cms, '\S\zs%s\s*', ' %s', ''), '%s\ze\S', '%s ', '')
     var [lnum1, lnum2] = [line("'["), line("']")]
-    var cms_l = split(escape(cms, '*.'), '\s*%s\s*')
+    var cms_l = split(escape(cms, '*.\'), '\s*%s\s*')
 
     var first_col = indent(lnum1)
     var start_col = getpos("'[")[2] - 1
index 800c2751b7193e2010e216152033ba42c30d25fe..1c50748137e207b84aa46ca7a0184ad87c95ac75 100644 (file)
@@ -59,6 +59,30 @@ func Test_basic_uncomment()
   call assert_equal(["# vim9script", "", "def Hello()", '  echo "Hello"', "enddef"], result)
 endfunc
 
+func Test_backward_slash_uncomment()
+  " Note this test depends on 'commentstring' setting in nroff ftplugin
+  CheckScreendump
+  let lines =<< trim END
+    .\" .TL Test backward slash uncomment
+  END
+
+  let input_file = "Test_backward_slash_uncomment_input.mom"
+  call writefile(lines, input_file, "D")
+
+  let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
+
+  call term_sendkeys(buf, "gcc")
+  let output_file = "backward_slash_uncomment_test.mom"
+  call term_sendkeys(buf, $":w {output_file}\<CR>")
+  defer delete(output_file)
+
+  call StopVimInTerminal(buf)
+
+  let result = readfile(output_file)
+
+  call assert_equal([".TL Test backward slash uncomment"], result)
+endfunc
+
 func Test_caseinsensitive_uncomment()
   CheckScreendump
   let lines =<< trim END
index 69cf433620de80b24476d93be519b62f3495dceb..a7b31cad5b7009f29514215171bf73e91e1bba20 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1456,
 /**/
     1455,
 /**/