2018-08-14 14:50:45 +02:00
|
|
|
# https://dartlang.org/
|
|
|
|
#
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*\.dart %{
|
|
|
|
set-option buffer filetype dart
|
|
|
|
}
|
|
|
|
|
2019-04-10 05:54:19 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=dart %{
|
2019-03-13 06:24:33 +01:00
|
|
|
require-module dart
|
2019-04-10 05:54:19 +02:00
|
|
|
|
|
|
|
set-option window static_words %opt{dart_static_words}
|
|
|
|
|
|
|
|
# cleanup trailing whitespaces when exiting insert mode
|
2022-03-16 23:20:07 +01:00
|
|
|
hook window ModeChange pop:insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group dart-insert dart-insert-on-new-line
|
2019-04-10 05:54:19 +02:00
|
|
|
hook window InsertChar \n -group dart-indent dart-indent-on-new-line
|
|
|
|
hook window InsertChar \{ -group dart-indent dart-indent-on-opening-curly-brace
|
|
|
|
hook window InsertChar \} -group dart-indent dart-indent-on-closing-curly-brace
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dart-.+ }
|
2019-03-13 06:24:33 +01:00
|
|
|
}
|
|
|
|
|
2019-04-10 05:54:19 +02:00
|
|
|
hook -group dart-highlight global WinSetOption filetype=dart %{
|
|
|
|
add-highlighter window/dart ref dart
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dart }
|
|
|
|
}
|
|
|
|
|
2019-04-13 21:57:57 +02:00
|
|
|
|
|
|
|
provide-module dart %§
|
2019-03-13 06:24:33 +01:00
|
|
|
|
2018-08-14 14:50:45 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
add-highlighter shared/dart regions
|
|
|
|
add-highlighter shared/dart/code default-region group
|
2021-05-19 22:44:27 +02:00
|
|
|
add-highlighter shared/dart/double_string region '"' (?<!\\)(\\\\)*" group
|
|
|
|
add-highlighter shared/dart/single_string region "'" (?<!\\)(\\\\)*' group
|
2018-08-14 14:50:45 +02:00
|
|
|
add-highlighter shared/dart/comment region /\* \*/ fill comment
|
|
|
|
add-highlighter shared/dart/comment_line region '//' $ fill comment
|
|
|
|
|
|
|
|
add-highlighter shared/dart/code/ regex %{-?([0-9]*\.(?!0[xX]))?\b([0-9]+|0[xX][0-9a-fA-F]+)\.?([eE][+-]?[0-9]+)?i?\b} 0:value
|
|
|
|
|
2021-05-19 22:44:27 +02:00
|
|
|
# String interpolation
|
|
|
|
add-highlighter shared/dart/double_string/ fill string
|
|
|
|
add-highlighter shared/dart/double_string/ regex \$\{.*?\} 0:value
|
|
|
|
add-highlighter shared/dart/single_string/ fill string
|
|
|
|
add-highlighter shared/dart/single_string/ regex \$\{.*?\} 0:value
|
|
|
|
|
2018-08-14 14:50:45 +02:00
|
|
|
evaluate-commands %sh{
|
|
|
|
# Grammar
|
|
|
|
keywords="abstract|do|import|super|as|in|switch|assert|else|interface|async"
|
|
|
|
keywords="${keywords}|enum|is|this|export|library|throw|await|external|mixin|break|extends"
|
2020-07-27 19:59:57 +02:00
|
|
|
keywords="${keywords}|new|try|case|factory|typedef|catch|operator|class|final|part|extension"
|
2018-08-14 14:50:45 +02:00
|
|
|
keywords="${keywords}|const|finally|rethrow|while|continue|for|return|with|covariant"
|
|
|
|
keywords="${keywords}|get|set|yield|default|if|static|deferred|implements"
|
|
|
|
generator_keywords="async\*|sync\*|yield\*"
|
|
|
|
|
|
|
|
types="void|bool|num|int|double|dynamic|var"
|
|
|
|
values="false|true|null"
|
|
|
|
|
|
|
|
annotations="@[a-zA-Z]+"
|
|
|
|
functions="(_?[a-z][a-zA-Z0-9]*)(\(|\w+=>)"
|
2019-06-17 21:11:19 +02:00
|
|
|
classes="_?[A-Z][a-zA-Z0-9]*"
|
2018-08-14 14:50:45 +02:00
|
|
|
|
|
|
|
# Add the language's grammar to the static completion list
|
2019-04-10 05:54:19 +02:00
|
|
|
printf %s\\n "declare-option str-list dart_static_words ${keywords} ${attributes} ${types} ${values}" | tr '|' ' '
|
2018-08-14 14:50:45 +02:00
|
|
|
|
|
|
|
# Highlight keywords
|
|
|
|
printf %s "
|
|
|
|
add-highlighter shared/dart/code/ regex \b(${keywords})\b 0:keyword
|
|
|
|
add-highlighter shared/dart/code/ regex \b(${generator_keywords}) 0:keyword
|
|
|
|
add-highlighter shared/dart/code/ regex \b(${attributes})\b 0:attribute
|
|
|
|
add-highlighter shared/dart/code/ regex \b(${types})\b 0:type
|
|
|
|
add-highlighter shared/dart/code/ regex \b(${values})\b 0:value
|
|
|
|
add-highlighter shared/dart/code/ regex \b(${functions}) 2:function
|
2019-06-16 10:53:19 +02:00
|
|
|
add-highlighter shared/dart/code/ regex (${annotations})\b 0:meta
|
2018-08-14 14:50:45 +02:00
|
|
|
add-highlighter shared/dart/code/ regex \b(${classes})\b 0:module
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden dart-insert-on-new-line %~
|
|
|
|
evaluate-commands -draft -itersel %=
|
|
|
|
# copy // comments prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
|
2021-04-17 10:17:01 +02:00
|
|
|
=
|
|
|
|
~
|
|
|
|
|
2018-08-14 14:50:45 +02:00
|
|
|
define-command -hidden dart-indent-on-new-line %~
|
|
|
|
evaluate-commands -draft -itersel %=
|
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon>K<a-&> }
|
2018-08-14 14:50:45 +02:00
|
|
|
# indent after lines ending with { or (
|
2022-03-16 23:20:07 +01:00
|
|
|
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
|
2018-08-14 14:50:45 +02:00
|
|
|
# cleanup trailing white spaces on the previous line
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft kx s \h+$ <ret>d }
|
2018-08-14 14:50:45 +02:00
|
|
|
# align to opening paren of previous line
|
|
|
|
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
|
|
|
|
# indent after a switch's case/default statements
|
2022-03-16 23:20:07 +01:00
|
|
|
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
|
2018-08-14 14:50:45 +02:00
|
|
|
# indent after if|else|while|for
|
2019-10-22 11:02:06 +02:00
|
|
|
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-space><a-gt> ]
|
2020-07-27 21:11:32 +02:00
|
|
|
# deindent closing brace when after cursor
|
2022-03-16 23:20:07 +01:00
|
|
|
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
|
2018-08-14 14:50:45 +02:00
|
|
|
=
|
|
|
|
~
|
|
|
|
|
|
|
|
define-command -hidden dart-indent-on-opening-curly-brace %[
|
|
|
|
# align indent with opening paren when { is entered on a new line after the closing paren
|
|
|
|
try %[ execute-keys -draft -itersel h<a-F>)M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
|
|
|
|
]
|
|
|
|
|
|
|
|
define-command -hidden dart-indent-on-closing-curly-brace %[
|
|
|
|
# align to opening curly brace when alone on a line
|
|
|
|
try %[ execute-keys -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\A|.\z<ret>1<a-&> ]
|
|
|
|
]
|
|
|
|
|
2019-04-13 21:57:57 +02:00
|
|
|
§
|