module Yi.Config.Users.Corey (config) where
import Yi
import Yi.Keymap.Vim
import Yi.Buffer.Indent (indentAsPreviousB)
import Yi.Keymap.Keys
import Yi.Misc (adjBlock)
import Yi.Style.Library (darkBlueTheme)
import Data.List (isPrefixOf)
import Control.Monad (replicateM_)
import Control.Applicative
prefIndent :: Mode s -> Mode s
prefIndent m = m {
modeIndentSettings = IndentSettings
{
expandTabs = True,
shiftWidth = 4,
tabSize = 4
}}
noHaskellAnnots m
| modeName m == "haskell" = m { modeGetAnnotations = modeGetAnnotations emptyMode }
| otherwise = m
config = defaultConfig
{
defaultKm = mkKeymap extendedVimKeymap,
modeTable = fmap (onMode $ noHaskellAnnots . prefIndent) (modeTable defaultConfig),
configUI = (configUI defaultConfig)
{
configTheme = darkBlueTheme
}
}
extendedVimKeymap = defKeymap `override` \super self -> super
{
v_top_level =
(deprioritize >> v_top_level super)
<|> (char 'o' ?>> beginIns self $ do
moveToEol
insertB '\n'
indentAsPreviousB
)
<|> ( pString "HXL" >> startExtesnionNameInsert self ),
v_ins_char =
(deprioritize >> v_ins_char super)
<|> ( spec KEnter ?>>! do
insertB '\n'
indentAsPreviousB
)
<|> ( spec KBS ?>>! do
c <- curCol
line <- readRegionB =<< regionOfPartB Line Backward
sw <- indentSettingsB >>= return . shiftWidth
let indentStr = replicate sw ' '
toDel = if (c `mod` sw) /= 0
then 1
else if indentStr `isPrefixOf` reverse line
then sw
else 1
adjBlock (toDel)
replicateM_ toDel $ deleteB Character Backward
)
<|> choice
[ pString open_tag >>! do
insertN $ open_tag ++ " \n"
indentAsPreviousB
insertN $ " " ++ close_tag
lineUp
| (open_tag, close_tag) <-
[ ("{-", "-}")
, ("/*", "*/")
]
]
}
startExtesnionNameInsert :: ModeMap -> I Event Action ()
startExtesnionNameInsert self = beginIns self $ do
p_current <- pointB
m_current <- getMarkB (Just "'")
setMarkPointB m_current p_current
moveTo $ Point 0
insertB '\n'
moveTo $ Point 0
insertN "{-# LANGUAGE "
p <- pointB
insertN " #-}"
moveTo p