module IDE.YiConfig (
defaultYiConfig
, Config
, Control
, ControlM
, YiM
, start
, runControl
, liftYi
) where
#ifdef LEKSAH_WITH_YI
import Data.List (reverse, isPrefixOf)
import Yi.Prelude
import Prelude ()
import Yi
import Yi.Keymap.Vim
import qualified Yi.UI.Pango
import Yi.UI.Pango.Control
import Control.Monad (replicateM_)
start yiConfig f =
startControl yiConfig $ do
yiControl <- getControl
controlIO (f yiControl)
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
defaultYiConfig = defaultConfig
{
startFrontEnd = Yi.UI.Pango.start,
defaultKm = mkKeymap extendedVimKeymap,
modeTable = fmap (onMode $ noHaskellAnnots . prefIndent) (modeTable defaultConfig),
configUI = (configUI defaultConfig)
{
configTheme = defaultLightTheme
}
}
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
#else
data Config = Config
data Control = Control
data ControlM a = ControlM
data YiM a = YiM
defaultYiConfig :: Config
defaultYiConfig = Config
start :: Config -> (Control -> IO a) -> IO a
start yiConfig f = f Control
runControl :: ControlM a -> Control -> IO a
runControl = undefined
liftYi :: YiM a -> ControlM a
liftYi = undefined
#endif