home/rc/filetype/haml.kak

73 lines
2.4 KiB
Plaintext
Raw Normal View History

2014-07-14 22:55:51 +02:00
# http://haml.info
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](haml) %{
set-option buffer filetype haml
2014-07-14 22:55:51 +02:00
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=haml %{
2019-03-13 22:00:59 +01:00
require-module haml
hook window ModeChange pop:insert:.* -group haml-trim-indent haml-trim-indent
hook window InsertChar \n -group haml-indent haml-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haml-.+ }
2019-03-13 22:00:59 +01:00
}
hook -group haml-highlight global WinSetOption filetype=haml %{
add-highlighter window/haml ref haml
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haml }
}
2019-03-13 22:00:59 +01:00
provide-module haml %[
require-module ruby
require-module coffee
require-module sass
2014-07-14 22:55:51 +02:00
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/haml regions
add-highlighter shared/haml/code default-region group
add-highlighter shared/haml/comment region ^\h*/ $ fill comment
2014-07-14 22:55:51 +02:00
# Filters
# http://haml.info/docs/yardoc/file.REFERENCE.html#filters
add-highlighter shared/haml/eval1 region -recurse \{ ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)?\{\K|#\{\K (?=\}) ref ruby
add-highlighter shared/haml/eval2 region ^\h*[=-]\K (?<!\|)(?=\n) ref ruby
add-highlighter shared/haml/coffee region ^\h*:coffee\K ^\h*[%=-]\K ref coffee
add-highlighter shared/haml/sass region ^\h*:sass\K ^\h*[%=-]\K ref sass
2014-07-14 22:55:51 +02:00
add-highlighter shared/haml/code/ regex ^\h*(:[a-z]+|-|=)|^(!!!)$ 0:meta
add-highlighter shared/haml/code/ regex ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)? 1:keyword 2:variable
2014-07-14 22:55:51 +02:00
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden haml-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
2014-07-14 22:55:51 +02:00
}
define-command -hidden haml-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '/' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K/\h* <ret> y gh j P }
2014-07-14 22:55:51 +02:00
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
2014-07-14 22:55:51 +02:00
# filter previous line
try %{ execute-keys -draft k : haml-trim-indent <ret> }
2014-07-14 22:55:51 +02:00
# indent after lines beginning with : or -
try %{ execute-keys -draft k <a-x> <a-k> ^\h*[:-] <ret> j <a-gt> }
2014-07-14 22:55:51 +02:00
}
}
2019-03-13 22:00:59 +01:00
]