module Ribosome.Mapping where import Ribosome.Control.Monad.Ribo (MonadRibo, NvimE, pluginName) import Ribosome.Data.Mapping (Mapping(Mapping), MappingIdent(MappingIdent)) import Ribosome.Data.Text (capitalize) import Ribosome.Nvim.Api.Data (Buffer) import Ribosome.Nvim.Api.IO (bufferGetNumber, vimCommand, vimGetCurrentBuffer, vimSetCurrentBuffer) activateMapping :: Mapping -> m () activateMapping :: Mapping -> m () activateMapping Mapping _ = m () forall a. HasCallStack => a undefined mapCommand :: Text -> Bool -> Text mapCommand :: Text -> Bool -> Text mapCommand Text mode Bool remap = Text mode Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> (if Bool remap then Text "map" else Text "noremap") activateBufferMapping :: MonadRibo m => NvimE e m => Buffer -> Mapping -> m () activateBufferMapping :: Buffer -> Mapping -> m () activateBufferMapping Buffer buffer (Mapping (MappingIdent Text ident) Text lhs Text mode Bool remap Bool _) = do Buffer previous <- m Buffer forall (m :: * -> *) e. (Nvim m, MonadDeepError e RpcError m) => m Buffer vimGetCurrentBuffer Text name <- m Text forall (m :: * -> *). MonadRibo m => m Text pluginName Int number <- Buffer -> m Int forall (m :: * -> *) e. (Nvim m, MonadDeepError e RpcError m) => Buffer -> m Int bufferGetNumber Buffer buffer Text -> m () forall (m :: * -> *) e. (Nvim m, MonadDeepError e RpcError m) => Text -> m () vimCommand ([Text] -> Text forall t. IsText t "unwords" => [t] -> t unwords (Text -> Int -> [Text] cmdline Text name Int number)) Bool -> m () -> m () forall (f :: * -> *). Applicative f => Bool -> f () -> f () when (Buffer buffer Buffer -> Buffer -> Bool forall a. Eq a => a -> a -> Bool /= Buffer previous) (Buffer -> m () forall (m :: * -> *) e. (Nvim m, MonadDeepError e RpcError m) => Buffer -> m () vimSetCurrentBuffer Buffer previous) where cmdline :: Text -> Int -> [Text] cmdline Text name Int number = [Int -> Text forall b a. (Show a, IsString b) => a -> b show Int number, Item [Text] "bufdo ", Text Item [Text] cmd, Item [Text] "<buffer>", Text Item [Text] lhs, Item [Text] ":silent call", Text -> Text func Text name Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text "('" Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text ident Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text "')<cr>"] cmd :: Text cmd = Text -> Bool -> Text mapCommand Text mode Bool remap func :: Text -> Text func Text name = Text -> Text capitalize Text name Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text "Mapping"