Improve comment-line command
This commit is contained in:
parent
43b72770ec
commit
5d689858df
|
@ -150,16 +150,32 @@ define-command comment-line -docstring '(un)comment selected lines using line co
|
||||||
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>
|
||||||
|
} catch %{
|
||||||
|
}
|
||||||
|
|
||||||
try %{
|
try %{
|
||||||
# Select the comment characters and remove them
|
set-register / "\A\Q%opt{comment_line}\E\h?"
|
||||||
set-register / "\A\Q%opt{comment_line}\E\h*"
|
|
||||||
execute-keys s<ret>d
|
try %{
|
||||||
} catch %{
|
# See if there are any uncommented lines in the selection
|
||||||
# Comment the line
|
execute-keys -draft <a-K><ret>
|
||||||
|
|
||||||
|
# There are uncommented lines, so comment everything
|
||||||
set-register '"' "%opt{comment_line} "
|
set-register '"' "%opt{comment_line} "
|
||||||
|
align-cursors-left
|
||||||
execute-keys P
|
execute-keys P
|
||||||
|
} catch %{
|
||||||
|
# All lines were commented, so uncomment everything
|
||||||
|
execute-keys s<ret>d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define-command align-cursors-left -docstring 'set all cursor (and anchor) columns to the column of the leftmost cursor' %{
|
||||||
|
%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 "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 @@
|
||||||
|
jXXX:comment-line<ret>
|
4
test/indent/comment/comment-multiple-lines-indented/in
Normal file
4
test/indent/comment/comment-multiple-lines-indented/in
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
a:
|
||||||
|
b: 1
|
||||||
|
|
||||||
|
c: 2
|
4
test/indent/comment/comment-multiple-lines-indented/out
Normal file
4
test/indent/comment/comment-multiple-lines-indented/out
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
a:
|
||||||
|
# b: 1
|
||||||
|
|
||||||
|
# c: 2
|
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>
|
4
test/indent/comment/comment-multiple-lines-unindented/in
Normal file
4
test/indent/comment/comment-multiple-lines-unindented/in
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
a:
|
||||||
|
b: 1
|
||||||
|
|
||||||
|
c: 2
|
|
@ -0,0 +1,4 @@
|
||||||
|
# a:
|
||||||
|
# b: 1
|
||||||
|
|
||||||
|
# c: 2
|
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,3 @@
|
||||||
|
a:
|
||||||
|
# b: 1
|
||||||
|
c: 2
|
|
@ -0,0 +1,3 @@
|
||||||
|
# a:
|
||||||
|
# # b: 1
|
||||||
|
# c: 2
|
|
@ -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