2016-12-21 20:35:15 +01:00
|
|
|
# http://handlebarsjs.com/
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](hbs) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype hbs
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
hook global WinSetOption filetype=hbs %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module hbs
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2019-10-16 11:19:43 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group hbs-trim-indent hbs-trim-indent
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group hbs-insert hbs-insert-on-new-line
|
2019-04-12 00:54:58 +02:00
|
|
|
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 }
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
provide-module hbs %[
|
|
|
|
|
2020-01-14 13:31:24 +01:00
|
|
|
require-module html
|
|
|
|
|
2016-12-21 20:35:15 +01:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/hbs regions
|
2021-04-17 11:51:25 +02:00
|
|
|
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
|
2016-12-21 20:35:15 +01:00
|
|
|
|
2018-09-10 14:22:29 +02:00
|
|
|
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 '"' (?<!\\)(\\\\)*" fill string
|
|
|
|
add-highlighter "shared/hbs/%arg{1}/double-quote" region "'" (?<!\\)(\\\\)*' fill string
|
|
|
|
add-highlighter "shared/hbs/%arg{1}/code/variable" regex \b([\w-]+)\b 1:variable
|
|
|
|
add-highlighter "shared/hbs/%arg{1}/code/attribute" regex \b([\w-]+)= 1:attribute
|
|
|
|
add-highlighter "shared/hbs/%arg{1}/code/helper" regex (?:(?:\{\{)|\()([#/]?[\w-]+(?:/[\w-]+)*) 1:keyword
|
|
|
|
~
|
2016-12-21 20:35:15 +01:00
|
|
|
|
2018-09-10 14:22:29 +02:00
|
|
|
add-mutual-highlighters expression
|
|
|
|
add-mutual-highlighters block-expression
|
2016-12-21 20:35:15 +01:00
|
|
|
|
2018-09-10 14:22:29 +02:00
|
|
|
add-highlighter shared/hbs/block-expression/code/yield regex \b(as)\s|[\w-]+|\}\} 1:keyword
|
2016-12-21 20:35:15 +01:00
|
|
|
|
|
|
|
|
2018-09-10 14:22:29 +02:00
|
|
|
# wrapper around shared/html highlighter. The shared/hbs highlighter will be
|
|
|
|
# added into shared/html when a buffer of filetype 'hbs' is actively displayed in the window.
|
|
|
|
add-highlighter shared/hbs-file regions
|
|
|
|
add-highlighter shared/hbs-file/html default-region ref html
|
2016-12-21 20:35:15 +01:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden hbs-trim-indent %{
|
2016-12-21 20:35:15 +01:00
|
|
|
# remove trailing white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
|
2018-09-10 14:22:29 +02:00
|
|
|
define-command -hidden hbs-indent-on-char %[
|
|
|
|
evaluate-commands -draft -itersel %[
|
|
|
|
# de-indent after closing a yielded block tag
|
2022-04-15 00:14:17 +02:00
|
|
|
try %[ execute-keys -draft , <a-h> s ^\h+\{\{/([\w-.]+(?:/[\w-.]+)*)\}\}$ <ret> {c\{\{#<c-r>1,\{\{/<c-r>1\}\} <ret> s \A|.\z <ret> 1<a-&> ]
|
2018-09-10 14:22:29 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden hbs-insert-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-01-11 14:56:48 +01:00
|
|
|
# copy '/' comment prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s ^\h*\K/\h* <ret> y j p }
|
2021-04-17 10:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define-command -hidden hbs-indent-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
2016-12-21 20:35:15 +01:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2016-12-21 20:35:15 +01:00
|
|
|
# filter previous line
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : hbs-trim-indent <ret> }
|
2016-12-21 20:35:15 +01:00
|
|
|
# indent after lines beginning with : or -
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x <a-k> ^\h*[:-] <ret> j <a-gt> }
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-09-10 14:22:29 +02:00
|
|
|
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
|
|
|
|
} }
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
]
|