From 05e02e38e3df7bd53dfc262d9db50243f6440f8d Mon Sep 17 00:00:00 2001 From: Jason Felice Date: Wed, 11 Nov 2020 11:48:07 -0500 Subject: [PATCH] rc: add graphql filetype --- rc/filetype/graphql.kak | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rc/filetype/graphql.kak diff --git a/rc/filetype/graphql.kak b/rc/filetype/graphql.kak new file mode 100644 index 00000000..5cb52464 --- /dev/null +++ b/rc/filetype/graphql.kak @@ -0,0 +1,75 @@ +# http://graphql.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](graphql) %{ + set-option buffer filetype graphql +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=graphql %{ + require-module graphql + + hook window ModeChange pop:insert:.* -group graphql-trim-indent graphql-trim-indent + hook window InsertChar .* -group graphql-indent graphql-indent-on-char + hook window InsertChar \n -group graphql-indent graphql-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window graphql-.+ } +} + +hook -group graphql-highlight global WinSetOption filetype=graphql %{ + add-highlighter window/graphql ref graphql + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/graphql } +} + + +provide-module graphql %( + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/graphql regions +add-highlighter shared/graphql/code default-region group +add-highlighter shared/graphql/string region '"' (? s \h+$ d } +} + +define-command -hidden graphql-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %< execute-keys -draft ^\h+[\]}]$ m 1 > + > +> + +define-command -hidden graphql-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 : graphql-trim-indent } + # indent after lines ending with opener token + try %< execute-keys -draft k [[{]\h*$ j > + # deindent closer token(s) when after cursor + try %< execute-keys -draft ^\h*[}\]] gh / [}\]] m 1 > + > +> + +)