diff options
author | Peter Hercek <phercek@gmail.com> | 2012-05-15 16:02:48 +0200 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2012-07-04 09:08:26 +0100 |
commit | ad16de235c7ea9a9be65c77c576dd548251ddb16 (patch) | |
tree | 19ebc164d0b1956cb95bfbb0ab30b7a2966adf8b /ghc | |
parent | 0d19922acd724991b7b97871b1404f3db5058b49 (diff) | |
download | haskell-ad16de235c7ea9a9be65c77c576dd548251ddb16.tar.gz |
prefer later defined commands (fixes #3858)
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/InteractiveUI.hs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs index d9d6bc235e..1dc203d4ad 100644 --- a/ghc/InteractiveUI.hs +++ b/ghc/InteractiveUI.hs @@ -209,7 +209,8 @@ helpText = " :cmd <expr> run the commands returned by <expr>::IO String\n" ++ " :ctags[!] [<file>] create tags file for Vi (default: \"tags\")\n" ++ " (!: use regex instead of line number)\n" ++ - " :def <cmd> <expr> define a command :<cmd>\n" ++ + " :def <cmd> <expr> define command :<cmd> (later defined command has\n" ++ + " precedence, ::<cmd> is always a builtin command)\n" ++ " :edit <file> edit file\n" ++ " :edit edit last module\n" ++ " :etags [<file>] create tags file for Emacs (default: \"TAGS\")\n" ++ @@ -908,12 +909,9 @@ lookupCommand' ":" = return Nothing lookupCommand' str' = do macros <- readIORef macros_ref let{ (str, cmds) = case str' of - ':' : rest -> (rest, builtin_commands) - _ -> (str', builtin_commands ++ macros) } + ':' : rest -> (rest, builtin_commands) -- "::" selects a builtin command + _ -> (str', macros ++ builtin_commands) } -- otherwise prefer macros -- look for exact match first, then the first prefix match - -- We consider builtin commands first: since new macros are appended - -- on the *end* of the macros list, this is consistent with the view - -- that things defined earlier should take precedence. See also #3858 return $ case [ c | c <- cmds, str == cmdName c ] of c:_ -> Just c [] -> case [ c | c@(s,_,_) <- cmds, str `isPrefixOf` s ] of @@ -1142,8 +1140,8 @@ defineMacro overwrite s = do handleSourceError (\e -> GHC.printException e) $ do hv <- GHC.compileExpr new_expr - liftIO (writeIORef macros_ref -- - (filtered ++ [(macro_name, lift . runMacro hv, noCompletion)])) + liftIO (writeIORef macros_ref -- later defined macros have precedence + ((macro_name, lift . runMacro hv, noCompletion) : filtered)) runMacro :: GHC.HValue{-String -> IO String-} -> String -> GHCi Bool runMacro fun s = do |