[edit of external commands added paolo.veronelli@gmail.com**20080203115648] { hunk ./Editor.hs 45 + | ExternalCommandErr String -- ^ io error executing an external program hunk ./Editor.hs 61 - writefileSio :: String -> String -> ErrorT String m () -- ^ write a file + writefileSio :: String -> String -> ErrorT String m (), -- ^ write a file + -- | runs an external command , first arg is the command + -- the output is returned or an error is signalled in the errort monad + externalSio :: String -> ErrorT String m String hunk ./Editor.hs 96 + -- | Load the output of an external command + | EditExternal String hunk ./Editor.hs 139 -liftStato :: Ctx m w => m a -> Editor m w a -liftStato = lift . lift . lift +liftSio :: Ctx m w => m a -> Editor m w a +liftSio = lift . lift . lift hunk ./Editor.hs 159 -pinput s = asks inputSio >>= liftStato . ($ s) +pinput s = asks inputSio >>= liftSio . ($ s) hunk ./Editor.hs 169 -output s = asks outputSio >>= liftStato . ($ s) +output s = asks outputSio >>= liftSio . ($ s) hunk ./Editor.hs 175 -history s = asks historySio >>= liftStato . ($ s) +history s = asks historySio >>= liftSio . ($ s) hunk ./Editor.hs 181 -errorlog s = asks errorSIO >>= liftStato . ($ s) +errorlog s = asks errorSIO >>= liftSio . ($ s) hunk ./Eval.hs 37 -eval (CC (Edit e) _) = asks readfileSio >>= liftStato . runErrorT . ($ e) >>= +eval (CC (Edit e) _) = asks readfileSio >>= liftSio . runErrorT . ($ e) >>= hunk ./Eval.hs 46 +eval (CC (EditExternal s) _) = asks externalSio >>= liftSio . runErrorT . ($ s) >>= + either (errorlog . ExternalCommandErr) (putfile . listIn . lines) hunk ./Eval.hs 60 - (liftStato . runErrorT) (writer name contents) >>= writefail + (liftSio . runErrorT) (writer name contents) >>= writefail hunk ./Main.hs 6 +import System.Process +import System.Exit hunk ./Main.hs 9 - +import IO hunk ./Main.hs 20 +externalCommand :: String -> ErrorT String IO String +externalCommand s = ErrorT $ do + (_,output,error,h) <- runInteractiveCommand s + status <- waitForProcess h + output <- hGetContents output + error <- hGetContents error + return $ case status of + ExitSuccess -> Right output + ExitFailure _ -> Left error hunk ./Main.hs 31 -programSio = SIO readline putStrLn addHistory print (handleWith show . strictReadFile) (\x y -> handleWith show (writeFile x y)) +programSio = SIO readline putStrLn addHistory print (handleWith show . strictReadFile) (\x y -> handleWith show (writeFile x y)) externalCommand hunk ./Operation.hs 47 - where aline jl = history jl >> inputMode >>= return . (jl:) + where aline jl = inputMode >>= return . (jl:) hunk ./Parser.hs 21 +parseExternalCommand = char '!' >> manyTill anyChar eof hunk ./Parser.hs 69 +defaultOR (EditExternal s) = ORN hunk ./Parser.hs 100 + extedit = char 'e' >> many1 space >> parseExternalCommand >>= rconst . EditExternal hunk ./Parser.hs 107 - print,smallg,bigg,edit,writen, - setfn,getfn,write]) <|> nocomm + print,smallg,bigg,extedit,edit + ,writen,write,setfn,getfn]) <|> nocomm hunk ./docs/Editor.html 209 +>| ExternalCommandErr StringexternalSio :: (String -> ErrorT String m String)| EditExternal StringliftStatoliftSioExternalCommandErr Stringio error executing an external program +externalSio :: (String -> ErrorT String m String)EditExternal StringLoad the output of an external command +liftStatoliftSioexternalCommand :: String -> ErrorT String IO StringexternalCommand :: String -> ErrorT String IO StringEditExternalEditorExternalCommandErrEditorexternalCommandMainexternalSioEditorliftStatoliftSio