diff --git a/rc/core/comment.kak b/rc/core/comment.kak index 2b101db8..aeee9080 100644 --- a/rc/core/comment.kak +++ b/rc/core/comment.kak @@ -59,7 +59,7 @@ hook global BufSetOption filetype=haml %{ hook global BufSetOption filetype=html %{ set-option buffer comment_line '' - set-option buffer comment_block_begin '!--' + set-option buffer comment_block_begin '' } @@ -121,14 +121,18 @@ define-command comment-block -docstring '(un)comment selections using block comm execute-keys \A\s*\z try %{ - # Assert that the selection has not been commented - execute-keys "\A\Q%opt{comment_block_begin}\E.*\Q%opt{comment_block_end}\E\n*\z" - - # Comment the selection - execute-keys -draft "a%opt{comment_block_end}i%opt{comment_block_begin}" + # Assert that the selection has been commented + set-register / "\A\Q%opt{comment_block_begin}\E.*\Q%opt{comment_block_end}\E\n*\z" + execute-keys "s" + # Uncomment it + set-register / "\A\Q%opt{comment_block_begin}\E|\Q%opt{comment_block_end}\E\n*\z" + execute-keys sd } catch %{ - # Uncomment the commented selection - execute-keys -draft "s(\A\Q%opt{comment_block_begin}\E)|(\Q%opt{comment_block_end}\E\n*\z)d" + # Comment the selection + set-register '"' "%opt{comment_block_begin}" + execute-keys P + set-register '"' "%opt{comment_block_end}" + execute-keys p } } } @@ -148,14 +152,13 @@ define-command comment-line -docstring '(un)comment selected lines using line co execute-keys \A\s*\z try %{ - # Assert that the line has not been commented - execute-keys "\A\Q%opt{comment_line}\E" - - # Comment the line - execute-keys -draft "i%opt{comment_line}" + # Select the comment characters and remove them + set-register / "\A\Q%opt{comment_line}\E\h*" + execute-keys sd } catch %{ - # Uncomment the line - execute-keys -draft "s\A\Q%opt{comment_line}\E\h*d" + # Comment the line + set-register '"' "%opt{comment_line}" + execute-keys P } } }