kakoune/rc/base/html.kak
Maxime Coste d49555fc75 Move highlighters into Scopes
That means we can now have highlighters active at global, buffer, and
window scope. The add-highlighter and remove-highlighter syntax changed
to take the parent path (scope/group/...) as a mandatory argument,
superseeding the previous -group switch.
2017-10-28 13:43:04 +08:00

82 lines
2.5 KiB
Plaintext

# http://w3.org/html
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.html %{
set buffer filetype html
}
hook global BufCreate .*\.xml %{
set buffer filetype xml
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/ regions html \
comment <!-- --> '' \
tag < > '' \
style <style\b.*?>\K (?=</style>) '' \
script <script\b.*?>\K (?=</script>) ''
add-highlighter shared/html/comment fill comment
add-highlighter shared/html/style ref css
add-highlighter shared/html/script ref javascript
add-highlighter shared/html/tag regex \b([a-zA-Z0-9_-]+)=? 1:attribute
add-highlighter shared/html/tag regex </?(\w+) 1:keyword
add-highlighter shared/html/tag regex <(!DOCTYPE(\h+\w+)+) 1:meta
add-highlighter shared/html/tag regions content \
string '"' (?<!\\)(\\\\)*" '' \
string "'" "'" ''
add-highlighter shared/html/tag/content/string fill string
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden html-filter-around-selections %{
# remove trailing white spaces
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
}
def -hidden html-indent-on-char %{
eval -draft -itersel %{
# align closing tag to opening when alone on a line
try %{ exec -draft <space> <a-h> s ^\h+</(\w+)>$ <ret> <a-\;> <a-?> <lt><c-r>1 <ret> s \A|.\z <ret> <a-r> 1<a-&> }
}
}
def -hidden html-indent-on-new-line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft \; K <a-&> }
# filter previous line
try %{ exec -draft k : html-filter-around-selections <ret> }
# indent after lines ending with opening tag
try %{ exec -draft k <a-x> <a-k> <[^/][^>]+>$ <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group html-highlight global WinSetOption filetype=(?:html|xml) %{ add-highlighter window ref html }
hook global WinSetOption filetype=(?:html|xml) %{
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 -group html-highlight global WinSetOption filetype=(?!html)(?!xml).* %{ remove-highlighter window/html }
hook global WinSetOption filetype=(?!html)(?!xml).* %{
remove-hooks window html-indent
remove-hooks window html-hooks
}