From 2454cf3345527f484abd003f4e7e9878f026ca70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Henrique=20Montesi=C3=A3o=20de=20Sousa?= Date: Fri, 23 Apr 2021 14:49:24 -0300 Subject: [PATCH] Add basic support for the Janet language --- rc/filetype/janet.kak | 78 +++++++++++++++++++++++++++++++++++++++++++ rc/tools/comment.kak | 6 ++++ 2 files changed, 84 insertions(+) create mode 100644 rc/filetype/janet.kak diff --git a/rc/filetype/janet.kak b/rc/filetype/janet.kak new file mode 100644 index 00000000..12db77b3 --- /dev/null +++ b/rc/filetype/janet.kak @@ -0,0 +1,78 @@ +# http://janet-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](janet|jdn) %{ + set-option buffer filetype janet +} + + +hook global WinSetOption filetype=janet %{ + require-module janet + + hook window ModeChange pop:insert:.* -group janet-trim-indent janet-trim-indent + hook window InsertChar \n -group janet-indent janet-indent-on-new-line + set-option buffer extra_word_chars ! @ $ '%' ^ & * - _ + = : < > . ? + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window janet-.+ } +} + +hook -group janet-highlight global WinSetOption filetype=janet %{ + add-highlighter window/janet ref janet + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/janet } +} + +provide-module janet %{ + +require-module lisp + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/janet regions +add-highlighter shared/janet/code default-region group +add-highlighter shared/janet/comment region '(?.?\w]+ 0:value +add-highlighter shared/janet/code/number regex \W\K(?:[\-+]?\dx?[\der._+a-f]*)\b 0:value +add-highlighter shared/janet/code/function-definition regex \((?:defn|fn)\s([!@$%\^&*\-_+=:<>.?\w]+) 1:function +add-highlighter shared/janet/code/function-call regex \(([!@$%\^&*\-_+=:<>.?\w/]+) 1:function +add-highlighter shared/janet/code/special regex \((def|defn|var|fn|do|quote|if|splice|while|break|set|quasiquote|unquote|upscope)\b\s 1:keyword +add-highlighter shared/janet/code/ regex \W\K(&|&opt)\W 1:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden janet-trim-indent lisp-trim-indent + +declare-option \ + -docstring 'regex matching the head of forms which have options *and* indented bodies' \ + regex janet_special_indent_forms \ + '(?:def.*|while|for|fn\*?|if(-.*|)|let.*|loop|seq|with(-.*|)|when(-.*|))|defer|do|match|var' + +define-command -hidden janet-indent-on-new-line %{ + # registers: i = best align point so far; w = start of first word of form + evaluate-commands -draft -save-regs '/"|^@iw' -itersel %{ + execute-keys -draft 'gk"iZ' + try %{ + execute-keys -draft '[bl"i"wZ' + + try %{ + # If a special form, indent another j + execute-keys -draft '"wze\A' %opt{janet_special_indent_forms} '\zs.\K.*;"i' + } catch %{ + # If not special and parameter appears on line 1, indent to parameter + execute-keys -draft '"wzes\h\K[^\s].*;"i' + } + } + try %{ execute-keys -draft '[rl"i' } + try %{ execute-keys -draft '[Bl"i' } + execute-keys -draft '"ia&' + } +} + +} diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 6a2817b5..e935d8ee 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -33,6 +33,12 @@ hook global BufSetOption filetype=clojure %{ set-option buffer comment_block_end ')' } +hook global BufSetOption filetype=janet %{ + set-option buffer comment_line '#' + set-option buffer comment_block_begin '(comment ' + set-option buffer comment_block_end ')' +} + hook global BufSetOption filetype=coffee %{ set-option buffer comment_block_begin '###' set-option buffer comment_block_end '###'