# Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](js) %{ set buffer filetype javascript } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter -group / regions -default code javascript \ double_string '"' (? s \h+$ d } } def -hidden javascript-indent-on-char %< eval -draft -itersel %< # align closer token to its opener when alone on a line try %/ exec -draft ^\h+[]}]$ m s \A|.\z 1 / > > def -hidden javascript-indent-on-new-line %< eval -draft -itersel %< # copy // comments prefix and following white spaces try %{ exec -draft k s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ exec -draft \; K } # filter previous line try %{ exec -draft k : javascript-filter-around-selections } # indent after lines beginning / ending with opener token try %_ exec -draft k ^\h*[[{]|[[{]$ j _ > > # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group javascript-highlight global WinSetOption filetype=javascript %{ add-highlighter ref javascript } hook global WinSetOption filetype=javascript %{ hook window InsertEnd .* -group javascript-hooks javascript-filter-around-selections hook window InsertChar .* -group javascript-indent javascript-indent-on-char hook window InsertChar \n -group javascript-indent javascript-indent-on-new-line } hook -group javascript-highlight global WinSetOption filetype=(?!javascript).* %{ remove-highlighter javascript } hook global WinSetOption filetype=(?!javascript).* %{ remove-hooks window javascript-indent remove-hooks window javascript-hooks }