summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2007-05-17 11:05:55 +0000
committerSimon Marlow <simonmar@microsoft.com>2007-05-17 11:05:55 +0000
commit622e67a80631c7528ebfa51e9a863c27e74f1c6b (patch)
treea176512512572e79610e4d49e45c51bb84f5f8d0 /compiler
parent79fb37d4fe333f5c3dd7f08a6df102aed05394d9 (diff)
downloadhaskell-622e67a80631c7528ebfa51e9a863c27e74f1c6b.tar.gz
add :cmd
:cmd <expr> executes <expr> :: IO String, takes the resulting string and executes it as a sequence of commands. This is useful for doing macro-ish things with ":set stop", for example.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ghci/InteractiveUI.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs
index 956d206a54..4fb92692d1 100644
--- a/compiler/ghci/InteractiveUI.hs
+++ b/compiler/ghci/InteractiveUI.hs
@@ -110,6 +110,7 @@ builtin_commands = [
("cd", keepGoing changeDirectory, False, completeFilename),
("check", keepGoing checkModule, False, completeHomeModule),
("continue", keepGoing continueCmd, False, completeNone),
+ ("cmd", keepGoing cmdCmd, False, completeIdentifier),
("ctags", keepGoing createCTagsFileCmd, False, completeFilename),
("def", keepGoing defineMacro, False, completeIdentifier),
("delete", keepGoing deleteCmd, False, completeNone),
@@ -154,6 +155,7 @@ helpText =
" :add <filename> ... add module(s) to the current target set\n" ++
" :browse [*]<module> display the names defined by <module>\n" ++
" :cd <dir> change directory to <dir>\n" ++
+ " :cmd <expr> run the commands returned by <expr>::IO String"++
" :ctags [<file>] create tags file for Vi (default: \"tags\")\n" ++
" :def <cmd> <expr> define a command :<cmd>\n" ++
" :edit <file> edit file\n" ++
@@ -782,6 +784,17 @@ undefineMacro macro_name = do
else do
io (writeIORef commands (filter ((/= macro_name) . cmdName) cmds))
+cmdCmd :: String -> GHCi ()
+cmdCmd str = do
+ let expr = '(' : str ++ ") :: IO String"
+ session <- getSession
+ maybe_hv <- io (GHC.compileExpr session expr)
+ case maybe_hv of
+ Nothing -> return ()
+ Just hv -> do
+ cmds <- io $ (unsafeCoerce# hv :: IO String)
+ enqueueCommands (lines cmds)
+ return ()
loadModule :: [(FilePath, Maybe Phase)] -> GHCi SuccessFlag
loadModule fs = timeIt (loadModule' fs)