Merge remote-tracking branch 'maximbaz/improve-comment-line'
This commit is contained in:
commit
f0b3925ba7
|
@ -143,23 +143,38 @@ define-command comment-line -docstring '(un)comment selected lines using line co
|
||||||
echo "fail \"The 'comment_line' option is empty, could not comment the line\""
|
echo "fail \"The 'comment_line' option is empty, could not comment the line\""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
evaluate-commands -draft %{
|
evaluate-commands -save-regs '"/' -draft %{
|
||||||
# Select the content of the lines, without indentation
|
# Select the content of the lines, without indentation
|
||||||
execute-keys <a-s>gi<a-l>
|
execute-keys <a-s>gi<a-l>
|
||||||
|
|
||||||
try %{
|
try %{
|
||||||
# Keep non-empty lines
|
# Keep non-empty lines
|
||||||
execute-keys <a-K>\A\s*\z<ret>
|
execute-keys <a-K>\A\s*\z<ret>
|
||||||
|
}
|
||||||
|
|
||||||
|
try %{
|
||||||
|
set-register / "\A\Q%opt{comment_line}\E\h?"
|
||||||
|
|
||||||
try %{
|
try %{
|
||||||
# Select the comment characters and remove them
|
# See if there are any uncommented lines in the selection
|
||||||
set-register / "\A\Q%opt{comment_line}\E\h*"
|
execute-keys -draft <a-K><ret>
|
||||||
execute-keys s<ret>d
|
|
||||||
} catch %{
|
# There are uncommented lines, so comment everything
|
||||||
# Comment the line
|
|
||||||
set-register '"' "%opt{comment_line} "
|
set-register '"' "%opt{comment_line} "
|
||||||
|
align-selections-left
|
||||||
execute-keys P
|
execute-keys P
|
||||||
|
} catch %{
|
||||||
|
# All lines were commented, so uncomment everything
|
||||||
|
execute-keys s<ret>d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define-command align-selections-left -docstring 'extend selections to the left to align with the leftmost selected column' %{
|
||||||
|
evaluate-commands %sh{
|
||||||
|
leftmost_column=$(echo "$kak_selections_desc" | tr ' ' '\n' | cut -d',' -f1 | cut -d'.' -f2 | sort -n | head -n1)
|
||||||
|
aligned_selections=$(echo "$kak_selections_desc" | sed -E "s/\.[0-9]+,/.$leftmost_column,/g")
|
||||||
|
echo "select $aligned_selections"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
test/indent/comment/comment-multiple-lines-indented/cmd
Normal file
1
test/indent/comment/comment-multiple-lines-indented/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
jXXXXX:comment-line<ret>
|
6
test/indent/comment/comment-multiple-lines-indented/in
Normal file
6
test/indent/comment/comment-multiple-lines-indented/in
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
a:
|
||||||
|
b: 1
|
||||||
|
c:
|
||||||
|
d: 2
|
||||||
|
|
||||||
|
e: 3
|
6
test/indent/comment/comment-multiple-lines-indented/out
Normal file
6
test/indent/comment/comment-multiple-lines-indented/out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
a:
|
||||||
|
# b: 1
|
||||||
|
# c:
|
||||||
|
# d: 2
|
||||||
|
|
||||||
|
# e: 3
|
4
test/indent/comment/comment-multiple-lines-indented/rc
Normal file
4
test/indent/comment/comment-multiple-lines-indented/rc
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
source "%val{runtime}/colors/default.kak"
|
||||||
|
source "%val{runtime}/rc/base/yaml.kak"
|
||||||
|
source "%val{runtime}/rc/core/comment.kak"
|
||||||
|
set buffer filetype yaml
|
|
@ -0,0 +1 @@
|
||||||
|
%:comment-line<ret>
|
6
test/indent/comment/comment-multiple-lines-unindented/in
Normal file
6
test/indent/comment/comment-multiple-lines-unindented/in
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
a:
|
||||||
|
b: 1
|
||||||
|
c:
|
||||||
|
d: 2
|
||||||
|
|
||||||
|
e: 3
|
|
@ -0,0 +1,6 @@
|
||||||
|
# a:
|
||||||
|
# b: 1
|
||||||
|
# c:
|
||||||
|
# d: 2
|
||||||
|
|
||||||
|
# e: 3
|
4
test/indent/comment/comment-multiple-lines-unindented/rc
Normal file
4
test/indent/comment/comment-multiple-lines-unindented/rc
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
source "%val{runtime}/colors/default.kak"
|
||||||
|
source "%val{runtime}/rc/base/yaml.kak"
|
||||||
|
source "%val{runtime}/rc/core/comment.kak"
|
||||||
|
set buffer filetype yaml
|
|
@ -0,0 +1 @@
|
||||||
|
%:comment-line<ret>
|
|
@ -0,0 +1,6 @@
|
||||||
|
a:
|
||||||
|
# b: 1
|
||||||
|
c:
|
||||||
|
d: 2
|
||||||
|
|
||||||
|
e: 3
|
|
@ -0,0 +1,6 @@
|
||||||
|
# a:
|
||||||
|
# # b: 1
|
||||||
|
# c:
|
||||||
|
# d: 2
|
||||||
|
|
||||||
|
# e: 3
|
|
@ -0,0 +1,4 @@
|
||||||
|
source "%val{runtime}/colors/default.kak"
|
||||||
|
source "%val{runtime}/rc/base/yaml.kak"
|
||||||
|
source "%val{runtime}/rc/core/comment.kak"
|
||||||
|
set buffer filetype yaml
|
|
@ -0,0 +1 @@
|
||||||
|
%:comment-line<ret>
|
3
test/indent/comment/uncomment-multiple-indented-lines/in
Normal file
3
test/indent/comment/uncomment-multiple-indented-lines/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# a:
|
||||||
|
# b: 1
|
||||||
|
# c: 2
|
|
@ -0,0 +1,3 @@
|
||||||
|
a:
|
||||||
|
b: 1
|
||||||
|
c: 2
|
4
test/indent/comment/uncomment-multiple-indented-lines/rc
Normal file
4
test/indent/comment/uncomment-multiple-indented-lines/rc
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
source "%val{runtime}/colors/default.kak"
|
||||||
|
source "%val{runtime}/rc/base/yaml.kak"
|
||||||
|
source "%val{runtime}/rc/core/comment.kak"
|
||||||
|
set buffer filetype yaml
|
Loading…
Reference in New Issue
Block a user