Commit 79f0c442 authored by simonmar's avatar simonmar

[project @ 2003-04-23 10:42:36 by simonmar]

Make a leading '~' expand to $HOME in commands that load source files
(:load, :add) in addition to :cd which already had this behaviour.
parent 8d594ee9
{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
-- $Id: InteractiveUI.hs,v 1.150 2003/04/12 16:27:24 panne Exp $
-- $Id: InteractiveUI.hs,v 1.151 2003/04/23 10:42:36 simonmar Exp $
--
-- GHC Interactive User Interface
--
......@@ -539,6 +539,7 @@ addModule files = do
state <- getGHCiState
dflags <- io (getDynFlags)
io (revertCAFs) -- always revert CAFs on load/add.
files <- mapM expandPath files
let new_targets = files ++ targets state
graph <- io (cmDepAnal (cmstate state) dflags new_targets)
(cmstate1, ok, mods) <- io (cmLoadModules (cmstate state) dflags graph)
......@@ -547,10 +548,9 @@ addModule files = do
modulesLoadedMsg ok mods dflags
changeDirectory :: String -> GHCi ()
changeDirectory ('~':d) = do
tilde <- io (getEnv "HOME") -- will fail if HOME not defined
io (setCurrentDirectory (tilde ++ '/':d))
changeDirectory d = io (setCurrentDirectory d)
changeDirectory dir = do
dir <- expandPath dir
io (setCurrentDirectory dir)
defineMacro :: String -> GHCi ()
defineMacro s = do
......@@ -605,6 +605,9 @@ loadModule' files = do
state <- getGHCiState
dflags <- io getDynFlags
-- expand tildes
files <- mapM expandPath files
-- do the dependency anal first, so that if it fails we don't throw
-- away the current set of modules.
graph <- io (cmDepAnal (cmstate state) dflags files)
......@@ -1070,3 +1073,15 @@ revertCAFs = do
foreign import ccall "revertCAFs" rts_revertCAFs :: IO ()
-- Make it "safe", just in case
-- -----------------------------------------------------------------------------
-- Utils
expandPath :: String -> GHCi String
expandPath path =
case dropWhile isSpace path of
('~':d) -> do
tilde <- io (getEnv "HOME") -- will fail if HOME not defined
return (tilde ++ '/':d)
other ->
return other
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