From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/haskell.kak | 127 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 autoload/filetype/haskell.kak (limited to 'autoload/filetype/haskell.kak') diff --git a/autoload/filetype/haskell.kak b/autoload/filetype/haskell.kak new file mode 100644 index 0000000..9beed99 --- /dev/null +++ b/autoload/filetype/haskell.kak @@ -0,0 +1,127 @@ +# http://haskell.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](hs) %{ + set-option buffer filetype haskell +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=haskell %{ + require-module haskell + + set-option buffer extra_word_chars '_' "'" + hook window ModeChange pop:insert:.* -group haskell-trim-indent haskell-trim-indent + hook window InsertChar \n -group haskell-insert haskell-insert-on-new-line + hook window InsertChar \n -group haskell-indent haskell-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haskell-.+ } +} + +hook -group haskell-highlight global WinSetOption filetype=haskell %{ + add-highlighter window/haskell ref haskell + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haskell } +} + + +provide-module haskell %[ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/haskell regions +add-highlighter shared/haskell/code default-region group +add-highlighter shared/haskell/string region (??@\\\^|~=]) $ fill comment +add-highlighter shared/haskell/quasiquote region \[\b[_a-z]['\w]*#?\| \|\] regex \[\b[_a-z]['\w]*#?\|(.*?)\|\] 1:string + +add-highlighter shared/haskell/code/ regex (?" +# Quantifier separator in "forall a . [a] -> [a]" +# Enum comprehensions like "[1..]" and "[a..b]" (making ".." and "Module..." illegal) + +# matches uppercase identifiers: Monad Control.Monad +# not non-space separated dot: Just.const +add-highlighter shared/haskell/code/ regex \b([A-Z]['\w]*\.)*[A-Z]['\w]*(?!['\w])(?![.a-z]) 0:variable + +# matches infix identifier: `mod` `Apa._T'M` +add-highlighter shared/haskell/code/ regex `\b([A-Z]['\w]*\.)*[\w]['\w]*` 0:operator +# matches imported operators: M.! M.. Control.Monad.>> +# not operator keywords: M... M.-> +add-highlighter shared/haskell/code/ regex \b[A-Z]['\w]*\.[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator +# matches dot: . +# not possibly incomplete import: a. +# not other operators: !. .! +add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])\.(?![~<=>|:!?/.@$*&#%+\^\-\\]) 0:operator +# matches other operators: ... > < <= ^ <*> <$> etc +# not dot: . +# not operator keywords: @ .. -> :: ~ +add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator + +# matches operator keywords: @ -> +add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])(@|~|<-|->|=>|::|=|:|[|])(?![~<=>|:!?/.@$*&#%+\^\-\\]) 1:keyword +# matches: forall [..variables..] . +# not the variables +add-highlighter shared/haskell/code/ regex \b(forall|∀)\b[^.\n]*?(\.) 1:keyword 2:keyword + +# matches 'x' '\\' '\'' '\n' '\0' +# not incomplete literals: '\' +# not valid identifiers: w' _' +add-highlighter shared/haskell/code/ regex \B'([^\\]|[\\]['"\w\d\\])' 0:string +# this has to come after operators so '-' etc is correct + +# matches function names in type signatures +add-highlighter shared/haskell/code/ regex ^\s*(?:where\s+|let\s+|default\s+)?([_a-z]['\w]*#?(?:,\s*[_a-z]['\w]*#?)*)\s+::\s 1:meta + +# matches deriving strategies +add-highlighter shared/haskell/code/ regex \bderiving\s+\b(stock|newtype|anyclass|via)\b 1:keyword +add-highlighter shared/haskell/code/ regex \bderiving\b\s+(?:[A-Z]['\w]+|\([',\w\s]+?\))\s+\b(via)\b 1:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +# http://en.wikibooks.org/wiki/Haskell/Indentation + +define-command -hidden haskell-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel x s \h+$ d } +} + +define-command -hidden haskell-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden haskell-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # align to first clause + try %{ execute-keys -draft k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|do|let|where)\h+\K.* s \A|.\z & } + # filter previous line + try %{ execute-keys -draft k : haskell-trim-indent } + # indent after lines beginning with condition or ending with expression or =( + try %{ execute-keys -draft k x ^\h*if|[=(]$|\b(case\h+[\w']+\h+of|do|let|where)$ j } + } +} + +] -- cgit v1.2.3