2015-09-04 11:31:19 +03:00
|
|
|
# http://dlang.org/
|
|
|
|
#
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*\.di? %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype d
|
2015-09-04 11:31:19 +03:00
|
|
|
}
|
|
|
|
|
2019-04-10 06:54:19 +03:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=d %{
|
2019-03-13 08:24:33 +03:00
|
|
|
require-module d
|
2019-04-10 06:54:19 +03:00
|
|
|
|
|
|
|
set-option window static_words %opt{d_static_words}
|
|
|
|
|
|
|
|
# cleanup trailing whitespaces when exiting insert mode
|
2019-10-16 12:19:43 +03:00
|
|
|
hook window ModeChange pop:insert:.* -group d-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
|
2021-04-17 11:17:01 +03:00
|
|
|
hook window InsertChar \n -group d-insert d-insert-on-new-line
|
2019-04-10 06:54:19 +03:00
|
|
|
hook window InsertChar \n -group d-indent d-indent-on-new-line
|
|
|
|
hook window InsertChar \{ -group d-indent d-indent-on-opening-curly-brace
|
|
|
|
hook window InsertChar \} -group d-indent d-indent-on-closing-curly-brace
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window d-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group d-highlight global WinSetOption filetype=d %{
|
|
|
|
add-highlighter window/d ref d
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/d }
|
2019-03-13 08:24:33 +03:00
|
|
|
}
|
|
|
|
|
2019-04-13 22:57:57 +03:00
|
|
|
provide-module d %§
|
2019-03-13 08:24:33 +03:00
|
|
|
|
2015-09-04 11:31:19 +03:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/d regions
|
|
|
|
add-highlighter shared/d/code default-region group
|
2018-07-02 13:59:12 +03:00
|
|
|
add-highlighter shared/d/string region %{(?<!')(?<!'\\)"} %{(?<!\\)(?:\\\\)*"} group
|
2019-06-24 10:18:43 +03:00
|
|
|
add-highlighter shared/d/verbatim_string region %{(?<!')(?<!'\\)`} %{(?<!\\)(?:\\\\)*`} fill meta
|
2018-08-09 12:27:40 +03:00
|
|
|
add-highlighter shared/d/verbatim_string_prefixed region %{r`([^(]*)\(} %{\)([^)]*)`} fill meta
|
2021-04-06 15:21:03 +03:00
|
|
|
add-highlighter shared/d/docstring1 region -recurse '/\+' '/\+\+' '\+/' fill documentation
|
2018-06-23 08:38:46 +03:00
|
|
|
add-highlighter shared/d/docstring2 region '/\*\*' '\*/' fill documentation
|
|
|
|
add-highlighter shared/d/docstring3 region /// $ fill documentation
|
2021-04-06 15:21:03 +03:00
|
|
|
add-highlighter shared/d/disabled region -recurse '/\+' '/\+[^+]?' '\+/' fill comment
|
2018-07-02 13:59:12 +03:00
|
|
|
add-highlighter shared/d/comment1 region '/\*[^*]?' '\*/' fill comment
|
|
|
|
add-highlighter shared/d/comment2 region '//[^/]?' $ fill comment
|
2018-07-01 12:53:35 +03:00
|
|
|
|
|
|
|
add-highlighter shared/d/string/ fill string
|
|
|
|
add-highlighter shared/d/string/ regex %{\\(x[0-9a-fA-F]{2}|[0-7]{1,3}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})\b} 0:value
|
|
|
|
add-highlighter shared/d/code/ regex %{'((\\.)?|[^'\\])'} 0:value
|
|
|
|
add-highlighter shared/d/code/ regex "-?([0-9_]*\.(?!0[xXbB]))?\b([0-9_]+|0[xX][0-9a-fA-F_]*\.?[0-9a-fA-F_]+|0[bb][01_]+)([ep]-?[0-9_]+)?[fFlLuUi]*\b" 0:value
|
|
|
|
add-highlighter shared/d/code/ regex "\b(this)\b\s*[^(]" 1:value
|
|
|
|
add-highlighter shared/d/code/ regex "((?:~|\b)this)\b\s*\(" 1:function
|
2019-06-24 10:12:29 +03:00
|
|
|
add-highlighter shared/d/code/ regex '(#line)\h+(\d+)(\h+"[^"\n]*")?' 1:meta 2:value 3:string
|
2016-03-14 15:08:51 +03:00
|
|
|
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2016-03-14 15:08:51 +03:00
|
|
|
# Grammar
|
2016-11-11 16:07:45 +03:00
|
|
|
|
|
|
|
keywords="abstract|alias|align|asm|assert|auto|body|break|case|cast"
|
|
|
|
keywords="${keywords}|catch|cent|class|const|continue|debug"
|
|
|
|
keywords="${keywords}|default|delegate|delete|deprecated|do|else|enum|export|extern"
|
|
|
|
keywords="${keywords}|final|finally|for|foreach|foreach_reverse|function|goto"
|
|
|
|
keywords="${keywords}|if|immutable|import|in|inout|interface|invariant"
|
|
|
|
keywords="${keywords}|is|lazy|macro|mixin|module|new|nothrow|out|override"
|
|
|
|
keywords="${keywords}|package|pragma|private|protected|public|pure|ref|return|scope"
|
|
|
|
keywords="${keywords}|shared|static|struct|super|switch|synchronized|template"
|
|
|
|
keywords="${keywords}|throw|try|typedef|typeid|typeof|union"
|
|
|
|
keywords="${keywords}|unittest|version|volatile|while|with"
|
2016-03-14 19:29:11 +03:00
|
|
|
attributes="abstract|align|auto|const|debug|deprecated|export|extern|final"
|
|
|
|
attributes="${attributes}|immutable|inout|nothrow|package|private|protected"
|
2016-11-11 16:07:45 +03:00
|
|
|
attributes="${attributes}|public|pure|ref|override|scope|shared|static|synchronized|version"
|
|
|
|
attributes="${attributes}|__gshared|__traits|__vector|__parameters"
|
|
|
|
types="bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|dstring|float"
|
2016-03-14 19:29:11 +03:00
|
|
|
types="${types}|idouble|ifloat|int|ireal|long|ptrdiff_t|real|size_t|short"
|
2016-11-11 16:07:45 +03:00
|
|
|
types="${types}|string|ubyte|ucent|uint|ulong|ushort|void|wchar|wstring"
|
|
|
|
values="true|false|null"
|
|
|
|
tokens="__FILE__|__MODULE__|__LINE__|__FUNCTION__"
|
2019-10-17 14:15:57 +03:00
|
|
|
tokens="${tokens}|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__"
|
2016-11-11 16:07:45 +03:00
|
|
|
tokens="${tokens}|__TIMESTAMP__|__VENDOR__|__VERSION__|#line"
|
|
|
|
properties="this|init|sizeof|alignof|mangleof|stringof|infinity|nan|dig|epsilon|mant_dig"
|
|
|
|
properties="${properties}|max_10_exp|min_exp|max|min_normal|re|im|classinfo"
|
|
|
|
properties="${properties}|length|dup|keys|values|rehash|clear"
|
2016-03-14 19:29:11 +03:00
|
|
|
decorators="disable|property|nogc|safe|trusted|system"
|
2016-03-14 15:08:51 +03:00
|
|
|
|
|
|
|
# Add the language's grammar to the static completion list
|
2019-04-10 06:54:19 +03:00
|
|
|
printf %s\\n "declare-option str-list d_static_words ${keywords} ${attributes} ${types} ${values} ${decorators} ${properties}" | tr '|' ' '
|
2016-03-14 15:08:51 +03:00
|
|
|
|
|
|
|
# Highlight keywords
|
2016-03-17 16:30:14 +03:00
|
|
|
printf %s "
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/d/code/ regex \b(${keywords})\b 0:keyword
|
|
|
|
add-highlighter shared/d/code/ regex \b(${attributes})\b 0:attribute
|
|
|
|
add-highlighter shared/d/code/ regex \b(${types})\b 0:type
|
|
|
|
add-highlighter shared/d/code/ regex \b(${values})\b 0:value
|
|
|
|
add-highlighter shared/d/code/ regex @(${decorators})\b 0:attribute
|
|
|
|
add-highlighter shared/d/code/ regex \b(${tokens})\b 0:builtin
|
|
|
|
add-highlighter shared/d/code/ regex \.(${properties})\b 1:builtin
|
2016-03-14 15:08:51 +03:00
|
|
|
"
|
|
|
|
}
|
2015-09-04 11:31:19 +03:00
|
|
|
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/d/code/ regex "\bimport\s+([\w._-]+)(?:\s*=\s*([\w._-]+))?" 1:module 2:module
|
|
|
|
add-highlighter shared/d/code/ regex "\bmodule\s+([\w_-]+)\b" 1:module
|
2018-03-25 10:25:52 +03:00
|
|
|
|
2015-09-04 11:31:19 +03:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2021-04-17 11:17:01 +03:00
|
|
|
define-command -hidden d-insert-on-new-line %~
|
|
|
|
evaluate-commands -draft -itersel %=
|
|
|
|
# copy // comments prefix and following white spaces
|
|
|
|
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
|
|
|
|
=
|
|
|
|
~
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden d-indent-on-new-line %~
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft -itersel %=
|
2015-09-04 11:31:19 +03:00
|
|
|
# preserve previous line indent
|
2019-10-22 12:02:06 +03:00
|
|
|
try %{ execute-keys -draft <semicolon>K<a-&> }
|
2015-09-04 11:31:19 +03:00
|
|
|
# indent after lines ending with { or (
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
|
2015-09-04 11:31:19 +03:00
|
|
|
# cleanup trailing white spaces on the previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
|
2015-09-04 11:31:19 +03:00
|
|
|
# align to opening paren of previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
|
2015-09-04 11:31:19 +03:00
|
|
|
# indent after a switch's case/default statements
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
|
2015-09-04 11:31:19 +03:00
|
|
|
# indent after if|else|while|for
|
2019-10-22 12:02:06 +03: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 22:15:05 +03:00
|
|
|
# deindent closing brace(s) when after cursor
|
2020-07-29 18:40:58 +03:00
|
|
|
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
|
2015-09-04 11:31:19 +03:00
|
|
|
=
|
|
|
|
~
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden d-indent-on-opening-curly-brace %[
|
2015-09-04 11:31:19 +03:00
|
|
|
# align indent with opening paren when { is entered on a new line after the closing paren
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -draft -itersel h<a-F>)M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
|
2015-09-04 11:31:19 +03:00
|
|
|
]
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden d-indent-on-closing-curly-brace %[
|
2015-09-04 11:31:19 +03:00
|
|
|
# align to opening curly brace when alone on a line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\A|.\z<ret>1<a-&> ]
|
2015-09-04 11:31:19 +03:00
|
|
|
]
|
|
|
|
|
2019-04-13 22:57:57 +03:00
|
|
|
§
|