Permalink
Browse files

Ex command history.

  • Loading branch information...
ethercrow committed Aug 5, 2013
1 parent 6a63887 commit f75f4d644e05111691e3ef0014ec3b85981a3932
Showing with 66 additions and 41 deletions.
  1. +0 −11 yi/src/library/Yi/History.hs
  2. +60 −29 yi/src/library/Yi/Keymap/Vim2/ExMap.hs
  3. +6 −1 yi/src/library/Yi/Keymap/Vim2/NormalMap.hs
@@ -52,7 +52,6 @@ historyStartGen :: String -> EditorM ()
historyStartGen ident = do
(History _cur cont pref) <- getA (dynKeyA ident . dynA)
putA (dynKeyA ident . dynA) (History 0 (nub ("":cont)) pref)
- debugHist
historyFinish :: EditorM ()
historyFinish = historyFinishGen miniBuffer (withBuffer0 elemsB)
@@ -67,15 +66,6 @@ historyFinishGen ident getCurValue = do
cont' `seq` -- force checking the top of the history, otherwise we'll build up thunks
putA (dynKeyA ident . dynA) $ History (-1) (curValue:cont') pref
--- historyGetGen :: String -> EditorM String
--- historyGetGen ident = do
--- (History cur cont) <- getA (dynKeyA ident .> dynA)
--- return $ cont !! cur
-
--- TODO: scrap
-debugHist :: EditorM ()
-debugHist = return ()
-
historyFind :: [String] -> Int -> Int -> Int -> String -> Int
historyFind cont len cur delta pref =
case (next < 0, next >= len) of
@@ -106,7 +96,6 @@ historyMoveGen ident delta getCurValue = do
return curValue
(_,_) -> do
putA (dynKeyA ident . dynA) (History next (take cur cont ++ [curValue] ++ drop (cur+1) cont) pref)
- debugHist
return nextValue
historyPrefixSet :: String -> EditorM ()
@@ -5,8 +5,11 @@ module Yi.Keymap.Vim2.ExMap
import Prelude ()
import Yi.Prelude
+import Data.Maybe (fromJust)
+
import Yi.Buffer hiding (Insert)
import Yi.Editor
+import Yi.History
import Yi.Keymap
import Yi.Keymap.Vim2.Common
import Yi.Keymap.Vim2.StateUtils
@@ -20,6 +23,7 @@ defExMap cmdParsers =
, finishBindingY cmdParsers
, finishBindingE cmdParsers
, failBindingE
+ , historyBinding
, printable
]
@@ -33,13 +37,20 @@ completionBinding commandParsers = VimBindingY prereq action
Just cmd -> do
maybeNewString <- cmdComplete cmd
case maybeNewString of
- Just s -> withBuffer $ replaceBufferContent s
+ Just s -> do
+ withBuffer $ replaceBufferContent s
+ withEditor $ do
+ historyPrefixSet s
+ modifyStateE $ \state -> state {
+ vsOngoingInsertEvents = s
+ }
Nothing -> return ()
Nothing -> return ()
return Drop
-exitEx :: EditorM ()
-exitEx = do
+exitEx :: Bool -> EditorM ()
+exitEx success = do
+ if success then historyFinish else return ()
resetCountE
switchModeE Normal
closeBufferAndWindowE
@@ -52,7 +63,7 @@ exitBinding = VimBindingE prereq action
= matchFromBool $ evs `elem` ["<Esc>", "<C-c>"]
prereq _ _ = NoMatch
action _ = do
- exitEx
+ exitEx False
return Drop
finishBindingY :: [String -> Maybe ExCommand] -> VimBinding
@@ -80,15 +91,15 @@ finishAction :: MonadEditor m => [String -> Maybe ExCommand] ->
([String -> Maybe ExCommand] -> String -> m ()) -> m RepeatToken
finishAction commandParsers execute = do
s <- withEditor $ withBuffer0 elemsB
- withEditor exitEx
+ withEditor $ exitEx True
execute commandParsers s
return Drop
failBindingE :: VimBinding
failBindingE = VimBindingE prereq action
where prereq evs s = matchFromBool . and $ [vsMode s == Ex, evs == "<CR>"]
action _ = do
- exitEx
+ exitEx False
printMsg "Unknown command"
return Drop
@@ -97,31 +108,51 @@ printable = VimBindingE prereq editAction
where prereq _ (VimState { vsMode = Ex }) = WholeMatch ()
prereq _ _ = NoMatch
+historyBinding :: VimBinding
+historyBinding = VimBindingE prereq action
+ where prereq evs (VimState { vsMode = Ex }) =
+ matchFromBool $ evs `elem` (fmap fst binds)
+ prereq _ _ = NoMatch
+ action evs = do
+ fromJust $ lookup evs binds
+ command <- withBuffer0 elemsB
+ modifyStateE $ \state -> state {
+ vsOngoingInsertEvents = command
+ }
+ return Drop
+ binds =
+ [ ("<Up>", historyUp)
+ , ("<C-p>", historyUp)
+ , ("<Down>", historyDown)
+ , ("<C-n>", historyDown)
+ ]
+
editAction :: EventString -> EditorM RepeatToken
editAction evs = do
- let bufAction = case evs of
- (c:[]) -> insertB c
- "<BS>" -> deleteB Character Backward
- "<C-h>" -> deleteB Character Backward
- "<C-w>" -> do
- r <- regionOfPartNonEmptyB unitViWordOnLine Backward
- deleteRegionB r
- "<C-r>" -> return () -- TODO
- "<lt>" -> insertB '<'
- "<Del>" -> deleteB Character Forward
- "<Left>" -> moveXorSol 1
- "<C-b>" -> moveXorSol 1
- "<Right>" -> moveXorEol 1
- "<C-f>" -> moveXorEol 1
- "<Home>" -> moveToSol
- "<C-a>" -> moveToSol
- "<End>" -> moveToEol
- "<C-e>" -> moveToEol
- "<C-u>" -> moveToSol >> deleteToEol
- "<C-k>" -> deleteToEol
- evs' -> error $ "Unhandled event " ++ evs' ++ " in ex mode"
- command <- withBuffer0 $ bufAction >> elemsB
+ withBuffer0 $ case evs of
+ (c:[]) -> insertB c
+ "<BS>" -> deleteB Character Backward
+ "<C-h>" -> deleteB Character Backward
+ "<C-w>" -> do
+ r <- regionOfPartNonEmptyB unitViWordOnLine Backward
+ deleteRegionB r
+ "<C-r>" -> return () -- TODO
+ "<lt>" -> insertB '<'
+ "<Del>" -> deleteB Character Forward
+ "<Left>" -> moveXorSol 1
+ "<C-b>" -> moveXorSol 1
+ "<Right>" -> moveXorEol 1
+ "<C-f>" -> moveXorEol 1
+ "<Home>" -> moveToSol
+ "<C-a>" -> moveToSol
+ "<End>" -> moveToEol
+ "<C-e>" -> moveToEol
+ "<C-u>" -> moveToSol >> deleteToEol
+ "<C-k>" -> deleteToEol
+ evs' -> error $ "Unhandled event " ++ evs' ++ " in ex mode"
+ command <- withBuffer0 elemsB
+ historyPrefixSet command
modifyStateE $ \state -> state {
vsOngoingInsertEvents = command
}
- return Continue
+ return Drop
@@ -15,6 +15,7 @@ import qualified Data.Rope as R
import Yi.Buffer hiding (Insert)
import Yi.Editor
import Yi.Event
+import Yi.History
import Yi.Keymap.Keys
import Yi.Keymap.Vim2.Common
import Yi.Keymap.Vim2.Eval
@@ -226,7 +227,11 @@ nonrepeatableBindings = fmap (mkBindingE Normal Drop)
, (char '&', return (), id) -- TODO
-- Transition to ex
- , (char ':', discard $ spawnMinibufferE ":" id, switchMode Ex)
+ , (char ':', do
+ discard (spawnMinibufferE ":" id)
+ historyStart
+ historyPrefixSet ""
+ , switchMode Ex)
-- Undo
, (char 'u', withCountOnBuffer0 undoB >> withBuffer0 leftOnEol, id)

0 comments on commit f75f4d6

Please sign in to comment.