module Yi.Mode.GHCi where
import Control.Lens
import Data.List (elemIndex)
import Yi.Core
import Yi.Lexer.Alex (Tok)
import Yi.Lexer.Compilation (Token())
import qualified Yi.Syntax.OnlineTree as OnlineTree
import qualified Yi.Mode.Interactive as I
mode :: Mode (OnlineTree.Tree (Tok Token))
mode = I.mode
{ modeName = "ghci",
modeKeymap = (topKeymapA %~ (choice [spec KHome ?>>! homeKey] <||)) . modeKeymap I.mode
}
homeKey :: BufferM ()
homeKey = do l <- readLnB
let epos = elemIndex '>' l
case epos of
Nothing -> moveToSol
Just pos -> do (_,mypos) <- getLineAndCol
if mypos == (pos+2) then moveToSol
else moveToSol >> moveXorEol (pos+2)
spawnProcess :: FilePath -> [String] -> YiM BufferRef
spawnProcess = I.spawnProcessMode mode