# http://haskell.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](hs) %{ set-option buffer filetype haskell } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ regions -default code haskell \ string '(??@\\\^|~=]|$) $ '' add-highlighter shared/haskell/string fill string add-highlighter shared/haskell/comment fill comment add-highlighter shared/haskell/pragma fill meta add-highlighter shared/haskell/macro fill meta 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]*(?!\.) 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 # Commands # ‾‾‾‾‾‾‾‾ # http://en.wikibooks.org/wiki/Haskell/Indentation define-command -hidden haskell-filter-around-selections %{ # remove trailing white spaces try %{ execute-keys -draft -itersel s \h+$ d } } define-command -hidden haskell-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } # 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-filter-around-selections } # indent after lines beginning with condition or ending with expression or =( try %{ execute-keys -draft \; k x ^\h*(if)|(case\h+[\w']+\h+of|do|let|where|[=(])$ j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group haskell-highlight global WinSetOption filetype=haskell %{ add-highlighter window ref haskell } hook global WinSetOption filetype=haskell %{ set-option window extra_word_chars "'" hook window InsertEnd .* -group haskell-hooks haskell-filter-around-selections hook window InsertChar \n -group haskell-indent haskell-indent-on-new-line } hook -group haskell-highlight global WinSetOption filetype=(?!haskell).* %{ remove-highlighter window/haskell } hook global WinSetOption filetype=(?!haskell).* %{ remove-hooks window haskell-indent remove-hooks window haskell-hooks }