2016-12-12 21:46:48 +01:00
|
|
|
# http://editorconfig.org/#file-format-details
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-09-28 13:41:44 +02:00
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](editorconfig) %{
|
|
|
|
set-option buffer filetype ini
|
|
|
|
set-option buffer static_words indent_style indent_size tab_width \
|
|
|
|
end_of_line charset insert_final_newline trim_trailing_whitespace root \
|
2019-06-12 23:55:40 +02:00
|
|
|
latin1 utf-8 utf-8-bom utf-16be utf-16le lf cr crlf unset space tab max_line_length
|
2018-09-28 13:41:44 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 19:28:32 +02:00
|
|
|
define-command editorconfig-load -params ..1 -docstring "editorconfig-load [file]: set formatting behavior according to editorconfig" %{
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %sh{
|
2019-11-14 08:32:55 +01:00
|
|
|
command -v editorconfig >/dev/null 2>&1 || { echo "fail editorconfig could not be found"; exit 1; }
|
2019-07-09 17:06:32 +02:00
|
|
|
|
|
|
|
file="${1:-$kak_buffile}"
|
|
|
|
case $file in
|
|
|
|
/*) # $kak_buffile is a full path that starts with a '/'
|
|
|
|
printf %s\\n "remove-hooks buffer editorconfig-hooks"
|
|
|
|
editorconfig "$file" | awk -v file="$file" -F= -- '
|
2021-02-04 07:25:37 +01:00
|
|
|
$1 == "indent_style" { indent_style = $2 }
|
|
|
|
$1 == "indent_size" { indent_size = $2 == "tab" ? 4 : $2 }
|
|
|
|
$1 == "tab_width" { tab_width = $2 }
|
|
|
|
$1 == "end_of_line" { end_of_line = $2 }
|
|
|
|
$1 == "charset" { charset = $2 }
|
|
|
|
$1 == "trim_trailing_whitespace" { trim_trailing_whitespace = $2 }
|
|
|
|
$1 == "max_line_length" { max_line_length = $2 }
|
2016-12-02 14:44:51 +01:00
|
|
|
|
2019-07-09 17:06:32 +02:00
|
|
|
END {
|
|
|
|
if (indent_style == "tab") {
|
|
|
|
print "set-option buffer indentwidth 0"
|
|
|
|
}
|
|
|
|
if (indent_style == "space") {
|
2021-02-04 07:25:37 +01:00
|
|
|
print "set-option buffer indentwidth " indent_size
|
2019-07-09 17:06:32 +02:00
|
|
|
}
|
|
|
|
if (indent_size || tab_width) {
|
|
|
|
print "set-option buffer tabstop " (tab_width ? tab_width : indent_size)
|
|
|
|
}
|
|
|
|
if (end_of_line == "lf" || end_of_line == "crlf") {
|
|
|
|
print "set-option buffer eolformat " end_of_line
|
|
|
|
}
|
|
|
|
if (charset == "utf-8-bom") {
|
|
|
|
print "set-option buffer BOM utf8"
|
|
|
|
}
|
|
|
|
if (trim_trailing_whitespace == "true") {
|
2022-04-15 00:14:17 +02:00
|
|
|
print "hook buffer BufWritePre \"" file "\" -group editorconfig-hooks %{ try %{ execute-keys -draft %{%s\\h+$|\\n+\\z<ret>d} } }"
|
2019-07-09 17:06:32 +02:00
|
|
|
}
|
|
|
|
if (max_line_length && max_line_length != "off") {
|
|
|
|
print "set window autowrap_column " max_line_length
|
|
|
|
print "autowrap-enable"
|
|
|
|
print "add-highlighter window/ column %sh{ echo $((" max_line_length "+1)) } default,bright-black"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
' ;;
|
|
|
|
esac
|
2016-02-23 00:11:20 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-29 20:48:35 +02:00
|
|
|
complete-command editorconfig-load file
|