module Rasa.Internal.BufAction
( BufAction(..)
, getText
, setText
, getBufRef
, getRange
, setRange
, getBufExt
, setBufExt
, overBufExt
, liftAction
) where
import Rasa.Internal.ActionMonads
import Rasa.Internal.Range
import Rasa.Internal.Buffer
import Control.Lens
import Data.Default
import Data.Typeable
import qualified Yi.Rope as Y
getText :: BufAction Y.YiString
getText = liftBufAction $ GetText id
setText :: Y.YiString -> BufAction ()
setText txt = liftBufAction $ SetText txt ()
getRange :: CrdRange -> BufAction Y.YiString
getRange rng = view (range rng) <$> getText
setRange :: CrdRange -> Y.YiString -> BufAction ()
setRange rng txt = liftBufAction $ SetRange rng txt ()
getBufRef :: BufAction BufRef
getBufRef = liftBufAction $ GetBufRef id
getBufExt :: (Typeable ext, Show ext, Default ext) => BufAction ext
getBufExt = liftBufAction $ GetBufExt id
setBufExt :: (Typeable ext, Show ext, Default ext) => ext -> BufAction ()
setBufExt newExt = liftBufAction $ SetBufExt newExt ()
overBufExt :: (Typeable ext, Show ext, Default ext) => (ext -> ext) -> BufAction ()
overBufExt f = getBufExt >>= setBufExt . f
liftAction :: Action r -> BufAction r
liftAction action = liftBufAction $ LiftAction action id