    {-# LANGUAGE OverloadedStrings #-}
    {-# OPTIONS_HADDOCK show-extensions #-}

    -- |
    -- Module      :  Yi.Keymap.Vim.Ex.Commands.Paste
    -- License     :  GPL-2
    -- Maintainer  :  yi-devel@googlegroups.com
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- Implements quit commands.

    module Yi.Keymap.Vim.Ex.Commands.Paste (parse) where

    import           Data.Monoid                      ((<>))
    import           Yi.Editor                        (getEditorDyn, printMsg)
    import           Yi.Keymap                        (Action (EditorA))
    import           Yi.Keymap.Vim.Common             (EventString, VimState (vsPaste))
    import           Yi.Keymap.Vim.Ex.Commands.Common (BoolOptionAction (..), parseBoolOption)
    import           Yi.Keymap.Vim.Ex.Types           (ExCommand)
    import           Yi.Keymap.Vim.StateUtils         (modifyStateE)
    import           Yi.String                        (showT)

    parse :: EventString -> Maybe ExCommand
    parse :: EventString -> Maybe ExCommand
    parse = Text
    -> (BoolOptionAction -> Action) -> EventString -> Maybe ExCommand
    parseBoolOption Text
    "paste" BoolOptionAction -> Action
    action

    action :: BoolOptionAction -> Action
    action :: BoolOptionAction -> Action
    action BoolOptionAction
    BoolOptionAsk = EditorM () -> Action
    forall a. Show a => EditorM a -> Action
    EditorA (EditorM () -> Action) -> EditorM () -> Action
    forall a b. (a -> b) -> a -> b
    $ do
        value <- VimState -> Bool
    vsPaste (VimState -> Bool) -> EditorM VimState -> EditorM Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> EditorM VimState
    forall (m :: * -> *) a.
    (MonadEditor m, YiVariable a, Default a, Functor m) =>
    m a
    getEditorDyn
        printMsg $ "paste = " <> showT value
    action (BoolOptionSet Bool
    b) = (Bool -> Bool) -> Action
    modPaste ((Bool -> Bool) -> Action) -> (Bool -> Bool) -> Action
    forall a b. (a -> b) -> a -> b
    $ Bool -> Bool -> Bool
    forall a b. a -> b -> a
    const Bool
    b
    action BoolOptionAction
    BoolOptionInvert = (Bool -> Bool) -> Action
    modPaste Bool -> Bool
    not

    modPaste :: (Bool -> Bool) -> Action
    modPaste :: (Bool -> Bool) -> Action
    modPaste Bool -> Bool
    f = EditorM () -> Action
    forall a. Show a => EditorM a -> Action
    EditorA (EditorM () -> Action)
    -> ((VimState -> VimState) -> EditorM ())
    -> (VimState -> VimState)
    -> Action
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (VimState -> VimState) -> EditorM ()
    modifyStateE ((VimState -> VimState) -> Action)
    -> (VimState -> VimState) -> Action
    forall a b. (a -> b) -> a -> b
    $ \VimState
    s -> VimState
    s { vsPaste = f (vsPaste s) }