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/gluon.kak | 103 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 autoload/filetype/gluon.kak (limited to 'autoload/filetype/gluon.kak') diff --git a/autoload/filetype/gluon.kak b/autoload/filetype/gluon.kak new file mode 100644 index 0000000..2c4b96b --- /dev/null +++ b/autoload/filetype/gluon.kak @@ -0,0 +1,103 @@ +# http://gluon-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](glu) %{ + set-option buffer filetype gluon +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=gluon %{ + require-module gluon + + set-option window extra_word_chars '_' "'" + hook window ModeChange pop:insert:.* -group gluon-trim-indent gluon-trim-indent + hook window InsertChar \n -group gluon-insert gluon-insert-on-new-line + hook window InsertChar \n -group gluon-indent gluon-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks window gluon-.+ + } +} + +hook -group gluon-highlight global WinSetOption filetype=gluon %{ + add-highlighter window/gluon ref gluon + hook -once -always window WinSetOption filetype=.* %{ + remove-highlighter window/gluon + } +} + + +provide-module gluon %§ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/gluon regions +add-highlighter shared/gluon/code default-region group +add-highlighter shared/gluon/string region (? < <= ^ <*> <$> etc +# matches dot: . +# matches keywords: @ : -> +add-highlighter shared/gluon/code/ regex (?|:!?/.@$*&#%+\^\-\\])[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator + +# matches 'x' '\\' '\'' '\n' '\0' +# not incomplete literals: '\' +add-highlighter shared/gluon/code/ regex \B'([^\\]|[\\]['"\w\d\\])' 0:string +# this has to come after operators so '-' etc is correct + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden gluon-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel x s \h+$ d } +} + +define-command -hidden gluon-insert-on-new-line %~ + evaluate-commands -draft -itersel %_ + # copy // and /// comments prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*\K///?\h* y gh j P } + _ +~ + +define-command -hidden gluon-indent-on-new-line %~ + evaluate-commands -draft -itersel %_ + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : gluon-trim-indent } + # indent after lines ending with (open) braces, =, ->, condition, rec, + # or in + try %{ execute-keys -draft \; k x (\(|\{|\[|=|->|\b(?:then|else|rec|in))$ j } + # deindent closing brace(s) when after cursor + try %< execute-keys -draft x ^\h*[})\]] gh / \})\]] m 1 > + _ +~ + +§ -- cgit v1.2.3