diff --git a/rc/html.kak b/rc/html.kak new file mode 100644 index 00000000..6dd36882 --- /dev/null +++ b/rc/html.kak @@ -0,0 +1,81 @@ +# http://w3.org/html +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-html %{ + set buffer filetype html +} + +hook global BufCreate .*[.](html) %{ + set buffer filetype html +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions html \ + comment '' \ + tag < > '' \ + style .*?>\K (?=) '' \ + script .*?>\K (?=) '' + +addhl -group /html/comment fill comment + +addhl -group /html/style ref css +addhl -group /html/script ref javascript + +addhl -group /html/tag regex + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _html_indent_on_char %{ + eval -draft -itersel %{ + # align closing tag to opening when alone on a line + try %{ exec -draft s ^\h+$ 1 s \`|.\' 1 } + } +} + +def -hidden _html_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _html_filter_around_selections } + # indent after lines ending with opening tag + try %{ exec -draft k x <[^/][^>]+>$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=html %{ + addhl ref html + + hook window InsertEnd .* -group html-hooks _html_filter_around_selections + hook window InsertChar .* -group html-indent _html_indent_on_char + hook window InsertChar \n -group html-indent _html_indent_on_new_line +} + +hook global WinSetOption filetype=(?!html).* %{ + rmhl html + rmhooks window html-indent + rmhooks window html-hooks +}