From 5b915eb425a026972df697cbcb729ddec5f6c7d2 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Thu, 12 Sep 2024 14:40:34 -0400 Subject: [PATCH] Add basic filetypes --- filetype/jq.kak | 54 ++++++++++++++++++++++++++++++++++ filetype/jsoncc.kak | 72 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 filetype/jq.kak create mode 100644 filetype/jsoncc.kak diff --git a/filetype/jq.kak b/filetype/jq.kak new file mode 100644 index 0000000..300e3bc --- /dev/null +++ b/filetype/jq.kak @@ -0,0 +1,54 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](jq) %{ + set-option buffer filetype jq + set-option buffer comment_line '#' + set-option buffer extra_word_chars '$' '_' +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=jq %{ + require-module jq + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window jq-.+ } +} + +hook -group jq-highlight global WinSetOption filetype=jq %{ + add-highlighter window/jq ref jq + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/jq } +} + + +provide-module jq %( + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/jq regions +add-highlighter shared/jq/code default-region group +add-highlighter shared/jq/string region '"' (? d } +} + +) diff --git a/filetype/jsoncc.kak b/filetype/jsoncc.kak new file mode 100644 index 0000000..0f7cd45 --- /dev/null +++ b/filetype/jsoncc.kak @@ -0,0 +1,72 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](jsoncc?) %{ + set-option buffer filetype jsoncc + set-option buffer comment_line '//' + set-option buffer comment_block_begin '/*' + set-option buffer comment_block_end '*/' +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=jsoncc %{ + require-module jsoncc + + hook window ModeChange pop:insert:.* -group jsoncc-trim-indent jsoncc-trim-indent + hook window InsertChar .* -group jsoncc-indent jsoncc-indent-on-char + hook window InsertChar \n -group jsoncc-indent jsoncc-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window jsoncc-.+ } +} + +hook -group jsoncc-highlight global WinSetOption filetype=jsoncc %{ + add-highlighter window/jsoncc ref jsoncc + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/jsoncc } +} + + +provide-module jsoncc %( + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/jsoncc regions +add-highlighter shared/jsoncc/code default-region group +add-highlighter shared/jsoncc/string region '"' (? d } +} + +define-command -hidden jsoncc-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 jsoncc-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 : jsoncc-trim-indent } + # indent after lines ending with opener token + try %< execute-keys -draft k x [[{]\h*$ j > + # deindent closer token(s) when after cursor + try %< execute-keys -draft x ^\h*[}\]] gh / [}\]] m 1 > + > +> + +)