diff --git a/rc/core/commenting.kak b/rc/core/commenting.kak index c2b7054a..8b749047 100644 --- a/rc/core/commenting.kak +++ b/rc/core/commenting.kak @@ -50,7 +50,7 @@ hook global BufSetOption filetype=ruby %{ def comment-selection -docstring "Comment/uncomment the current selection" %{ %sh{ - function exec_proof { + exec_proof() { ## Replace the '<' sign that is interpreted differently in `exec` printf %s\\n "$@" | sed 's,<,,g' } @@ -63,51 +63,52 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{ exit fi - printf %s\\n "try %{ + printf %s\\n "eval -draft %{ try %{ ## The selection is empty - exec -draft %{\A[\h\v\n]*\z} + exec \\A[\\h\\v\\n]*\\z try %{ ## The selection has already been commented - exec -draft %{\A\Q${opening}\E.*\Q${closing}\E\z} + exec %{\\A\\Q${opening}\\E.*\\Q${closing}\\E\\n*\\z} ## Comment the selection - exec %{a${closing}i${opening}${#opening}H} + exec -draft %{a${closing}i${opening}} } catch %{ ## Uncomment the commented selection - exec -draft %{s(\A\Q${opening}\E)|(\Q${closing}\E\z)d} + exec -draft %{s(\\A\\Q${opening}\\E)|(\\Q${closing}\\E\\n*\\z)d} } - }" + } }" } } def comment-line -docstring "Comment/uncomment the current line" %{ %sh{ readonly opening="${kak_opt_comment_line_chars}" - readonly opening_escaped="\Q${opening}\E" + readonly opening_escaped="\\Q${opening}\\E" if [ -z "${opening}" ]; then echo "echo -debug 'The \`comment_line_chars\` variable is empty, could not comment the line'" exit fi - printf %s\\n " - ## 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} + printf %s\\n "eval -draft %{ + ## Select the content of the line, without indentation + exec I try %{ - ## The line has already been commented - exec -draft %{\A${opening_escaped}} + ## There's no text on the line + exec \\A[\\h\\v\\n]*\\z - ## Comment the line - exec %{i${opening}${#opening}H} - } catch %{ - ## Uncomment the line - exec -draft %{s\A${opening_escaped}\h*d} + try %{ + ## The line has already been commented + exec %{\\A${opening_escaped}} + + ## Comment the line + exec -draft %{i${opening}} + } catch %{ + ## Uncomment the line + exec -draft %{s\\A${opening_escaped}\\h*d} + } } }" }