From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/toml.kak | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 autoload/filetype/toml.kak (limited to 'autoload/filetype/toml.kak') diff --git a/autoload/filetype/toml.kak b/autoload/filetype/toml.kak new file mode 100644 index 0000000..d02e074 --- /dev/null +++ b/autoload/filetype/toml.kak @@ -0,0 +1,76 @@ +# https://github.com/toml-lang/toml/tree/v0.4.0 +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.(toml) %{ + set-option buffer filetype toml +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=toml %{ + require-module toml + + hook window ModeChange pop:insert:.* -group toml-trim-indent toml-trim-indent + hook window InsertChar \n -group toml-insert toml-insert-on-new-line + hook window InsertChar \n -group toml-indent toml-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window toml-.+ } +} + +hook -group toml-highlight global WinSetOption filetype=toml %{ + add-highlighter window/toml ref toml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/toml } +} + + +provide-module toml %{ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/toml regions +add-highlighter shared/toml/code default-region group +add-highlighter shared/toml/comment region '#' $ fill comment +add-highlighter shared/toml/string1 region '"""' (? d } +} + +define-command -hidden toml-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy # comments prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*\K#\h* y gh j P } + } +} + +define-command -hidden toml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k : toml-trim-indent } + } +} + +} -- cgit v1.2.3