2017-01-15 16:58:07 +03:00
|
|
|
|
## Line comments
|
2017-11-03 10:34:41 +03:00
|
|
|
|
declare-option -docstring "characters inserted at the beginning of a commented line" \
|
2017-05-16 14:35:43 +03:00
|
|
|
|
str comment_line '#'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
|
2017-01-15 16:58:07 +03:00
|
|
|
|
## Block comments
|
2017-11-03 10:34:41 +03:00
|
|
|
|
declare-option -docstring "colon separated tuple containing the characters inserted before/after a commented line" \
|
2017-05-16 14:35:43 +03:00
|
|
|
|
str-list comment_block
|
2015-10-25 15:17:36 +03:00
|
|
|
|
|
2017-01-15 16:58:07 +03:00
|
|
|
|
## Default comments for all languages
|
2016-10-15 11:04:43 +03:00
|
|
|
|
hook global BufSetOption filetype=asciidoc %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_block '///:///'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 14:23:11 +03:00
|
|
|
|
hook global BufSetOption filetype=(c|cpp|go|java|javascript|objc|php|sass|scala|scss|swift) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '//'
|
|
|
|
|
set-option buffer comment_block '/*:*/'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=(cabal|haskell|moon) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '--'
|
|
|
|
|
set-option buffer comment_block '{-:-}'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=clojure %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '#_ '
|
|
|
|
|
set-option buffer comment_block '(comment :)'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 22:12:01 +03:00
|
|
|
|
hook global BufSetOption filetype=coffee %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_block '###:###'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=css %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line ''
|
|
|
|
|
set-option buffer comment_block '/*:*/'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=d %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '//'
|
|
|
|
|
set-option buffer comment_block '/+:+/'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 11:04:43 +03:00
|
|
|
|
hook global BufSetOption filetype=(gas|ini) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line ';'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=haml %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '-#'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 22:12:01 +03:00
|
|
|
|
hook global BufSetOption filetype=html %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line ''
|
|
|
|
|
set-option buffer comment_block '<!--:-->'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=latex %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '%'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=lisp %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line ';'
|
|
|
|
|
set-option buffer comment_block '#|:|#'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=lua %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '--'
|
|
|
|
|
set-option buffer comment_block '--[[:]]'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 11:04:43 +03:00
|
|
|
|
hook global BufSetOption filetype=markdown %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line ''
|
|
|
|
|
set-option buffer comment_block '[//]: # (:)'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=perl %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_block '#[:]'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=(pug|rust) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '//'
|
2016-10-15 11:04:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=python %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_block "''':'''"
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 11:04:43 +03:00
|
|
|
|
hook global BufSetOption filetype=ragel %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_line '%%'
|
|
|
|
|
set-option buffer comment_block '%%{:}%%'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook global BufSetOption filetype=ruby %{
|
2017-11-03 10:34:41 +03:00
|
|
|
|
set-option buffer comment_block '^begin=:^=end'
|
2016-10-14 22:12:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
|
define-command comment-block -docstring '(un)comment selected lines using block comments' %{
|
2015-10-25 15:17:36 +03:00
|
|
|
|
%sh{
|
2016-10-14 22:15:35 +03:00
|
|
|
|
exec_proof() {
|
2017-11-03 11:09:45 +03:00
|
|
|
|
## Replace the '<' sign that is interpreted differently in `execute-keys`
|
2016-04-23 08:47:01 +03:00
|
|
|
|
printf %s\\n "$@" | sed 's,<,<lt>,g'
|
2015-10-25 15:17:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 16:58:07 +03:00
|
|
|
|
readonly opening=$(exec_proof "${kak_opt_comment_block%:*}")
|
|
|
|
|
readonly closing=$(exec_proof "${kak_opt_comment_block##*:}")
|
2015-10-25 15:17:36 +03:00
|
|
|
|
|
2016-03-15 14:51:19 +03:00
|
|
|
|
if [ -z "${opening}" ] || [ -z "${closing}" ]; then
|
2017-01-15 16:58:07 +03:00
|
|
|
|
echo "echo -debug 'The \`comment_block\` variable is empty, could not comment the selection'"
|
2015-10-25 15:17:36 +03:00
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2017-11-03 11:09:45 +03:00
|
|
|
|
printf %s\\n "evaluate-commands -draft %{ try %{
|
2015-10-25 15:17:36 +03:00
|
|
|
|
## The selection is empty
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys <a-K>\\A[\\h\\v\\n]*\\z<ret>
|
2015-10-25 15:17:36 +03:00
|
|
|
|
|
|
|
|
|
try %{
|
|
|
|
|
## The selection has already been commented
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys %{<a-K>\\A\\Q${opening}\\E.*\\Q${closing}\\E\\n*\\z<ret>}
|
2015-10-25 15:17:36 +03:00
|
|
|
|
|
|
|
|
|
## Comment the selection
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys -draft %{a${closing}<esc>i${opening}}
|
2015-10-25 15:17:36 +03:00
|
|
|
|
} catch %{
|
|
|
|
|
## Uncomment the commented selection
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys -draft %{s(\\A\\Q${opening}\\E)|(\\Q${closing}\\E\\n*\\z)<ret>d}
|
2015-10-25 15:17:36 +03:00
|
|
|
|
}
|
2016-10-14 22:15:35 +03:00
|
|
|
|
} }"
|
2015-10-25 15:17:36 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
|
define-command comment-line -docstring '(un)comment selected lines using line comments' %{
|
2015-10-25 15:17:36 +03:00
|
|
|
|
%sh{
|
2017-01-15 16:58:07 +03:00
|
|
|
|
readonly opening="${kak_opt_comment_line}"
|
2016-10-14 22:15:35 +03:00
|
|
|
|
readonly opening_escaped="\\Q${opening}\\E"
|
2015-10-25 15:17:36 +03:00
|
|
|
|
|
|
|
|
|
if [ -z "${opening}" ]; then
|
2017-01-15 16:58:07 +03:00
|
|
|
|
echo "echo -debug 'The \`comment_line\` variable is empty, could not comment the line'"
|
2015-10-25 15:17:36 +03:00
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2017-11-03 11:09:45 +03:00
|
|
|
|
printf %s\\n "evaluate-commands -draft %{
|
2017-01-15 16:43:45 +03:00
|
|
|
|
## Select the content of the lines, without indentation
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys <a-s>I<esc><a-l>
|
2015-10-25 15:17:36 +03:00
|
|
|
|
|
|
|
|
|
try %{
|
2017-01-15 17:05:01 +03:00
|
|
|
|
## There’s no text on the line
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys <a-K>\\A[\\h\\v\\n]*\\z<ret>
|
2016-10-14 22:15:35 +03:00
|
|
|
|
|
|
|
|
|
try %{
|
|
|
|
|
## The line has already been commented
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys %{<a-K>\\A${opening_escaped}<ret>}
|
2016-10-14 22:15:35 +03:00
|
|
|
|
|
|
|
|
|
## Comment the line
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys -draft %{i${opening}}
|
2016-10-14 22:15:35 +03:00
|
|
|
|
} catch %{
|
|
|
|
|
## Uncomment the line
|
2017-11-03 11:09:45 +03:00
|
|
|
|
execute-keys -draft %{s\\A${opening_escaped}\\h*<ret>d}
|
2016-10-14 22:15:35 +03:00
|
|
|
|
}
|
2015-10-25 15:17:36 +03:00
|
|
|
|
}
|
|
|
|
|
}"
|
|
|
|
|
}
|
|
|
|
|
}
|