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

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

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

    import           Control.Applicative              (Alternative ((<|>)))
    import           Control.Monad                    (void)
    import qualified Data.Attoparsec.Text             as P (string, try, match)
    import           Data.Maybe                       (fromMaybe)
    import           Data.Text                        ()
    import           Data.Semigroup                   ((<>))
    import           Lens.Micro.Platform
    import           Yi.Buffer                        hiding (Delete)
    import           Yi.Keymap                        (Action (BufferA))
    import           Yi.Keymap.Vim.Common             (EventString)
    import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common (parse, pureExCommand, parseRange)
    import           Yi.Keymap.Vim.Ex.Types           (ExCommand (cmdAction, cmdShow))

    parse :: EventString -> Maybe ExCommand
    parse :: EventString -> Maybe ExCommand
    parse = Parser ExCommand -> EventString -> Maybe ExCommand
    Common.parse (Parser ExCommand -> EventString -> Maybe ExCommand)
    -> Parser ExCommand -> EventString -> Maybe ExCommand
    forall a b. (a -> b) -> a -> b
    $ do
        (rangeText, rangeB) <- ASetter
      (Text, Maybe (BufferM Region))
      (Text, BufferM Region)
      (Maybe (BufferM Region))
      (BufferM Region)
    -> (Maybe (BufferM Region) -> BufferM Region)
    -> (Text, Maybe (BufferM Region))
    -> (Text, BufferM Region)
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    over ASetter
      (Text, Maybe (BufferM Region))
      (Text, BufferM Region)
      (Maybe (BufferM Region))
      (BufferM Region)
    forall s t a b. Field2 s t a b => Lens s t a b
    Lens
      (Text, Maybe (BufferM Region))
      (Text, BufferM Region)
      (Maybe (BufferM Region))
      (BufferM Region)
    _2 (BufferM Region -> Maybe (BufferM Region) -> BufferM Region
    forall a. a -> Maybe a -> a
    fromMaybe BufferM Region
    currentLineRegionB)
          ((Text, Maybe (BufferM Region)) -> (Text, BufferM Region))
    -> Parser Text (Text, Maybe (BufferM Region))
    -> Parser Text (Text, BufferM Region)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Parser (Maybe (BufferM Region))
    -> Parser Text (Text, Maybe (BufferM Region))
    forall a. Parser a -> Parser (Text, a)
    P.match Parser (Maybe (BufferM Region))
    Common.parseRange
        void $ P.try ( P.string "delete") <|> P.string "d"
        return $ Common.pureExCommand {
            cmdShow = rangeText <> "delete"
          , cmdAction = BufferA $ deleteRegionB =<< rangeB
          }
      where currentLineRegionB :: BufferM Region
    currentLineRegionB = (Region -> RegionStyle -> BufferM Region)
    -> RegionStyle -> Region -> BufferM Region
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip Region -> RegionStyle -> BufferM Region
    convertRegionToStyleB RegionStyle
    LineWise (Region -> BufferM Region) -> BufferM Region -> BufferM Region
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< TextUnit -> BufferM Region
    regionOfB TextUnit
    Line