From e71c0818e3c5d7b0f8a681f887b6ee00532948a9 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Fri, 19 Oct 2007 11:57:51 +0000 Subject: [PATCH] implement #1468, :browse on its own uses the currently-loaded module --- compiler/ghci/InteractiveUI.hs | 30 +++++++++++++++++++++--------- docs/users_guide/ghci.xml | 15 +++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index 0ac7e1c..d524ff1 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -164,7 +164,7 @@ helpText = "\n" ++ " evaluate/run \n" ++ " :add ... add module(s) to the current target set\n" ++ - " :browse [*] display the names defined by \n" ++ + " :browse [[*]] display the names defined by \n" ++ " :cd change directory to \n" ++ " :cmd run the commands returned by ::IO String\n" ++ " :ctags [] create tags file for Vi (default: \"tags\")\n" ++ @@ -1025,16 +1025,27 @@ shellEscape str = io (system str >> return False) browseCmd :: String -> GHCi () browseCmd m = case words m of - ['*':m] | looksLikeModuleName m -> browseModule m False - [m] | looksLikeModuleName m -> browseModule m True + ['*':s] | looksLikeModuleName s -> do + m <- wantInterpretedModule s + browseModule m False + [s] | looksLikeModuleName s -> do + m <- lookupModule s + browseModule m True + [] -> do + s <- getSession + (as,bs) <- io $ GHC.getContext s + -- Guess which module the user wants to browse. Pick + -- modules that are interpreted first. The most + -- recently-added module occurs last, it seems. + case (as,bs) of + (as@(_:_), _) -> browseModule (last as) True + ([], bs@(_:_)) -> browseModule (last bs) True + ([], []) -> throwDyn (CmdLineError ":browse: no current module") _ -> throwDyn (CmdLineError "syntax: :browse ") -browseModule :: String -> Bool -> GHCi () -browseModule m exports_only = do +browseModule :: Module -> Bool -> GHCi () +browseModule modl exports_only = do s <- getSession - modl <- if exports_only then lookupModule m - else wantInterpretedModule m - -- Temporarily set the context to the module we're interested in, -- just so we can get an appropriate PrintUnqualified (as,bs) <- io (GHC.getContext s) @@ -1046,7 +1057,8 @@ browseModule m exports_only = do mb_mod_info <- io $ GHC.getModuleInfo s modl case mb_mod_info of - Nothing -> throwDyn (CmdLineError ("unknown module: " ++ m)) + Nothing -> throwDyn (CmdLineError ("unknown module: " ++ + GHC.moduleNameString (GHC.moduleName modl))) Just mod_info -> do let names | exports_only = GHC.modInfoExports mod_info diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index 579cf23..e7bd8c2 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -1680,17 +1680,20 @@ $ ghci -lm - :browse *module ... + :browse *module ... :browse Displays the identifiers defined by the module module, which must be either - loaded into GHCi or be a member of a package. If the - * symbol is placed before the module - name, then all the identifiers defined - in module are shown; otherwise - the list is limited to the exports of + loaded into GHCi or be a member of a package. If + module is omitted, the most + recently-loaded module is used. + + If the * symbol is placed before + the module name, then all the + identifiers in scope in module are + shown; otherwise the list is limited to the exports of module. The *-form is only available for modules which are interpreted; for compiled modules (including -- 1.7.10.4