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) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype pug
|
2016-04-01 15:20:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 05:54:19 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=pug %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module pug
|
2019-04-10 05:54:19 +02:00
|
|
|
|
2022-04-30 11:22:47 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group pug-trim-indent pug-trim-indent
|
2019-04-10 05:54:19 +02:00
|
|
|
hook window InsertChar \n -group pug-indent pug-indent-on-new-line
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pug-.+ }
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-10 05:54:19 +02:00
|
|
|
hook -group pug-highlight global WinSetOption filetype=pug %{
|
|
|
|
add-highlighter window/pug ref pug
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pug }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
provide-module pug %{
|
|
|
|
|
2016-04-01 15:20:31 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/pug regions
|
|
|
|
add-highlighter shared/pug/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/pug/text region ^\h*\|\s $ regex \h*(\|) 1:meta
|
|
|
|
add-highlighter shared/pug/text2 region '^\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.*' $ regex \h*(\|) 1:meta
|
|
|
|
add-highlighter shared/pug/javascript region ^\h*[-=!] $ ref javascript
|
|
|
|
add-highlighter shared/pug/double_string region '"' (?:(?<!\\)(\\\\)*"|$) fill string
|
|
|
|
add-highlighter shared/pug/single_string region "'" (?:(?<!\\)(\\\\)*'|$) fill string
|
|
|
|
add-highlighter shared/pug/comment region // $ fill comment
|
|
|
|
add-highlighter shared/pug/attribute region -recurse \( \( \) group
|
|
|
|
add-highlighter shared/pug/puglang region ^\h*\b(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin)\b $ group
|
2016-04-01 15:20:31 +02:00
|
|
|
|
|
|
|
# Filters
|
|
|
|
# ‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/pug/attribute/ ref javascript
|
|
|
|
add-highlighter shared/pug/attribute/ regex [()=] 0:operator
|
|
|
|
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/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 15:20:31 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden pug-trim-indent %{
|
2016-04-01 15:20:31 +02:00
|
|
|
# remove trailing white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
|
2016-04-01 15:20:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden pug-indent-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2016-04-01 15:20:31 +02:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2016-04-01 15:20:31 +02:00
|
|
|
# filter previous line
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : pug-trim-indent <ret> }
|
2016-04-01 15:20:31 +02:00
|
|
|
# copy '//', '|', '-' or '(!)=' prefix and following whitespace
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k 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
|
2022-04-15 00:14:17 +02:00
|
|
|
try %{ execute-keys -draft <a-gt> , b s \S <ret> g l <a-lt> }
|
2016-04-01 15:20:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|