# 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-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 '"' (? # remove trailing white spaces try %{ execute-keys -draft s \h + $ d } } } 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 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 } # deindent closing brace(s) when after cursor try %[ execute-keys -draft ^\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 ] ] ]