module Yi.Buffer.Basic where
import Prelude (reverse)
import Data.Binary
import Yi.Prelude
import qualified Data.Rope as R
import Data.DeriveTH
import Data.Ix
data Direction = Backward
| Forward
deriving (Eq,Ord,Typeable,Show,Bounded,Enum)
$(derive makeBinary ''Direction)
reverseDir :: Direction -> Direction
reverseDir Forward = Backward
reverseDir Backward = Forward
mayReverse :: Direction -> [a] -> [a]
mayReverse Forward = id
mayReverse Backward = reverse
directionElim :: Direction -> a -> a -> a
directionElim Backward b _ = b
directionElim Forward _ f = f
newtype Mark = Mark {markId::Int} deriving (Eq, Ord, Show, Typeable, Binary)
newtype BufferRef = BufferRef Int
deriving (Eq, Ord, Typeable, Binary)
deriving instance Num BufferRef
instance Show BufferRef where
show (BufferRef r) = "B#" ++ show r
newtype Point = Point {fromPoint :: Int}
deriving (Eq, Ord, Enum, Bounded, Typeable, Binary, Ix)
deriving instance Num Point
deriving instance Real Point
deriving instance Integral Point
instance Show Point where
show (Point p) = show p
newtype Size = Size {fromSize :: Int}
deriving (Show, Eq, Ord, Num, Enum, Real, Integral, Binary)
instance SemiNum Point Size where
Point p +~ Size s = Point (p + s)
Point p -~ Size s = Point (p s)
Point p ~- Point q = Size (abs (p q))
fromString :: String -> Rope
fromString = R.fromString
newtype WindowRef = WindowRef { unWindowRef :: Int }
deriving(Eq, Ord, Enum, Show, Typeable, Binary)
instance Initializable WindowRef where initial = WindowRef (1)