summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorPeter Hercek <phercek@gmail.com>2009-05-12 17:24:59 +0000
committerPeter Hercek <phercek@gmail.com>2009-05-12 17:24:59 +0000
commitb8a331a4a5567251c9616d8f9ad609901bfef170 (patch)
tree924d446bfff0096cba2b8f97bad98f404cbd1273 /ghc
parentf314da8e1877e24c405630c6e8335b8f5bd49778 (diff)
downloadhaskell-b8a331a4a5567251c9616d8f9ad609901bfef170.tar.gz
alow macros to redefine builtin GHCi commands (implements #3084)
Diffstat (limited to 'ghc')
-rw-r--r--ghc/InteractiveUI.hs20
1 files changed, 14 insertions, 6 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 7d9eaca38b..6722722beb 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -127,7 +127,6 @@ builtin_commands = [
("def", keepGoing (defineMacro False), completeExpression),
("def!", keepGoing (defineMacro True), completeExpression),
("delete", keepGoing deleteCmd, noCompletion),
- ("e", keepGoing editFile, completeFilename),
("edit", keepGoing editFile, completeFilename),
("etags", keepGoing createETagsFileCmd, completeFilename),
("force", keepGoing forceCmd, completeExpression),
@@ -753,9 +752,12 @@ lookupCommand str = do
Nothing -> BadCommand
lookupCommand' :: String -> IO (Maybe Command)
-lookupCommand' str = do
+lookupCommand' ":" = return Nothing
+lookupCommand' str' = do
macros <- readIORef macros_ref
- let cmds = builtin_commands ++ macros
+ let{ (str, cmds) = case str' of
+ ':' : rest -> (rest, builtin_commands)
+ _ -> (str', macros ++ builtin_commands) }
-- look for exact match first, then the first prefix match
return $ case [ c | c <- cmds, str == cmdName c ] of
c:_ -> Just c
@@ -934,6 +936,8 @@ chooseEditFile =
fromTarget _ = Nothing -- when would we get a module target?
defineMacro :: Bool{-overwrite-} -> String -> GHCi ()
+defineMacro _ (':':_) =
+ io $ putStrLn "macro name cannot start with a colon"
defineMacro overwrite s = do
let (macro_name, definition) = break isSpace s
macros <- io (readIORef macros_ref)
@@ -1627,9 +1631,13 @@ ghciCompleteWord line@(left,_) = case firstWord of
Nothing -> return completeFilename
completeCmd = wrapCompleter " " $ \w -> do
- cmds <- liftIO $ readIORef macros_ref
- return (filter (w `isPrefixOf`) (map (':':)
- (map cmdName (builtin_commands ++ cmds))))
+ macros <- liftIO $ readIORef macros_ref
+ let macro_names = map (':':) . map cmdName $ macros
+ let command_names = map (':':) . map cmdName $ builtin_commands
+ let{ candidates = case w of
+ ':' : ':' : _ -> map (':':) command_names
+ _ -> nub $ macro_names ++ command_names }
+ return $ filter (w `isPrefixOf`) candidates
completeMacro = wrapIdentCompleter $ \w -> do
cmds <- liftIO $ readIORef macros_ref