diff --git a/rc/c-family.kak b/rc/c-family.kak index f09a5b49..0413301f 100644 --- a/rc/c-family.kak +++ b/rc/c-family.kak @@ -187,20 +187,41 @@ def c-family-alternative-file -docstring "Jump to the alternate file (header/imp def c-family-comment-selection -docstring "Comment the current selection" %{ try %{ ## The selection is empty - exec %{\A[\h\v]*\z} + exec -draft %{\A[\h\v\n]*\z} try %{ ## The selection has already been commented - exec %{\A[\h\v]*/\*.*\*/[\h\v]*\z} + exec -draft %{\A/\*.*\*/\z} - try %{ - ## Comment the selection - exec %{a */i/* 3H} - } + ## Comment the selection + exec %{a */i/* 3H} } catch %{ try %{ ## Uncomment the commented selection - exec %{s(\A(?:[\h\v]*)/\* ?)|( ?\*/(?:[\h\v]*)\z)d } + exec -draft %{s(\A/\* )|( \*/\z)d} + } + } + } +} + +def c-family-comment-line -docstring "Comment the current line" %{ + ## Select the content of the line, without indentation + exec %{I} + + try %{ + ## There's no text on the line + exec -draft %{\A[\h\v\n]*\z} + + try %{ + ## The line has already been commented + exec -draft %{^//} + + ## Comment the line + exec %{i// 3H} + } catch %{ + try %{ + ## Uncomment the line + exec -draft %{s^//\h*d} } } }