2020-09-16 21:09:27 +02:00
|
|
|
# ref: https://ninja-build.org/manual.html#ref_ninja_file
|
|
|
|
|
2020-09-16 00:03:17 +02:00
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .+\.ninja %{
|
|
|
|
set-option buffer filetype ninja
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=ninja %{
|
|
|
|
require-module ninja
|
|
|
|
|
|
|
|
set-option window static_words %opt{ninja_static_words}
|
|
|
|
|
2021-02-28 21:07:21 +01:00
|
|
|
hook window ModeChange pop:insert:.* -group ninja-trim-indent ninja-trim-indent
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group ninja-insert ninja-insert-on-new-line
|
2020-09-16 00:03:17 +02:00
|
|
|
hook window InsertChar \n -group ninja-indent ninja-indent-on-new-line
|
|
|
|
# cleanup trailing whitespaces on current line insert end
|
2022-03-16 23:20:07 +01:00
|
|
|
hook window ModeChange pop:insert:.* -group ninja-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
|
2020-09-16 00:03:17 +02:00
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ninja-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group ninja-highlight global WinSetOption filetype=ninja %{
|
|
|
|
add-highlighter window/ninja ref ninja
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ninja }
|
|
|
|
}
|
|
|
|
|
2020-10-11 09:25:33 +02:00
|
|
|
|
2020-09-16 00:03:17 +02:00
|
|
|
provide-module ninja %{
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
add-highlighter shared/ninja regions
|
|
|
|
|
|
|
|
# `#`
|
|
|
|
add-highlighter shared/ninja/comment region '#' '\n' fill comment
|
|
|
|
|
2020-10-11 09:25:33 +02:00
|
|
|
# `subninja`, `include`, `rule`, `pool` and `default` declarations
|
2024-03-05 12:19:08 +01:00
|
|
|
add-highlighter shared/ninja/sirpd region '^(subninja|include|rule|pool|default)\b' '(?<!\$)\n' group
|
2020-10-11 09:25:33 +02:00
|
|
|
add-highlighter shared/ninja/sirpd/default regex '^(subninja|include)\b' 0:module
|
|
|
|
add-highlighter shared/ninja/sirpd/rulepool regex '^(rule|pool|default)\b' 0:keyword
|
|
|
|
add-highlighter shared/ninja/sirpd/linebreak regex '\$$' 0:operator
|
2020-09-16 00:03:17 +02:00
|
|
|
|
|
|
|
# `build`
|
2024-03-05 12:19:08 +01:00
|
|
|
add-highlighter shared/ninja/build region '^build\b' '(?<!\$)\n' group
|
2020-10-11 09:25:33 +02:00
|
|
|
add-highlighter shared/ninja/build/build regex '^build\b' 0:keyword
|
|
|
|
add-highlighter shared/ninja/build/rule regex ':\h+((\w|-)+)' 0:function
|
2020-09-16 00:03:17 +02:00
|
|
|
add-highlighter shared/ninja/build/colonpipe regex ':|\||\|\|' 0:operator
|
2020-10-11 09:25:33 +02:00
|
|
|
add-highlighter shared/ninja/build/linebreak regex '\$$' 0:operator
|
|
|
|
add-highlighter shared/ninja/build/variables regex '\$(\w|-)+|\$\{(\w|-)+\}' 0:value
|
2020-09-16 00:03:17 +02:00
|
|
|
|
2020-10-11 09:25:33 +02:00
|
|
|
# variables declarations
|
2024-03-05 12:19:08 +01:00
|
|
|
add-highlighter shared/ninja/variable region '^\h*(\w|-)+\h*=' '(?<!\$)\n' group
|
2020-10-11 09:25:33 +02:00
|
|
|
add-highlighter shared/ninja/variable/declaredname regex '^\h*((\w|-)+)\h*(=)' 1:variable 0:operator
|
|
|
|
add-highlighter shared/ninja/variable/linebreak regex '\$$' 0:operator
|
|
|
|
add-highlighter shared/ninja/variable/variables regex '\$(\w|-)+|\$\{(\w|-)+\}' 0:value
|
2020-09-16 00:03:17 +02:00
|
|
|
|
|
|
|
# keywords/builtin variable names
|
|
|
|
evaluate-commands %sh{
|
2020-09-21 13:41:19 +02:00
|
|
|
keywords="rule build command default subninja include"
|
2020-09-16 00:03:17 +02:00
|
|
|
reserved_names="builddir ninja_required_version pool depfile deps depfile msvc_deps_prefix description dyndep generator restat rspfile rspfile_content"
|
|
|
|
|
|
|
|
printf %s "
|
|
|
|
declare-option str-list ninja_static_words ${keywords} ${reserved_names}
|
|
|
|
"
|
|
|
|
|
|
|
|
reserved_names_regex="$(echo ${reserved_names} | tr ' ' '|')"
|
|
|
|
printf %s "
|
2020-10-11 09:25:33 +02:00
|
|
|
add-highlighter shared/ninja/variable/reserved_names regex '^\h*(${reserved_names_regex})\b' 0:meta
|
2020-09-16 00:03:17 +02:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2020-10-11 09:25:33 +02:00
|
|
|
|
2020-09-16 21:09:27 +02:00
|
|
|
# Indent
|
|
|
|
# ‾‾‾‾‾‾
|
2020-09-16 00:03:17 +02:00
|
|
|
|
|
|
|
define-command -hidden ninja-trim-indent %{
|
|
|
|
# remove trailing white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
|
2020-09-16 00:03:17 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden ninja-insert-on-new-line %{
|
2020-09-16 00:03:17 +02:00
|
|
|
evaluate-commands -draft -itersel %{
|
|
|
|
# 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 ninja-indent-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
2020-09-16 00:03:17 +02:00
|
|
|
# preserve previous line indent
|
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
|
|
|
# filter previous line
|
|
|
|
try %{ execute-keys -draft k : ninja-trim-indent <ret> }
|
2020-10-11 09:25:33 +02:00
|
|
|
# indent after lines begining with rule and pool
|
|
|
|
try %{ execute-keys -draft \; k x <a-k> ^(rule|pool|build)\b <ret> j <a-gt> }
|
2020-09-16 00:03:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|