# 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-.+ }