# http://hjson.github.io # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](hjson) %{ set-option buffer filetype hjson } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=hjson %{ require-module hjson hook window ModeChange pop:insert:.* -group hjson-trim-indent hjson-trim-indent hook window InsertChar .* -group hjson-indent hjson-indent-on-char hook window InsertChar \n -group hjson-indent hjson-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hjson-.+ } } hook -group hjson-highlight global WinSetOption filetype=hjson %{ add-highlighter window/hjson ref hjson hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hjson } } provide-module hjson %( # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/hjson regions add-highlighter shared/hjson/code default-region group add-highlighter shared/hjson/string region '"' (? d } } define-command -hidden hjson-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 hjson-indent-on-new-line %{ evaluate-commands -itersel -draft %{ execute-keys try %{ evaluate-commands -draft -save-regs '/"' %{ # Ensure previous line is a comment # This only supports "#" comments (because hjson supporting # and // comments was a mistake) execute-keys -draft kxs^\h*#+\h* # now handle the coment continuation logic try %{ # try and match a regular block comment, copying the prefix execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ y execute-keys -draft P } catch %{ try %{ # try and match a regular block comment followed by a single # empty comment line execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ y execute-keys -draft P } catch %{ try %{ # try and match a pair of empty comment lines, and delete # them if we match execute-keys -draft kKx ^\h*#+\h*\n\h*#+\h*$ } catch %{ # finally, we need a special case for a new line inserted # into a file that consists of a single empty comment - in # that case we can't expect to copy the trailing whitespace, # so we add our own execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$ y execute-keys -draft P execute-keys -draft i } } } } # trim trailing whitespace on the previous line try %{ execute-keys -draft k x s\h+$ d } } } } )