1
1
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:
Maxime Coste 2018-07-07 09:39:46 +10:00
commit f0b3925ba7
17 changed files with 83 additions and 6 deletions

View File

@ -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"
}
}

View File

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

View File

@ -0,0 +1,6 @@
a:
b: 1
c:
d: 2
e: 3

View File

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

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,6 @@
a:
b: 1
c:
d: 2
e: 3

View File

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

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,6 @@
a:
# b: 1
c:
d: 2
e: 3

View File

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

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