From 2a86d5c7db21b39673aa8f4ba2c6aee714719262 Mon Sep 17 00:00:00 2001 From: Max Bolingbroke Date: Sat, 2 Apr 2011 23:59:06 +0100 Subject: [PATCH] Prefer builtin commands to macros in GHCi command resolution (#3858) Current precedence rules in GHCi are that: * User macros are *always* preferred in command resolution * User macros that are defined earlier are preferred to those that are defined earlier on * Builtin commands have lowest precedence However this caused user confusion because e.g. defining a macro beginning with "i" would override the standard :info command whenever the user typed the abbreviated command :i. The new precedence rules are based on the view that things defined earlier are always preferred to things defined later. The builtin commands are logically defined earliest of all (when GHCi starts) so they always take precedence. --- ghc/InteractiveUI.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs index 3062133..2685377 100644 --- a/ghc/InteractiveUI.hs +++ b/ghc/InteractiveUI.hs @@ -848,8 +848,11 @@ lookupCommand' str' = do macros <- readIORef macros_ref let{ (str, cmds) = case str' of ':' : rest -> (rest, builtin_commands) - _ -> (str', macros ++ builtin_commands) } + _ -> (str', builtin_commands ++ 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 -- 1.7.10.4