{-# LANGUAGE CPP                        #-}
{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE DeriveFoldable             #-}
{-# LANGUAGE DeriveFunctor              #-}
{-# LANGUAGE DeriveTraversable          #-}
{-# LANGUAGE ExistentialQuantification  #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# OPTIONS_HADDOCK show-extensions #-}

-- |
-- Module      :  Yi.Types
-- License     :  GPL-2
-- Maintainer  :  yi-devel@googlegroups.com
-- Stability   :  experimental
-- Portability :  portable
--
-- This module is the host of the most prevalent types throughout Yi.
-- It is unfortunately a necessary evil to avoid use of bootfiles.
--
-- You're encouraged to import from more idiomatic modules which will
-- re-export these where appropriate.

module Yi.Types where

import           Control.Concurrent             (MVar, modifyMVar, modifyMVar_, readMVar)
import           Control.Monad.Base             (MonadBase, liftBase)
import qualified Control.Monad.Fail as Fail
import           Control.Monad.Reader
import           Control.Monad.State.Strict
import           Control.Monad (ap, liftM3, void, forever)
import qualified Data.Set                       as Set
import           Data.Binary                    (Binary)
import qualified Data.Binary                    as B (get, put)
import           Data.Default                   (Default, def)
import qualified Data.DelayList                 as DelayList (DelayList)
import qualified Data.DynamicState              as ConfigState (DynamicState)
import qualified Data.DynamicState.Serializable as DynamicState (DynamicState)
import           Data.Function                  (on)
import           Data.List.NonEmpty             (NonEmpty)
import           Data.List.PointedList          (PointedList)
import qualified Data.Map.Strict                as M (Map)
import qualified Data.Text                      as T (Text)
import qualified Data.Text.Encoding             as E (decodeUtf8, encodeUtf8)
import           Data.Time                      (UTCTime (..))
import           Data.Typeable                  (Typeable)
import qualified Data.Sequence                  as S
import           Data.Word                      (Word8)
import           Yi.Buffer.Basic                (BufferRef, WindowRef)
import           Yi.Buffer.Implementation
import           Yi.Buffer.Undo                 (URList)
import           Yi.Config.Misc                 (ScrollStyle)
import           Yi.Event                       (Event)
import qualified Yi.Interact                    as I (I, P (End))
import           Yi.KillRing                    (Killring)
import           Yi.Layout                      (AnyLayoutManager)
import           Yi.Monad                       (getsAndModify)
import           Yi.Process                     (SubprocessId, SubprocessInfo)
import qualified Yi.Rope                        as R (YiString)
import           Yi.Style                       (StyleName)
import           Yi.Style.Library               (Theme)
import           Yi.Syntax                      (ExtHL, Stroke)
import           Yi.Tab                         (Tab)
import           Yi.UI.Common                   (UI)
import           Yi.Window                      (Window)


-- Yi.Keymap

-- TODO: refactor this!

data Action = forall a. Show a => YiA (YiM a)
            | forall a. Show a => EditorA (EditorM a)
            | forall a. Show a => BufferA (BufferM a)
            deriving Typeable

emptyAction :: Action
emptyAction :: Action
emptyAction = BufferM () -> Action
forall a. Show a => BufferM a -> Action
BufferA (() -> BufferM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())

class (Default a, Binary a, Typeable a) => YiVariable a
class (Default a, Typeable a) => YiConfigVariable a

instance Eq Action where
    Action
_ == :: Action -> Action -> Bool
== Action
_ = Bool
False

instance Show Action where
    show :: Action -> String
show (YiA YiM a
_) = String
"@Y"
    show (EditorA EditorM a
_) = String
"@E"
    show (BufferA BufferM a
_) = String
"@B"

type Interact ev a = I.I ev Action a

type KeymapM a = Interact Event a

type Keymap = KeymapM ()

type KeymapEndo = Keymap -> Keymap

type KeymapProcess = I.P Event Action

data IsRefreshNeeded = MustRefresh | NoNeedToRefresh
    deriving (Int -> IsRefreshNeeded -> ShowS
[IsRefreshNeeded] -> ShowS
IsRefreshNeeded -> String
(Int -> IsRefreshNeeded -> ShowS)
-> (IsRefreshNeeded -> String)
-> ([IsRefreshNeeded] -> ShowS)
-> Show IsRefreshNeeded
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsRefreshNeeded] -> ShowS
$cshowList :: [IsRefreshNeeded] -> ShowS
show :: IsRefreshNeeded -> String
$cshow :: IsRefreshNeeded -> String
showsPrec :: Int -> IsRefreshNeeded -> ShowS
$cshowsPrec :: Int -> IsRefreshNeeded -> ShowS
Show, IsRefreshNeeded -> IsRefreshNeeded -> Bool
(IsRefreshNeeded -> IsRefreshNeeded -> Bool)
-> (IsRefreshNeeded -> IsRefreshNeeded -> Bool)
-> Eq IsRefreshNeeded
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsRefreshNeeded -> IsRefreshNeeded -> Bool
$c/= :: IsRefreshNeeded -> IsRefreshNeeded -> Bool
== :: IsRefreshNeeded -> IsRefreshNeeded -> Bool
$c== :: IsRefreshNeeded -> IsRefreshNeeded -> Bool
Eq)

data Yi = Yi { Yi -> UI Editor
yiUi          :: UI Editor
             , Yi -> [Event] -> IO ()
yiInput       :: [Event] -> IO ()    -- ^ input stream
             , Yi -> IsRefreshNeeded -> [Action] -> IO ()
yiOutput      :: IsRefreshNeeded -> [Action] -> IO ()   -- ^ output stream
             , Yi -> Config
yiConfig      :: Config
               -- TODO: this leads to anti-patterns and seems like one itself
               -- too coarse for actual concurrency, otherwise pointless
               -- And MVars can be empty so this causes soundness problems
               -- Also makes code a bit opaque
             , Yi -> MVar YiVar
yiVar         :: MVar YiVar           -- ^ The only mutable state in the program
             }
             deriving Typeable

data YiVar = YiVar { YiVar -> Editor
yiEditor             :: !Editor
                   , YiVar -> SubprocessId
yiSubprocessIdSupply :: !SubprocessId
                   , YiVar -> Map SubprocessId SubprocessInfo
yiSubprocesses       :: !(M.Map SubprocessId SubprocessInfo)
                   }

-- | The type of user-bindable functions
-- TODO: doc how these are actually user-bindable
-- are they?
newtype YiM a = YiM {YiM a -> ReaderT Yi IO a
runYiM :: ReaderT Yi IO a}
    deriving (Applicative YiM
a -> YiM a
Applicative YiM
-> (forall a b. YiM a -> (a -> YiM b) -> YiM b)
-> (forall a b. YiM a -> YiM b -> YiM b)
-> (forall a. a -> YiM a)
-> Monad YiM
YiM a -> (a -> YiM b) -> YiM b
YiM a -> YiM b -> YiM b
forall a. a -> YiM a
forall a b. YiM a -> YiM b -> YiM b
forall a b. YiM a -> (a -> YiM b) -> YiM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> YiM a
$creturn :: forall a. a -> YiM a
>> :: YiM a -> YiM b -> YiM b
$c>> :: forall a b. YiM a -> YiM b -> YiM b
>>= :: YiM a -> (a -> YiM b) -> YiM b
$c>>= :: forall a b. YiM a -> (a -> YiM b) -> YiM b
$cp1Monad :: Applicative YiM
Monad, Functor YiM
a -> YiM a
Functor YiM
-> (forall a. a -> YiM a)
-> (forall a b. YiM (a -> b) -> YiM a -> YiM b)
-> (forall a b c. (a -> b -> c) -> YiM a -> YiM b -> YiM c)
-> (forall a b. YiM a -> YiM b -> YiM b)
-> (forall a b. YiM a -> YiM b -> YiM a)
-> Applicative YiM
YiM a -> YiM b -> YiM b
YiM a -> YiM b -> YiM a
YiM (a -> b) -> YiM a -> YiM b
(a -> b -> c) -> YiM a -> YiM b -> YiM c
forall a. a -> YiM a
forall a b. YiM a -> YiM b -> YiM a
forall a b. YiM a -> YiM b -> YiM b
forall a b. YiM (a -> b) -> YiM a -> YiM b
forall a b c. (a -> b -> c) -> YiM a -> YiM b -> YiM c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: YiM a -> YiM b -> YiM a
$c<* :: forall a b. YiM a -> YiM b -> YiM a
*> :: YiM a -> YiM b -> YiM b
$c*> :: forall a b. YiM a -> YiM b -> YiM b
liftA2 :: (a -> b -> c) -> YiM a -> YiM b -> YiM c
$cliftA2 :: forall a b c. (a -> b -> c) -> YiM a -> YiM b -> YiM c
<*> :: YiM (a -> b) -> YiM a -> YiM b
$c<*> :: forall a b. YiM (a -> b) -> YiM a -> YiM b
pure :: a -> YiM a
$cpure :: forall a. a -> YiM a
$cp1Applicative :: Functor YiM
Applicative, MonadReader Yi, MonadBase IO, Typeable, a -> YiM b -> YiM a
(a -> b) -> YiM a -> YiM b
(forall a b. (a -> b) -> YiM a -> YiM b)
-> (forall a b. a -> YiM b -> YiM a) -> Functor YiM
forall a b. a -> YiM b -> YiM a
forall a b. (a -> b) -> YiM a -> YiM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> YiM b -> YiM a
$c<$ :: forall a b. a -> YiM b -> YiM a
fmap :: (a -> b) -> YiM a -> YiM b
$cfmap :: forall a b. (a -> b) -> YiM a -> YiM b
Functor, Monad YiM
Monad YiM -> (forall a. String -> YiM a) -> MonadFail YiM
String -> YiM a
forall a. String -> YiM a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> YiM a
$cfail :: forall a. String -> YiM a
$cp1MonadFail :: Monad YiM
Fail.MonadFail)

instance MonadState Editor YiM where
    get :: YiM Editor
get = YiVar -> Editor
yiEditor (YiVar -> Editor) -> YiM YiVar -> YiM Editor
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (IO YiVar -> YiM YiVar
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO YiVar -> YiM YiVar)
-> (MVar YiVar -> IO YiVar) -> MVar YiVar -> YiM YiVar
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MVar YiVar -> IO YiVar
forall a. MVar a -> IO a
readMVar (MVar YiVar -> YiM YiVar) -> YiM (MVar YiVar) -> YiM YiVar
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Yi -> MVar YiVar
yiVar (Yi -> MVar YiVar) -> YiM Yi -> YiM (MVar YiVar)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> YiM Yi
forall r (m :: * -> *). MonadReader r m => m r
ask)
    put :: Editor -> YiM ()
put Editor
v = IO () -> YiM ()
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO () -> YiM ()) -> (MVar YiVar -> IO ()) -> MVar YiVar -> YiM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MVar YiVar -> (YiVar -> IO YiVar) -> IO ())
-> (YiVar -> IO YiVar) -> MVar YiVar -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip MVar YiVar -> (YiVar -> IO YiVar) -> IO ()
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ (\YiVar
x -> YiVar -> IO YiVar
forall (m :: * -> *) a. Monad m => a -> m a
return (YiVar -> IO YiVar) -> YiVar -> IO YiVar
forall a b. (a -> b) -> a -> b
$ YiVar
x {yiEditor :: Editor
yiEditor = Editor
v}) (MVar YiVar -> YiM ()) -> YiM (MVar YiVar) -> YiM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Yi -> MVar YiVar
yiVar (Yi -> MVar YiVar) -> YiM Yi -> YiM (MVar YiVar)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> YiM Yi
forall r (m :: * -> *). MonadReader r m => m r
ask

instance MonadEditor YiM where
    askCfg :: YiM Config
askCfg = Yi -> Config
yiConfig (Yi -> Config) -> YiM Yi -> YiM Config
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> YiM Yi
forall r (m :: * -> *). MonadReader r m => m r
ask
    withEditor :: EditorM a -> YiM a
withEditor EditorM a
f = do
      MVar YiVar
r <- (Yi -> MVar YiVar) -> YiM (MVar YiVar)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Yi -> MVar YiVar
yiVar
      Config
cfg <- (Yi -> Config) -> YiM Config
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Yi -> Config
yiConfig
      IO a -> YiM a
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO a -> YiM a) -> IO a -> YiM a
forall a b. (a -> b) -> a -> b
$ Config -> MVar YiVar -> EditorM a -> IO a
forall a. Config -> MVar YiVar -> EditorM a -> IO a
unsafeWithEditor Config
cfg MVar YiVar
r EditorM a
f


unsafeWithEditor :: Config -> MVar YiVar -> EditorM a -> IO a
unsafeWithEditor :: Config -> MVar YiVar -> EditorM a -> IO a
unsafeWithEditor Config
cfg MVar YiVar
r EditorM a
f = MVar YiVar -> (YiVar -> IO (YiVar, a)) -> IO a
forall a b. MVar a -> (a -> IO (a, b)) -> IO b
modifyMVar MVar YiVar
r ((YiVar -> IO (YiVar, a)) -> IO a)
-> (YiVar -> IO (YiVar, a)) -> IO a
forall a b. (a -> b) -> a -> b
$ \YiVar
var -> do
  let e :: Editor
e = YiVar -> Editor
yiEditor YiVar
var
  let (Editor
e',a
a) = Config -> EditorM a -> Editor -> (Editor, a)
forall a. Config -> EditorM a -> Editor -> (Editor, a)
runEditor Config
cfg EditorM a
f Editor
e
  -- Make sure that the result of runEditor is evaluated before
  -- replacing the editor state. Otherwise, we might replace e
  -- with an exception-producing thunk, which makes it impossible
  -- to look at or update the editor state.
  -- Maybe this could also be fixed by -fno-state-hack flag?
  -- TODO: can we simplify this?
  Editor
e' Editor -> IO (YiVar, a) -> IO (YiVar, a)
`seq` a
a a -> IO (YiVar, a) -> IO (YiVar, a)
`seq` (YiVar, a) -> IO (YiVar, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (YiVar
var {yiEditor :: Editor
yiEditor = Editor
e'}, a
a)


data KeymapSet = KeymapSet
    { KeymapSet -> Keymap
topKeymap :: Keymap         -- ^ Content of the top-level loop.
    , KeymapSet -> Keymap
insertKeymap :: Keymap      -- ^ For insertion-only modes
    }

extractTopKeymap :: KeymapSet -> Keymap
extractTopKeymap :: KeymapSet -> Keymap
extractTopKeymap KeymapSet
kms = Keymap -> Keymap
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (KeymapSet -> Keymap
topKeymap KeymapSet
kms)
    -- Note the use of "forever": this has quite subtle implications, as it means that
    -- failures in one iteration can yield to jump to the next iteration seamlessly.
    -- eg. in emacs keybinding, failures in incremental search, like <left>, will "exit"
    -- incremental search and immediately move to the left.

-- Yi.Buffer.Misc

-- | The BufferM monad writes the updates performed.
newtype BufferM a = BufferM { BufferM a -> ReaderT Window (State FBuffer) a
fromBufferM :: ReaderT Window (State FBuffer) a }
    deriving ( Applicative BufferM
a -> BufferM a
Applicative BufferM
-> (forall a b. BufferM a -> (a -> BufferM b) -> BufferM b)
-> (forall a b. BufferM a -> BufferM b -> BufferM b)
-> (forall a. a -> BufferM a)
-> Monad BufferM
BufferM a -> (a -> BufferM b) -> BufferM b
BufferM a -> BufferM b -> BufferM b
forall a. a -> BufferM a
forall a b. BufferM a -> BufferM b -> BufferM b
forall a b. BufferM a -> (a -> BufferM b) -> BufferM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> BufferM a
$creturn :: forall a. a -> BufferM a
>> :: BufferM a -> BufferM b -> BufferM b
$c>> :: forall a b. BufferM a -> BufferM b -> BufferM b
>>= :: BufferM a -> (a -> BufferM b) -> BufferM b
$c>>= :: forall a b. BufferM a -> (a -> BufferM b) -> BufferM b
$cp1Monad :: Applicative BufferM
Monad, a -> BufferM b -> BufferM a
(a -> b) -> BufferM a -> BufferM b
(forall a b. (a -> b) -> BufferM a -> BufferM b)
-> (forall a b. a -> BufferM b -> BufferM a) -> Functor BufferM
forall a b. a -> BufferM b -> BufferM a
forall a b. (a -> b) -> BufferM a -> BufferM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> BufferM b -> BufferM a
$c<$ :: forall a b. a -> BufferM b -> BufferM a
fmap :: (a -> b) -> BufferM a -> BufferM b
$cfmap :: forall a b. (a -> b) -> BufferM a -> BufferM b
Functor, Typeable
             , MonadState FBuffer
             , MonadReader Window )

instance Fail.MonadFail BufferM where
   fail :: String -> BufferM a
fail = String -> BufferM a
forall a. HasCallStack => String -> a
error

-- | Currently duplicates some of Vim's indent settings. Allowing a
-- buffer to specify settings that are more dynamic, perhaps via
-- closures, could be useful.
data IndentSettings = IndentSettings
  { IndentSettings -> Bool
expandTabs :: !Bool -- ^ Insert spaces instead of tabs as possible
  , IndentSettings -> Int
tabSize    :: !Int  -- ^ Size of a Tab
  , IndentSettings -> Int
shiftWidth :: !Int  -- ^ Indent by so many columns
  } deriving (IndentSettings -> IndentSettings -> Bool
(IndentSettings -> IndentSettings -> Bool)
-> (IndentSettings -> IndentSettings -> Bool) -> Eq IndentSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndentSettings -> IndentSettings -> Bool
$c/= :: IndentSettings -> IndentSettings -> Bool
== :: IndentSettings -> IndentSettings -> Bool
$c== :: IndentSettings -> IndentSettings -> Bool
Eq, Int -> IndentSettings -> ShowS
[IndentSettings] -> ShowS
IndentSettings -> String
(Int -> IndentSettings -> ShowS)
-> (IndentSettings -> String)
-> ([IndentSettings] -> ShowS)
-> Show IndentSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndentSettings] -> ShowS
$cshowList :: [IndentSettings] -> ShowS
show :: IndentSettings -> String
$cshow :: IndentSettings -> String
showsPrec :: Int -> IndentSettings -> ShowS
$cshowsPrec :: Int -> IndentSettings -> ShowS
Show, Typeable)

instance Applicative BufferM where
    pure :: a -> BufferM a
pure = a -> BufferM a
forall (m :: * -> *) a. Monad m => a -> m a
return
    <*> :: BufferM (a -> b) -> BufferM a -> BufferM b
(<*>) = BufferM (a -> b) -> BufferM a -> BufferM b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

data FBuffer = forall syntax.
        FBuffer { ()
bmode  :: !(Mode syntax)
                , ()
rawbuf :: !(BufferImpl syntax)
                , FBuffer -> Attributes
attributes :: !Yi.Types.Attributes
               }
        deriving Typeable

instance Eq FBuffer where
    == :: FBuffer -> FBuffer -> Bool
(==) = BufferRef -> BufferRef -> Bool
forall a. Eq a => a -> a -> Bool
(==) (BufferRef -> BufferRef -> Bool)
-> (FBuffer -> BufferRef) -> FBuffer -> FBuffer -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Attributes -> BufferRef
bkey__ (Attributes -> BufferRef)
-> (FBuffer -> Attributes) -> FBuffer -> BufferRef
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FBuffer -> Attributes
attributes

type WinMarks = MarkSet Mark

data MarkSet a = MarkSet { MarkSet a -> a
fromMark, MarkSet a -> a
insMark, MarkSet a -> a
selMark :: !a }
               deriving (Functor MarkSet
Foldable MarkSet
Functor MarkSet
-> Foldable MarkSet
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> MarkSet a -> f (MarkSet b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MarkSet (f a) -> f (MarkSet a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MarkSet a -> m (MarkSet b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MarkSet (m a) -> m (MarkSet a))
-> Traversable MarkSet
(a -> f b) -> MarkSet a -> f (MarkSet b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => MarkSet (m a) -> m (MarkSet a)
forall (f :: * -> *) a.
Applicative f =>
MarkSet (f a) -> f (MarkSet a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MarkSet a -> m (MarkSet b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MarkSet a -> f (MarkSet b)
sequence :: MarkSet (m a) -> m (MarkSet a)
$csequence :: forall (m :: * -> *) a. Monad m => MarkSet (m a) -> m (MarkSet a)
mapM :: (a -> m b) -> MarkSet a -> m (MarkSet b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MarkSet a -> m (MarkSet b)
sequenceA :: MarkSet (f a) -> f (MarkSet a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
MarkSet (f a) -> f (MarkSet a)
traverse :: (a -> f b) -> MarkSet a -> f (MarkSet b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MarkSet a -> f (MarkSet b)
$cp2Traversable :: Foldable MarkSet
$cp1Traversable :: Functor MarkSet
Traversable, MarkSet a -> Bool
(a -> m) -> MarkSet a -> m
(a -> b -> b) -> b -> MarkSet a -> b
(forall m. Monoid m => MarkSet m -> m)
-> (forall m a. Monoid m => (a -> m) -> MarkSet a -> m)
-> (forall m a. Monoid m => (a -> m) -> MarkSet a -> m)
-> (forall a b. (a -> b -> b) -> b -> MarkSet a -> b)
-> (forall a b. (a -> b -> b) -> b -> MarkSet a -> b)
-> (forall b a. (b -> a -> b) -> b -> MarkSet a -> b)
-> (forall b a. (b -> a -> b) -> b -> MarkSet a -> b)
-> (forall a. (a -> a -> a) -> MarkSet a -> a)
-> (forall a. (a -> a -> a) -> MarkSet a -> a)
-> (forall a. MarkSet a -> [a])
-> (forall a. MarkSet a -> Bool)
-> (forall a. MarkSet a -> Int)
-> (forall a. Eq a => a -> MarkSet a -> Bool)
-> (forall a. Ord a => MarkSet a -> a)
-> (forall a. Ord a => MarkSet a -> a)
-> (forall a. Num a => MarkSet a -> a)
-> (forall a. Num a => MarkSet a -> a)
-> Foldable MarkSet
forall a. Eq a => a -> MarkSet a -> Bool
forall a. Num a => MarkSet a -> a
forall a. Ord a => MarkSet a -> a
forall m. Monoid m => MarkSet m -> m
forall a. MarkSet a -> Bool
forall a. MarkSet a -> Int
forall a. MarkSet a -> [a]
forall a. (a -> a -> a) -> MarkSet a -> a
forall m a. Monoid m => (a -> m) -> MarkSet a -> m
forall b a. (b -> a -> b) -> b -> MarkSet a -> b
forall a b. (a -> b -> b) -> b -> MarkSet a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: MarkSet a -> a
$cproduct :: forall a. Num a => MarkSet a -> a
sum :: MarkSet a -> a
$csum :: forall a. Num a => MarkSet a -> a
minimum :: MarkSet a -> a
$cminimum :: forall a. Ord a => MarkSet a -> a
maximum :: MarkSet a -> a
$cmaximum :: forall a. Ord a => MarkSet a -> a
elem :: a -> MarkSet a -> Bool
$celem :: forall a. Eq a => a -> MarkSet a -> Bool
length :: MarkSet a -> Int
$clength :: forall a. MarkSet a -> Int
null :: MarkSet a -> Bool
$cnull :: forall a. MarkSet a -> Bool
toList :: MarkSet a -> [a]
$ctoList :: forall a. MarkSet a -> [a]
foldl1 :: (a -> a -> a) -> MarkSet a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> MarkSet a -> a
foldr1 :: (a -> a -> a) -> MarkSet a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> MarkSet a -> a
foldl' :: (b -> a -> b) -> b -> MarkSet a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> MarkSet a -> b
foldl :: (b -> a -> b) -> b -> MarkSet a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> MarkSet a -> b
foldr' :: (a -> b -> b) -> b -> MarkSet a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> MarkSet a -> b
foldr :: (a -> b -> b) -> b -> MarkSet a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> MarkSet a -> b
foldMap' :: (a -> m) -> MarkSet a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> MarkSet a -> m
foldMap :: (a -> m) -> MarkSet a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> MarkSet a -> m
fold :: MarkSet m -> m
$cfold :: forall m. Monoid m => MarkSet m -> m
Foldable, a -> MarkSet b -> MarkSet a
(a -> b) -> MarkSet a -> MarkSet b
(forall a b. (a -> b) -> MarkSet a -> MarkSet b)
-> (forall a b. a -> MarkSet b -> MarkSet a) -> Functor MarkSet
forall a b. a -> MarkSet b -> MarkSet a
forall a b. (a -> b) -> MarkSet a -> MarkSet b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MarkSet b -> MarkSet a
$c<$ :: forall a b. a -> MarkSet b -> MarkSet a
fmap :: (a -> b) -> MarkSet a -> MarkSet b
$cfmap :: forall a b. (a -> b) -> MarkSet a -> MarkSet b
Functor, Int -> MarkSet a -> ShowS
[MarkSet a] -> ShowS
MarkSet a -> String
(Int -> MarkSet a -> ShowS)
-> (MarkSet a -> String)
-> ([MarkSet a] -> ShowS)
-> Show (MarkSet a)
forall a. Show a => Int -> MarkSet a -> ShowS
forall a. Show a => [MarkSet a] -> ShowS
forall a. Show a => MarkSet a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MarkSet a] -> ShowS
$cshowList :: forall a. Show a => [MarkSet a] -> ShowS
show :: MarkSet a -> String
$cshow :: forall a. Show a => MarkSet a -> String
showsPrec :: Int -> MarkSet a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> MarkSet a -> ShowS
Show)

instance Binary a => Binary (MarkSet a) where
  put :: MarkSet a -> Put
put (MarkSet a
f a
i a
s) = a -> Put
forall t. Binary t => t -> Put
B.put a
f Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> Put
forall t. Binary t => t -> Put
B.put a
i Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> Put
forall t. Binary t => t -> Put
B.put a
s
  get :: Get (MarkSet a)
get = (a -> a -> a -> MarkSet a)
-> Get a -> Get a -> Get a -> Get (MarkSet a)
forall (m :: * -> *) a1 a2 a3 r.
Monad m =>
(a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 a -> a -> a -> MarkSet a
forall a. a -> a -> a -> MarkSet a
MarkSet Get a
forall t. Binary t => Get t
B.get Get a
forall t. Binary t => Get t
B.get Get a
forall t. Binary t => Get t
B.get

data Attributes
    = Attributes
    { Attributes -> BufferId
ident :: !BufferId
    , Attributes -> BufferRef
bkey__   :: !BufferRef -- ^ immutable unique key
    , Attributes -> URList
undos  :: !URList -- ^ undo/redo list
    , Attributes -> DynamicState
bufferDynamic :: !DynamicState.DynamicState -- ^ dynamic components
    , Attributes -> Maybe Int
preferCol :: !(Maybe Int)
    -- ^ prefered column to arrive at when we do a lineDown / lineUp
    , Attributes -> Maybe Int
preferVisCol :: !(Maybe Int)
    -- ^ prefered column to arrive at visually (ie, respecting wrap)
    , Attributes -> Bool
stickyEol :: !Bool
    -- ^ stick to the end of line (used by vim bindings mostly)
    , Attributes -> Seq UIUpdate
pendingUpdates :: !(S.Seq UIUpdate)
    -- ^ updates that haven't been synched in the UI yet
    , Attributes -> SelectionStyle
selectionStyle :: !SelectionStyle
    , Attributes -> KeymapProcess
keymapProcess :: !KeymapProcess
    , Attributes -> Map WindowRef WinMarks
winMarks :: !(M.Map WindowRef WinMarks)
    , Attributes -> Window
lastActiveWindow :: !Window
    , Attributes -> UTCTime
lastSyncTime :: !UTCTime
    -- ^ time of the last synchronization with disk
    , Attributes -> Bool
readOnly :: !Bool -- ^ read-only flag
    , Attributes -> Bool
inserting :: !Bool -- ^ the keymap is ready for insertion into this buffer
    , Attributes -> Bool
directoryContent :: !Bool -- ^ does buffer contain directory contents
    , Attributes -> Set WindowRef
pointFollowsWindow :: !(Set.Set WindowRef)
    , Attributes -> Bool
updateTransactionInFlight :: !Bool
    , Attributes -> Seq Update
updateTransactionAccum :: !(S.Seq Update)
    , Attributes -> Int
fontsizeVariation :: !Int
      -- ^ How many points (frontend-specific) to change
      -- the font by in this buffer
    , Attributes -> Seq Update
updateStream :: !(S.Seq Update)
    -- ^ Updates that we've seen in this buffer, basically
    -- "write-only". Work-around for broken WriterT.
    } deriving Typeable


instance Binary Yi.Types.Attributes where
    put :: Attributes -> Put
put (Yi.Types.Attributes BufferId
n BufferRef
b URList
u DynamicState
bd Maybe Int
pc Maybe Int
pv Bool
se Seq UIUpdate
pu SelectionStyle
selectionStyle_
         KeymapProcess
_proc Map WindowRef WinMarks
wm Window
law UTCTime
lst Bool
ro Bool
ins Bool
_dc Set WindowRef
_pfw Bool
isTransacPresent Seq Update
transacAccum Int
fv Seq Update
lg') = do
      let putTime :: UTCTime -> Put
putTime (UTCTime Day
x DiffTime
y) = Int -> Put
forall t. Binary t => t -> Put
B.put (Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
x) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
B.put (DiffTime -> Int
forall a. Enum a => a -> Int
fromEnum DiffTime
y)
      BufferId -> Put
forall t. Binary t => t -> Put
B.put BufferId
n Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BufferRef -> Put
forall t. Binary t => t -> Put
B.put BufferRef
b Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> URList -> Put
forall t. Binary t => t -> Put
B.put URList
u Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DynamicState -> Put
forall t. Binary t => t -> Put
B.put DynamicState
bd
      Maybe Int -> Put
forall t. Binary t => t -> Put
B.put Maybe Int
pc Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Int -> Put
forall t. Binary t => t -> Put
B.put Maybe Int
pv Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
se Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Seq UIUpdate -> Put
forall t. Binary t => t -> Put
B.put Seq UIUpdate
pu Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SelectionStyle -> Put
forall t. Binary t => t -> Put
B.put SelectionStyle
selectionStyle_ Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Map WindowRef WinMarks -> Put
forall t. Binary t => t -> Put
B.put Map WindowRef WinMarks
wm
      Window -> Put
forall t. Binary t => t -> Put
B.put Window
law Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> UTCTime -> Put
putTime UTCTime
lst Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
ro Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
ins Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
_dc
      Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
isTransacPresent Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Seq Update -> Put
forall t. Binary t => t -> Put
B.put Seq Update
transacAccum Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
B.put Int
fv Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Seq Update -> Put
forall t. Binary t => t -> Put
B.put Seq Update
lg'
    get :: Get Attributes
get = BufferId
-> BufferRef
-> URList
-> DynamicState
-> Maybe Int
-> Maybe Int
-> Bool
-> Seq UIUpdate
-> SelectionStyle
-> KeymapProcess
-> Map WindowRef WinMarks
-> Window
-> UTCTime
-> Bool
-> Bool
-> Bool
-> Set WindowRef
-> Bool
-> Seq Update
-> Int
-> Seq Update
-> Attributes
Yi.Types.Attributes (BufferId
 -> BufferRef
 -> URList
 -> DynamicState
 -> Maybe Int
 -> Maybe Int
 -> Bool
 -> Seq UIUpdate
 -> SelectionStyle
 -> KeymapProcess
 -> Map WindowRef WinMarks
 -> Window
 -> UTCTime
 -> Bool
 -> Bool
 -> Bool
 -> Set WindowRef
 -> Bool
 -> Seq Update
 -> Int
 -> Seq Update
 -> Attributes)
-> Get BufferId
-> Get
     (BufferRef
      -> URList
      -> DynamicState
      -> Maybe Int
      -> Maybe Int
      -> Bool
      -> Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get BufferId
forall t. Binary t => Get t
B.get Get
  (BufferRef
   -> URList
   -> DynamicState
   -> Maybe Int
   -> Maybe Int
   -> Bool
   -> Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get BufferRef
-> Get
     (URList
      -> DynamicState
      -> Maybe Int
      -> Maybe Int
      -> Bool
      -> Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get BufferRef
forall t. Binary t => Get t
B.get Get
  (URList
   -> DynamicState
   -> Maybe Int
   -> Maybe Int
   -> Bool
   -> Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get URList
-> Get
     (DynamicState
      -> Maybe Int
      -> Maybe Int
      -> Bool
      -> Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get URList
forall t. Binary t => Get t
B.get Get
  (DynamicState
   -> Maybe Int
   -> Maybe Int
   -> Bool
   -> Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get DynamicState
-> Get
     (Maybe Int
      -> Maybe Int
      -> Bool
      -> Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get DynamicState
forall t. Binary t => Get t
B.get Get
  (Maybe Int
   -> Maybe Int
   -> Bool
   -> Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get (Maybe Int)
-> Get
     (Maybe Int
      -> Bool
      -> Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
          Get (Maybe Int)
forall t. Binary t => Get t
B.get Get
  (Maybe Int
   -> Bool
   -> Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get (Maybe Int)
-> Get
     (Bool
      -> Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (Maybe Int)
forall t. Binary t => Get t
B.get Get
  (Bool
   -> Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get Bool
-> Get
     (Seq UIUpdate
      -> SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Bool
forall t. Binary t => Get t
B.get Get
  (Seq UIUpdate
   -> SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get (Seq UIUpdate)
-> Get
     (SelectionStyle
      -> KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (Seq UIUpdate)
forall t. Binary t => Get t
B.get Get
  (SelectionStyle
   -> KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get SelectionStyle
-> Get
     (KeymapProcess
      -> Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get SelectionStyle
forall t. Binary t => Get t
B.get Get
  (KeymapProcess
   -> Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get KeymapProcess
-> Get
     (Map WindowRef WinMarks
      -> Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> KeymapProcess -> Get KeymapProcess
forall (f :: * -> *) a. Applicative f => a -> f a
pure KeymapProcess
forall event w. P event w
I.End Get
  (Map WindowRef WinMarks
   -> Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get (Map WindowRef WinMarks)
-> Get
     (Window
      -> UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (Map WindowRef WinMarks)
forall t. Binary t => Get t
B.get Get
  (Window
   -> UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get Window
-> Get
     (UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Window
forall t. Binary t => Get t
B.get
          Get
  (UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get UTCTime
-> Get
     (Bool
      -> Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get UTCTime
getTime Get
  (Bool
   -> Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get Bool
-> Get
     (Bool
      -> Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Bool
forall t. Binary t => Get t
B.get Get
  (Bool
   -> Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get Bool
-> Get
     (Bool
      -> Set WindowRef
      -> Bool
      -> Seq Update
      -> Int
      -> Seq Update
      -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Bool
forall t. Binary t => Get t
B.get Get
  (Bool
   -> Set WindowRef
   -> Bool
   -> Seq Update
   -> Int
   -> Seq Update
   -> Attributes)
-> Get Bool
-> Get
     (Set WindowRef
      -> Bool -> Seq Update -> Int -> Seq Update -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Bool
forall t. Binary t => Get t
B.get
          Get
  (Set WindowRef
   -> Bool -> Seq Update -> Int -> Seq Update -> Attributes)
-> Get (Set WindowRef)
-> Get (Bool -> Seq Update -> Int -> Seq Update -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set WindowRef -> Get (Set WindowRef)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ({- TODO can serialise now -}Set WindowRef
forall a. Monoid a => a
mempty) Get (Bool -> Seq Update -> Int -> Seq Update -> Attributes)
-> Get Bool -> Get (Seq Update -> Int -> Seq Update -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Bool
forall t. Binary t => Get t
B.get Get (Seq Update -> Int -> Seq Update -> Attributes)
-> Get (Seq Update) -> Get (Int -> Seq Update -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (Seq Update)
forall t. Binary t => Get t
B.get Get (Int -> Seq Update -> Attributes)
-> Get Int -> Get (Seq Update -> Attributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
B.get Get (Seq Update -> Attributes)
-> Get (Seq Update) -> Get Attributes
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (Seq Update)
forall t. Binary t => Get t
B.get
      where
        getTime :: Get UTCTime
getTime = Day -> DiffTime -> UTCTime
UTCTime (Day -> DiffTime -> UTCTime)
-> Get Day -> Get (DiffTime -> UTCTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Day
forall a. Enum a => Int -> a
toEnum (Int -> Day) -> Get Int -> Get Day
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int
forall t. Binary t => Get t
B.get) Get (DiffTime -> UTCTime) -> Get DiffTime -> Get UTCTime
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> DiffTime
forall a. Enum a => Int -> a
toEnum (Int -> DiffTime) -> Get Int -> Get DiffTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int
forall t. Binary t => Get t
B.get)

data BufferId = MemBuffer !T.Text
              | FileBuffer !FilePath
              deriving (Int -> BufferId -> ShowS
[BufferId] -> ShowS
BufferId -> String
(Int -> BufferId -> ShowS)
-> (BufferId -> String) -> ([BufferId] -> ShowS) -> Show BufferId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferId] -> ShowS
$cshowList :: [BufferId] -> ShowS
show :: BufferId -> String
$cshow :: BufferId -> String
showsPrec :: Int -> BufferId -> ShowS
$cshowsPrec :: Int -> BufferId -> ShowS
Show, BufferId -> BufferId -> Bool
(BufferId -> BufferId -> Bool)
-> (BufferId -> BufferId -> Bool) -> Eq BufferId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferId -> BufferId -> Bool
$c/= :: BufferId -> BufferId -> Bool
== :: BufferId -> BufferId -> Bool
$c== :: BufferId -> BufferId -> Bool
Eq, Eq BufferId
Eq BufferId
-> (BufferId -> BufferId -> Ordering)
-> (BufferId -> BufferId -> Bool)
-> (BufferId -> BufferId -> Bool)
-> (BufferId -> BufferId -> Bool)
-> (BufferId -> BufferId -> Bool)
-> (BufferId -> BufferId -> BufferId)
-> (BufferId -> BufferId -> BufferId)
-> Ord BufferId
BufferId -> BufferId -> Bool
BufferId -> BufferId -> Ordering
BufferId -> BufferId -> BufferId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BufferId -> BufferId -> BufferId
$cmin :: BufferId -> BufferId -> BufferId
max :: BufferId -> BufferId -> BufferId
$cmax :: BufferId -> BufferId -> BufferId
>= :: BufferId -> BufferId -> Bool
$c>= :: BufferId -> BufferId -> Bool
> :: BufferId -> BufferId -> Bool
$c> :: BufferId -> BufferId -> Bool
<= :: BufferId -> BufferId -> Bool
$c<= :: BufferId -> BufferId -> Bool
< :: BufferId -> BufferId -> Bool
$c< :: BufferId -> BufferId -> Bool
compare :: BufferId -> BufferId -> Ordering
$ccompare :: BufferId -> BufferId -> Ordering
$cp1Ord :: Eq BufferId
Ord)

instance Binary BufferId where
  get :: Get BufferId
get = Get Word8
forall t. Binary t => Get t
B.get Get Word8 -> (Word8 -> Get BufferId) -> Get BufferId
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    (Word8
0 :: Word8) -> Text -> BufferId
MemBuffer (Text -> BufferId)
-> (ByteString -> Text) -> ByteString -> BufferId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
E.decodeUtf8 (ByteString -> BufferId) -> Get ByteString -> Get BufferId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ByteString
forall t. Binary t => Get t
B.get
    Word8
1 -> String -> BufferId
FileBuffer (String -> BufferId) -> Get String -> Get BufferId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
B.get
    Word8
x -> String -> Get BufferId
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get BufferId) -> String -> Get BufferId
forall a b. (a -> b) -> a -> b
$ String
"Binary failed on BufferId, tag: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
x
  put :: BufferId -> Put
put (MemBuffer Text
t) = Word8 -> Put
forall t. Binary t => t -> Put
B.put (Word8
0 :: Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
forall t. Binary t => t -> Put
B.put (Text -> ByteString
E.encodeUtf8 Text
t)
  put (FileBuffer String
t) = Word8 -> Put
forall t. Binary t => t -> Put
B.put (Word8
1 :: Word8) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
B.put String
t


data SelectionStyle = SelectionStyle
  { SelectionStyle -> Bool
highlightSelection :: !Bool
  , SelectionStyle -> Bool
rectangleSelection :: !Bool
  } deriving (Typeable, Int -> SelectionStyle -> ShowS
[SelectionStyle] -> ShowS
SelectionStyle -> String
(Int -> SelectionStyle -> ShowS)
-> (SelectionStyle -> String)
-> ([SelectionStyle] -> ShowS)
-> Show SelectionStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SelectionStyle] -> ShowS
$cshowList :: [SelectionStyle] -> ShowS
show :: SelectionStyle -> String
$cshow :: SelectionStyle -> String
showsPrec :: Int -> SelectionStyle -> ShowS
$cshowsPrec :: Int -> SelectionStyle -> ShowS
Show)

instance Binary SelectionStyle where
  put :: SelectionStyle -> Put
put (SelectionStyle Bool
h Bool
r) = Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
h Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
B.put Bool
r
  get :: Get SelectionStyle
get = Bool -> Bool -> SelectionStyle
SelectionStyle (Bool -> Bool -> SelectionStyle)
-> Get Bool -> Get (Bool -> SelectionStyle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Bool
forall t. Binary t => Get t
B.get Get (Bool -> SelectionStyle) -> Get Bool -> Get SelectionStyle
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Bool
forall t. Binary t => Get t
B.get


data AnyMode = forall syntax. AnyMode (Mode syntax)
  deriving Typeable

-- | A Mode customizes the Yi interface for editing a particular data
-- format. It specifies when the mode should be used and controls
-- file-specific syntax highlighting and command input, among other
-- things.
data Mode syntax = Mode
  { Mode syntax -> Text
modeName :: T.Text
    -- ^ so this can be serialized, debugged.
  , Mode syntax -> String -> YiString -> Bool
modeApplies :: FilePath -> R.YiString -> Bool
    -- ^ What type of files does this mode apply to?
  , Mode syntax -> ExtHL syntax
modeHL :: ExtHL syntax
    -- ^ Syntax highlighter
  , Mode syntax -> syntax -> BufferM ()
modePrettify :: syntax -> BufferM ()
    -- ^ Prettify current \"paragraph\"
  , Mode syntax -> KeymapSet -> KeymapSet
modeKeymap :: KeymapSet -> KeymapSet
    -- ^ Buffer-local keymap modification
  , Mode syntax -> syntax -> IndentBehaviour -> BufferM ()
modeIndent :: syntax -> IndentBehaviour -> BufferM ()
    -- ^ emacs-style auto-indent line
  , Mode syntax -> syntax -> Action
modeFollow :: syntax -> Action
    -- ^ Follow a \"link\" in the file. (eg. go to location of error message)
  , Mode syntax -> IndentSettings
modeIndentSettings :: IndentSettings
  , Mode syntax -> Maybe (BufferM ())
modeToggleCommentSelection :: Maybe (BufferM ())
  , Mode syntax -> syntax -> Point -> Point -> Point -> [Stroke]
modeGetStrokes :: syntax -> Point -> Point -> Point -> [Stroke]
    -- ^ Strokes that should be applied when displaying a syntax element
    -- should this be an Action instead?
  , Mode syntax -> BufferM ()
modeOnLoad :: BufferM ()
    -- ^ An action that is to be executed when this mode is set
  , Mode syntax -> [Text] -> BufferM Text
modeModeLine :: [T.Text] -> BufferM T.Text
    -- ^ buffer-local modeline formatting method
  , Mode syntax -> BufferM ()
modeGotoDeclaration :: BufferM ()
    -- ^ go to the point where the variable is declared
  }

-- | Used to specify the behaviour of the automatic indent command.
data IndentBehaviour =
    IncreaseCycle -- ^ Increase the indentation to the next higher indentation
                  --   hint. If we are currently at the highest level of
                  --   indentation then cycle back to the lowest.
  | DecreaseCycle -- ^ Decrease the indentation to the next smaller indentation
                  --   hint. If we are currently at the smallest level then
                  --   cycle back to the largest
  | IncreaseOnly  -- ^ Increase the indentation to the next higher hint
                  --   if no such hint exists do nothing.
  | DecreaseOnly  -- ^ Decrease the indentation to the next smaller indentation
                  --   hint, if no such hint exists do nothing.
    deriving (IndentBehaviour -> IndentBehaviour -> Bool
(IndentBehaviour -> IndentBehaviour -> Bool)
-> (IndentBehaviour -> IndentBehaviour -> Bool)
-> Eq IndentBehaviour
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndentBehaviour -> IndentBehaviour -> Bool
$c/= :: IndentBehaviour -> IndentBehaviour -> Bool
== :: IndentBehaviour -> IndentBehaviour -> Bool
$c== :: IndentBehaviour -> IndentBehaviour -> Bool
Eq, Int -> IndentBehaviour -> ShowS
[IndentBehaviour] -> ShowS
IndentBehaviour -> String
(Int -> IndentBehaviour -> ShowS)
-> (IndentBehaviour -> String)
-> ([IndentBehaviour] -> ShowS)
-> Show IndentBehaviour
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndentBehaviour] -> ShowS
$cshowList :: [IndentBehaviour] -> ShowS
show :: IndentBehaviour -> String
$cshow :: IndentBehaviour -> String
showsPrec :: Int -> IndentBehaviour -> ShowS
$cshowsPrec :: Int -> IndentBehaviour -> ShowS
Show)

-- Yi.Editor

type Status = ([T.Text], StyleName)
type Statuses = DelayList.DelayList Status

-- | The Editor state
data Editor = Editor
  { Editor -> NonEmpty BufferRef
bufferStack     :: !(NonEmpty BufferRef)
    -- ^ Stack of all the buffers.
    -- Invariant: first buffer is the current one.
  , Editor -> Map BufferRef FBuffer
buffers         :: !(M.Map BufferRef FBuffer)
  , Editor -> Int
refSupply       :: !Int  -- ^ Supply for buffer, window and tab ids.
  , Editor -> PointedList Tab
tabs_           :: !(PointedList Tab)
    -- ^ current tab contains the visible windows pointed list.
  , Editor -> DynamicState
dynamic         :: !DynamicState.DynamicState -- ^ dynamic components
  , Editor -> Statuses
statusLines     :: !Statuses
  , Editor -> Int
maxStatusHeight :: !Int
  , Editor -> Killring
killring        :: !Killring
  , Editor -> Maybe SearchExp
currentRegex    :: !(Maybe SearchExp)
    -- ^ currently highlighted regex (also most recent regex for use
    -- in vim bindings)
  , Editor -> Direction
searchDirection :: !Direction
  , Editor -> [Event]
pendingEvents   :: ![Event]
    -- ^ Processed events that didn't yield any action yet.
  , Editor -> Map BufferRef (EditorM ())
onCloseActions  :: !(M.Map BufferRef (EditorM ()))
    -- ^ Actions to be run when the buffer is closed; should be scrapped.
  } deriving Typeable


newtype EditorM a = EditorM {EditorM a -> ReaderT Config (State Editor) a
fromEditorM :: ReaderT Config (State Editor) a}
    deriving (Applicative EditorM
a -> EditorM a
Applicative EditorM
-> (forall a b. EditorM a -> (a -> EditorM b) -> EditorM b)
-> (forall a b. EditorM a -> EditorM b -> EditorM b)
-> (forall a. a -> EditorM a)
-> Monad EditorM
EditorM a -> (a -> EditorM b) -> EditorM b
EditorM a -> EditorM b -> EditorM b
forall a. a -> EditorM a
forall a b. EditorM a -> EditorM b -> EditorM b
forall a b. EditorM a -> (a -> EditorM b) -> EditorM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> EditorM a
$creturn :: forall a. a -> EditorM a
>> :: EditorM a -> EditorM b -> EditorM b
$c>> :: forall a b. EditorM a -> EditorM b -> EditorM b
>>= :: EditorM a -> (a -> EditorM b) -> EditorM b
$c>>= :: forall a b. EditorM a -> (a -> EditorM b) -> EditorM b
$cp1Monad :: Applicative EditorM
Monad, Functor EditorM
a -> EditorM a
Functor EditorM
-> (forall a. a -> EditorM a)
-> (forall a b. EditorM (a -> b) -> EditorM a -> EditorM b)
-> (forall a b c.
    (a -> b -> c) -> EditorM a -> EditorM b -> EditorM c)
-> (forall a b. EditorM a -> EditorM b -> EditorM b)
-> (forall a b. EditorM a -> EditorM b -> EditorM a)
-> Applicative EditorM
EditorM a -> EditorM b -> EditorM b
EditorM a -> EditorM b -> EditorM a
EditorM (a -> b) -> EditorM a -> EditorM b
(a -> b -> c) -> EditorM a -> EditorM b -> EditorM c
forall a. a -> EditorM a
forall a b. EditorM a -> EditorM b -> EditorM a
forall a b. EditorM a -> EditorM b -> EditorM b
forall a b. EditorM (a -> b) -> EditorM a -> EditorM b
forall a b c. (a -> b -> c) -> EditorM a -> EditorM b -> EditorM c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: EditorM a -> EditorM b -> EditorM a
$c<* :: forall a b. EditorM a -> EditorM b -> EditorM a
*> :: EditorM a -> EditorM b -> EditorM b
$c*> :: forall a b. EditorM a -> EditorM b -> EditorM b
liftA2 :: (a -> b -> c) -> EditorM a -> EditorM b -> EditorM c
$cliftA2 :: forall a b c. (a -> b -> c) -> EditorM a -> EditorM b -> EditorM c
<*> :: EditorM (a -> b) -> EditorM a -> EditorM b
$c<*> :: forall a b. EditorM (a -> b) -> EditorM a -> EditorM b
pure :: a -> EditorM a
$cpure :: forall a. a -> EditorM a
$cp1Applicative :: Functor EditorM
Applicative, MonadState Editor,
              MonadReader Config, a -> EditorM b -> EditorM a
(a -> b) -> EditorM a -> EditorM b
(forall a b. (a -> b) -> EditorM a -> EditorM b)
-> (forall a b. a -> EditorM b -> EditorM a) -> Functor EditorM
forall a b. a -> EditorM b -> EditorM a
forall a b. (a -> b) -> EditorM a -> EditorM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> EditorM b -> EditorM a
$c<$ :: forall a b. a -> EditorM b -> EditorM a
fmap :: (a -> b) -> EditorM a -> EditorM b
$cfmap :: forall a b. (a -> b) -> EditorM a -> EditorM b
Functor, Typeable)

instance MonadEditor EditorM where
    askCfg :: EditorM Config
askCfg = EditorM Config
forall r (m :: * -> *). MonadReader r m => m r
ask
    withEditor :: EditorM a -> EditorM a
withEditor = EditorM a -> EditorM a
forall a. a -> a
id

instance Fail.MonadFail EditorM where
   fail :: String -> EditorM a
fail = String -> EditorM a
forall a. HasCallStack => String -> a
error

class (Monad m, MonadState Editor m) => MonadEditor m where
  askCfg :: m Config

  withEditor :: EditorM a -> m a
  withEditor EditorM a
f = do
    Config
cfg <- m Config
forall (m :: * -> *). MonadEditor m => m Config
askCfg
    (Editor -> (Editor, a)) -> m a
forall s (m :: * -> *) a. MonadState s m => (s -> (s, a)) -> m a
getsAndModify (Config -> EditorM a -> Editor -> (Editor, a)
forall a. Config -> EditorM a -> Editor -> (Editor, a)
runEditor Config
cfg EditorM a
f)

  withEditor_ :: EditorM a -> m ()
  withEditor_ = EditorM () -> m ()
forall (m :: * -> *) a. MonadEditor m => EditorM a -> m a
withEditor (EditorM () -> m ())
-> (EditorM a -> EditorM ()) -> EditorM a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EditorM a -> EditorM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void


runEditor :: Config -> EditorM a -> Editor -> (Editor, a)
runEditor :: Config -> EditorM a -> Editor -> (Editor, a)
runEditor Config
cfg EditorM a
f Editor
e = let (a
a, Editor
e') = State Editor a -> Editor -> (a, Editor)
forall s a. State s a -> s -> (a, s)
runState (ReaderT Config (State Editor) a -> Config -> State Editor a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (EditorM a -> ReaderT Config (State Editor) a
forall a. EditorM a -> ReaderT Config (State Editor) a
fromEditorM EditorM a
f) Config
cfg) Editor
e
                    in (Editor
e',a
a)

-- Yi.Config

data UIConfig = UIConfig {
   UIConfig -> Maybe String
configFontName :: Maybe String,  -- ^ Font name, for the UI that support it.
   UIConfig -> Maybe Int
configFontSize :: Maybe Int,     -- ^ Font size, for the UI that support it.
   UIConfig -> Maybe ScrollStyle
configScrollStyle :: Maybe ScrollStyle,
   -- ^ Style of scroll
   UIConfig -> Int
configScrollWheelAmount :: Int,  -- ^ Amount to move the buffer when using the scroll wheel
   UIConfig -> Bool
configLeftSideScrollBar :: Bool, -- ^ Should the scrollbar be shown on the left side?
   UIConfig -> Bool
configAutoHideScrollBar :: Bool, -- ^ Hide scrollbar automatically if text fits on one page.
   UIConfig -> Bool
configAutoHideTabBar :: Bool,    -- ^ Hide the tabbar automatically if only one tab is present
   UIConfig -> Bool
configLineWrap :: Bool,          -- ^ Wrap lines at the edge of the window if too long to display.
   UIConfig -> CursorStyle
configCursorStyle :: CursorStyle,
   UIConfig -> Char
configWindowFill :: Char,
   -- ^ The char with which to fill empty window space.  Usually '~' for vi-like
   -- editors, ' ' for everything else.
   UIConfig -> Theme
configTheme :: Theme,            -- ^ UI colours
   UIConfig -> Bool
configLineNumbers :: Bool        -- ^ Should we show line numbers by default?
  }


type UIBoot = Config -> ([Event] -> IO ())
              -> ([Action] -> IO ()) ->  Editor -> IO (UI Editor)

-- | When should we use a "fat" cursor (i.e. 2 pixels wide, rather than 1)? Fat
-- cursors have only been implemented for the Pango frontend.
data CursorStyle = AlwaysFat
                 | NeverFat
                 | FatWhenFocused
                 | FatWhenFocusedAndInserting

-- | Configuration record. All Yi hooks can be set here.
data Config = Config {Config -> UIBoot
startFrontEnd :: UIBoot,
                      -- ^ UI to use.
                      Config -> UIConfig
configUI :: !UIConfig,
                      -- ^ UI-specific configuration.
                      Config -> [Action]
startActions :: ![Action],
                      -- ^ Actions to run when the editor is started.
                      Config -> [Action]
initialActions :: ![Action],
                      -- ^ Actions to run after startup (after startActions) or reload.
                      Config -> KeymapSet
defaultKm :: !KeymapSet,
                      -- ^ Default keymap to use.
                      Config -> P Event Event
configInputPreprocess :: !(I.P Event Event),
                      Config -> [AnyMode]
modeTable :: ![AnyMode],
                      -- ^ List modes by order of preference.
                      Config -> Bool
debugMode :: !Bool,
                      -- ^ Produce a .yi.dbg file with a lot of debug information.
                      Config -> RegionStyle
configRegionStyle :: !RegionStyle,
                      -- ^ Set to 'Exclusive' for an emacs-like behaviour.
                      Config -> Bool
configKillringAccumulate :: !Bool,
                      -- ^ Set to 'True' for an emacs-like behaviour, where
                      -- all deleted text is accumulated in a killring.
                      Config -> Bool
configCheckExternalChangesObsessively :: !Bool,
                      Config -> Seq (Seq Update -> BufferM ())
bufferUpdateHandler :: !(S.Seq (S.Seq Update -> BufferM ())),
                      Config -> [AnyLayoutManager]
layoutManagers :: ![AnyLayoutManager],
                      -- ^ List of layout managers for 'cycleLayoutManagersNext'
                      Config -> DynamicState
configVars :: !ConfigState.DynamicState
                      -- ^ Custom configuration, containing the 'YiConfigVariable's. Configure with 'configVariableA'.
                     }


-- Yi.Buffer.Normal

-- Region styles are relative to the buffer contents.
-- They likely should be considered a TextUnit.
data RegionStyle = LineWise
                 | Inclusive
                 | Exclusive
                 | Block
  deriving (RegionStyle -> RegionStyle -> Bool
(RegionStyle -> RegionStyle -> Bool)
-> (RegionStyle -> RegionStyle -> Bool) -> Eq RegionStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegionStyle -> RegionStyle -> Bool
$c/= :: RegionStyle -> RegionStyle -> Bool
== :: RegionStyle -> RegionStyle -> Bool
$c== :: RegionStyle -> RegionStyle -> Bool
Eq, Typeable, Int -> RegionStyle -> ShowS
[RegionStyle] -> ShowS
RegionStyle -> String
(Int -> RegionStyle -> ShowS)
-> (RegionStyle -> String)
-> ([RegionStyle] -> ShowS)
-> Show RegionStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegionStyle] -> ShowS
$cshowList :: [RegionStyle] -> ShowS
show :: RegionStyle -> String
$cshow :: RegionStyle -> String
showsPrec :: Int -> RegionStyle -> ShowS
$cshowsPrec :: Int -> RegionStyle -> ShowS
Show)

instance Binary RegionStyle where
  put :: RegionStyle -> Put
put RegionStyle
LineWise = Word8 -> Put
forall t. Binary t => t -> Put
B.put (Word8
0 :: Word8)
  put RegionStyle
Inclusive = Word8 -> Put
forall t. Binary t => t -> Put
B.put (Word8
1 :: Word8)
  put RegionStyle
Exclusive = Word8 -> Put
forall t. Binary t => t -> Put
B.put (Word8
2 :: Word8)
  put RegionStyle
Block = Word8 -> Put
forall t. Binary t => t -> Put
B.put (Word8
3 :: Word8)

  get :: Get RegionStyle
get = Get Word8
forall t. Binary t => Get t
B.get Get Word8 -> (Word8 -> Get RegionStyle) -> Get RegionStyle
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    (Word8
0 :: Word8) -> RegionStyle -> Get RegionStyle
forall (m :: * -> *) a. Monad m => a -> m a
return RegionStyle
LineWise
    Word8
1 -> RegionStyle -> Get RegionStyle
forall (m :: * -> *) a. Monad m => a -> m a
return RegionStyle
Inclusive
    Word8
2 -> RegionStyle -> Get RegionStyle
forall (m :: * -> *) a. Monad m => a -> m a
return RegionStyle
Exclusive
    Word8
3 -> RegionStyle -> Get RegionStyle
forall (m :: * -> *) a. Monad m => a -> m a
return RegionStyle
Block
    Word8
n -> String -> Get RegionStyle
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get RegionStyle) -> String -> Get RegionStyle
forall a b. (a -> b) -> a -> b
$ String
"Binary RegionStyle fail with " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
n

-- TODO: put in the buffer state proper.
instance Default RegionStyle where
  def :: RegionStyle
def = RegionStyle
Inclusive

instance YiVariable RegionStyle