# http://handlebarsjs.com/ # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](hbs) %{ set-option buffer filetype hbs } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/hbs regions add-highlighter shared/hbs/comment region \{\{!-- --\}\} fill comment add-highlighter shared/hbs/comment_alt region \{\{! \}\} fill comment add-highlighter shared/hbs/block-expression region \{\{[#/] \}\} regions add-highlighter shared/hbs/expression region \{\{ \}\} regions define-command -hidden add-mutual-highlighters -params 1 %~ add-highlighter "shared/hbs/%arg{1}/code" default-region group add-highlighter "shared/hbs/%arg{1}/single-quote" region '"' (? s \h+$ d } } define-command -hidden hbs-indent-on-char %[ evaluate-commands -draft -itersel %[ # de-indent after closing a yielded block tag try %[ execute-keys -draft s ^\h+\{\{/([\w-.]+(?:/[\w-.]+)*)\}\}$ {c\{\{#1,\{\{/1\}\} s \A|.\z 1 ] ] ] define-command -hidden hbs-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '/' comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K/\h* y j p } # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line try %{ execute-keys -draft k : hbs-filter-around-selections } # indent after lines beginning with : or - try %{ execute-keys -draft k ^\h*[:-] j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ declare-option bool hbs_highlighters_enabled false define-command -hidden maybe-add-hbs-to-html %{ evaluate-commands %sh{ if [ "$kak_opt_hbs_highlighters_enabled" == "false" ]; then printf %s " add-highlighter shared/html/hbs region '\{\{' '\}\}' ref hbs add-highlighter shared/html/tag/hbs region '\{\{' '\}\}' ref hbs set-option global hbs_highlighters_enabled true " fi } } define-command -hidden remove-hbs-from-html %{ remove-highlighter shared/html/hbs remove-highlighter shared/html/tag/hbs set-option global hbs_highlighters_enabled false } # The two hooks below are wrapped in this "-once" so that they only get enabled # when atleast one .hbs file is opened. This way people who don't edit .hbs files # aren't paying a performance penality of these hooks always executing. hook -once global BufCreate .*\.(hbs) %{ hook -group hbs-highlight global WinDisplay .*\.(hbs) %{ evaluate-commands %sh{ if [ "$kak_opt_filetype" = "hbs" ]; then printf %s "maybe-add-hbs-to-html" fi } } hook -group hbs-highlight global WinDisplay .*\.(?!hbs).* %{ remove-hbs-from-html } } hook -group hbs-highlight global WinSetOption filetype=hbs %{ add-highlighter window/hbs-file ref hbs-file } hook global WinSetOption filetype=hbs %{ hook window ModeChange insert:.* -group hbs-hooks hbs-filter-around-selections hook window InsertChar \n -group hbs-indent hbs-indent-on-new-line hook window InsertChar .* -group hbs-ident hbs-indent-on-char hook window ModeChange insert:.* -group hbs-hooks html-filter-around-selections hook window InsertChar '>' -group hbs-indent html-indent-on-greater-than hook window InsertChar \n -group hbs-indent html-indent-on-new-line } hook -group hbs-highlight global WinSetOption filetype=(?!hbs).* %{ remove-highlighter window/hbs-file } hook global WinSetOption filetype=(?!hbs).* %{ remove-hooks window hbs-.+ }