From d557b09ac668470d3b512da3c4c1fa7c03f06cd6 Mon Sep 17 00:00:00 2001 From: Justin Frank Date: Wed, 15 Aug 2018 21:39:29 -0700 Subject: [PATCH] added protobuf syntax support --- rc/extra/protobuf.kak | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 rc/extra/protobuf.kak diff --git a/rc/extra/protobuf.kak b/rc/extra/protobuf.kak new file mode 100644 index 00000000..faea941e --- /dev/null +++ b/rc/extra/protobuf.kak @@ -0,0 +1,87 @@ +# https://developers.google.com/protocol-buffers/ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.proto$ %{ + set-option buffer filetype protobuf +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/protobuf regions +add-highlighter shared/protobuf/code default-region group +add-highlighter shared/protobuf/double_string region '"' (? } + # indent after lines ending with { + try %[ execute-keys -draft k \{\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,}(\h*(?=\S))? yP } + ] +~ + +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 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group protobuf-highlight global WinSetOption filetype=protobuf %{ add-highlighter window/protobuf ref protobuf } + +hook global WinSetOption filetype=protobuf %[ + 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 -group protobuf-highlight global WinSetOption filetype=(?!protobuf).* %{ remove-highlighter window/protobuf } + +hook global WinSetOption filetype=(?!protobuf).* %{ + remove-hooks window protobuf-hooks + remove-hooks window protobuf-indent +}