Skip to content

Commit bd2d184

Browse files
committed
Refactor f/t/F/T and enable ; and , - part 5
Finally, delete original implementation. Now f/t/F/T store the searched-for characeter even when they are used for d/c/y commands, so ; and , behave accordingly. Not what's left is some thorough review and hopefully some cleanup.
1 parent 4c17d83 commit bd2d184

File tree

4 files changed

+86
-146
lines changed

4 files changed

+86
-146
lines changed

System/Console/Haskeline/Command.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module System.Console.Haskeline.Command(
2525
choiceCmd,
2626
keyChoiceCmd,
2727
keyChoiceCmdM,
28+
doAfter,
2829
doBefore
2930
) where
3031

@@ -112,10 +113,10 @@ keyChoiceCmdM :: [KeyMap (CmdM m a)] -> CmdM m a
112113
keyChoiceCmdM = GetKey . choiceCmd
113114

114115
doBefore :: Monad m => Command m s t -> KeyCommand m t u -> KeyCommand m s u
115-
g `doBefore` km = fmap (g >=>) km
116+
doBefore g km = fmap (g >=>) km
116117

117118
doAfter :: Monad m => KeyCommand m s t -> Command m t u -> KeyCommand m s u
118-
km `doAfter` g = fmap (>=> g) km
119+
doAfter km g = fmap (>=> g) km
119120

120121
infixr 6 >+>
121122
(>+>) :: Monad m => KeyCommand m s t -> Command m t u -> KeyCommand m s u

System/Console/Haskeline/Command/KillRing.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,55 +38,55 @@ runKillRing act = do
3838
pasteCommand :: (Save s, MonadState KillRing m, MonadState Undo m)
3939
=> ([Grapheme] -> s -> s) -> Command m (ArgMode s) s
4040
pasteCommand use = \s -> do
41-
ms <- liftM peek get
41+
ms <- peek <$> get
4242
case ms of
4343
Nothing -> return $ argState s
4444
Just p -> do
4545
modify $ saveToUndo $ argState s
4646
setState $ applyArg (use p) s
4747

48-
deleteFromDiff' :: InsertMode -> InsertMode -> ([Grapheme],InsertMode)
48+
deleteFromDiff' :: InsertMode -> InsertMode -> ([Grapheme], InsertMode)
4949
deleteFromDiff' (IMode xs1 ys1) (IMode xs2 ys2)
5050
| posChange >= 0 = (take posChange ys1, IMode xs1 ys2)
51-
| otherwise = (take (negate posChange) ys2 ,IMode xs2 ys1)
51+
| otherwise = (take (negate posChange) ys2, IMode xs2 ys1)
5252
where
5353
posChange = length xs2 - length xs1
5454

5555
killFromHelper :: (MonadState KillRing m, MonadState Undo m,
5656
Save s, Save t)
5757
=> KillHelper -> Command m s t
5858
killFromHelper helper = saveForUndo >=> \oldS -> do
59-
let (gs,newIM) = applyHelper helper (save oldS)
59+
let (gs, newIM) = applyHelper helper (save oldS)
6060
modify (push gs)
6161
setState (restore newIM)
6262

6363
killFromArgHelper :: (MonadState KillRing m, MonadState Undo m, Save s, Save t)
6464
=> KillHelper -> Command m (ArgMode s) t
6565
killFromArgHelper helper = saveForUndo >=> \oldS -> do
66-
let (gs,newIM) = applyArgHelper helper (fmap save oldS)
66+
let (gs, newIM) = applyArgHelper helper (fmap save oldS)
6767
modify (push gs)
6868
setState (restore newIM)
6969

7070
copyFromArgHelper :: (MonadState KillRing m, Save s)
7171
=> KillHelper -> Command m (ArgMode s) s
7272
copyFromArgHelper helper = \oldS -> do
73-
let (gs,_) = applyArgHelper helper (fmap save oldS)
73+
let (gs, _) = applyArgHelper helper (fmap save oldS)
7474
modify (push gs)
7575
setState (argState oldS)
7676

7777

7878
data KillHelper = SimpleMove (InsertMode -> InsertMode)
79-
| GenericKill (InsertMode -> ([Grapheme],InsertMode))
79+
| GenericKill (InsertMode -> ([Grapheme], InsertMode))
8080
-- a generic kill gives more flexibility, but isn't repeatable.
81-
-- for example: dd,cc, %
81+
-- for example: dd, cc, %
8282

8383
killAll :: KillHelper
8484
killAll = GenericKill $ \(IMode xs ys) -> (reverse xs ++ ys, emptyIM)
8585

86-
applyHelper :: KillHelper -> InsertMode -> ([Grapheme],InsertMode)
86+
applyHelper :: KillHelper -> InsertMode -> ([Grapheme], InsertMode)
8787
applyHelper (SimpleMove move) im = deleteFromDiff' im (move im)
8888
applyHelper (GenericKill act) im = act im
8989

90-
applyArgHelper :: KillHelper -> ArgMode InsertMode -> ([Grapheme],InsertMode)
90+
applyArgHelper :: KillHelper -> ArgMode InsertMode -> ([Grapheme], InsertMode)
9191
applyArgHelper (SimpleMove move) im = deleteFromDiff' (argState im) (applyArg move im)
9292
applyArgHelper (GenericKill act) im = act (argState im)

System/Console/Haskeline/Command/Undo.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ initialUndo = Undo {pastUndo = [emptyIM], futureRedo = []}
1919

2020
saveToUndo :: Save s => s -> Undo -> Undo
2121
saveToUndo s undo
22-
| not isSame = Undo {pastUndo = toSave:pastUndo undo,futureRedo=[]}
22+
| not isSame = Undo {pastUndo = toSave:pastUndo undo, futureRedo=[]}
2323
| otherwise = undo
2424
where
2525
toSave = save s
@@ -39,7 +39,7 @@ redoFuture ls u@Undo {futureRedo = (futureLS:lss)}
3939

4040

4141
saveForUndo :: (Save s, MonadState Undo m)
42-
=> Command m s s
42+
=> Command m s s
4343
saveForUndo s = do
4444
modify (saveToUndo s)
4545
return s

0 commit comments

Comments
 (0)