packages feed

yi-keymap-vim 0.14.0 → 0.14.1

raw patch · 7 files changed

+88/−26 lines, 7 files

Files

src/Yi/Keymap/Vim/Ex.hs view
@@ -18,6 +18,7 @@ import           Yi.Keymap.Vim.Common                   (EventString) import qualified Yi.Keymap.Vim.Ex.Commands.Buffer       as Buffer (parse) import qualified Yi.Keymap.Vim.Ex.Commands.BufferDelete as BufferDelete (parse)+import qualified Yi.Keymap.Vim.Ex.Commands.BufferNew    as BufferNew (parse) import qualified Yi.Keymap.Vim.Ex.Commands.Buffers      as Buffers (parse) import qualified Yi.Keymap.Vim.Ex.Commands.Cabal        as Cabal (parse) import qualified Yi.Keymap.Vim.Ex.Commands.Delete       as Delete (parse)@@ -48,6 +49,7 @@     [ Buffer.parse     , Buffers.parse     , BufferDelete.parse+    , BufferNew.parse     , Cabal.parse     , Delete.parse     , Edit.parse
src/Yi/Keymap/Vim/Ex/Commands/Buffer.hs view
@@ -10,7 +10,7 @@ -- -- :buffer ex command to switch to named or numbered buffer. -module Yi.Keymap.Vim.Ex.Commands.Buffer (parse) where+module Yi.Keymap.Vim.Ex.Commands.Buffer (parse,bufferIdentifier) where  import           Control.Applicative              (Alternative ((<|>))) import           Control.Monad                    (void)@@ -29,9 +29,7 @@  parse :: EventString -> Maybe ExCommand parse = Common.parseWithBangAndCount nameParser $ \ _ bang mcount -> do-  bufIdent <- (T.pack <$> P.many1 P.digit) <|> bufferSymbol <|>-              (T.pack <$> P.many1 P.space) *> (T.pack <$> P.many' P.anyChar) <|>-              P.endOfInput *> return ""+  bufIdent <- bufferIdentifier   return $ Common.pureExCommand {       cmdShow = "buffer"     , cmdAction = EditorA $ do@@ -42,9 +40,14 @@             Just i  -> switchByRef $ BufferRef i           else Common.errorNoWrite     }-  where-    bufferSymbol = P.string "%" <|> P.string "#" +bufferSymbol :: P.Parser T.Text+bufferSymbol = P.string "%" <|> P.string "#"++bufferIdentifier :: P.Parser T.Text+bufferIdentifier = (T.pack <$> P.many1 P.digit) <|> bufferSymbol <|>+    (T.pack <$> P.many1 P.space) *> (T.pack <$> P.many' P.anyChar) <|>+    P.endOfInput *> return ""  nameParser :: P.Parser () nameParser = void . P.choice . fmap P.string $ ["buffer", "buf", "bu", "b"]
src/Yi/Keymap/Vim/Ex/Commands/BufferDelete.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings, UnboxedTuples #-} {-# OPTIONS_HADDOCK show-extensions #-}  -- |@@ -10,20 +10,41 @@  module Yi.Keymap.Vim.Ex.Commands.BufferDelete (parse) where -import           Control.Applicative              (Alternative ((<|>)))-import           Control.Monad                    (void)-import           Data.Text                        ()-import qualified Data.Attoparsec.Text             as P (string, try)-import           Yi.Editor                        (closeBufferAndWindowE)-import           Yi.Keymap                        (Action (EditorA))+import           Control.Applicative              (Alternative (some))+import           Control.Monad                    (void, when)+import qualified Data.Text                        as T (null)+import qualified Data.Attoparsec.Text             as P (Parser, choice, digit, parseOnly, string)+import           Lens.Micro.Platform              (use)+import           Yi.Buffer.Basic                  (BufferRef (..))+import           Yi.Core                          (closeWindow, errorEditor)+import           Yi.Editor                        (currentWindowA, deleteBuffer, getBufferWithName, withEditor)+import           Yi.Keymap                        (Action (YiA)) import           Yi.Keymap.Vim.Common             (EventString)-import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common (parse, pureExCommand)+import           Yi.Keymap.Vim.Ex.Commands.Buffer (bufferIdentifier)+import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common (needsSaving, parseWithBangAndCount, impureExCommand) import           Yi.Keymap.Vim.Ex.Types           (ExCommand (cmdAction, cmdShow))+import           Yi.Window                        (bufkey)  parse :: EventString -> Maybe ExCommand-parse = Common.parse $ do-    void $ P.try ( P.string "bdelete") <|> P.try ( P.string "bdel") <|> P.try (P.string "bd")-    return $ Common.pureExCommand {+parse = Common.parseWithBangAndCount nameParser $ \ _ bang mcount -> do+    bufIdent <- bufferIdentifier+    return $ Common.impureExCommand {         cmdShow = "bdelete"-      , cmdAction = EditorA closeBufferAndWindowE+      , cmdAction = YiA $ do+            buffer <- case (# mcount, P.parseOnly bufferRef bufIdent #) of+                (# Just i, _ #) -> return $ BufferRef i+                _ | T.null bufIdent -> withEditor $ bufkey <$> use currentWindowA+                (# _, Right ref #) -> return ref+                (# _, Left _ #) -> getBufferWithName bufIdent+            q <- if bang then pure True else not <$> Common.needsSaving buffer+            if q+                then do+                    deleteBuffer buffer+                    when (T.null bufIdent) $ closeWindow -- Because this function closed the window before I started altering it+                else errorEditor "No write since last change (add ! to override)"       }+  where+    bufferRef = BufferRef . read <$> some P.digit++nameParser :: P.Parser ()+nameParser = void . P.choice . fmap P.string $ ["bdelete","bdel","bd"]
+ src/Yi/Keymap/Vim/Ex/Commands/BufferNew.hs view
@@ -0,0 +1,35 @@+{-# LANGUAGE OverloadedStrings #-}+-- |+-- Module      : Yi.Keymap.Vim.Ex.Commands.BufferNew+-- License     : GPL-2+-- Maintainer  : yi-devel@googlegroups.com+-- Stability   : experimental+-- Portability : portable++module Yi.Keymap.Vim.Ex.Commands.BufferNew (parse) where++import           Control.Applicative              (Alternative(..))+import           Control.Monad                    (void)+import qualified Data.Attoparsec.Text as P        (anyChar, char, string)+import           Data.List                        (null)+import           Data.Text as T                   (Text, pack)+import           Yi.Buffer                        (BufferId (MemBuffer))+import           Yi.Editor                        (newEmptyBufferE, newTempBufferE, switchToBufferE)+import           Yi.Keymap                        (Action (EditorA))+import           Yi.Keymap.Vim.Common             (EventString)+import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common (parse, pureExCommand)+import           Yi.Keymap.Vim.Ex.Types           (ExCommand (cmdAction, cmdShow))++parse :: EventString -> Maybe ExCommand+parse = Common.parse $ do+    void $ P.string "new"+    n <- (some (P.char ' ') *> many (P.anyChar)) <|>+      ("" <$ many (P.char ' '))+    return $ Common.pureExCommand {+        cmdShow = "new"+      , cmdAction = EditorA $ do+              b <- if null n+                  then newTempBufferE+                  else newEmptyBufferE (MemBuffer $ T.pack n)+              switchToBufferE b+      }
src/Yi/Keymap/Vim/Ex/Commands/Shell.hs view
@@ -12,8 +12,8 @@  import           Control.Monad                    (void) import qualified Data.Text                        as T (pack)-import qualified Data.Attoparsec.Text             as P (char, many1)-import           Yi.Command                       (buildRun)+import qualified Data.Attoparsec.Text             as P (char,many1,satisfy)+import           Yi.Command                       (interactiveRun) import           Yi.Keymap                        (Action (YiA)) import           Yi.Keymap.Vim.Common             (EventString) import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common (commandArgs, impureExCommand, parse)@@ -22,9 +22,9 @@ parse :: EventString -> Maybe ExCommand parse = Common.parse $ do     void $ P.char '!'-    cmd <- T.pack <$> P.many1 (P.char ' ')+    cmd <- T.pack <$> P.many1 (P.satisfy  (/=' '))     args <- Common.commandArgs     return $ Common.impureExCommand {         cmdShow = "!"-      , cmdAction = YiA $ buildRun cmd args (const $ return ())+      , cmdAction = YiA $ interactiveRun cmd args (const $ return ())       }
src/Yi/Keymap/Vim/NormalMap.hs view
@@ -126,11 +126,11 @@ jumpBindings = fmap (mkBindingE Normal Drop)     [ (ctrlCh 'o', jumpBackE, id)     , (spec KTab, jumpForwardE, id)-    , (ctrlCh '^', controlCarrot, resetCount)-    , (ctrlCh '6', controlCarrot, resetCount)+    , (ctrlCh '^', controlCaret, resetCount)+    , (ctrlCh '6', controlCaret, resetCount)     ]   where-    controlCarrot = alternateBufferE . (+ (-1)) =<< getCountE+    controlCaret = alternateBufferE . (+ (-1)) =<< getCountE  finishingBingings :: [VimBinding] finishingBingings = fmap (mkStringBindingE Normal Finish)
yi-keymap-vim.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           yi-keymap-vim-version:        0.14.0+version:        0.14.1 synopsis:       Vim keymap for Yi editor category:       Yi homepage:       https://github.com/yi-editor/yi#readme@@ -560,6 +560,7 @@       Yi.Keymap.Vim.Utils       Yi.Keymap.Vim.VisualMap   other-modules:+      Yi.Keymap.Vim.Ex.Commands.BufferNew       Yi.Keymap.Vim.Ex.Commands.Stack       Paths_yi_keymap_vim   default-language: Haskell2010