# Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](jsoncc?) %{ set-option buffer filetype jsoncc set-option buffer comment_line '//' set-option buffer comment_block_begin '/*' set-option buffer comment_block_end '*/' } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=jsoncc %{ require-module jsoncc hook window ModeChange pop:insert:.* -group jsoncc-trim-indent jsoncc-trim-indent hook window InsertChar .* -group jsoncc-indent jsoncc-indent-on-char hook window InsertChar \n -group jsoncc-indent jsoncc-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window jsoncc-.+ } } hook -group jsoncc-highlight global WinSetOption filetype=jsoncc %{ add-highlighter window/jsoncc ref jsoncc hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/jsoncc } } provide-module jsoncc %( # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/jsoncc regions add-highlighter shared/jsoncc/code default-region group add-highlighter shared/jsoncc/string region '"' (? d } } define-command -hidden jsoncc-indent-on-char %< evaluate-commands -draft -itersel %< # align closer token to its opener when alone on a line try %< execute-keys -draft ^\h+[\]}]$ m 1 > > > define-command -hidden jsoncc-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 : jsoncc-trim-indent } # indent after lines ending with opener token try %< execute-keys -draft k x [[{]\h*$ j > # deindent closer token(s) when after cursor try %< execute-keys -draft x ^\h*[}\]] gh / [}\]] m 1 > > > )