From c7f568f6960f3066e5d94d996446bf23e4ad4a68 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 22 Sep 2015 14:32:14 +0300 Subject: [PATCH] Clean up and improve the commenting functions Simplifies the selection commenting function, add proper draft options to the exec statements, and make the uncommenting bit keep the selection. Add a function that comments the current line with "//", uncommenting is supported as well. --- rc/c-family.kak | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/rc/c-family.kak b/rc/c-family.kak index f04ee2db..3d71fc5f 100644 --- a/rc/c-family.kak +++ b/rc/c-family.kak @@ -157,20 +157,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} } } }