summaryrefslogtreecommitdiff
path: root/compiler/ghci/InteractiveUI.hs
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2008-03-12 21:57:24 +0000
committerSimon Marlow <simonmar@microsoft.com>2008-03-12 21:57:24 +0000
commit2f3a4395da6771abe46d45d48694c3c82f72ad7c (patch)
treec54bb422ef464317f121de7800fe5dfc75f6bb91 /compiler/ghci/InteractiveUI.hs
parentc6ce13642a2035789b6821a4a2927bc4349d1f15 (diff)
downloadhaskell-2f3a4395da6771abe46d45d48694c3c82f72ad7c.tar.gz
#2050: save the GHCi history in ~/.ghc/ghci_history
Modified version of Judah's patch
Diffstat (limited to 'compiler/ghci/InteractiveUI.hs')
-rw-r--r--compiler/ghci/InteractiveUI.hs24
1 files changed, 19 insertions, 5 deletions
diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs
index 8ff83f92b4..8b1566a6a5 100644
--- a/compiler/ghci/InteractiveUI.hs
+++ b/compiler/ghci/InteractiveUI.hs
@@ -316,6 +316,11 @@ interactiveUI session srcs maybe_exprs = do
is_tty <- hIsTerminalDevice stdin
when is_tty $ do
Readline.initialize
+
+ withGhcAppData
+ (\dir -> Readline.readHistory (dir </> "ghci_history"))
+ (return True)
+
Readline.setAttemptedCompletionFunction (Just completeWord)
--Readline.parseAndBind "set show-all-if-ambiguous 1"
@@ -349,11 +354,22 @@ interactiveUI session srcs maybe_exprs = do
}
#ifdef USE_READLINE
+ Readline.stifleHistory 100
+ withGhcAppData (\dir -> Readline.writeHistory (dir </> "ghci_history"))
+ (return True)
Readline.resetTerminal Nothing
#endif
return ()
+withGhcAppData :: (FilePath -> IO a) -> IO a -> IO a
+withGhcAppData right left = do
+ either_dir <- IO.try (getAppUserDataDirectory "ghc")
+ case either_dir of
+ Right dir -> right dir
+ _ -> left
+
+
runGHCi :: [(FilePath, Maybe Phase)] -> Maybe [String] -> GHCi ()
runGHCi paths maybe_exprs = do
let
@@ -361,11 +377,9 @@ runGHCi paths maybe_exprs = do
current_dir = return (Just ".ghci")
- app_user_dir = do
- either_dir <- io $ IO.try (getAppUserDataDirectory "ghc")
- case either_dir of
- Right dir -> return (Just (dir </> "ghci.conf"))
- _ -> return Nothing
+ app_user_dir = io $ withGhcAppData
+ (\dir -> return (Just (dir </> "ghci.conf")))
+ (return Nothing)
home_dir = do
either_dir <- io $ IO.try (getEnv "HOME")