diff options
author | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-11 14:34:25 +0100 |
---|---|---|
committer | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-11 18:03:02 +0100 |
commit | 76bde331226e933b65b6433e983c50da1ce3b532 (patch) | |
tree | e404e7e3f8e45a2591ed49ccbee65c7027444066 | |
parent | ab52df86f5f76da6e19ee6562792ea43972a6f24 (diff) | |
download | haskell-76bde331226e933b65b6433e983c50da1ce3b532.tar.gz |
Add support for additional .ghci files in GHCi (#5265)
Patch by Sam Anklesaria <amsay@amsay.net>
-rw-r--r-- | compiler/main/DynFlags.hs | 7 | ||||
-rw-r--r-- | docs/users_guide/flags.xml | 6 | ||||
-rw-r--r-- | docs/users_guide/ghci.xml | 12 | ||||
-rw-r--r-- | ghc/InteractiveUI.hs | 4 |
4 files changed, 26 insertions, 3 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 2cc8446ba1..13a5f01e7f 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -597,6 +597,7 @@ data DynFlags = DynFlags { flushErr :: FlushErr, haddockOptions :: Maybe String, + ghciScripts :: [String], -- | what kind of {-# SCC #-} to add automatically profAuto :: ProfAuto, @@ -941,6 +942,7 @@ defaultDynFlags mySettings = haddockOptions = Nothing, flags = IntSet.fromList (map fromEnum defaultFlags), warningFlags = IntSet.fromList (map fromEnum standardWarnings), + ghciScripts = [], language = Nothing, safeHaskell = Sf_SafeInfered, thOnLoc = noSrcSpan, @@ -1183,7 +1185,7 @@ setObjectDir, setHiDir, setStubDir, setDumpDir, setOutputDir, setDylibInstallName, setObjectSuf, setHiSuf, setHcSuf, parseDynLibLoaderMode, setPgmP, addOptl, addOptP, - addCmdlineFramework, addHaddockOpts + addCmdlineFramework, addHaddockOpts, addGhciScript :: String -> DynFlags -> DynFlags setOutputFile, setOutputHi, setDumpPrefixForce :: Maybe String -> DynFlags -> DynFlags @@ -1255,6 +1257,8 @@ addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d} addHaddockOpts f d = d{ haddockOptions = Just f} +addGhciScript f d = d{ ghciScripts = f : ghciScripts d} + -- ----------------------------------------------------------------------------- -- Command-line options @@ -1545,6 +1549,7 @@ dynamic_flags = [ , Flag "haddock" (NoArg (setDynFlag Opt_Haddock)) , Flag "haddock-opts" (hasArg addHaddockOpts) , Flag "hpcdir" (SepArg setOptHpcDir) + , Flag "ghci-script" (hasArg addGhciScript) ------- recompilation checker -------------------------------------- , Flag "recomp" (NoArg (do unSetDynFlag Opt_ForceRecomp diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index 53bd4bfb17..0572039e87 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -493,6 +493,12 @@ <entry>-</entry> </row> <row> + <entry><option>-ghci-script</option></entry> + <entry>Read additional <filename>.ghci</filename> files</entry> + <entry>dynamic</entry> + <entry>-</entry> + </row> + <row> <entry><option>-read-dot-ghci</option></entry> <entry>Enable reading of <filename>.ghci</filename> files</entry> <entry>static</entry> diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index 3e0d341f83..87ba79d7b1 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -3105,6 +3105,10 @@ warning settings: wiki page: <ulink url="http://haskell.org/haskellwiki/GHC/GHCi">GHC/GHCi</ulink></para> + <para>Additionally, any files specified with + <literal>-ghci-script</literal> flags will be read after the + standard files, allowing the use of custom .ghci files.</para> + <para>Two command-line options control whether the startup files files are read:</para> @@ -3131,6 +3135,14 @@ warning settings: be used to override a previous <option>-ignore-dot-ghci</option> option.</para> </listitem> + <term> + <option>-ghci-script</option> + <indexterm><primary><option>-ghci-script</option></primary></indexterm> + </term> + <listitem> + <para>Read a specific file after the usual startup files. + Maybe be specified repeatedly for multiple inputs.</para> + </listitem> </varlistentry> </variablelist> diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs index 9761f42003..b7e6241033 100644 --- a/ghc/InteractiveUI.hs +++ b/ghc/InteractiveUI.hs @@ -432,8 +432,9 @@ runGHCi paths maybe_exprs = do setGHCContextFromGHCiState + dflags <- getDynFlags when (read_dot_files) $ do - mcfgs0 <- sequence [ current_dir, app_user_dir, home_dir ] + mcfgs0 <- sequence $ [ current_dir, app_user_dir, home_dir ] ++ map (return . Just ) (ghciScripts dflags) mcfgs <- liftIO $ mapM canonicalizePath' (catMaybes mcfgs0) mapM_ sourceConfigFile $ nub $ catMaybes mcfgs -- nub, because we don't want to read .ghci twice if the @@ -455,7 +456,6 @@ runGHCi paths maybe_exprs = do -- if verbosity is greater than 0, or we are connected to a -- terminal, display the prompt in the interactive loop. is_tty <- liftIO (hIsTerminalDevice stdin) - dflags <- getDynFlags let show_prompt = verbosity dflags > 0 || is_tty -- reset line number |