packages feed

yi-keymap-vim 0.13.3 → 0.13.4

raw patch · 7 files changed

+93/−9 lines, 7 files

Files

src/Yi/Keymap/Vim/Common.hs view
@@ -101,7 +101,7 @@ data Register = Register     { regRegionStyle :: RegionStyle     , regContent     :: YiString-    } deriving (Generic)+    } deriving (Show, Generic)  data VimMode     = Normal@@ -127,7 +127,7 @@     , vsRegisterMap           :: !(HM.HashMap RegisterName Register)     , vsActiveRegister        :: !RegisterName     , vsRepeatableAction      :: !(Maybe RepeatableAction)-    , vsStringToEval          :: !EventString -- ^ see Yi.Keymap.Vim.vimEval comment+    , vsStringToEval          :: !EventString -- ^ see Yi.Keymap.Vim.pureEval comment     , vsOngoingInsertEvents   :: !EventString     , vsLastGotoCharCommand   :: !(Maybe GotoCharCommand)     , vsBindingAccumulator    :: !EventString
src/Yi/Keymap/Vim/Eval.hs view
@@ -8,7 +8,7 @@ -- Portability :  portable -- -- This module doesn't contains actual eval, see--- 'Yi.Keymap.Vim.vimEval' comment.+-- 'Yi.Keymap.Vim.pureEval' comment.  module Yi.Keymap.Vim.Eval (scheduleActionStringForEval) where 
src/Yi/Keymap/Vim/Ex.hs view
@@ -40,6 +40,7 @@ import qualified Yi.Keymap.Vim.Ex.Commands.Yi           as Yi (parse) import qualified Yi.Keymap.Vim.Ex.Commands.Copy         as Copy (parse) import qualified Yi.Keymap.Vim.Ex.Commands.Stack        as Stack (parse)+import qualified Yi.Keymap.Vim.Ex.Commands.Registers    as Registers (parse) import           Yi.Keymap.Vim.Ex.Eval                  (exEvalE, exEvalY) import           Yi.Keymap.Vim.Ex.Types                 (ExCommand (..), evStringToExCommand) @@ -69,4 +70,5 @@     , Yi.parse     , Copy.parse     , Stack.parse+    , Registers.parse     ]
+ src/Yi/Keymap/Vim/Ex/Commands/Registers.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HADDOCK show-extensions #-}++-- |+-- Module      :  Yi.Keymap.Vim.Ex.Commands.BufferDelete+-- License     :  GPL-2+--+-- :reg[isters] ex command to list yanked texts.+module Yi.Keymap.Vim.Ex.Commands.Registers (printRegisters, parse) where++import           Control.Applicative              (Alternative ((<|>)), (<*))+import           Control.Monad                    (void)+import           Data.Monoid                      ((<>))+import           Yi.Keymap                        (Action (EditorA))+import           Yi.Keymap.Vim.Ex.Types           (ExCommand (cmdAction, cmdShow))+import           Yi.Keymap.Vim.Common             (EventString, RegisterName, Register (regContent), VimState (vsRegisterMap))+import           Yi.Editor                        (EditorM, getEditorDyn, newBufferE)+import           Yi.Rope                          (YiString)+import           Yi.Types                         (withEditor, BufferId (MemBuffer))+import qualified Data.Attoparsec.Text             as P (string, try, endOfInput)+import qualified Data.HashMap.Strict              as HM (toList)+import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common (parse, pureExCommand)+import qualified Yi.Rope                          as R (concat, toString, fromString)+++-- | Show registered register and content in new buffer+printRegisters :: EditorM ()+printRegisters = do+  xs <- HM.toList . vsRegisterMap <$> getEditorDyn+  let xs'       = visualizeConvert xs+      registers = flip map xs' $ \(nameWithSep, content) -> nameWithSep <> content <> "\n"+      bufDetail = "--- Register ---\n" <> R.concat registers+  void $ newBufferE (MemBuffer "Register list") bufDetail+  where+    replaceName n | n == '\NUL' = "\\NUL | "+                  | otherwise   = ['"', n] ++ "   | "  -- Straighten diff of \NUL+    replaceContent = let replaceContentChar c | c == '\n' = "^J"+                                              | otherwise = [c]+                     in concatMap replaceContentChar+    visualizeConvert :: [(RegisterName, Register)] -> [(YiString, YiString)]+    visualizeConvert = map $ \(name, reg) ->+      let content = R.toString . regContent $ reg+      in ( R.fromString . replaceName $ name+         , R.fromString . replaceContent $ content+         )+++-- | See :help :registers on Vim+parse :: EventString -> Maybe ExCommand+parse = Common.parse $ do+  P.string "reg" <* (     P.try (P.string "isters")+                      <|> P.try (P.string "ister")+                      <|> P.try (P.string "iste")+                      <|> P.try (P.string "ist")+                      <|> P.try (P.string "is")+                      <|> P.try (P.string "i")+                      <|> P.string ""+                    )+                 <* P.endOfInput+  return Common.pureExCommand+    { cmdShow   = "registers"+    , cmdAction = EditorA $ withEditor printRegisters+    }
src/Yi/Keymap/Vim/ExMap.hs view
@@ -174,6 +174,8 @@       "<C-r>" -> return () -- TODO       "<lt>" -> insertB '<'       "<Del>" -> deleteB Character Forward+      "<C-d>" -> deleteB Character Forward+      "<M-d>" -> deleteB unitWord Forward       "<Left>" -> moveXorSol 1       "<C-b>" -> moveXorSol 1       "<Right>" -> moveXorEol 1
tests/Vim/TestExCommandParsers.hs view
@@ -13,14 +13,15 @@ import qualified Yi.Keymap.Vim.Ex.Commands.Buffer as Buffer import qualified Yi.Keymap.Vim.Ex.Commands.BufferDelete as BufferDelete import qualified Yi.Keymap.Vim.Ex.Commands.Delete as Delete+import qualified Yi.Keymap.Vim.Ex.Commands.Registers as Registers  data CommandParser = CommandParser-    { cpDescription :: String-    , cpParser      :: String -> Maybe ExCommand-    , cpNames       :: [String]-    , cpAcceptsBang :: Bool+    { cpDescription  :: String+    , cpParser       :: String -> Maybe ExCommand+    , cpNames        :: [String]+    , cpAcceptsBang  :: Bool     , cpAcceptsCount :: Bool-    , cpArgs        :: Gen String+    , cpArgs         :: Gen String     }  addingSpace :: Gen String -> Gen String@@ -97,6 +98,21 @@                  , addingSpace count                  , (<>) <$> addingSpace registerName <*> addingSpace count                  ])++    , CommandParser+          "Registers.parse"+          (Registers.parse . Ev . T.pack)+          [ "reg"+          , "regi"+          , "regis"+          , "regist"+          , "registe"+          , "register"+          , "registers"+          ]+          False+          False+          (pure "")     ]  
yi-keymap-vim.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           yi-keymap-vim-version:        0.13.3+version:        0.13.4 synopsis:       Vim keymap for Yi editor category:       Yi homepage:       https://github.com/yi-editor/yi#readme@@ -74,6 +74,7 @@       Yi.Keymap.Vim.Ex.Commands.Undo       Yi.Keymap.Vim.Ex.Commands.Write       Yi.Keymap.Vim.Ex.Commands.Yi+      Yi.Keymap.Vim.Ex.Commands.Registers       Yi.Keymap.Vim.Ex.Eval       Yi.Keymap.Vim.Ex.Types       Yi.Keymap.Vim.ExMap