[write command incomplete paolo.veronelli@gmail.com**20080202180152] { hunk ./Editor.hs 16 - file :: w, -- ^ data holding the file - lastre :: String -- ^ a regex + file :: w, -- ^ data holding the file + lastre :: String, -- ^ a regex + filename :: Maybe String -- ^ the file we are editing hunk ./Editor.hs 29 +setfilename x = get >>= \y -> put y {filename = x} hunk ./Editor.hs 42 - | FileNotFound -- ^ error try to load a file - deriving Show + | FileReadErr String -- ^ io error trying to load a file + | FileNameMissing -- ^ filename is not set + | FileWriteErr String -- ^ io error trying to write the file + deriving Show hunk ./Editor.hs 84 + -- | Write the file + | Write hunk ./Eval.hs 7 +import Control.Monad.State hunk ./Eval.hs 38 - either output (putfile . listIn . lines) + either (errorlog . FileReadErr) (putfile . listIn . lines) >> setfilename (Just e) +eval (CC Write _) = do + name <- gets filename >>= maybe (errorlog FileNameMissing >> return "") return + contents <- concat `fmap` through listOut + writer <- asks writefileSio + operation <- lift . lift . lift . runErrorT $ writer name contents + either (errorlog . FileWriteErr) return operation hunk ./Main.hs 23 -main = run (commandLoop parse eval) programSio (Stato empty "") :: IO (Stato InsideAppend) +main = run (commandLoop parse eval) programSio (Stato empty "" Nothing) :: IO (Stato InsideAppend) hunk ./Parser.hs 20 -filename = manyTill anyChar ((many1 space >> return ()) <|> eof) +parseFilename = manyTill anyChar ((many1 space >> return ()) <|> eof) + hunk ./Parser.hs 64 -defaultOR (Write _) = ORN +defaultOR Write = ORN hunk ./Parser.hs 95 - edit = char 'e' >> many space >> filename >>= rconst . Edit - write = char 'w' >> rconst . Write - in choice (map try [append,insert,change,delete,print,smallg,bigg,edit]) <|> nocomm + edit = char 'e' >> many space >> parseFilename >>= rconst . Edit + write = char 'w' >> rconst Write + in choice (map try [append,insert,change,delete,print,smallg,bigg,edit,write]) <|> nocomm hunk ./docs/Editor.html 100 +>filename :: (Maybe String)| FileNotFound| FileReadErr String| FileNameMissing| FileWriteErr String| Writefilename :: (Maybe String)the file we are editing +FileReadErr Stringio error trying to load a file +FileNotFoundFileNameMissingerror try to load a file +>filename is not set +FileWriteErr Stringio error trying to write the file hunk ./docs/Editor.html 1271 +>WriteWrite the file +FileNotFoundFileNameMissingEditorFileReadErrEditorFileWriteErrfilenameEditorWriteEditor