Add basic filetypes
This commit is contained in:
parent
7c0145e9e3
commit
5b915eb425
54
filetype/jq.kak
Normal file
54
filetype/jq.kak
Normal file
@ -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 '"' (?<!\\)(\\\\)*" fill string
|
||||
|
||||
add-highlighter shared/jq/comment_line region '#' $ fill comment
|
||||
|
||||
add-highlighter shared/jq/code/ regex \b([a-zA-Z_]\w*): 1:string
|
||||
add-highlighter shared/jq/code/ regex \b(true|false|null|\d+(?:\.\d+)?(?:[eE][+-]?\d*)?)\b 0:value
|
||||
add-highlighter shared/jq/code/ regex \b(dev)\s+([a-zA-Z_]+)\b.*?:\s*(\w*) 1:keyword 2:attribute 3:attribute
|
||||
|
||||
add-highlighter shared/jq/code/ regex (?:\|\s*(?:if|try|else|catch|elif)|then|\[|\||[\x28])\s*([a-zA-Z_]\w*) 1:attribute
|
||||
add-highlighter shared/jq/code/ regex \b([a-zA-Z_]\w*)\s*[\x28] 1:attribute
|
||||
add-highlighter shared/jq/code/ regex \$\w* 0:variable
|
||||
add-highlighter shared/jq/code/ regex \.(\w+) 1:value
|
||||
add-highlighter shared/jq/code/ regex \b(if|elif|else|then|end|as|try|catch|and|or)\b 1:keyword
|
||||
|
||||
# Commands
|
||||
# ‾‾‾‾‾‾‾‾
|
||||
|
||||
define-command -hidden jq-trim-indent %{
|
||||
# remove trailing white spaces
|
||||
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
|
||||
}
|
||||
|
||||
)
|
72
filetype/jsoncc.kak
Normal file
72
filetype/jsoncc.kak
Normal file
@ -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 '"' (?<!\\)(\\\\)*" fill string
|
||||
|
||||
add-highlighter shared/jsoncc/comment region /\* \*/ fill comment
|
||||
add-highlighter shared/jsoncc/comment_line region // $ fill comment
|
||||
|
||||
add-highlighter shared/jsoncc/code/ regex \b(true|false|null|\d+(?:\.\d+)?(?:[eE][+-]?\d*)?)\b 0:value
|
||||
|
||||
# Commands
|
||||
# ‾‾‾‾‾‾‾‾
|
||||
|
||||
define-command -hidden jsoncc-trim-indent %{
|
||||
# remove trailing white spaces
|
||||
try %{ execute-keys -draft -itersel x s \h+$ <ret> 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 <a-h> <a-k> ^\h+[\]}]$ <ret> m <a-S> 1<a-&> >
|
||||
>
|
||||
>
|
||||
|
||||
define-command -hidden jsoncc-indent-on-new-line %<
|
||||
evaluate-commands -draft -itersel %<
|
||||
# preserve previous line indent
|
||||
try %{ execute-keys -draft <semicolon> K <a-&> }
|
||||
# filter previous line
|
||||
try %{ execute-keys -draft k : jsoncc-trim-indent <ret> }
|
||||
# indent after lines ending with opener token
|
||||
try %< execute-keys -draft k x <a-k> [[{]\h*$ <ret> j <a-gt> >
|
||||
# deindent closer token(s) when after cursor
|
||||
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
|
||||
>
|
||||
>
|
||||
|
||||
)
|
Loading…
Reference in New Issue
Block a user