Rework editorconfig.kak to make it more robust and handle tabs more correctly
This commit is contained in:
parent
089ee8ac0a
commit
d88d0bac42
|
@ -1,33 +1,35 @@
|
||||||
def editorconfig-load -docstring "Set indentation options according to editorconfig file" %{
|
def editorconfig-load -docstring "Set indentation options according to editorconfig file" %{
|
||||||
%sh{
|
%sh{
|
||||||
command -v editorconfig >/dev/null 2>&1 || { echo 'echo -color Error The editorconfig tool could not be found'; exit 1; }
|
command -v editorconfig >/dev/null 2>&1 || { echo 'echo -color Error The editorconfig tool could not be found'; exit 1; }
|
||||||
editorconfig $kak_buffile | awk -F= -- \
|
editorconfig $kak_buffile | awk -F= -- '
|
||||||
'{
|
/indent_style=/ { indent_style = $2 }
|
||||||
if ($1 == "indent_style" && $2 == "tab") {
|
/indent_size=/ { indent_size = $2 == "tab" ? 4 : $2 }
|
||||||
print "set buffer indentwidth 0"
|
/tab_width=/ { tab_width = $2 }
|
||||||
}
|
/end_of_line=/ { end_of_line = $2 }
|
||||||
else if ($1 == "indent_size" && $2 ~ "[0-9]+") {
|
/charset=/ { charset = $2 }
|
||||||
print "set buffer indentwidth", $2
|
|
||||||
}
|
END {
|
||||||
else if ($1 == "tab_width" && $2 ~ "[0-9]+") {
|
if (indent_style == "tab")
|
||||||
print "set buffer tabstop", $2
|
{
|
||||||
}
|
print "set buffer indentwidth 0"
|
||||||
else if ($1 == "end_of_line") {
|
print "set buffer aligntab true"
|
||||||
if ($2 == "lf" || $2 == "crlf") {
|
}
|
||||||
print "set buffer eolformat", $2
|
if (indent_style == "spaces") {
|
||||||
}
|
print "set buffer indentwidth " (indent_size == "tab" ? 4 : indent_size)
|
||||||
else {
|
print "set buffer aligntab false"
|
||||||
print "echo -color yellow",$2,"is not a valid eolformat string: ignored\""
|
}
|
||||||
}
|
if (indent_size || tab_width) {
|
||||||
}
|
print "set buffer tabstop " (tab_width ? tab_width : indent_size)
|
||||||
else if ($1 == "charset") {
|
}
|
||||||
if ($2 == "utf-8-bom") {
|
if (end_of_line) {
|
||||||
print "set buffer BOM utf8"
|
if (end_of_line == "lf" || end_of_line == "crlf")
|
||||||
}
|
print "set buffer eolformat " end_of_line
|
||||||
else {
|
else
|
||||||
print "set buffer BOM none"
|
print "error"
|
||||||
}
|
}
|
||||||
}
|
if (charset)
|
||||||
}'
|
print "set buffer BOM" (charset == "utf-8-bom" ? true : false)
|
||||||
|
}
|
||||||
|
'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user