2016-04-01 16:20:31 +03: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) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype pug
|
2016-04-01 16:20:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter shared/ regions -default code pug \
|
2016-04-01 16:32:15 +03:00
|
|
|
text ^\h*\|\s $ '' \
|
2017-10-02 15:59:22 +03:00
|
|
|
text '^\h*([A-Za-z][A-Za-z0-9_-]*)?(#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(?<!\t)(?<! )(?<!\n)\h+\K.*' $ '' \
|
2016-04-01 16:32:15 +03:00
|
|
|
javascript ^\h*[-=!] $ '' \
|
2016-04-01 16:20:31 +03:00
|
|
|
double_string '"' (?:(?<!\\)(\\\\)*"|$) '' \
|
|
|
|
single_string "'" (?:(?<!\\)(\\\\)*'|$) '' \
|
|
|
|
comment // $ '' \
|
2016-04-01 16:32:15 +03:00
|
|
|
attribute \( \) \( \
|
2016-04-21 22:43:17 +03:00
|
|
|
puglang ^\h*\b(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin)\b $ '' \
|
2016-04-01 16:20:31 +03:00
|
|
|
|
|
|
|
# Filters
|
|
|
|
# ‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter shared/pug/double_string fill string
|
|
|
|
add-highlighter shared/pug/single_string fill string
|
|
|
|
add-highlighter shared/pug/comment fill comment
|
|
|
|
add-highlighter shared/pug/javascript ref javascript
|
|
|
|
add-highlighter shared/pug/attribute ref javascript
|
|
|
|
add-highlighter shared/pug/puglang ref javascript
|
|
|
|
add-highlighter shared/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 shared/pug/attribute regex [()=] 0:operator
|
|
|
|
add-highlighter shared/pug/text regex \h*(\|) 1:meta
|
|
|
|
add-highlighter shared/pug/code regex ^\h*([A-Za-z][A-Za-z0-9_-]*) 1:type
|
|
|
|
add-highlighter shared/pug/code regex '(#[A-Za-z][A-Za-z0-9_-]*)' 1:variable
|
|
|
|
add-highlighter shared/pug/code regex ((?:\.[A-Za-z][A-Za-z0-9_-]*)*) 1:value
|
2016-04-01 16:20:31 +03:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden pug-filter-around-selections %{
|
2016-04-01 16:20:31 +03:00
|
|
|
# remove trailing white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
|
2016-04-01 16:20:31 +03:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden pug-indent-on-new-line %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft -itersel %{
|
2016-04-01 16:20:31 +03:00
|
|
|
# preserve previous line indent
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
2016-04-01 16:20:31 +03:00
|
|
|
# filter previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k : pug-filter-around-selections <ret> }
|
2016-04-01 16:20:31 +03:00
|
|
|
# copy '//', '|', '-' or '(!)=' prefix and following whitespace
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k <a-x> s ^\h*\K[/|!=-]{1,2}\h* <ret> y gh j P }
|
2016-04-01 16:20:31 +03:00
|
|
|
# indent unless we copied something above
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft <a-gt> <space> b s \S <ret> g l <a-lt> }
|
2016-04-01 16:20:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
hook -group pug-highlight global WinSetOption filetype=pug %{ add-highlighter window ref pug }
|
2016-04-01 16:20:31 +03:00
|
|
|
|
2016-09-25 16:15:07 +03:00
|
|
|
hook global WinSetOption filetype=pug %{
|
2018-01-21 02:35:05 +03:00
|
|
|
hook window ModeChange insert:.* -group pug-hooks pug-filter-around-selections
|
2017-01-13 03:56:30 +03:00
|
|
|
hook window InsertChar \n -group pug-indent pug-indent-on-new-line
|
2016-04-01 16:20:31 +03:00
|
|
|
}
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
hook -group pug-highlight global WinSetOption filetype=(?!pug).* %{ remove-highlighter window/pug }
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2016-04-01 16:20:31 +03:00
|
|
|
hook global WinSetOption filetype=(?!pug).* %{
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks window pug-indent
|
|
|
|
remove-hooks window pug-hooks
|
2016-04-01 16:20:31 +03:00
|
|
|
}
|