From 21673744967c0ac5335915a40a6d25dfe16f4196 Mon Sep 17 00:00:00 2001 From: lePerdu Date: Sat, 9 Nov 2019 09:22:19 -0500 Subject: [PATCH 1/2] Add Gluon highlighting/indent --- rc/filetype/gluon.kak | 99 +++++++++++++++++++++++++++++++++++++++++++ rc/tools/comment.kak | 2 +- 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 rc/filetype/gluon.kak diff --git a/rc/filetype/gluon.kak b/rc/filetype/gluon.kak new file mode 100644 index 00000000..b6ec9925 --- /dev/null +++ b/rc/filetype/gluon.kak @@ -0,0 +1,99 @@ +# 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 insert:.* -group gluon-trim-indent gluon-trim-indent + 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 s \h+$ d } +} + +define-command -hidden gluon-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K//\h* y gh j P } + # 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 (\(|\{|\[|=|->|then|else|rec|in)$ j + # balance out brackets } ] + } + } +} + +] diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 39d62501..1dac5d9a 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -14,7 +14,7 @@ hook global BufSetOption filetype=asciidoc %{ set-option buffer comment_block_end '///' } -hook global BufSetOption filetype=(c|cpp|dart|go|java|javascript|objc|php|rust|sass|scala|scss|swift|typescript) %{ +hook global BufSetOption filetype=(c|cpp|dart|gluon|go|java|javascript|objc|php|rust|sass|scala|scss|swift|typescript) %{ set-option buffer comment_line '//' set-option buffer comment_block_begin '/*' set-option buffer comment_block_end '*/' From 6aab2f54dde3df5cf681c7bd6fee57d1a5ded40f Mon Sep 17 00:00:00 2001 From: lePerdu Date: Sat, 9 Nov 2019 09:41:11 -0500 Subject: [PATCH 2/2] Copy doc comment (///) prefix to new lines --- rc/filetype/gluon.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/gluon.kak b/rc/filetype/gluon.kak index b6ec9925..2298737c 100644 --- a/rc/filetype/gluon.kak +++ b/rc/filetype/gluon.kak @@ -80,8 +80,8 @@ define-command -hidden gluon-trim-indent %{ define-command -hidden gluon-indent-on-new-line %{ evaluate-commands -draft -itersel %{ - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K//\h* y gh j P } + # copy // and /// comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K///?\h* y gh j P } # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line