1{-# LANGUAGE ExistentialQuantification #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE InstanceSigs #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE Rank2Types #-}
7{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE UndecidableInstances #-}
17import Control.Applicative (Alternative (..))
18import Control.Monad.Base (MonadBase (..), liftBaseDefault)
19import Control.Monad.Catch (MonadThrow, throwM)
20import Control.Monad.State (MonadIO (..), MonadPlus (..),
21 MonadState (..), StateT (..),
22 liftM, modify, runStateT, when)
23import Control.Monad.Trans.Class (MonadTrans (lift))
24import Control.Monad.Trans.Control (ComposeSt, MonadBaseControl (..),
25 MonadTransControl (..),
28import Data.Dynamic (Typeable)
32--import Debug.Trace (traceM)
34------------------------------------------------------------------------------
36------------------------------------------------------------------------------
38-- | If the first parameter is 'Nothing' return the second parameter otherwise
39-- return the first parameter..
40onNothing :: Monad m => m (Maybe b) -> m b -> m b
47------------------------------------------------------------------------------
49------------------------------------------------------------------------------
52-- | Run the closure (the 'x' in 'x >>= f') of the current bind operation.
53runClosure :: EventF -> StateM m (Maybe a)
54runClosure EventF { xcomp = x } = runAsyncT (unsafeCoerce x)
56-- | Run the continuation (the 'f' in 'x >>= f') of the current bind operation with the current state.
57runContinuation :: MonadIO m => EventF -> a -> StateM m (Maybe b)
58runContinuation EventF { fcomp = fs } =
59 runAsyncT . (compose $ (unsafeCoerce fs))
61data Backtrack b = Show b => Backtrack
62 { backtracking :: Maybe b
63 , backStack :: [EventF]
66backStateOf :: (Monad m, Show a) => a -> m (Backtrack a)
67backStateOf reason = return $ Backtrack (Nothing `asTypeOf` (Just reason)) []
69-- | Start the undo process for the given undo track id. Performs all the undo
70-- actions registered till now in reverse order. An undo action can use
71-- 'forward' to stop the undo process and resume forward execution. If there
72-- are no more undo actions registered execution stops and a 'stop' action is
75back :: (MonadIO m, Typeable b, Show b) => b -> AsyncT m a
76back reason = AsyncT $ do
77 bs <- getData `onNothing` backStateOf reason
82 goBackt (Backtrack _ [] )= return Nothing
83 goBackt (Backtrack _ (stack@(first : bs)) )= do
84 (setData $ Backtrack (Just reason) stack)
86 mr <- runClosure first
88 Backtrack b _ <- getData `onNothing` backStateOf reason
90 Nothing -> return empty
92 Nothing -> runContinuation first x
93 justreason -> goBackt $ Backtrack justreason bs
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list