Created
September 6, 2019 00:39
-
-
Save pema99/94ff3434f56e35d83701bf594731bf99 to your computer and use it in GitHub Desktop.
Bootleg F# language support for Kakoune, use at your own disgression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://fsharp.org | |
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ | |
# Detection | |
# ‾‾‾‾‾‾‾‾‾ | |
hook global BufCreate .*\.(fs|fsi|fsx|fsscript)$ %{ | |
set-option buffer filetype fsharp | |
} | |
# Initialization | |
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ | |
hook global WinSetOption filetype=fsharp %{ | |
require-module fsharp | |
set-option window static_words %opt{fsharp_static_words} | |
hook window InsertChar \n -group fsharp-indent fsharp-indent-on-new-line | |
evaluate-commands %sh{ printf "%s\n" "map window insert <tab> <space><space>" } | |
} | |
hook -group fsharp-highlight global WinSetOption filetype=fsharp %{ | |
add-highlighter window/fsharp ref fsharp | |
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fsharp } | |
} | |
provide-module fsharp %{ | |
# Highlighters | |
# ‾‾‾‾‾‾‾‾‾‾‾‾ | |
add-highlighter shared/fsharp regions | |
add-highlighter shared/fsharp/code default-region group | |
add-highlighter shared/fsharp/string region '"' (?<!\\)(\\\\)*" fill string | |
add-highlighter shared/fsharp/comment region '//' '\n' fill comment | |
add-highlighter shared/fsharp/multiline_comment region \Q(* \Q*) fill comment | |
# Macro | |
# ‾‾‾‾‾ | |
evaluate-commands %sh{ | |
keywords="and|as|asr|assert|begin|class|constraint|do|done|downto|else|end|exception|external|false" | |
keywords="${keywords}|for|fun|function|functor|if|in|include|inherit|initializer|land|lazy|let|lor" | |
keywords="${keywords}|lsl|lsr|lxor|match|method|mod|module|mutable|new|nonrec|object|of|open|or" | |
keywords="${keywords}|private|rec|sig|struct|then|to|true|try|type|val|virtual|when|while|with" | |
printf %s\\n "declare-option str-list fsharp_static_words ${keywords}" | tr '|' ' ' | |
printf %s " | |
add-highlighter shared/fsharp/code/ regex \b(${keywords})\b 0:keyword | |
" | |
} | |
define-command -hidden fsharp-indent-on-new-line %{ | |
evaluate-commands -draft -itersel %{ | |
# preserve previous line indent | |
try %{ execute-keys -draft \; K <a-&> } | |
# cleanup trailing whitespaces from previous line | |
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d } | |
# indent after line ending with : | |
try %{ execute-keys -draft <space> k <a-x> <a-k> :$ <ret> j <a-gt> } | |
} | |
} | |
# integer literals | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b[1-9]('?\d+)*(ul?l?|ll?u?)?\b(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b0b[01]('?[01]+)*(ul?l?|ll?u?)?\b(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b0('?[0-7]+)*(ul?l?|ll?u?)?\b(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b0x[\da-f]('?[\da-f]+)*(ul?l?|ll?u?)?\b(?!\.)} 0:value | |
# floating point literals | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b\d('?\d+)*\.([fl]\b|\B)(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b\d('?\d+)*\.?e[+-]?\d('?\d+)*[fl]?\b(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)(\b(\d('?\d+)*)|\B)\.\d('?[\d]+)*(e[+-]?\d('?\d+)*)?[fl]?\b(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b0x[\da-f]('?[\da-f]+)*\.([fl]\b|\B)(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b0x[\da-f]('?[\da-f]+)*\.?p[+-]?\d('?\d+)*)?[fl]?\b(?!\.)} 0:value | |
add-highlighter shared/fsharp/code/ regex %{(?i)(?<!\.)\b0x([\da-f]('?[\da-f]+)*)?\.\d('?[\d]+)*(p[+-]?\d('?\d+)*)?[fl]?\b(?!\.)} 0:value | |
# character literals (no multi-character literals) | |
add-highlighter shared/fsharp/code/char regex %{(\b(u8|u|U|L)|\B)'((\\.)|[^'\\])'\B} 0:value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment