From e7150aff2e5dbbce9d8930478d97fec2607e343c Mon Sep 17 00:00:00 2001
From: Sam Anklesaria <amsay@amsay.net>
Date: Sun, 19 Jun 2011 17:36:07 -0500
Subject: [PATCH] trac #5265 (support for additional .ghci files)
---
compiler/main/StaticFlags.hs | 11 ++++++++++-
docs/users_guide/flags.xml | 6 ++++++
docs/users_guide/ghci.xml | 4 ++++
ghc/InteractiveUI.hs | 3 ++-
4 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/compiler/main/StaticFlags.hs b/compiler/main/StaticFlags.hs
index f6d0af2..d8e63ab 100644
|
a
|
b
|
|
| 72 | 72 | |
| 73 | 73 | -- misc opts |
| 74 | 74 | opt_IgnoreDotGhci, |
| | 75 | opt_GhciScripts, |
| 75 | 76 | opt_ErrorSpans, |
| 76 | 77 | opt_GranMacros, |
| 77 | 78 | opt_HiVersion, |
| … |
… |
|
| 92 | 93 | import Config |
| 93 | 94 | import FastString |
| 94 | 95 | import Util |
| 95 | | import Maybes ( firstJusts ) |
| | 96 | import Maybes ( firstJusts, catMaybes ) |
| 96 | 97 | import Panic |
| 97 | 98 | |
| 98 | 99 | import Data.Maybe ( listToMaybe ) |
| … |
… |
|
| 121 | 122 | lookup_def_int :: String -> Int -> Int |
| 122 | 123 | lookup_def_float :: String -> Float -> Float |
| 123 | 124 | lookup_str :: String -> Maybe String |
| | 125 | lookup_all_str :: String -> [String] |
| 124 | 126 | |
| 125 | 127 | -- holds the static opts while they're being collected, before |
| 126 | 128 | -- being unsafely read by unpacked_static_opts below. |
| … |
… |
|
| 151 | 153 | Just str -> Just str |
| 152 | 154 | Nothing -> Nothing |
| 153 | 155 | |
| | 156 | lookup_all_str sw = map f $ catMaybes (map (stripPrefix sw) staticFlags) where |
| | 157 | f ('=' : str) = str |
| | 158 | f str = str |
| | 159 | |
| 154 | 160 | lookup_def_int sw def = case (lookup_str sw) of |
| 155 | 161 | Nothing -> def -- Use default |
| 156 | 162 | Just xx -> try_read sw xx |
| … |
… |
|
| 189 | 195 | |
| 190 | 196 | opt_IgnoreDotGhci :: Bool |
| 191 | 197 | opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci") |
| | 198 | |
| | 199 | opt_GhciScripts :: [String] |
| | 200 | opt_GhciScripts = lookup_all_str "-ghci-script" |
| 192 | 201 | |
| 193 | 202 | -- debugging options |
| 194 | 203 | -- | Suppress all that is suppressable in core dumps. |
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml
index 43c713e..7ef9e80 100644
|
a
|
b
|
|
| 487 | 487 | <entry>-</entry> |
| 488 | 488 | </row> |
| 489 | 489 | <row> |
| | 490 | <entry><option>-ghci-script</option></entry> |
| | 491 | <entry>Load the given additional <filename>.ghci</filename> file</entry> |
| | 492 | <entry>static</entry> |
| | 493 | <entry>-</entry> |
| | 494 | </row> |
| | 495 | <row> |
| 490 | 496 | <entry><option>-read-dot-ghci</option></entry> |
| 491 | 497 | <entry>Enable reading of <filename>.ghci</filename> files</entry> |
| 492 | 498 | <entry>static</entry> |
diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml
index 72481eb..62522e8 100644
|
a
|
b
|
|
| 2872 | 2872 | </varlistentry> |
| 2873 | 2873 | </variablelist> |
| 2874 | 2874 | |
| | 2875 | <para>Additional <filename>.ghci</filename> files can be added |
| | 2876 | through the <option>-ghci-script</option> option. These are |
| | 2877 | loaded after the normal <filename>.ghci</filename> files.</para> |
| | 2878 | |
| 2875 | 2879 | </sect1> |
| 2876 | 2880 | |
| 2877 | 2881 | <sect1 id="ghci-obj"> |
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 1869040..981abdf 100644
|
a
|
b
|
|
| 426 | 426 | getDirectory f = case takeDirectory f of "" -> "."; d -> d |
| 427 | 427 | |
| 428 | 428 | when (read_dot_files) $ do |
| 429 | | mcfgs0 <- sequence [ current_dir, app_user_dir, home_dir ] |
| | 429 | mcfgs0 <- sequence $ [ current_dir, app_user_dir, home_dir ] |
| | 430 | ++ map (return . Just) opt_GhciScripts |
| 430 | 431 | mcfgs <- liftIO $ mapM canonicalizePath' (catMaybes mcfgs0) |
| 431 | 432 | mapM_ sourceConfigFile $ nub $ catMaybes mcfgs |
| 432 | 433 | -- nub, because we don't want to read .ghci twice if the |