1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-24 20:13:00 +03:00
kakoune/rc/extra/haml.kak

70 lines
2.6 KiB
Plaintext
Raw Normal View History

2014-07-15 00:55:51 +04:00
# http://haml.info
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](haml) %{
set-option buffer filetype haml
2014-07-15 00:55:51 +04:00
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/ regions -default code haml \
comment ^\h*/ $ '' \
2014-07-15 00:55:51 +04:00
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*[%=-]\K '' \
sass ^\h*:sass\K ^\h*[%=-]\K ''
2014-07-15 00:55:51 +04:00
# Filters
# http://haml.info/docs/yardoc/file.REFERENCE.html#filters
add-highlighter shared/haml/comment fill comment
2014-07-15 00:55:51 +04:00
add-highlighter shared/haml/eval ref ruby
add-highlighter shared/haml/coffee ref coffee
add-highlighter shared/haml/sass ref sass
2014-07-15 00:55:51 +04: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-15 00:55:51 +04:00
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden haml-filter-around-selections %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
2014-07-15 00:55:51 +04: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-15 00:55:51 +04:00
# preserve previous line indent
try %{ execute-keys -draft \; K <a-&> }
2014-07-15 00:55:51 +04:00
# filter previous line
try %{ execute-keys -draft k : haml-filter-around-selections <ret> }
2014-07-15 00:55:51 +04:00
# indent after lines beginning with : or -
try %{ execute-keys -draft k <a-x> <a-k> ^\h*[:-] <ret> j <a-gt> }
2014-07-15 00:55:51 +04:00
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group haml-highlight global WinSetOption filetype=haml %{ add-highlighter window ref haml }
2014-07-15 00:55:51 +04:00
hook global WinSetOption filetype=haml %{
hook window ModeChange insert:.* -group haml-hooks haml-filter-around-selections
hook window InsertChar \n -group haml-indent haml-indent-on-new-line
2014-07-15 00:55:51 +04:00
}
hook -group haml-highlight global WinSetOption filetype=(?!haml).* %{ remove-highlighter window/haml }
2014-07-15 00:55:51 +04:00
hook global WinSetOption filetype=(?!haml).* %{
2017-01-04 03:07:45 +03:00
remove-hooks window haml-indent
remove-hooks window haml-hooks
2014-07-15 00:55:51 +04:00
}