packages feed

rasa-ext-vim 0.1.5 → 0.1.6

raw patch · 2 files changed

+70/−60 lines, 2 filesdep −rasa-ext-status-bardep ~rasadep ~rasa-ext-cursorsdep ~rasa-ext-files

Dependencies removed: rasa-ext-status-bar

Dependency ranges changed: rasa, rasa-ext-cursors, rasa-ext-files, rasa-ext-views, rasa-ext-vim

Files

rasa-ext-vim.cabal view
@@ -1,5 +1,5 @@ name: rasa-ext-vim-version: 0.1.5+version: 0.1.6 cabal-version: >=1.10 build-type: Simple license: GPL-3@@ -22,11 +22,10 @@         Rasa.Ext.Vim     build-depends:         base >=4.8 && <5,-        rasa >=0.1.9 && <0.2,-        rasa-ext-files >=0.1.3 && <0.2,-        rasa-ext-views >=0.1.3 && <0.2,-        rasa-ext-cursors >=0.1.5 && <0.2,-        rasa-ext-status-bar >=0.1.3 && <0.2,+        rasa >=0.1.10 && <0.2,+        rasa-ext-files >=0.1.4 && <0.2,+        rasa-ext-views >=0.1.4 && <0.2,+        rasa-ext-cursors >=0.1.6 && <0.2,         text >=1.2.2.1 && <1.3,         yi-rope >=0.7.0.2 && <0.8,         text-lens >=0.1.1 && <0.2,@@ -42,7 +41,7 @@     main-is: Spec.hs     build-depends:         base >=4.9.0.0 && <4.10,-        rasa-ext-vim >=0.1.5 && <0.2,+        rasa-ext-vim >=0.1.6 && <0.2,         hspec >=2.2.4 && <2.3     default-language: Haskell2010     default-extensions: OverloadedStrings
src/Rasa/Ext/Vim.hs view
@@ -1,4 +1,4 @@-{-# Language OverloadedStrings, TemplateHaskell #-}+{-# Language OverloadedStrings #-} module Rasa.Ext.Vim   ( vim   ) where@@ -7,7 +7,6 @@ import Rasa.Ext.Views import Rasa.Ext.Files (save) import Rasa.Ext.Cursors-import Rasa.Ext.StatusBar  import Control.Monad import Control.Lens@@ -24,23 +23,32 @@ instance Default VimMode where   def = Normal +getMode :: BufAction VimMode+getMode = getBufExt++setMode :: VimMode -> BufAction ()+setMode = setBufExt+ -- | A history of any keypresses which haven't matched a pattern-newtype VimHist = VimHist-  { _histKeys :: [Keypress]-  } deriving (Show, Typeable)-makeLenses ''VimHist+newtype VimHist =+  VimHist [Keypress]+  deriving (Show, Typeable)  instance Default VimHist where   def = VimHist [] --- | A hlens into vim's current mode.-mode :: HasBufExts s => Lens' s VimMode-mode = bufExt+addHist :: Keypress -> BufAction ()+addHist keypress = overBufExt extend+  where extend (VimHist hist) = VimHist $ hist ++ [keypress] --- | A lens into the current unresolved keypress history-hist :: HasBufExts s => Lens' s [Keypress]-hist = bufExt.histKeys+getHist :: BufAction [Keypress]+getHist = do+  VimHist h <- getBufExt+  return h +setHist :: [Keypress] -> BufAction ()+setHist = setBufExt . VimHist+ -- | The main export for the vim keybinding extension. Add this to your user config. -- -- e.g.@@ -50,56 +58,57 @@ -- >    ... vim :: Action () vim = do-  -- Register to listen for keypresses-  onEveryTrigger_ handleKeypress-  -- Set the status bar to the current mode before each render-  beforeEveryRender_ setStatus+  void $ onKeypress handleKeypress+  onEveryNewBuffer_ . addBottomStatus $ do+    mode <- getMode+    return $ case mode of+      Normal -> styleText "NORMAL" $ fg Magenta+      Insert -> styleText "INSERT" $ fg Green  -- | The event listener which listens for keypresses and responds appropriately handleKeypress :: Keypress -> Action () handleKeypress keypress = focusDo_ $ do-    mode' <- use mode-    preHist <- use hist-    case mode' of-      Normal -> normal $ preHist ++ [keypress]-      Insert -> insert $ preHist ++ [keypress]-    anyMode $ preHist ++ [keypress]-    postHist <- use hist-    -- If nothing changed than an action must have happened-    unless (preHist /= postHist) (hist .= [])---- | Sets the status bar to the current mode and current VimHist-setStatus :: Action ()-setStatus = focusDo_ $ do-  modeDisp <- use (mode.to show.to Y.fromString)-  histDisp <- use (hist.to show.to Y.fromString)-  centerStatus modeDisp-  rightStatus histDisp+  mode <- getMode+  preHist <- getHist+  case mode of+    Normal -> normal $ preHist ++ [keypress]+    Insert -> insert $ preHist ++ [keypress]+  anyMode $ preHist ++ [keypress]+  postHist <- getHist+  -- If nothing changed than an action must have happened+  unless (preHist /= postHist) (setHist [])  -- | Listeners for keypresses that run regardless of current mode. anyMode :: [Keypress] -> BufAction () anyMode [Keypress 'c' [Ctrl]] = liftAction exit+anyMode [KPageDown []] = liftAction $ scrollBy 14 -- Page down+anyMode [KPageUp []] = liftAction $ scrollBy (-14) -- Page up+anyMode [KHome []] = startOfLine+anyMode [KEnd []] = endOfLine anyMode _ = return ()  -- | Listeners for keypresses when in 'Insert' mode insert :: [Keypress] -> BufAction ()-insert [KEsc] = mode .= Normal+insert [KEsc []] = setMode Normal -insert [KBS] = moveRangesByN (-1) >> delete-insert [KEnter] = insertText "\n" >> moveRangesByC (Coord 1 0) >> startOfLine-insert [Keypress c _] = insertText (Y.singleton c) >> moveRangesByN 1+insert [KBS []] = moveRangesByN (-1) >> delete+insert [KDel []] = delete+insert [KEnter []] = insertText "\n" >> moveRangesByC (Coord 1 0) >> startOfLine+insert [Keypress c []] = insertText (Y.singleton c) >> moveRangesByN 1 insert _ = return ()  -- | Listeners for keypresses when in 'Normal' mode normal :: [Keypress] -> BufAction ()-normal [Keypress 'i' []] = mode .= Insert-normal [Keypress 'I' []] = startOfLine >> mode .= Insert-normal [Keypress 'a' []] = moveRangesByN 1 >> mode .= Insert-normal [Keypress 'A' []] = endOfLine >> mode .= Insert+normal [Keypress 'i' []] = setMode Insert+normal [Keypress 'I' []] = startOfLine >> setMode Insert+normal [Keypress 'a' []] = moveRangesByN 1 >> setMode Insert+normal [Keypress 'A' []] = endOfLine >> setMode Insert normal [Keypress '0' []] = startOfLine normal [Keypress '$' []] = endOfLine-normal [Keypress 'g' []] = hist <>= [Keypress 'g' []]+normal [Keypress 'g' []] = addHist $ Keypress 'g' [] normal [Keypress 'g' [], Keypress 'g' []] = setRanges [Range (Coord 0 0) (Coord 0 1)]+normal [Keypress 's' []] = addHist $ Keypress 's' []+normal [Keypress 's' [], Keypress 'n' []] = toggleLineNumbers  normal [Keypress '+' []] = liftAction nextBuf normal [Keypress '-' []] = liftAction prevBuf@@ -113,18 +122,18 @@ normal [Keypress 'y' [Ctrl]] = liftAction $ scrollBy (-1) -- Scroll up normal [Keypress 'u' [Ctrl]] = liftAction $ scrollBy (-7) -- Half-Page up -normal [KLeft] = liftAction focusViewLeft-normal [KRight] = liftAction focusViewRight-normal [KUp] = liftAction focusViewAbove-normal [KDown] = liftAction focusViewBelow+normal [KLeft []] = liftAction focusViewLeft+normal [KRight []] = liftAction focusViewRight+normal [KUp []] = liftAction focusViewAbove+normal [KDown []] = liftAction focusViewBelow   normal [Keypress 'G' []] = do   txt <- getText   setRanges [Range ((Offset $ Y.length txt - 1)^.asCoord txt) ((Offset $ Y.length txt)^.asCoord txt)] -normal [Keypress 'o' []] = endOfLine >> insertText "\n" >> moveRangesByC (Coord 1 0) >> mode .= Insert-normal [Keypress 'O' []] = startOfLine >> insertText "\n" >> mode .= Insert+normal [Keypress 'o' []] = endOfLine >> insertText "\n" >> moveRangesByC (Coord 1 0) >> setMode Insert+normal [Keypress 'O' []] = startOfLine >> insertText "\n" >> setMode Insert normal [Keypress 'h' []] = moveRangesByN (-1) normal [Keypress 'l' []] = moveRangesByN 1 normal [Keypress 'k' []] = moveRangesByC $ Coord (-1) 0@@ -149,20 +158,22 @@           newEnd = moveCursorByN 1 newStart       addRange $ Range newStart newEnd -normal [Keypress 'f' []] = hist <>= [Keypress 'f' []]+normal [Keypress 'f' []] = addHist $ Keypress 'f' [] normal [Keypress 'f' [],Keypress x []] = findNext $ Y.singleton x-normal [Keypress 't' []] = hist <>= [Keypress 't' []]+normal [Keypress 't' []] = addHist $ Keypress 't' [] normal [Keypress 't' [],Keypress x []] = findNext (Y.singleton x) >> moveRangesByN (-1)-normal [Keypress 'T' []] = hist <>= [Keypress 'T' []]+normal [Keypress 'T' []] = addHist $ Keypress 'T' [] normal [Keypress 'T' [],Keypress x []] = findPrev (Y.singleton x)-normal [Keypress 'F' []] = hist <>= [Keypress 'F' []]+normal [Keypress 'F' []] = addHist $ Keypress 'F' [] normal [Keypress 'F' [],Keypress x []] = findPrev (Y.singleton x) >> moveRangesByN (-1) normal [Keypress 'X' []] = moveRangesByN (-1) >> delete normal [Keypress 'x' []] = delete normal [Keypress 's' [Ctrl]] = save normal [Keypress ';' []] = do-  rngs <- getRanges +  rngs <- getRanges   setRanges (rngs^.reversed.to (take 1))+normal [Keypress 'r' []] = addHist $ Keypress 'r' []+normal [Keypress 'r' [],Keypress c []] = delete >> insertText (Y.singleton c) normal _ = return ()  -- | Move cursors to end of the line