2016-12-21 20:35:15 +01:00
|
|
|
# http://handlebarsjs.com/
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](hbs) %{
|
|
|
|
set buffer filetype hbs
|
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-04 01:07:45 +01:00
|
|
|
add-highlighter -group / regions -default html hbs \
|
2016-12-21 20:35:15 +01:00
|
|
|
comment {{!-- --}} '' \
|
|
|
|
comment {{! }} '' \
|
|
|
|
block-expression {{ }} ''
|
|
|
|
|
2017-01-10 14:44:11 +01:00
|
|
|
add-highlighter -group /hbs/html ref html
|
2017-01-04 01:07:45 +01:00
|
|
|
add-highlighter -group /hbs/comment fill comment
|
|
|
|
add-highlighter -group /hbs/block-expression regex {{((#|/|)(\w|-)+) 1:meta
|
2016-12-21 20:35:15 +01:00
|
|
|
|
|
|
|
# some hbs tags have a special meaning
|
2017-01-04 01:07:45 +01:00
|
|
|
add-highlighter -group /hbs/block-expression regex {{((#|/|)(if|else|unless|with|lookup|log)) 1:keyword
|
2016-12-21 20:35:15 +01:00
|
|
|
|
|
|
|
# 'each' is special as it really is two words 'each' and 'as'
|
2017-01-04 01:07:45 +01:00
|
|
|
add-highlighter -group /hbs/block-expression regex {{((#|/|)((each).*(as))) 2:keyword 4:keyword 5:keyword
|
2016-12-21 20:35:15 +01:00
|
|
|
|
2017-01-04 01:07:45 +01:00
|
|
|
add-highlighter -group /hbs/block-expression regex ((\w|-)+)= 1:attribute
|
2016-12-21 20:35:15 +01:00
|
|
|
|
|
|
|
# highlight the string values of attributes as a bonus
|
2017-01-04 01:07:45 +01:00
|
|
|
add-highlighter -group /hbs/block-expression regex ((\w|-)+)=(('|").*?('|")) 1:attribute 3:value
|
2016-12-21 20:35:15 +01:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-13 01:56:30 +01:00
|
|
|
def -hidden hbs-filter-around-selections %{
|
2016-12-21 20:35:15 +01:00
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
|
|
|
|
}
|
|
|
|
|
2017-01-13 01:56:30 +01:00
|
|
|
def -hidden hbs-indent-on-new-line %{
|
2016-12-21 20:35:15 +01:00
|
|
|
eval -draft -itersel %{
|
2017-01-11 14:56:48 +01:00
|
|
|
# copy '/' comment prefix and following white spaces
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft k <a-x> s ^\h*\K/\h* <ret> y j p }
|
2016-12-21 20:35:15 +01:00
|
|
|
# preserve previous line indent
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft \; K <a-&> }
|
2016-12-21 20:35:15 +01:00
|
|
|
# filter previous line
|
2017-01-13 01:56:30 +01:00
|
|
|
try %{ exec -draft k : hbs-filter-around-selections <ret> }
|
2016-12-21 20:35:15 +01:00
|
|
|
# indent after lines beginning with : or -
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft k <a-x> <a-k> ^\h*[:-] <ret> j <a-gt> }
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-09 02:29:36 +01:00
|
|
|
hook -group hbs-highlight global WinSetOption filetype=hbs %{
|
2017-01-10 14:44:11 +01:00
|
|
|
add-highlighter ref hbs
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=hbs %{
|
2017-01-13 01:56:30 +01:00
|
|
|
hook window InsertEnd .* -group hbs-hooks hbs-filter-around-selections
|
|
|
|
hook window InsertChar \n -group hbs-indent hbs-indent-on-new-line
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
|
2017-01-09 02:29:36 +01:00
|
|
|
hook -group hbs-highlight global WinSetOption filetype=(?!hbs).* %{
|
2017-01-10 14:44:11 +01:00
|
|
|
remove-highlighter hbs
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!hbs).* %{
|
2017-01-04 01:07:45 +01:00
|
|
|
remove-hooks window hbs-indent
|
|
|
|
remove-hooks window hbs-hooks
|
2016-12-21 20:35:15 +01:00
|
|
|
}
|