module Yi.Mode.GHCi where
import GHC.Generics (Generic)
import Control.Lens (makeLenses, (%~), (&), (.~))
import Data.Binary (Binary (..))
import Data.Default (Default (..))
import Data.Text ()
import qualified Data.Text as T (findIndex)
import Data.Typeable (Typeable)
import Yi.Buffer
import Yi.Keymap (YiM, topKeymapA)
import Yi.Keymap.Keys (Key (KHome), important, spec, (?>>!))
import Yi.Lexer.Alex (Tok)
import Yi.Lexer.Compilation (Token ())
import qualified Yi.Mode.Interactive as I (mode, spawnProcessMode)
import qualified Yi.Rope as R (toText)
import Yi.Syntax.OnlineTree (Tree)
import Yi.Types (YiVariable)
data GhciProcessName = GhciProcessName
{ _ghciProcessName :: FilePath
, _ghciProcessArgs :: [String]
} deriving (Typeable, Show, Generic)
instance Default GhciProcessName where
def = GhciProcessName { _ghciProcessName = "ghci"
, _ghciProcessArgs = []
}
instance Binary GhciProcessName
makeLenses ''GhciProcessName
instance YiVariable GhciProcessName
mode :: Mode (Tree (Tok Token))
mode = I.mode
& modeNameA .~ "ghci"
& modeKeymapA .~ topKeymapA %~ important (spec KHome ?>>! homeKey)
homeKey :: BufferM ()
homeKey = readLnB >>= \l -> case T.findIndex ('>' ==) (R.toText l) of
Nothing -> moveToSol
Just pos -> do
(_,mypos) <- getLineAndCol
moveToSol >> if mypos == (pos + 2)
then return ()
else moveXorEol (pos + 2)
spawnProcess :: FilePath
-> [String]
-> YiM BufferRef
spawnProcess = I.spawnProcessMode mode