From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/dart.kak | 126 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 autoload/filetype/dart.kak (limited to 'autoload/filetype/dart.kak') diff --git a/autoload/filetype/dart.kak b/autoload/filetype/dart.kak new file mode 100644 index 0000000..d662359 --- /dev/null +++ b/autoload/filetype/dart.kak @@ -0,0 +1,126 @@ +# https://dartlang.org/ +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.dart %{ + set-option buffer filetype dart +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=dart %{ + require-module dart + + set-option window static_words %opt{dart_static_words} + + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange pop:insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft xs^\h+$d } } + hook window InsertChar \n -group dart-insert dart-insert-on-new-line + 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-.+ } +} + +hook -group dart-highlight global WinSetOption filetype=dart %{ + add-highlighter window/dart ref dart + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dart } +} + + +provide-module dart %§ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/dart regions +add-highlighter shared/dart/code default-region group +add-highlighter shared/dart/double_string region '"' (?)" + classes="_?[A-Z][a-zA-Z0-9]*" + + # Add the language's grammar to the static completion list + printf %s\\n "declare-option str-list dart_static_words ${keywords} ${attributes} ${types} ${values}" | tr '|' ' ' + + # 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 + add-highlighter shared/dart/code/ regex (${annotations})\b 0:meta + add-highlighter shared/dart/code/ regex \b(${classes})\b 0:module + " +} + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden dart-insert-on-new-line %~ + evaluate-commands -draft -itersel %= + # copy // comments prefix and following white spaces + try %{ execute-keys -draft kx s ^\h*\K/{2,}\h* yP } + = +~ + +define-command -hidden dart-indent-on-new-line %~ + evaluate-commands -draft -itersel %= + # preserve previous line indent + try %{ execute-keys -draft K } + # indent after lines ending with { or ( + try %[ execute-keys -draft kx [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft kx s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # indent after a switch's case/default statements + try %[ execute-keys -draft kx ^\h*(case|default).*:$ j ] + # indent after if|else|while|for + try %[ execute-keys -draft )MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + # deindent closing brace when after cursor + try %[ execute-keys -draft x ^\h*\} gh / \} m 1 ] + = +~ + +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)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden dart-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +§ -- cgit v1.2.3