2014-07-15 00:58:40 +04:00
|
|
|
# http://w3.org/html
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-12-14 16:40:00 +03:00
|
|
|
hook global BufCreate .*\.html %{
|
2014-07-15 00:58:40 +04:00
|
|
|
set buffer filetype html
|
|
|
|
}
|
|
|
|
|
2016-12-14 16:40:00 +03:00
|
|
|
hook global BufCreate .*\.xml %{
|
|
|
|
set buffer filetype xml
|
2014-07-15 00:58:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group / regions html \
|
2014-07-15 00:58:40 +04:00
|
|
|
comment <!-- --> '' \
|
|
|
|
tag < > '' \
|
2016-04-21 22:43:17 +03:00
|
|
|
style <style\b.*?>\K (?=</style>) '' \
|
|
|
|
script <script\b.*?>\K (?=</script>) ''
|
2014-07-15 00:58:40 +04:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /html/comment fill comment
|
2014-07-15 00:58:40 +04:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /html/style ref css
|
|
|
|
add-highlighter -group /html/script ref javascript
|
2014-07-15 00:58:40 +04:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /html/tag regex </?(\w+) 1:keyword
|
2014-07-15 00:58:40 +04:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /html/tag regions content \
|
2014-07-15 00:58:40 +04:00
|
|
|
string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
string "'" "'" ''
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /html/tag/content/string fill string
|
2014-07-15 00:58:40 +04:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden html-filter-around-selections %{
|
2015-11-04 12:48:47 +03:00
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
|
2014-07-15 00:58:40 +04:00
|
|
|
}
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden html-indent-on-char %{
|
2014-07-15 00:58:40 +04:00
|
|
|
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 \`|.\' <ret> <a-r> 1<a-&> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden html-indent-on-new-line %{
|
2014-07-15 00:58:40 +04:00
|
|
|
eval -draft -itersel %{
|
|
|
|
# preserve previous line indent
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft \; K <a-&> }
|
2014-07-15 00:58:40 +04:00
|
|
|
# filter previous line
|
2017-01-13 03:56:30 +03:00
|
|
|
try %{ exec -draft k : html-filter-around-selections <ret> }
|
2014-07-15 00:58:40 +04:00
|
|
|
# indent after lines ending with opening tag
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft k <a-x> <a-k> <[^/][^>]+>$ <ret> j <a-gt> }
|
2014-07-15 00:58:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
hook -group html-highlight global WinSetOption filetype=(?:html|xml) %{ add-highlighter ref html }
|
2014-07-15 00:58:40 +04:00
|
|
|
|
2016-12-14 16:40:00 +03:00
|
|
|
hook global WinSetOption filetype=(?:html|xml) %{
|
2017-01-13 03:56:30 +03:00
|
|
|
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
|
2014-07-15 00:58:40 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
hook -group html-highlight global WinSetOption filetype=(?!html|xml).* %{ remove-highlighter html }
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2016-12-14 16:40:00 +03:00
|
|
|
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
|
|
|
}
|