[Fencommits] fenserve: deleting items: ':del <path>'
Benja Fallenstein
benja.fallenstein at gmail.com
Fri Apr 27 18:00:10 EEST 2007
Fri Apr 27 17:59:57 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* deleting items: ':del <path>'
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-04-27 18:00:10.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-04-27 18:00:10.000000000 +0300
@@ -5,6 +5,7 @@
import Data.Generics (Typeable)
import Data.Binary hiding (get,put)
import Data.Char
+import Data.List (isPrefixOf)
data Note = Note String [Note] deriving (Eq,Ord,Read,Show,Typeable)
@@ -19,9 +20,17 @@
renderNotes notes = "<ol>" ++ concatMap renderNote notes ++ "</ol>" where
renderNote (Note title children) = "<li>" ++ title ++ renderNotes children
-execute line0 = addToPath (map (subtract 1) path) line where
+execute line0 = if ":del " `isPrefixOf` line0
+ then delete (map (subtract 1) $ read $ drop 5 line)
+ else addToPath (map (subtract 1) path) line where
(path, line) = case reads line0 of ((p,l):_) -> (p, dropWhile isSpace l)
[] -> ([], line0)
+
+ delete [i] notes = take i notes ++ drop (i+1) notes
+ delete (i:is) notes = take i notes ++ [note'] ++ drop (i+1) notes
+ where Note title children = notes !! i
+ note' = Note title (delete is children)
+
addToPath [] line notes = notes ++ [Note line []]
addToPath (i:is) line notes = take i notes ++ [note'] ++ drop (i+1) notes
where Note title children = notes !! i
More information about the Fencommits
mailing list