mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 20:41:49 +03:00
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\""
|
||||
fi
|
||||
}
|
||||
evaluate-commands -draft %{
|
||||
evaluate-commands -save-regs '"/' -draft %{
|
||||
# Select the content of the lines, without indentation
|
||||
execute-keys <a-s>gi<a-l>
|
||||
|
||||
try %{
|
||||
# Keep non-empty lines
|
||||
execute-keys <a-K>\A\s*\z<ret>
|
||||
}
|
||||
|
||||
try %{
|
||||
# Select the comment characters and remove them
|
||||
set-register / "\A\Q%opt{comment_line}\E\h*"
|
||||
execute-keys s<ret>d
|
||||
} catch %{
|
||||
# Comment the line
|
||||
set-register / "\A\Q%opt{comment_line}\E\h?"
|
||||
|
||||
try %{
|
||||
# See if there are any uncommented lines in the selection
|
||||
execute-keys -draft <a-K><ret>
|
||||
|
||||
# There are uncommented lines, so comment everything
|
||||
set-register '"' "%opt{comment_line} "
|
||||
align-selections-left
|
||||
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