[completed write command paolo.veronelli@gmail.com**20080202224212] { hunk ./Editor.hs 86 + -- | Write a new file + | WriteNew String hunk ./Editor.hs 129 +liftStato :: Ctx m w => m a -> Editor m w a +liftStato = lift . lift . lift hunk ./Eval.hs 37 -eval (CC (Edit e) _) = asks readfileSio >>= lift . lift . lift . runErrorT . ($ e) >>= - either (errorlog . FileReadErr) (putfile . listIn . lines) >> setfilename (Just e) -eval (CC Write _) = do - name <- gets filename >>= maybe (errorlog FileNameMissing >> return "") return - contents <- foldr ((++).(++ "\n")) "" `fmap` through listOut - writer <- asks writefileSio - operation <- lift . lift . lift . runErrorT $ writer name contents - either (errorlog . FileWriteErr) return operation - +eval (CC (Edit e) _) = asks readfileSio >>= liftStato . runErrorT . ($ e) >>= + either (errorlog . FileReadErr) (putfile . listIn . lines) >> + setfilename (Just e) +eval (CC Write _) = getname (errorlog FileNameMissing >> return "") >>= write hunk ./Eval.hs 42 --- eval (CC SmallG +eval (CC (WriteNew nname) _) = getname (return nname) >>= \name -> write nname >> + setfilename (Just name) -- eventually set it + +-- | throw a writerSio error to Editor +writefail :: Ctx m w => Either String () -> Editor m w () +writefail = either (errorlog . FileWriteErr) return +-- | dump the engine content to a file via writefileSio +write :: Ctx m w + => String -- ^ filename + -> Editor m w () -- ^ monading +write name = do + writer <- asks writefileSio + contents <- unlines `fmap` through listOut + (liftStato . runErrorT) (writer name contents) >>= writefail +-- | get the filename defaulting to some other action to produce one +getname defaul = gets filename >>= maybe defaul return hunk ./Parser.hs 65 +defaultOR (WriteNew _) = ORN hunk ./Parser.hs 96 - edit = char 'e' >> many space >> parseFilename >>= rconst . Edit + edit = char 'e' >> many1 space >> parseFilename >>= rconst . Edit + writen = char 'w' >> many1 space >> parseFilename >>= rconst . WriteNew hunk ./Parser.hs 99 - in choice (map try [append,insert,change,delete,print,smallg,bigg,edit,write]) <|> nocomm + in choice (map try [append,insert,change,delete, + print,smallg,bigg,edit,writen,write]) <|> nocomm hunk ./docs/Editor.html 347 +>| WriteNew StringliftStato :: Ctx m w => m a -> Editor m w aWriteNew StringWrite a new file +liftStato :: Ctx m w => m a -> Editor m w awritefail :: Ctx m w => Either String () -> Editor m w ()write :: Ctx m w => String -> Editor m w ()writefail :: Ctx m w => Either String () -> Editor m w ()throw a writerSio error to Editor +write
:: Ctx m w
=> Stringfilename +
-> Editor m w ()monading +
dump the engine content to a file via writefileSio +liftStato
WriteNew
write
writefail