-- settings :set editor gvim -- :. -- source commands from :undef . :def . readFile -- os&shell-independent pwd, ls :undef pwd :def pwd \_->return "System.Directory.getCurrentDirectory >>= putStrLn" :undef ls :def ls \p->return $ "mapM_ putStrLn =<< System.Directory.getDirectoryContents "++if (null p) then show "." else show p -- a strict readFile, to prevent dangling handles/locks let readFileNow f = readFile f >>= \t->length t `seq` return t -- :redir -- execute , redirecting stdout to let redir varcmd = let { file = "ghci.tmp" } in case span (not . Data.Char.isSpace) varcmd of { (var,_:cmd) -> return $ unlines [":set -fno-print-bind-result","h <- IO.openFile "++show file++" IO.WriteMode","sto <- GHC.Handle.hDuplicate IO.stdout","GHC.Handle.hDuplicateTo h IO.stdout","IO.hClose h",cmd,"GHC.Handle.hDuplicateTo sto IO.stdout",var++" <- readFileNow "++show file]; _ -> return "putStrLn \"usage: :redir \"" } :undef redir :def redir redir -- :grep -- filter lines matching from the output of let grep patcmd = case span (not . Data.Char.isSpace) patcmd of { (pat,_:cmd) -> return $ unlines [":redir out "++cmd,"putStrLn $ unlines $ (\"\":) $ filter (Data.Maybe.isJust . Text.Regex.matchRegex (Text.Regex.mkRegex "++show pat++")) $ lines out"]; _ -> return "putStrLn \"usage: :grep \""} :undef grep :def grep grep -- :find -- call editor (:set editor) on definition of let find id = return $ unlines [":redir out :info "++id,"let ls = filter (Data.List.isInfixOf \"-- Defined\") $ lines out","let match = Text.Regex.matchRegex (Text.Regex.mkRegex \"-- Defined at ([^<:]*):([^:]*):\") $ head ls",":cmd return $ case (ls,match) of { (_:_,Just [mod,line]) -> (\":e +\"++line++\" \"++mod); _ -> \"\" }"] :undef find :def find find