2014-07-21 00:19:52 +02:00
|
|
|
# http://haskell.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](hs) %{
|
|
|
|
set buffer filetype haskell
|
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/ regions -default code haskell \
|
2017-10-08 06:17:18 +02:00
|
|
|
string '(?<!\'\\)(?<!\')"' (?<!\\)(\\\\)*" '' \
|
|
|
|
macro ^\h*?\K# (?<!\\)\n '' \
|
|
|
|
pragma \{-# '#-\}' \{- \
|
|
|
|
comment \{- -\} \{- \
|
|
|
|
comment --(?:[^!#$%&*+./<>?@\\\^|~=]|$) $ ''
|
2014-07-21 00:19:52 +02:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
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
|
2014-07-21 00:19:52 +02:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex (?<!')\b0x+[A-Fa-f0-9]+ 0:value
|
|
|
|
add-highlighter shared/haskell/code regex (?<!')\b\d+([.]\d+)? 0:value
|
|
|
|
add-highlighter shared/haskell/code regex (?<!')\b(import|hiding|qualified|module)(?!')\b 0:keyword
|
|
|
|
add-highlighter shared/haskell/code regex (?<!')\b(import)(?!')\b[^\n]+(?<!')\b(as)(?!')\b 2:keyword
|
|
|
|
add-highlighter shared/haskell/code regex (?<!')\b(class|data|default|deriving|infix|infixl|infixr|instance|module|newtype|pattern|type|where)(?!')\b 0:keyword
|
|
|
|
add-highlighter shared/haskell/code regex (?<!')\b(case|do|else|if|in|let|mdo|of|proc|rec|then)(?!')\b 0:attribute
|
2017-05-15 21:45:05 +02:00
|
|
|
|
|
|
|
# The complications below is because period has many uses:
|
|
|
|
# As function composition operator (possibly without spaces) like "." and "f.g"
|
|
|
|
# Hierarchical modules like "Data.Maybe"
|
|
|
|
# Qualified imports like "Data.Maybe.Just", "Data.Maybe.maybe", "Control.Applicative.<$>"
|
|
|
|
# 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
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex \b([A-Z]['\w]*\.)*[A-Z]['\w]*(?!\.) 0:variable
|
2017-05-15 21:45:05 +02:00
|
|
|
|
|
|
|
# matches infix identifier: `mod` `Apa._T'M`
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex `\b([A-Z]['\w]*\.)*[\w]['\w]*` 0:operator
|
2017-05-15 21:45:05 +02:00
|
|
|
# matches imported operators: M.! M.. Control.Monad.>>
|
|
|
|
# not operator keywords: M... M.->
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex \b[A-Z]['\w]*\.[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator
|
2017-05-15 21:45:05 +02:00
|
|
|
# matches dot: .
|
|
|
|
# not possibly incomplete import: a.
|
|
|
|
# not other operators: !. .!
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex (?<![\w~<=>|:!?/.@$*&#%+\^\-\\])\.(?![~<=>|:!?/.@$*&#%+\^\-\\]) 0:operator
|
2017-05-15 21:45:05 +02:00
|
|
|
# matches other operators: ... > < <= ^ <*> <$> etc
|
|
|
|
# not dot: .
|
|
|
|
# not operator keywords: @ .. -> :: ~
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex (?<![~<=>|:!?/.@$*&#%+\^\-\\])[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator
|
2017-05-15 21:45:05 +02:00
|
|
|
|
|
|
|
# matches operator keywords: @ ->
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex (?<![~<=>|:!?/.@$*&#%+\^\-\\])(@|~|<-|->|=>|::|=|:|[|])(?![~<=>|:!?/.@$*&#%+\^\-\\]) 1:keyword
|
2017-05-15 21:45:05 +02:00
|
|
|
# matches: forall [..variables..] .
|
|
|
|
# not the variables
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex \b(forall)\b[^.\n]*?(\.) 1:keyword 2:keyword
|
2017-05-15 21:45:05 +02:00
|
|
|
|
|
|
|
# matches 'x' '\\' '\'' '\n' '\0'
|
|
|
|
# not incomplete literals: '\'
|
|
|
|
# not valid identifiers: w' _'
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/haskell/code regex \B'([^\\]|[\\]['"\w\d\\])' 0:string
|
2017-05-15 21:45:05 +02:00
|
|
|
# this has to come after operators so '-' etc is correct
|
2014-07-21 00:19:52 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# http://en.wikibooks.org/wiki/Haskell/Indentation
|
|
|
|
|
2017-01-13 01:56:30 +01:00
|
|
|
def -hidden haskell-filter-around-selections %{
|
2015-11-04 10:48:47 +01:00
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
|
2014-07-21 00:19:52 +02:00
|
|
|
}
|
|
|
|
|
2017-01-13 01:56:30 +01:00
|
|
|
def -hidden haskell-indent-on-new-line %{
|
2014-07-21 00:19:52 +02:00
|
|
|
eval -draft -itersel %{
|
2017-01-11 14:56:48 +01:00
|
|
|
# copy -- comments prefix and following white spaces
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
|
2014-07-21 00:19:52 +02:00
|
|
|
# preserve previous line indent
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft \; K <a-&> }
|
2014-07-21 00:19:52 +02:00
|
|
|
# align to first clause
|
2017-09-29 04:39:59 +02:00
|
|
|
try %{ exec -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|do|let|where)\h+\K.* <ret> s \A|.\z <ret> & }
|
2014-07-21 00:19:52 +02:00
|
|
|
# filter previous line
|
2017-01-13 01:56:30 +01:00
|
|
|
try %{ exec -draft k : haskell-filter-around-selections <ret> }
|
2014-07-21 00:19:52 +02:00
|
|
|
# indent after lines beginning with condition or ending with expression or =(
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft \; k x <a-k> ^\h*(if)|(case\h+[\w']+\h+of|do|let|where|[=(])$ <ret> j <a-gt> }
|
2014-07-21 00:19:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group haskell-highlight global WinSetOption filetype=haskell %{ add-highlighter window ref haskell }
|
2014-07-21 00:19:52 +02:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook global WinSetOption filetype=haskell %{
|
2017-06-26 16:28:41 +02:00
|
|
|
set window extra_word_chars "'"
|
2017-01-13 01:56:30 +01:00
|
|
|
hook window InsertEnd .* -group haskell-hooks haskell-filter-around-selections
|
|
|
|
hook window InsertChar \n -group haskell-indent haskell-indent-on-new-line
|
2014-07-21 00:19:52 +02:00
|
|
|
}
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group haskell-highlight global WinSetOption filetype=(?!haskell).* %{ remove-highlighter window/haskell }
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2014-07-21 00:19:52 +02:00
|
|
|
hook global WinSetOption filetype=(?!haskell).* %{
|
2017-01-04 01:07:45 +01:00
|
|
|
remove-hooks window haskell-indent
|
|
|
|
remove-hooks window haskell-hooks
|
2014-07-21 00:19:52 +02:00
|
|
|
}
|