1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-10 13:25:25 +03:00
kakoune/rc/base/html.kak

82 lines
2.7 KiB
Plaintext
Raw Normal View History

2014-07-15 00:58:40 +04:00
# http://w3.org/html
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.html %{
set-option buffer filetype html
2014-07-15 00:58:40 +04:00
}
hook global BufCreate .*\.xml %{
set-option buffer filetype xml
2014-07-15 00:58:40 +04:00
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/ regions html \
2014-07-15 00:58:40 +04:00
comment <!-- --> '' \
tag < > '' \
style <style\b.*?>\K (?=</style>) '' \
script <script\b.*?>\K (?=</script>) ''
2014-07-15 00:58:40 +04:00
add-highlighter shared/html/comment fill comment
2014-07-15 00:58:40 +04:00
add-highlighter shared/html/style ref css
add-highlighter shared/html/script ref javascript
2014-07-15 00:58:40 +04:00
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
2014-07-15 00:58:40 +04:00
add-highlighter shared/html/tag regions content \
2014-07-15 00:58:40 +04:00
string '"' (?<!\\)(\\\\)*" '' \
string "'" "'" ''
add-highlighter shared/html/tag/content/string fill string
2014-07-15 00:58:40 +04:00
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden html-filter-around-selections %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
2014-07-15 00:58:40 +04:00
}
define-command -hidden html-indent-on-greater-than %[
evaluate-commands -draft -itersel %[
2014-07-15 00:58:40 +04:00
# align closing tag to opening when alone on a line
try %[ execute-keys -draft <space> <a-h> s ^\h+<lt>/(\w+)<gt>$ <ret> {c<lt><c-r>1,<lt>/<c-r>1<gt> <ret> s \A|.\z <ret> 1<a-&> ]
]
]
2014-07-15 00:58:40 +04:00
define-command -hidden html-indent-on-new-line %{
evaluate-commands -draft -itersel %{
2014-07-15 00:58:40 +04:00
# preserve previous line indent
try %{ execute-keys -draft \; K <a-&> }
2014-07-15 00:58:40 +04:00
# filter previous line
try %{ execute-keys -draft k : html-filter-around-selections <ret> }
2014-07-15 00:58:40 +04:00
# indent after lines ending with opening tag
try %{ execute-keys -draft k <a-x> <a-k> <[^/][^>]+>$ <ret> j <a-gt> }
2014-07-15 00:58:40 +04:00
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group html-highlight global WinSetOption filetype=(?:html|xml) %{ add-highlighter window ref html }
2014-07-15 00:58:40 +04:00
hook global WinSetOption filetype=(?:html|xml) %{
hook window ModeChange insert:.* -group html-hooks html-filter-around-selections
hook window InsertChar '>' -group html-indent html-indent-on-greater-than
hook window InsertChar \n -group html-indent html-indent-on-new-line
2014-07-15 00:58:40 +04:00
}
hook -group html-highlight global WinSetOption filetype=(?!html)(?!xml).* %{ remove-highlighter window/html }
hook global WinSetOption filetype=(?!html)(?!xml).* %{
2017-01-04 03:07:45 +03:00
remove-hooks window html-indent
remove-hooks window html-hooks
2014-07-15 00:58:40 +04:00
}