[Fencommits] fenserve: ':move oldpath newpath'
Benja Fallenstein
benja.fallenstein at gmail.com
Sat Apr 28 17:08:11 EEST 2007
Sat Apr 28 17:08:04 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* ':move oldpath newpath'
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-04-28 17:08:11.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-04-28 17:08:11.000000000 +0300
@@ -12,7 +12,7 @@
type Path = [Int]
data Body = Body String | Add Path String
- | Edit Path String | DeleteOne Path | Delete Path
+ | Edit Path String | Move Path Path | DeleteOne Path | Delete Path
| MakeOwnPage Path | Unpage Path
deriving (Eq,Ord,Read,Show,Typeable)
data Line = Line { lineTime :: EpochTime, lineNick :: String,
@@ -72,6 +72,7 @@
readBody :: String -> Body
readBody s | ":add " `isPrefixOf` s = readPath' s 5 $ \p l -> Add p l
| ":edit " `isPrefixOf` s = readPath' s 6 $ \p l -> Edit p l
+ | ":move " `isPrefixOf` s = readPath' s 6 $ \p l -> Move p (readPath l)
| ":del " `isPrefixOf` s = readPath' s 5 $ \p "" -> DeleteOne p
| ":deltree " `isPrefixOf` s = readPath' s 9 $ \p "" -> Delete p
| ":page " `isPrefixOf` s = readPath' s 6 $ \p "" -> MakeOwnPage p
@@ -80,17 +81,24 @@
execute (Line _ _ (Body _)) = id
execute (Line _ _ body) =
- case body of Add p l -> on p $ \(Note t o cs) -> [Note t o (cs++[Note l False []])]
- Edit p l -> on p $ \(Note _ o cs) -> [Note l o cs]
- DeleteOne p -> on p $ \(Note _ _ cs) -> cs
- Delete p -> on p $ \(Note _ _ cs) -> []
- MakeOwnPage p -> on p $ \(Note t _ cs) -> [Note t True cs]
- Unpage p -> on p $ \(Note t _ cs) -> [Note t False cs]
-
- where on is f note = head $ on' is f note
- on' [] f note = f note
- on' (i:is) f (Note t o cs) =
- [Note t o (take i cs ++ on' is f (cs !! i) ++ drop (i+1) cs)]
+ case body of
+ Add p l -> on p $ \(Note t o cs) -> [Note t o (cs++[Note l False []])]
+ Edit p l -> on p $ \(Note _ o cs) -> [Note l o cs]
+ Move p q -> move p q
+ DeleteOne p -> on p $ \(Note _ _ cs) -> cs
+ Delete p -> on p $ \(Note _ _ cs) -> []
+ MakeOwnPage p -> on p $ \(Note t _ cs) -> [Note t True cs]
+ Unpage p -> on p $ \(Note t _ cs) -> [Note t False cs]
+
+ where
+ on is f note = head $ on' is f note
+ on' [] f note = f note
+ on' (i:is) f (Note t o cs) =
+ [Note t o (take i cs ++ on' is f (cs !! i) ++ drop (i+1) cs)]
+
+ move p q root = (on p $ \(Note _ _ cs) -> [])
+ $ (on q $ \(Note t o cs) -> [Note t o (cs++[getPath p root])])
+ $ root
getNick m = case lookM m "nick" of Nothing -> "(anon)"; Just "" -> "(anon)"
Just x -> x
@@ -116,6 +124,7 @@
msg (Add [] l) = printf "adds:</i> %s" l
msg (Add p l) = printf "adds to '%s':</i> %s" (renderPath p) l
msg (Edit p l) = printf "edits '%s':</i> %s" (renderPath p) l
+ msg (Move p q) = printf "moves '%s' to '%s.'</i>" (renderPath p) (renderPath q)
msg (DeleteOne p) = printf "deletes '%s.'</i>" (renderPath p)
msg (Delete p) = printf "deletes subtree '%s.'</i>" (renderPath p)
msg (MakeOwnPage p) = printf "made '%s' its own page.</i>" (renderPath p)
More information about the Fencommits
mailing list