Commit 76bde331 authored by pcapriotti's avatar pcapriotti

Add support for additional .ghci files in GHCi (#5265)

Patch by Sam Anklesaria <amsay@amsay.net>
parent ab52df86
......@@ -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
......
......@@ -492,6 +492,12 @@
<entry>static</entry>
<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>
......
......@@ -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>
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment