Improve comment-line command

This commit is contained in:
Maxim Baz 2018-06-28 23:43:00 +02:00
parent 43b72770ec
commit 5d689858df
No known key found for this signature in database
GPG Key ID: 011FDC52DA839335
13 changed files with 58 additions and 5 deletions

View File

@ -150,16 +150,32 @@ define-command comment-line -docstring '(un)comment selected lines using line co
try %{
# Keep non-empty lines
execute-keys <a-K>\A\s*\z<ret>
} catch %{
}
try %{
set-register / "\A\Q%opt{comment_line}\E\h?"
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
# 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-cursors-left
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"
}
}

View File

@ -0,0 +1 @@
jXXX:comment-line<ret>

View File

@ -0,0 +1,4 @@
a:
b: 1
c: 2

View File

@ -0,0 +1,4 @@
a:
# b: 1
# c: 2

View 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

View File

@ -0,0 +1 @@
%:comment-line<ret>

View File

@ -0,0 +1,4 @@
a:
b: 1
c: 2

View File

@ -0,0 +1,4 @@
# a:
# b: 1
# c: 2

View 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

View File

@ -0,0 +1 @@
%:comment-line<ret>

View File

@ -0,0 +1,3 @@
a:
# b: 1
c: 2

View File

@ -0,0 +1,3 @@
# a:
# # b: 1
# c: 2

View 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