First commit

This commit is contained in:
James Dugan 2025-02-04 21:06:01 -07:00
commit 847c9e64c0
51 changed files with 4058 additions and 0 deletions

View file

@ -0,0 +1,90 @@
# https://capnproto.org/
hook global BufCreate .*[.](capnp) %{
set-option buffer filetype capnp
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=capnp %{
require-module capnp
set-option window static_words %opt{capnp_static_words}
hook window ModeChange pop:insert:.* -group capnp-trim-indent capnp-trim-indent
hook window InsertChar .* -group capnp-indent capnp-indent-on-char
hook window InsertChar \n -group capnp-indent capnp-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window capnp-.+ }
}
hook -group capnp-highlight global WinSetOption filetype=capnp %{
add-highlighter window/capnp ref capnp
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/capnp }
}
provide-module capnp %@
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/capnp regions
add-highlighter shared/capnp/code default-region group
add-highlighter shared/capnp/line_comment region '#' '$' fill comment
add-highlighter shared/capnp/string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/capnp/code/ regex '(?i)\b0b[01]+l?\b' 0:value
add-highlighter shared/capnp/code/ regex '(?i)\b0x[\da-f]+l?\b' 0:value
add-highlighter shared/capnp/code/ regex '(?i)\b0o?[0-7]+l?\b' 0:value
add-highlighter shared/capnp/code/ regex '(?i)\b([1-9]\d*|0)l?\b' 0:value
add-highlighter shared/capnp/code/ regex '\b\d+[eE][+-]?\d+\b' 0:value
add-highlighter shared/capnp/code/ regex '(\b\d+)?\.\d+\b' 0:value
add-highlighter shared/capnp/code/ regex '\b\d+\.' 0:value
evaluate-commands %sh{
builtin_types="Void Bool Text Data List union group Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64"
declarations="struct union enum interface const annotation"
keywords="using extends import"
values="true false inf"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
printf %s\\n "declare-option str-list capnp_static_words $(join "${builtin_types}" ' ') $(join "${declarations}" ' ') $(join "${keywords}" ' ') $(join "${values}" ' ')"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${builtin_types}" '|'))\b' 0:type"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${declarations}" '|'))\b' 0:keyword"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${keywords}" '|'))\b' 0:keyword"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${values}" '|'))\b' 0:value"
}
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden capnp-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden capnp-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 capnp-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 : capnp-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-&> >
>
>
@

View file

@ -0,0 +1,97 @@
# https://kdl.dev
hook global BufCreate .*[.](kdl) %{
set-option buffer filetype kdl
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=kdl %{
require-module kdl
hook window ModeChange pop:insert:.* -group kdl-trim-indent kdl-trim-indent
hook window InsertChar .* -group kdl-indent kdl-indent-on-char
hook window InsertChar \n -group kdl-indent kdl-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kdl-.+ }
}
hook -group kdl-highlight global WinSetOption filetype=kdl %{
add-highlighter window/kdl ref kdl
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kdl }
}
provide-module kdl %@
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/kdl regions
add-highlighter shared/kdl/code default-region group
add-highlighter shared/kdl/raw_string region -match-capture 'r(#*)"' '"(#*)' fill string
add-highlighter shared/kdl/string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/kdl/comment region -recurse /\* /\* \*/ fill comment
add-highlighter shared/kdl/line_comment region // $ fill comment
# Slashdash (/-) comments are annoying to highlight properly without a proper parser due to the fact that they can comment
# out any kdl construct..
# The below is, at best, an approximation, and there are almost certainly edge cases missed.
add-highlighter shared/kdl/slashdash_child region -recurse \{ /-[^\n]+\{ \} fill comment
add-highlighter shared/kdl/slashdash_string region '/-\s+"' (?<!\\)(\\\\)*" fill comment
add-highlighter shared/kdl/slashdash_raw_string region -match-capture '/-\s+r"(#*)' '"(#*)' fill comment
add-highlighter shared/kdl/slashdash_builtin_value region /-\s+(true|false|null) \s fill comment
add-highlighter shared/kdl/slashdash_binary region /-\s+0b[01_]+ \s fill comment
add-highlighter shared/kdl/slashdash_octal region /-\s+0o[0-7_]+ \s fill comment
add-highlighter shared/kdl/slashdash_hex region /-\s+0x[a-fA-F0-9_]+ \s fill comment
add-highlighter shared/kdl/slashdash_decimal region /-\s+[0-9-+][0-9_]* \s fill comment
add-highlighter shared/kdl/slashdash_float region /-\s+[0-9-+][0-9_]*\.[0-9_]+ \s fill comment
add-highlighter shared/kdl/slashdash_float_exp region /-\s+[0-9-+][0-9_]*(\.[0-9_]+)?[eE][-+]?[0-9_]+ \s fill comment
add-highlighter shared/kdl/slashdash_prop_string region '/-\s+[\u000021-\u00FFFF]+="' (?<!\\)(\\\\)*" fill comment
add-highlighter shared/kdl/slashdash_prop_raw_string region -match-capture '/-\s+[\u000021-\u00FFFF]+=r"(#*)' '"(#*)' fill comment
add-highlighter shared/kdl/slashdash_prop_other region /-\s+[\u000021-\u00FFFF]+= \s fill comment
add-highlighter shared/kdl/slashdash_node region /-\s+[\u000021-\u00FFFF]+ $ fill comment
add-highlighter shared/kdl/code/node regex \b([\u000021-\u00FFFF]*)\b 0:variable # Everything not covered below is a node
add-highlighter shared/kdl/code/property regex \b([\u000021-\u00FFFF]+)(=) 0:operator 1:attribute
add-highlighter shared/kdl/code/builtin_value regex \b(true|false|null)\b 0:value
add-highlighter shared/kdl/code/binary regex \b(0b[01_]+)\b 0:value
add-highlighter shared/kdl/code/octal regex \b(0o[0-7_]+)\b 0:value
add-highlighter shared/kdl/code/hex regex \b(0x[a-fA-F0-9_]+)\b 0:value
add-highlighter shared/kdl/code/decimal regex \b([0-9-+][0-9_]*)\b 0:value
add-highlighter shared/kdl/code/float regex \b([0-9-+][0-9_]*\.[0-9_]+)\b 0:value
add-highlighter shared/kdl/code/float_exp regex \b([0-9-+][0-9_]*(\.[0-9_]+)?[eE][-+]?[0-9_]+)\b 0:value
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden kdl-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden kdl-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 kdl-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 : kdl-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-&> >
>
>
@

View file

@ -0,0 +1,32 @@
# Opinionated rainbow csv implementation
hook global BufCreate .*[.](csv) %{
set-option buffer filetype csv
}
hook global WinSetOption filetype=csv %{
try %{
remove-highlighter window/csv
}
lua %{
rgx = "(^[^\n,]*[,$])?"
-- These colors are designed to match the Everforest Dark colorscheme.
colors = {"blue", "green", "magenta", "rgb:e69875"}
faces = {}
for idx, color in pairs(colors) do
if idx > 1 then
rgx = rgx .. "([^\n,]*[,$])?"
end
faces[idx] = idx .. ":" .. color
end
kak.add_highlighter("window/csv", "regions")
kak.add_highlighter("window/csv/comment", "region", "^", "\n", "group")
kak.add_highlighter("window/csv/comment/", "regex", rgx, table.unpack(faces))
}
}
hook global WinSetOption filetype=(?!csv).* %{
try %{
remove-highlighter window/csv
}
}

View file

@ -0,0 +1,116 @@
hook global BufCreate .*/\.ssh/config %{
set-option buffer filetype ssh
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=ssh %{
require-module ssh
set-option window static_words %opt{ssh_static_words}
hook window InsertChar \n -group ssh-insert ssh-insert-on-new-line
hook window InsertChar \n -group ssh-indent ssh-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ssh-.+ }
}
hook -group ssh-highlight global WinSetOption filetype=ssh %{
add-highlighter window/ssh ref ssh
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ssh }
}
provide-module ssh %@
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/ssh regions
add-highlighter shared/ssh/code default-region group
add-highlighter shared/ssh/double_string region %{(?<!\\)(?:\\\\)*\K"} %{(?<!\\)(?:\\\\)*"} group
add-highlighter shared/ssh/single_string region %{(?<!\\)(?:\\\\)*\K'} %{'} fill string
add-highlighter shared/ssh/comment region (?<!\\)(?:\\\\)*(?:^|\h)\K# '$' fill comment
add-highlighter shared/ssh/double_string/fill fill string
evaluate-commands %sh{
keywords="AddKeysToAgent AddressFamily AskPassGUI BatchMode BindAddress CanonicalDomains CanonicalizeFallbackLocal CanonicalizeHostname
CanonicalizeMaxDots CanonicalizePermittedCNAMEs ChallengeResponseAuthentication CheckHostIP Cipher Ciphers ClearAllForwardings
Compression CompressionLevel ConnectionAttempts ConnectTimeout ControlMaster ControlPath ControlPersist DynamicForward
EnableSSHKeysign EscapeChar ExitOnForwardFailure FingerprintHash ForwardAgent ForwardX11 ForwardX11Timeout ForwardX11Trusted
GatewayPorts GlobalKnownHostsFile GSSAPIAuthentication GSSAPIClientIdentity GSSAPIDelegateCredentials GSSAPIKeyExchange
GSSAPIRenewalForcesRekey GSSAPIServerIdentity GSSAPITrustDns HashKnownHosts Host HostbasedAuthentication HostbasedKeyTypes
HostKeyAlgorithms HostKeyAlias HostName IdentitiesOnly IdentityFile IgnoreUnknown IPQoS KbdInteractiveAuthentication
KbdInteractiveDevices KexAlgorithms KeychainIntegration LocalCommand LocalForward LogLevel MACs Match NoHostAuthenticationForLocalhost
NumberOfPasswordPrompts PasswordAuthentication PermitLocalCommand PKCS11Provider Port PreferredAuthentications Protocol ProxyCommand
ProxyJump ProxyUseFdpass PubkeyAuthentication RekeyLimit RemoteForward RequestTTY RevokedHostKeys RhostsRSAAuthentication
RSAAuthentication SendEnv ServerAliveCountMax ServerAliveInterval SmartcardDevice StreamLocalBindMask StreamLocalBindUnlink
StrictHostKeyChecking TCPKeepAlive Tunnel TunnelDevice UpdateHostKeys UseKeychain UsePrivilegedPort User UserKnownHostsFile
VerifyHostKeyDNS VisualHostKey XAuthLocation"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
printf %s\\n "declare-option str-list ssh_static_words $(join "${keywords}" ' ') $(join "${builtins}" ' ')"
printf %s\\n "add-highlighter shared/ssh/code/ regex (?<!-)\b($(join "${keywords}" '|'))\b(?!-) 0:keyword"
}
add-highlighter shared/ssh/code/ regex ^host\s+ 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden ssh-insert-on-new-line %{ evaluate-commands -itersel -draft %{
execute-keys <semicolon>
try %{
evaluate-commands -draft -save-regs '/"' %{
# Ensure previous line is a comment
execute-keys -draft kxs^\h*#+\h*<ret>
# now handle the coment continuation logic
try %{
# try and match a regular block comment, copying the prefix
execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ <ret> y
execute-keys -draft P
} catch %{
try %{
# try and match a regular block comment followed by a single
# empty comment line
execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ <ret> y
execute-keys -draft P
} catch %{
try %{
# try and match a pair of empty comment lines, and delete
# them if we match
execute-keys -draft kKx <a-k> ^\h*#+\h*\n\h*#+\h*$ <ret> <a-d>
} catch %{
# finally, we need a special case for a new line inserted
# into a file that consists of a single empty comment - in
# that case we can't expect to copy the trailing whitespace,
# so we add our own
execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$<ret> y
execute-keys -draft P
execute-keys -draft i<space>
}
}
}
}
# trim trailing whitespace on the previous line
try %{ execute-keys -draft k x s\h+$<ret> d }
}
} }
define-command -hidden ssh-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k x s \h+$ <ret> d }
>
>
@