From f9c860d2352e2f86bd3d210f9506bb3a16fe8e22 Mon Sep 17 00:00:00 2001 From: Harm Aarts Date: Wed, 21 Dec 2016 20:35:15 +0100 Subject: [PATCH 1/2] Add Handlebars syntax highlighting. This is based on the HAML syntax highlighting. Of note is the loading of the html highlighter since Handlebars is embedded in html. --- rc/extra/hbs.kak | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rc/extra/hbs.kak diff --git a/rc/extra/hbs.kak b/rc/extra/hbs.kak new file mode 100644 index 00000000..8e350ffc --- /dev/null +++ b/rc/extra/hbs.kak @@ -0,0 +1,75 @@ +# http://handlebarsjs.com/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](hbs) %{ + set buffer filetype hbs +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default html hbs \ + comment {{!-- --}} '' \ + comment {{! }} '' \ + block-expression {{ }} '' + +addhl -group /hbs/comment fill comment +addhl -group /hbs/block-expression regex {{((#|/|)(\w|-)+) 1:meta + +# some hbs tags have a special meaning +addhl -group /hbs/block-expression regex {{((#|/|)(if|else|unless|with|lookup|log)) 1:keyword + +# 'each' is special as it really is two words 'each' and 'as' +addhl -group /hbs/block-expression regex {{((#|/|)((each).*(as))) 2:keyword 4:keyword 5:keyword + +addhl -group /hbs/block-expression regex ((\w|-)+)= 1:attribute + +# highlight the string values of attributes as a bonus +addhl -group /hbs/block-expression regex ((\w|-)+)=(('|").*?('|")) 1:attribute 3:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _hbs_filter_around_selections %{ + # remove trailing white spaces + try %{ exec -draft -itersel s \h+$ d } +} + +def -hidden _hbs_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _hbs_filter_around_selections } + # copy '/' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K/\h* y j p } + # indent after lines beginning with : or - + try %{ exec -draft k x ^\h*[:-] j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group hbs-highlight global WinSetOption filetype=hbs %{ + addhl ref hbs + addhl ref html +} + +hook global WinSetOption filetype=hbs %{ + hook window InsertEnd .* -group hbs-hooks _hbs_filter_around_selections + hook window InsertChar \n -group hbs-indent _hbs_indent_on_new_line +} + +hook -group hbs-highlight global WinSetOption filetype=(?!hbs).* %{ + rmhl hbs + rmhl html +} + +hook global WinSetOption filetype=(?!hbs).* %{ + rmhooks window hbs-indent + rmhooks window hbs-hooks +}