Adding :m + and :m -. Closes #298.

This commit is contained in:
Andrew Gibiansky 2015-02-11 21:56:13 -08:00
parent 7bff2be3f4
commit 20aa688a9a
3 changed files with 32 additions and 1 deletions

View File

@ -452,6 +452,22 @@ evalCommand output (Directive SetExtension opts) state = do
let set = concatMap (" -X" ++) $ words opts
evalCommand output (Directive SetDynFlag set) state
evalCommand output (Directive LoadModule mods) state = wrapExecution state $ do
write $ "Load Module: " ++ mods
let stripped@(firstChar:remainder) = mods
(modules, removeModule) =
case firstChar of
'+' -> (words remainder, False)
'-' -> (words remainder, True)
_ -> (words stripped, False)
forM_ modules $ \modl ->
if removeModule
then removeImport modl
else evalImport $ "import " ++ modl
return mempty
evalCommand a (Directive SetOption opts) state = do
write $ "Option: " ++ opts
let (existing, nonExisting) = partition optionExists $ words opts

View File

@ -67,6 +67,7 @@ data DirectiveType
| SearchHoogle -- ^ Search for something via Hoogle.
| GetDoc -- ^ Get documentation for an identifier via Hoogle.
| GetKind -- ^ Get the kind of a type via ':kind'.
| LoadModule -- ^ Load and unload modules via ':module'.
deriving (Show, Eq)
-- | Pragma types. Only LANGUAGE pragmas are currently supported.
@ -268,7 +269,8 @@ parseDirective (':':directive) line = case find rightDirective directives of
[] -> False
dir:_ -> dir `elem` tail (inits dirname)
directives =
[ (GetType, "type")
[ (LoadModule, "module")
, (GetType, "type")
, (GetKind, "kind")
, (GetInfo, "info")
, (SearchHoogle, "hoogle")

View File

@ -11,6 +11,7 @@ module IHaskell.Eval.Util (
-- * Code Evaluation
evalImport,
removeImport,
evalDeclarations,
getType,
getDescription,
@ -196,6 +197,18 @@ evalImport imports = do
Just (True, _) -> True
_ -> False
removeImport :: GhcMonad m => String -> m ()
removeImport moduleName = do
flags <- getSessionDynFlags
ctx <- getContext
let ctx' = filter (not . (isImportOf $ mkModuleName moduleName)) ctx
setContext ctx'
where
isImportOf :: ModuleName -> InteractiveImport -> Bool
isImportOf name (IIModule modName) = name == modName
isImportOf name (IIDecl impDecl) = name == unLoc (ideclName impDecl)
-- | Evaluate a series of declarations.
-- Return all names which were bound by these declarations.
evalDeclarations :: GhcMonad m => String -> m [String]