# Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](js) %{ set buffer filetype javascript } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter -group / regions -default code javascript \ double_string '"' (? 0:keyword # Commands # ‾‾‾‾‾‾‾‾ def -hidden javascript-filter-around-selections %{ # remove trailing white spaces try %{ exec -draft -itersel 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 \`|.\' 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 } # suggested hook #hook global WinSetOption filetype=javascript %{ #set window formatcmd 'prettier --stdin --semi false --single-quote --jsx-bracket-same-line --trailing-comma all' #}