{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable, ScopedTypeVariables, ExistentialQuantification, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TemplateHaskell #-}-- Copyright 2008 JP Bernardy-- | Basic types useful everywhere we play with buffers.moduleYi.Buffer.BasicwhereimportPrelude(reverse)importData.BinaryimportYi.PreludeimportqualifiedData.RopeasRimportData.DeriveTHimportData.Ix-- | Direction of movement inside a bufferdataDirection=Backward|Forwardderiving(Eq,Ord,Typeable,Show,Bounded,Enum)$(derivemakeBinary''Direction)reverseDir::Direction->DirectionreverseDirForward=BackwardreverseDirBackward=Forward-- | reverse if BackwardmayReverse::Direction->[a]->[a]mayReverseForward=idmayReverseBackward=reverse-- | 'direction' is in the same style of 'maybe' or 'either' functions,-- It takes one argument per direction (backward, then forward) and a-- direction to select the output.directionElim::Direction->a->a->adirectionElimBackwardb_=bdirectionElimForward_f=f-- | A mark in a buffernewtypeMark=Mark{markId::Int}deriving(Eq,Ord,Show,Typeable,Binary)-- | Reference to a buffer.newtypeBufferRef=BufferRefIntderiving(Eq,Ord,Typeable,Binary)derivinginstanceNumBufferRefinstanceShowBufferRefwhereshow(BufferRefr)="B#"++showr-- | A point in a buffernewtypePoint=Point{fromPoint::Int}-- offset in the buffer (#codepoints, NOT bytes)deriving(Eq,Ord,Enum,Bounded,Typeable,Binary,Ix)derivinginstanceNumPointderivinginstanceRealPointderivinginstanceIntegralPointinstanceShowPointwhereshow(Pointp)=showp-- | Size of a buffer regionnewtypeSize=Size{fromSize::Int}-- size in bytes (#bytes, NOT codepoints)deriving(Show,Eq,Ord,Num,Enum,Real,Integral,Binary)instanceSemiNumPointSizewherePointp+~Sizes=Point(p+s)Pointp-~Sizes=Point(p-s)Pointp~-Pointq=Size(abs(p-q))fromString::String->RopefromString=R.fromString-- | Window referencesnewtypeWindowRef=WindowRef{unWindowRef::Int}deriving(Eq,Ord,Enum,Show,Typeable,Binary)instanceInitializableWindowRefwhereinitial=WindowRef(-1)