From 2f3a4395da6771abe46d45d48694c3c82f72ad7c Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 12 Mar 2008 21:57:24 +0000 Subject: [PATCH] #2050: save the GHCi history in ~/.ghc/ghci_history Modified version of Judah's patch --- compiler/ghci/InteractiveUI.hs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index 8ff83f9..8b1566a 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") -- 1.7.10.4