From 809f825e668576592cd25e3dbf0077108c2fc64b Mon Sep 17 00:00:00 2001 From: Henri Jones Date: Wed, 16 May 2018 22:32:12 +0100 Subject: [PATCH 2/2] Add TOML v4.0.0 config --- rc/extra/toml.kak | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 rc/extra/toml.kak diff --git a/rc/extra/toml.kak b/rc/extra/toml.kak new file mode 100644 index 00000000..29a4b674 --- /dev/null +++ b/rc/extra/toml.kak @@ -0,0 +1,72 @@ +# https://github.com/toml-lang/toml/tree/v0.4.0 +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.(toml) %{ + set-option buffer filetype toml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared regions -default code toml \ + comment '#' $ '' \ + string '"""' (? s \h+$ d } +} + +define-command -hidden toml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : toml-filter-around-selections } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group toml-highlight global WinSetOption filetype=toml %{ + add-highlighter window ref toml +} + +hook global WinSetOption filetype=toml %{ + hook window ModeChange insert:.* -group toml-hooks toml-filter-around-selections + hook window InsertChar \n -group toml-indent toml-indent-on-new-line +} + +hook -group toml-highlight global WinSetOption filetype=(?!toml).* %{ + remove-highlighter window/toml +} + +hook global WinSetOption filetype=(?!toml).* %{ + remove-hooks window toml-indent + remove-hooks window toml-hooks +} +