2017-10-16 16:07:52 +02:00
|
|
|
# Line comments
|
2017-11-03 08:34:41 +01:00
|
|
|
declare-option -docstring "characters inserted at the beginning of a commented line" \
|
2017-05-16 13:35:43 +02:00
|
|
|
str comment_line '#'
|
2016-10-15 10:04:43 +02:00
|
|
|
|
2017-10-16 16:07:52 +02:00
|
|
|
# Block comments
|
|
|
|
declare-option -docstring "characters inserted before a commented block" \
|
|
|
|
str comment_block_begin
|
|
|
|
declare-option -docstring "characters inserted after a commented block" \
|
|
|
|
str comment_block_end
|
2015-10-25 13:17:36 +01:00
|
|
|
|
2017-10-16 16:07:52 +02:00
|
|
|
# Default comments for all languages
|
2016-10-15 10:04:43 +02:00
|
|
|
hook global BufSetOption filetype=asciidoc %{
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '///'
|
|
|
|
set-option buffer comment_block_end '///'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2017-10-16 16:07:43 +02:00
|
|
|
hook global BufSetOption filetype=(c|cpp|go|java|javascript|objc|php|rust|sass|scala|scss|swift) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '//'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '/*'
|
|
|
|
set-option buffer comment_block_end '*/'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=(cabal|haskell|moon) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '--'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '{-'
|
|
|
|
set-option buffer comment_block_end '-}'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=clojure %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '#_ '
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '(comment '
|
|
|
|
set-option buffer comment_block_end ')'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:12:01 +02:00
|
|
|
hook global BufSetOption filetype=coffee %{
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '###'
|
|
|
|
set-option buffer comment_block_end '###'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=css %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line ''
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '/*'
|
|
|
|
set-option buffer comment_block_end '*/'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=d %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '//'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '/+'
|
|
|
|
set-option buffer comment_block_end '+/'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 10:04:43 +02:00
|
|
|
hook global BufSetOption filetype=(gas|ini) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line ';'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=haml %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '-#'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:12:01 +02:00
|
|
|
hook global BufSetOption filetype=html %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line ''
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '<lt>!--'
|
|
|
|
set-option buffer comment_block_end '-->'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=latex %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '%'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=lisp %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line ';'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '#|'
|
|
|
|
set-option buffer comment_block_end '|#'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=lua %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '--'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '--[['
|
|
|
|
set-option buffer comment_block_end ']]'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 10:04:43 +02:00
|
|
|
hook global BufSetOption filetype=markdown %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line ''
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '[//]'
|
|
|
|
set-option buffer comment_block_end '# (:)'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=perl %{
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '#['
|
|
|
|
set-option buffer comment_block_end ']'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2017-10-16 16:07:43 +02:00
|
|
|
hook global BufSetOption filetype=pug %{
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_line '//'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=python %{
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin "'''"
|
|
|
|
set-option buffer comment_block_end "'''"
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 10:04:43 +02:00
|
|
|
hook global BufSetOption filetype=ragel %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '%%'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '%%{'
|
|
|
|
set-option buffer comment_block_end '}%%'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=ruby %{
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_begin '^begin='
|
|
|
|
set-option buffer comment_block_end '^=end'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-16 16:07:52 +02:00
|
|
|
define-command comment-block -docstring '(un)comment selections using block comments' %{
|
2015-10-25 13:17:36 +01:00
|
|
|
%sh{
|
2017-10-16 16:07:52 +02:00
|
|
|
if [ -z "${kak_opt_comment_block_begin}" ] || [ -z "${kak_opt_comment_block_end}" ]; then
|
|
|
|
echo "fail \"The 'comment_block' options are empty, could not comment the selection\""
|
2015-10-25 13:17:36 +01:00
|
|
|
fi
|
2017-10-16 16:07:52 +02:00
|
|
|
}
|
|
|
|
evaluate-commands -draft %{
|
|
|
|
# Keep non-empty selections
|
|
|
|
execute-keys <a-K>\A\s*\z<ret>
|
|
|
|
|
|
|
|
try %{
|
|
|
|
# Assert that the selection has not been commented
|
|
|
|
execute-keys "<a-K>\A\Q%opt{comment_block_begin}\E.*\Q%opt{comment_block_end}\E\n*\z<ret>"
|
|
|
|
|
|
|
|
# Comment the selection
|
|
|
|
execute-keys -draft "a%opt{comment_block_end}<esc>i%opt{comment_block_begin}"
|
|
|
|
} catch %{
|
|
|
|
# Uncomment the commented selection
|
|
|
|
execute-keys -draft "s(\A\Q%opt{comment_block_begin}\E)|(\Q%opt{comment_block_end}\E\n*\z)<ret>d"
|
|
|
|
}
|
2015-10-25 13:17:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command comment-line -docstring '(un)comment selected lines using line comments' %{
|
2015-10-25 13:17:36 +01:00
|
|
|
%sh{
|
2017-10-16 16:07:52 +02:00
|
|
|
if [ -z "${kak_opt_comment_line}" ]; then
|
|
|
|
echo "fail \"The 'comment_line' option is empty, could not comment the line\""
|
2015-10-25 13:17:36 +01:00
|
|
|
fi
|
2017-10-16 16:07:52 +02:00
|
|
|
}
|
|
|
|
evaluate-commands -draft %{
|
|
|
|
# Select the content of the lines, without indentation
|
|
|
|
execute-keys <a-s>gi<a-l>
|
2015-10-25 13:17:36 +01:00
|
|
|
|
2017-10-16 16:07:52 +02:00
|
|
|
try %{
|
|
|
|
# Keep non-empty lines
|
|
|
|
execute-keys <a-K>\A\s*\z<ret>
|
2015-10-25 13:17:36 +01:00
|
|
|
|
|
|
|
try %{
|
2017-10-16 16:07:52 +02:00
|
|
|
# Assert that the line has not been commented
|
|
|
|
execute-keys "<a-K>\A\Q%opt{comment_line}\E<ret>"
|
|
|
|
|
|
|
|
# Comment the line
|
|
|
|
execute-keys -draft "i%opt{comment_line}"
|
|
|
|
} catch %{
|
|
|
|
# Uncomment the line
|
|
|
|
execute-keys -draft "s\A\Q%opt{comment_line}\E\h*<ret>d"
|
2015-10-25 13:17:36 +01:00
|
|
|
}
|
2017-10-16 16:07:52 +02:00
|
|
|
}
|
2015-10-25 13:17:36 +01:00
|
|
|
}
|
|
|
|
}
|