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/ninja.kak | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 autoload/filetype/ninja.kak (limited to 'autoload/filetype/ninja.kak') diff --git a/autoload/filetype/ninja.kak b/autoload/filetype/ninja.kak new file mode 100644 index 0000000..757b7ad --- /dev/null +++ b/autoload/filetype/ninja.kak @@ -0,0 +1,106 @@ +# ref: https://ninja-build.org/manual.html#ref_ninja_file + +# 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} + + hook window ModeChange pop:insert:.* -group ninja-trim-indent ninja-trim-indent + hook window InsertChar \n -group ninja-insert ninja-insert-on-new-line + hook window InsertChar \n -group ninja-indent ninja-indent-on-new-line + # cleanup trailing whitespaces on current line insert end + hook window ModeChange pop:insert:.* -group ninja-trim-indent %{ try %{ execute-keys -draft x s ^\h+$ d } } + + 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 } +} + + +provide-module ninja %{ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/ninja regions + +# `#` +add-highlighter shared/ninja/comment region '#' '\n' fill comment + +# `subninja`, `include`, `rule`, `pool` and `default` declarations +add-highlighter shared/ninja/sirpd region '^(subninja|include|rule|pool|default)\b' '(? d } +} + +define-command -hidden ninja-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 ninja-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 : ninja-trim-indent } + # indent after lines begining with rule and pool + try %{ execute-keys -draft \; k x ^(rule|pool|build)\b j } + } +} + +} -- cgit v1.2.3