Commit e639fb47 authored by Boris Lykah's avatar Boris Lykah
Browse files

:unset settings support

Added support for settings [args, prog, prompt, editor and stop].
Now :unset supports the same set of options as :set.
parent c54980ff
...@@ -294,6 +294,11 @@ findEditor = do ...@@ -294,6 +294,11 @@ findEditor = do
foreign import ccall unsafe "rts_isProfiled" isProfiled :: IO CInt foreign import ccall unsafe "rts_isProfiled" isProfiled :: IO CInt
default_progname = "<interactive>"
default_args = []
default_prompt = "%s> "
default_stop = ""
interactiveUI :: [(FilePath, Maybe Phase)] -> Maybe [String] interactiveUI :: [(FilePath, Maybe Phase)] -> Maybe [String]
-> Ghc () -> Ghc ()
interactiveUI srcs maybe_exprs = do interactiveUI srcs maybe_exprs = do
...@@ -344,10 +349,10 @@ interactiveUI srcs maybe_exprs = do ...@@ -344,10 +349,10 @@ interactiveUI srcs maybe_exprs = do
default_editor <- liftIO $ findEditor default_editor <- liftIO $ findEditor
startGHCi (runGHCi srcs maybe_exprs) startGHCi (runGHCi srcs maybe_exprs)
GHCiState{ progname = "<interactive>", GHCiState{ progname = default_progname,
args = [], args = default_args,
prompt = "%s> ", prompt = default_prompt,
stop = "", stop = default_stop,
editor = default_editor, editor = default_editor,
-- session = session, -- session = session,
options = [], options = [],
...@@ -1518,22 +1523,32 @@ newDynFlags minus_opts = do ...@@ -1518,22 +1523,32 @@ newDynFlags minus_opts = do
unsetOptions :: String -> GHCi () unsetOptions :: String -> GHCi ()
unsetOptions str unsetOptions str
= do -- first, deal with the GHCi opts (+s, +t, etc.) = -- first, deal with the GHCi opts (+s, +t, etc.)
let opts = words str let opts = words str
(minus_opts, rest1) = partition isMinus opts (minus_opts, rest1) = partition isMinus opts
(plus_opts, rest2) = partitionWith isPlus rest1 (plus_opts, rest2) = partitionWith isPlus rest1
(other_opts, rest3) = partition (`elem` map fst defaulters) rest2
if (not (null rest2))
then liftIO (putStrLn ("unknown option: '" ++ head rest2 ++ "'")) defaulters =
else do [ ("args" , setArgs default_args)
, ("prog" , setProg default_progname)
mapM_ unsetOpt plus_opts , ("prompt", setPrompt default_prompt)
, ("editor", liftIO findEditor >>= setEditor)
let no_flag ('-':'f':rest) = return ("-fno-" ++ rest) , ("stop" , setStop default_stop)
no_flag f = ghcError (ProgramError ("don't know how to reverse " ++ f)) ]
no_flags <- mapM no_flag minus_opts no_flag ('-':'f':rest) = return ("-fno-" ++ rest)
newDynFlags no_flags no_flag f = ghcError (ProgramError ("don't know how to reverse " ++ f))
in if (not (null rest3))
then liftIO (putStrLn ("unknown option: '" ++ head rest3 ++ "'"))
else do
mapM_ (fromJust.flip lookup defaulters) other_opts
mapM_ unsetOpt plus_opts
no_flags <- mapM no_flag minus_opts
newDynFlags no_flags
isMinus :: String -> Bool isMinus :: String -> Bool
isMinus ('-':_) = True isMinus ('-':_) = True
......
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