# http://json5.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](json5) %{ set-option buffer filetype json5 } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=json5 %{ require-module json5 hook window ModeChange pop:insert:.* -group json5-trim-indent json5-trim-indent hook window InsertChar \n -group json5-insert json5-insert-on-new-line hook window InsertChar \n -group json5-indent json5-indent-on-new-line hook window InsertChar .* -group json5-indent json5-indent-on-char hook -once -always window WinSetOption filetype=.* %{ remove-hooks window json5-.+ } } hook -group json5-highlight global WinSetOption filetype=json5 %{ add-highlighter window/json5 ref json5 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/json5 } } provide-module json5 %( # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/json5 regions add-highlighter shared/json5/code default-region group add-highlighter shared/json5/string region '"' (?kx s ^\h*\K/{2,}\h* yP } ] define-command -hidden json5-trim-indent %{ # remove trailing white spaces try %{ execute-keys -draft -itersel x s \h+$ d } } define-command -hidden json5-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 json5-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 : json5-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 > > > )