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 %{
|
2020-06-02 10:50:13 +02:00
|
|
|
set-option buffer comment_line '//'
|
|
|
|
set-option buffer comment_block_begin '////'
|
|
|
|
set-option buffer comment_block_end '////'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2019-11-09 15:22:19 +01:00
|
|
|
hook global BufSetOption filetype=(c|cpp|dart|gluon|go|java|javascript|objc|php|rust|sass|scala|scss|swift|typescript) %{
|
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
|
|
|
}
|
|
|
|
|
2021-05-30 14:39:58 +02:00
|
|
|
hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm|dhall|purescript) %{
|
2018-05-22 13:24:54 +02: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 %{
|
2018-05-22 13:24:54 +02: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
|
|
|
}
|
|
|
|
|
2018-02-28 05:07:25 +01:00
|
|
|
hook global BufSetOption filetype=(html|xml) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line ''
|
2017-11-23 10:30:10 +01:00
|
|
|
set-option buffer comment_block_begin '<!--'
|
2017-10-16 16:07:52 +02:00
|
|
|
set-option buffer comment_block_end '-->'
|
2016-10-14 21:12:01 +02:00
|
|
|
}
|
|
|
|
|
2020-08-31 08:13:18 +02:00
|
|
|
hook global BufSetOption filetype=(latex|mercury) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer comment_line '%'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 13:57:48 +02:00
|
|
|
hook global BufSetOption filetype=ledger %{
|
|
|
|
set-option buffer comment_line ';'
|
|
|
|
}
|
|
|
|
|
2021-02-21 13:21:04 +01:00
|
|
|
hook global BufSetOption filetype=(lisp|scheme) %{
|
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 ''
|
2019-11-12 13:21:54 +01:00
|
|
|
set-option buffer comment_block_begin '[//]: # "'
|
|
|
|
set-option buffer comment_block_end '"'
|
2016-10-15 10:04:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 08:08:56 +01:00
|
|
|
hook global BufSetOption filetype=(ocaml|coq) %{
|
|
|
|
set-option buffer comment_block_begin '(* '
|
|
|
|
set-option buffer comment_block_end ' *)'
|
|
|
|
}
|
|
|
|
|
2020-12-28 19:14:57 +01:00
|
|
|
hook global BufSetOption filetype=((free|object)?pascal|delphi) %{
|
2021-07-17 09:21:47 +02:00
|
|
|
set-option buffer comment_line '//'
|
2020-12-28 19:14:57 +01: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
|
|
|
}
|
|
|
|
|
2021-07-16 17:55:10 +02:00
|
|
|
hook global BufSetOption filetype=(pug|zig|cue) %{
|
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
|
|
|
}
|
|
|
|
|
2021-01-21 15:35:35 +01:00
|
|
|
hook global BufSetOption filetype=r %{
|
2021-01-21 15:12:41 +01:00
|
|
|
set-option buffer comment_line '#'
|
|
|
|
}
|
|
|
|
|
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' %{
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %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
|
|
|
}
|
2018-07-05 20:49:05 +02:00
|
|
|
evaluate-commands -save-regs '"/' -draft %{
|
2017-10-16 16:07:52 +02:00
|
|
|
# Keep non-empty selections
|
|
|
|
execute-keys <a-K>\A\s*\z<ret>
|
|
|
|
|
|
|
|
try %{
|
2017-11-23 10:30:10 +01:00
|
|
|
# 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<ret>"
|
|
|
|
# Uncomment it
|
|
|
|
set-register / "\A\Q%opt{comment_block_begin}\E|\Q%opt{comment_block_end}\E\n*\z"
|
|
|
|
execute-keys s<ret>d
|
2017-10-16 16:07:52 +02:00
|
|
|
} catch %{
|
2017-11-23 10:30:10 +01:00
|
|
|
# Comment the selection
|
|
|
|
set-register '"' "%opt{comment_block_begin}"
|
|
|
|
execute-keys P
|
|
|
|
set-register '"' "%opt{comment_block_end}"
|
|
|
|
execute-keys p
|
2017-10-16 16:07:52 +02:00
|
|
|
}
|
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' %{
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %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
|
|
|
}
|
2018-07-05 23:29:53 +02:00
|
|
|
evaluate-commands -save-regs '"/' -draft %{
|
2017-10-16 16:07:52 +02:00
|
|
|
# Select the content of the lines, without indentation
|
2018-03-30 00:29:05 +02:00
|
|
|
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>
|
2018-06-28 23:43:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try %{
|
|
|
|
set-register / "\A\Q%opt{comment_line}\E\h?"
|
2015-10-25 13:17:36 +01:00
|
|
|
|
|
|
|
try %{
|
2018-06-28 23:43:00 +02:00
|
|
|
# See if there are any uncommented lines in the selection
|
|
|
|
execute-keys -draft <a-K><ret>
|
|
|
|
|
|
|
|
# There are uncommented lines, so comment everything
|
2018-05-22 13:24:54 +02:00
|
|
|
set-register '"' "%opt{comment_line} "
|
2018-06-29 00:56:37 +02:00
|
|
|
align-selections-left
|
2017-11-23 10:30:10 +01:00
|
|
|
execute-keys P
|
2018-06-28 23:43:00 +02:00
|
|
|
} catch %{
|
|
|
|
# All lines were commented, so uncomment everything
|
|
|
|
execute-keys s<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
|
|
|
}
|
|
|
|
}
|
2018-06-28 23:43:00 +02:00
|
|
|
|
2018-06-29 00:56:37 +02:00
|
|
|
define-command align-selections-left -docstring 'extend selections to the left to align with the leftmost selected column' %{
|
2018-07-05 23:29:53 +02:00
|
|
|
evaluate-commands %sh{
|
2018-07-05 23:46:21 +02:00
|
|
|
leftmost_column=$(echo "$kak_selections_desc" | tr ' ' '\n' | cut -d',' -f1 | cut -d'.' -f2 | sort -n | head -n1)
|
2018-06-29 01:05:00 +02:00
|
|
|
aligned_selections=$(echo "$kak_selections_desc" | sed -E "s/\.[0-9]+,/.$leftmost_column,/g")
|
2018-06-28 23:43:00 +02:00
|
|
|
echo "select $aligned_selections"
|
|
|
|
}
|
|
|
|
}
|