From 858650ea577f09b40e3e9eea299af15650400867 Mon Sep 17 00:00:00 2001 From: antab Date: Sun, 11 Oct 2020 09:25:33 +0200 Subject: [PATCH] refactor(ninjafile): simplify ninja.kak and fix few things MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix multilines for declarations * fix names with `-`, which Ninja allows * fix few cases of `=` operators * fix reserved keywords in `command = …` right-hand side Co-authored-by: Frank LENORMAND <1379068+lenormf@users.noreply.github.com> --- rc/filetype/ninja.kak | 54 ++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/rc/filetype/ninja.kak b/rc/filetype/ninja.kak index a3da18eb..e6609845 100644 --- a/rc/filetype/ninja.kak +++ b/rc/filetype/ninja.kak @@ -29,7 +29,7 @@ hook -group ninja-highlight global WinSetOption filetype=ninja %{ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ninja } } -# Lazy loading + provide-module ninja %{ # Highlighters @@ -40,40 +40,25 @@ add-highlighter shared/ninja regions # `#` add-highlighter shared/ninja/comment region '#' '\n' fill comment -# `rule` -add-highlighter shared/ninja/rule region '^rule' '\n' group -add-highlighter shared/ninja/rule/rule regex '^rule' 0:keyword - -# `command` -add-highlighter shared/ninja/command region '^\h+command' '[^$]\n' group -add-highlighter shared/ninja/command/command regex 'command' 0:variable -add-highlighter shared/ninja/command/equal regex '=' 0:operator -add-highlighter shared/ninja/command/linebreak regex '\$$' 0:operator -add-highlighter shared/ninja/command/variables regex '\$\w+|\$\{\w+\}' 0:value +# `subninja`, `include`, `rule`, `pool` and `default` declarations +add-highlighter shared/ninja/sirpd region '^(subninja|include|rule|pool|default)\b' '[^$]\n' group +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 # `build` -add-highlighter shared/ninja/build region '^build\b' '\n' group -add-highlighter shared/ninja/build/build regex '^build' 0:keyword -add-highlighter shared/ninja/build/rule regex ':\h+(\w+)' 0:function +add-highlighter shared/ninja/build region '^build\b' '[^$]\n' group +add-highlighter shared/ninja/build/build regex '^build\b' 0:keyword +add-highlighter shared/ninja/build/rule regex ':\h+((\w|-)+)' 0:function add-highlighter shared/ninja/build/colonpipe regex ':|\||\|\|' 0:operator -add-highlighter shared/ninja/build/variables regex '\$\w+|\$\{\w+\}' 0:value +add-highlighter shared/ninja/build/linebreak regex '\$$' 0:operator +add-highlighter shared/ninja/build/variables regex '\$(\w|-)+|\$\{(\w|-)+\}' 0:value -# variables -add-highlighter shared/ninja/variable region '^\h*\w+\h*=' '\n' group -add-highlighter shared/ninja/variable/name regex '(\w+)\h*=' 0:variable -add-highlighter shared/ninja/variable/equal regex '=' 0:operator - -# `default` -add-highlighter shared/ninja/default region '^default' '\n' group -add-highlighter shared/ninja/default/default regex '^default' 0:keyword - -# `subninja` and `include` -add-highlighter shared/ninja/subinc region '^subninja|include' '\n' group -add-highlighter shared/ninja/subinc/default regex '^subninja|include' 0:module - -# `pool` -add-highlighter shared/ninja/pool region '^pool' '\n' group -add-highlighter shared/ninja/pool/pool regex '^pool' 0:keyword +# variables declarations +add-highlighter shared/ninja/variable region '^\h*(\w|-)+\h*=' '[^$]\n' group +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 # keywords/builtin variable names evaluate-commands %sh{ @@ -86,10 +71,11 @@ evaluate-commands %sh{ reserved_names_regex="$(echo ${reserved_names} | tr ' ' '|')" printf %s " - add-highlighter shared/ninja/variable/reserved_names regex ${reserved_names_regex} 0:meta + add-highlighter shared/ninja/variable/reserved_names regex '^\h*(${reserved_names_regex})\b' 0:meta " } + # Indent # ‾‾‾‾‾‾ @@ -106,8 +92,8 @@ define-command -hidden ninja-indent-on-new-line %{ try %{ execute-keys -draft \; K } # filter previous line try %{ execute-keys -draft k : ninja-trim-indent } - # indent after lines begining with rule and pool (do people want build too ?) - try %{ execute-keys -draft \; k x ^(\brule|pool) j } + # indent after lines begining with rule and pool + try %{ execute-keys -draft \; k x ^(rule|pool|build)\b j } } }