From d2388929f1f05cc48cff826a74e2a34133b85603 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Mon, 14 Jul 2014 22:55:51 +0200 Subject: [PATCH] add rc/haml.kak --- rc/haml.kak | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rc/haml.kak diff --git a/rc/haml.kak b/rc/haml.kak new file mode 100644 index 00000000..20a898e9 --- /dev/null +++ b/rc/haml.kak @@ -0,0 +1,75 @@ +# http://haml.info +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-haml %{ + set buffer filetype haml +} + +hook global BufCreate .*[.](haml) %{ + set buffer filetype haml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code haml \ + comment ^\h*/ $ '' \ + eval ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)?\{\K|#\{\K (?=\}) \{ \ + eval ^\h*[=-]\K (?=[^|]\n) '' \ + coffee ^\h*:coffee\K (?=^\h*[%=-]) '' \ + sass ^\h*:sass\K (?=^\h*[%=-]) '' + +# Filters +# http://haml.info/docs/yardoc/file.REFERENCE.html#filters + +addhl -group /haml/comment fill comment + +addhl -group /haml/eval ref ruby +addhl -group /haml/coffee ref coffee +addhl -group /haml/sass ref sass + +addhl -group /haml/code regex ^\h*(:[a-z]+|-|=)|^(!!!)$ 0:meta +addhl -group /haml/code regex ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)? 1:keyword 2:identifier + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _haml_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _haml_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _haml_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 global WinSetOption filetype=haml %{ + addhl ref haml + + hook window InsertEnd .* -group haml-hooks _haml_filter_around_selections + hook window InsertChar \n -group haml-indent _haml_indent_on_new_line +} + +hook global WinSetOption filetype=(?!haml).* %{ + rmhl haml + rmhooks window haml-indent + rmhooks window haml-hooks +}