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