import DynFlags
import Packages
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
import PackageConfig
import UniqFM
#endif
import qualified System.Win32
#endif
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
import Control.Concurrent ( yield ) -- Used in readline loop
-import System.Console.Readline as Readline
+import System.Console.Editline.Readline as Readline
#endif
--import SystemExts
import Data.IORef ( IORef, readIORef, writeIORef )
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
import System.Posix.Internals ( setNonBlockingFD )
#endif
cmdName :: Command -> String
cmdName (n,_,_,_) = n
-macros_ref :: IORef [Command]
GLOBAL_VAR(macros_ref, [], [Command])
builtin_commands :: [Command]
--
-- NOTE: in order for us to override the default correctly, any custom entry
-- must be a SUBSET of word_break_chars.
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
word_break_chars :: String
word_break_chars = let symbols = "!#$%&*+/<=>?@\\^|-~"
specials = "(),;[]`{}"
-- intended for the program, so unbuffer stdin.
hSetBuffering stdin NoBuffering
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
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"
remembered_ctx = []
}
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
+ 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
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")
-- exception handler above.
-- read commands from stdin
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
if (is_tty)
then runCommands readlineLoop
else runCommands (fileLoop stdin show_prompt is_tty)
return (showSDoc (f (prompt st)))
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
readlineLoop :: GHCi (Maybe String)
readlineLoop = do
io yield
completeHomeModuleOrFile
:: String -> IO [String]
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
completeWord :: String -> Int -> Int -> IO (Maybe (String, [String]))
completeWord w start end = do
line <- Readline.getLineBuffer
breakSwitch _session [] = do
io $ putStrLn "The break command requires at least one argument."
breakSwitch session (arg1:rest)
- | looksLikeModuleName arg1 = do
+ | looksLikeModuleName arg1 && not (null rest) = do
mod <- wantInterpretedModule arg1
breakByModule mod rest
| all isDigit arg1 = do