Ticket #3858: 0001-prefer-later-defined-commands-fixes-3858.patch

File 0001-prefer-later-defined-commands-fixes-3858.patch, 2.5 KB (added by phercek, 3 years ago)

patch implementing the proposed solution (more recent commands have precedence)

  • ghc/InteractiveUI.hs

    From 33eef8b888dc30d5cae9cbfbc061902f13445d59 Mon Sep 17 00:00:00 2001
    From: Peter Hercek <[email protected]>
    Date: Tue, 15 May 2012 16:02:48 +0200
    Subject: [PATCH] prefer later defined commands (fixes #3858)
    
    ---
     ghc/InteractiveUI.hs |   14 ++++++--------
     1 file changed, 6 insertions(+), 8 deletions(-)
    
    diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
    index efafd25..6d72cf1 100644
    a b helpText = 
    207207  "   :cmd <expr>                 run the commands returned by <expr>::IO String\n" ++
    208208  "   :ctags[!] [<file>]          create tags file for Vi (default: \"tags\")\n" ++
    209209  "                               (!: use regex instead of line number)\n" ++
    210   "   :def <cmd> <expr>           define a command :<cmd>\n" ++
     210  "   :def <cmd> <expr>           define command :<cmd> (later defined command has\n" ++
     211  "                               precedence, ::<cmd> is always a builtin command)\n" ++
    211212  "   :edit <file>                edit file\n" ++
    212213  "   :edit                       edit last module\n" ++
    213214  "   :etags [<file>]             create tags file for Emacs (default: \"TAGS\")\n" ++
    lookupCommand' ":" = return Nothing 
    891892lookupCommand' str' = do
    892893  macros <- readIORef macros_ref
    893894  let{ (str, cmds) = case str' of
    894       ':' : rest -> (rest, builtin_commands)
    895       _ -> (str', builtin_commands ++ macros) }
     895      ':' : rest -> (rest, builtin_commands) -- "::" selects a builtin command
     896      _ -> (str', macros ++ builtin_commands) } -- otherwise prefer macros
    896897  -- look for exact match first, then the first prefix match
    897   -- We consider builtin commands first: since new macros are appended
    898   -- on the *end* of the macros list, this is consistent with the view
    899   -- that things defined earlier should take precedence. See also #3858
    900898  return $ case [ c | c <- cmds, str == cmdName c ] of
    901899           c:_ -> Just c
    902900           [] -> case [ c | c@(s,_,_) <- cmds, str `isPrefixOf` s ] of
    defineMacro overwrite s = do 
    11241122  handleSourceError (\e -> GHC.printException e) $
    11251123   do
    11261124    hv <- GHC.compileExpr new_expr
    1127     liftIO (writeIORef macros_ref --
    1128             (filtered ++ [(macro_name, lift . runMacro hv, noCompletion)]))
     1125    liftIO (writeIORef macros_ref -- later defined macros have precedence
     1126            ((macro_name, lift . runMacro hv, noCompletion) : filtered))
    11291127
    11301128runMacro :: GHC.HValue{-String -> IO String-} -> String -> GHCi Bool
    11311129runMacro fun s = do