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/protobuf.kak | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 autoload/filetype/protobuf.kak (limited to 'autoload/filetype/protobuf.kak') diff --git a/autoload/filetype/protobuf.kak b/autoload/filetype/protobuf.kak new file mode 100644 index 0000000..b85295e --- /dev/null +++ b/autoload/filetype/protobuf.kak @@ -0,0 +1,109 @@ +# https://developers.google.com/protocol-buffers/ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.proto$ %{ + set-option buffer filetype protobuf +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=protobuf %[ + require-module protobuf + + set-option window static_words %opt{protobuf_static_words} + + hook window ModeChange pop:insert:.* -group protobuf-trim-indent protobuf-trim-indent + hook -group protobuf-insert window InsertChar \n protobuf-insert-on-newline + hook -group protobuf-indent window InsertChar \n protobuf-indent-on-newline + hook -group protobuf-indent window InsertChar \{ protobuf-indent-on-opening-curly-brace + hook -group protobuf-indent window InsertChar \} protobuf-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window protobuf-.+ } +] + +hook -group protobuf-highlight global WinSetOption filetype=protobuf %{ + add-highlighter window/protobuf ref protobuf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/protobuf } +} + +provide-module protobuf %[ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/protobuf regions +add-highlighter shared/protobuf/code default-region group +add-highlighter shared/protobuf/double_string region '"' (? d } + } +} + +define-command -hidden protobuf-insert-on-newline %{ + evaluate-commands -draft -itersel %[ + # copy // comments prefix + try %{ execute-keys -draft kx s ^\h*\K/{2,}(\h*(?=\S))? yP } + ] +} + +define-command -hidden protobuf-indent-on-newline %~ + evaluate-commands -draft -itersel %[ + # preserve previous line indent + try %{ execute-keys -draft K } + # indent after lines ending with { + try %[ execute-keys -draft kx \{\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft kx s \h+$ d } + # deindent closing brace(s) when after cursor + try %[ execute-keys -draft x ^\h*\} gh / \} m 1 ] + ] +~ + +define-command -hidden protobuf-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden protobuf-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +] -- cgit v1.2.3