2018-05-16 23:32:12 +02:00
|
|
|
# https://github.com/toml-lang/toml/tree/v0.4.0
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*\.(toml) %{
|
|
|
|
set-option buffer filetype toml
|
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=toml %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module toml
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2019-10-16 11:19:43 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group toml-trim-indent toml-trim-indent
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group toml-insert toml-insert-on-new-line
|
2019-04-12 00:54:58 +02:00
|
|
|
hook window InsertChar \n -group toml-indent toml-indent-on-new-line
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window toml-.+ }
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
hook -group toml-highlight global WinSetOption filetype=toml %{
|
|
|
|
add-highlighter window/toml ref toml
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/toml }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
provide-module toml %{
|
|
|
|
|
2018-05-16 23:32:12 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-06-30 01:49:57 +02:00
|
|
|
add-highlighter shared/toml regions
|
|
|
|
add-highlighter shared/toml/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/toml/comment region '#' $ fill comment
|
2021-09-15 17:00:02 +02:00
|
|
|
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-16 23:32:12 +02:00
|
|
|
|
2018-06-30 01:49:57 +02:00
|
|
|
add-highlighter shared/toml/code/ regex \
|
2018-05-16 23:32:12 +02:00
|
|
|
"^\h*\[\[?([A-Za-z0-9._-]*)\]\]?" 1:title
|
2018-06-30 01:49:57 +02:00
|
|
|
add-highlighter shared/toml/code/ regex \
|
2018-05-16 23:32:12 +02:00
|
|
|
(?<!\w)[+-]?[0-9](_?\d)*(\.[0-9](_?\d)*)?([eE][+-]?[0-9](_?\d)*)?\b 0:value
|
2018-06-30 01:49:57 +02:00
|
|
|
add-highlighter shared/toml/code/ regex \
|
2018-05-16 23:32:12 +02:00
|
|
|
true|false 0:value
|
2018-06-30 01:49:57 +02:00
|
|
|
add-highlighter shared/toml/code/ regex \
|
2018-05-16 23:32:12 +02:00
|
|
|
'\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(.\d+)?([Zz]|[+-]\d{2}:\d{2})' 0:value
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden toml-trim-indent %{
|
2018-05-16 23:32:12 +02:00
|
|
|
# remove trailing white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
|
2018-05-16 23:32:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden toml-insert-on-new-line %{
|
2018-05-16 23:32:12 +02:00
|
|
|
evaluate-commands -draft -itersel %{
|
2021-04-17 10:17:01 +02:00
|
|
|
# copy # comments prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
|
2021-04-17 10:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define-command -hidden toml-indent-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
2018-05-16 23:32:12 +02:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2018-05-16 23:32:12 +02:00
|
|
|
# filter previous line
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : toml-trim-indent <ret> }
|
2018-05-16 23:32:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|