home/rc/extra/pug.kak

81 lines
3.5 KiB
Plaintext
Raw Normal View History

2016-04-01 15:20:31 +02:00
# Note: jade is changing its name to pug (https://github.com/pugjs/pug/issues/2184)
# This appears to be a work in progress -- the pug-lang domain is parked, while
# the jade-lang one is active. This highlighter will recognize .pug and .jade extensions,
# http://jade-lang.com (will be http://pug-lang.com)
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](pug|jade) %{
set buffer filetype pug
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
2017-01-04 01:07:45 +01:00
add-highlighter -group / regions -default code pug \
2016-04-01 15:32:15 +02:00
text ^\h*\|\s $ '' \
2016-04-01 15:20:31 +02:00
text ^\h*([A-Za-z][A-Za-z0-9_-]*)?(\#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(?<=\S)\h+\K.* $ '' \
2016-04-01 15:32:15 +02:00
javascript ^\h*[-=!] $ '' \
2016-04-01 15:20:31 +02:00
double_string '"' (?:(?<!\\)(\\\\)*"|$) '' \
single_string "'" (?:(?<!\\)(\\\\)*'|$) '' \
comment // $ '' \
2016-04-01 15:32:15 +02:00
attribute \( \) \( \
puglang ^\h*\b(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin)\b $ '' \
2016-04-01 15:20:31 +02:00
# Filters
# ‾‾‾‾‾‾‾
2017-01-04 01:07:45 +01:00
add-highlighter -group /pug/double_string fill string
add-highlighter -group /pug/single_string fill string
add-highlighter -group /pug/comment fill comment
add-highlighter -group /pug/javascript ref javascript
add-highlighter -group /pug/attribute ref javascript
add-highlighter -group /pug/puglang ref javascript
add-highlighter -group /pug/puglang regex \b(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin|of|in)\b 0:keyword
add-highlighter -group /pug/attribute regex [()=] 0:operator
add-highlighter -group /pug/text regex \h*(\|) 1:meta
add-highlighter -group /pug/code regex ^\h*([A-Za-z][A-Za-z0-9_-]*) 1:type
add-highlighter -group /pug/code regex (\#[A-Za-z][A-Za-z0-9_-]*) 1:variable
2017-01-04 01:07:45 +01:00
add-highlighter -group /pug/code regex ((?:\.[A-Za-z][A-Za-z0-9_-]*)*) 1:value
2016-04-01 15:20:31 +02:00
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden pug-filter-around-selections %{
2016-04-01 15:20:31 +02:00
# remove trailing white spaces
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
}
def -hidden pug-indent-on-new-line %{
2016-04-01 15:20:31 +02:00
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft \; K <a-&> }
2016-04-01 15:20:31 +02:00
# filter previous line
try %{ exec -draft k : pug-filter-around-selections <ret> }
2016-04-01 15:20:31 +02:00
# copy '//', '|', '-' or '(!)=' prefix and following whitespace
try %{ exec -draft k <a-x> s ^\h*\K[/|!=-]{1,2}\h* <ret> y gh j P }
2016-04-01 15:20:31 +02:00
# indent unless we copied something above
try %{ exec -draft <a-gt> <space> b s \S <ret> g l <a-lt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
2017-01-04 01:07:45 +01:00
hook -group pug-highlight global WinSetOption filetype=pug %{ add-highlighter ref pug }
2016-04-01 15:20:31 +02:00
hook global WinSetOption filetype=pug %{
hook window InsertEnd .* -group pug-hooks pug-filter-around-selections
hook window InsertChar \n -group pug-indent pug-indent-on-new-line
2016-04-01 15:20:31 +02:00
}
2017-01-04 01:07:45 +01:00
hook -group pug-highlight global WinSetOption filetype=(?!pug).* %{ remove-highlighter pug }
2016-04-01 15:20:31 +02:00
hook global WinSetOption filetype=(?!pug).* %{
2017-01-04 01:07:45 +01:00
remove-hooks window pug-indent
remove-hooks window pug-hooks
2016-04-01 15:20:31 +02:00
}