1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-01 16:32:54 +03:00
kakoune/rc/extra/toml.kak

70 lines
2.4 KiB
Plaintext
Raw Normal View History

2018-05-17 00:32:12 +03:00
# https://github.com/toml-lang/toml/tree/v0.4.0
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.(toml) %{
set-option buffer filetype 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 '"""' (?<!\\)(\\\\)*""" fill string
add-highlighter shared/toml/string2 region "'''" "'''" fill string
add-highlighter shared/toml/string3 region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/toml/string4 region "'" "'" fill string
2018-05-17 00:32:12 +03:00
add-highlighter shared/toml/code/ regex \
2018-05-17 00:32:12 +03:00
"^\h*\[\[?([A-Za-z0-9._-]*)\]\]?" 1:title
add-highlighter shared/toml/code/ regex \
2018-05-17 00:32:12 +03:00
(?<!\w)[+-]?[0-9](_?\d)*(\.[0-9](_?\d)*)?([eE][+-]?[0-9](_?\d)*)?\b 0:value
add-highlighter shared/toml/code/ regex \
2018-05-17 00:32:12 +03:00
true|false 0:value
add-highlighter shared/toml/code/ regex \
2018-05-17 00:32:12 +03:00
'\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(.\d+)?([Zz]|[+-]\d{2}:\d{2})' 0:value
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden toml-filter-around-selections %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K#\h* <ret> y gh j P }
# preserve previous line indent
try %{ execute-keys -draft \; K <a-&> }
# filter previous line
try %{ execute-keys -draft k : toml-filter-around-selections <ret> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group toml-highlight global WinSetOption filetype=toml %{
add-highlighter window/toml ref toml
2018-05-17 00:32:12 +03:00
}
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).* %{
2018-09-19 20:59:57 +03:00
remove-hooks window toml-.+
2018-05-17 00:32:12 +03:00
}