From fff7e9b064b85d0b790790d8c1cfc2745ec94bed Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Tue, 21 May 2019 18:24:38 +0200 Subject: [PATCH] Add support for Crystal https://crystal-lang.org --- rc/filetype/crystal.kak | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rc/filetype/crystal.kak diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak new file mode 100644 index 000000000..96804beed --- /dev/null +++ b/rc/filetype/crystal.kak @@ -0,0 +1,38 @@ +# Crystal +# https://crystal-lang.org + +hook global BufCreate '.*\.cr' %{ + set-option buffer filetype crystal +} + +hook global WinSetOption filetype=crystal %{ + require-module crystal + add-highlighter window/ ref crystal + hook -group crystal window InsertChar '\n' crystal-new-line-inserted + hook -always -once window WinSetOption filetype=.* %{ + remove-highlighter window/crystal + remove-hooks window crystal + } +} + +provide-module crystal %[ + add-highlighter shared/crystal regions + add-highlighter shared/crystal/code default-region group + add-highlighter shared/crystal/code/keywords regex '\b(abstract|alias|annotation|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|false|for|fun|if|include|instance_sizeof|is_a?|lib|macro|module|next|nil|nil?|of|offsetof|out|pointerof|private|protected|require|rescue|responds_to?|return|select|self|sizeof|struct|super|then|true|type|typeof|uninitialized|union|unless|until|verbatim|when|while|with|yield)\b' 0:keyword + add-highlighter shared/crystal/string region '"' '(?') + # Remove empty line indent + try %(execute-keys -draft 'ks^\h+$d') + } + define-command -hidden crystal-fetch-keywords %{ + set-register dquote %sh{ + curl --location https://github.com/crystal-lang/crystal/raw/master/src/compiler/crystal/syntax/lexer.cr | + kak -f '%1scheck_ident_or_keyword\(:(\w+\??), \w+\)y%aa|sort' + } + } +]