From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/hbs.kak | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 autoload/filetype/hbs.kak (limited to 'autoload/filetype/hbs.kak') diff --git a/autoload/filetype/hbs.kak b/autoload/filetype/hbs.kak new file mode 100644 index 0000000..5ea99bc --- /dev/null +++ b/autoload/filetype/hbs.kak @@ -0,0 +1,112 @@ +# http://handlebarsjs.com/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](hbs) %{ + set-option buffer filetype hbs +} + +hook global WinSetOption filetype=hbs %{ + require-module hbs + + hook window ModeChange pop:insert:.* -group hbs-trim-indent hbs-trim-indent + hook window InsertChar \n -group hbs-insert hbs-insert-on-new-line + hook window InsertChar \n -group hbs-indent hbs-indent-on-new-line + hook window InsertChar .* -group hbs-indent hbs-indent-on-char + hook window InsertChar '>' -group hbs-indent html-indent-on-greater-than + hook window InsertChar \n -group hbs-indent html-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hbs-.+ } +} + +hook -group hbs-highlight global WinSetOption filetype=hbs %{ + maybe-add-hbs-to-html + add-highlighter window/hbs-file ref hbs-file + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hbs-file } +} + + +provide-module hbs %[ + +require-module html + +# 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 '"' (? 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-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*\K/\h* y j p } + } +} + +define-command -hidden hbs-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 : hbs-trim-indent } + # indent after lines beginning with : or - + try %{ execute-keys -draft k x ^\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 +} } + +] -- cgit v1.2.3