summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Main.hs30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 328c641..f217310 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -105,30 +105,16 @@ uiThread cf putState getState = forever $ do
--withOutput cf $ do
-- putStrLn $ show cmd
- ((_, lns), q1) <- runVT cf q0 (execCommand cmd)
+ ((eitCmd, lns), q1) <- runVT cf q0 (execCommand cmd)
-- TODO only putState if it has changed (?)
putState q1
- -- XXX dummy for following legacy code
- let eitCmd = Right cmd
-
- let mbErr = case eitCmd of
- Left err -> Just err
- Right c ->
- -- TODO move this to execCommand / throwError
- case c of
- MotionCommand motion | buffer q0 == buffer q1 ->
- Just (OtherError $ "motion failed: " ++ show motion)
- _ ->
- Nothing
-
withOutput cf $ do
forM_ lns putStrLn
- case mbErr of
- Just err -> ringBell >> putStrLn (prettyError err)
- Nothing -> return ()
+ whenLeft eitCmd $ \err ->
+ ringBell >> putStrLn (prettyError err)
--when (mode st /= mode st') $ do
-- putStrLn $ "change mode: " ++ (show $ mode st')
@@ -143,6 +129,7 @@ data Command
| KillNextChar
| ExecuteInputBuffer
| MotionCommand LeftRightMotion
+ | MotionCommandWarn LeftRightMotion
| ChangeMode Mode
-- TODO Move Count Motion
-- Delete Count Register Motion
@@ -238,6 +225,15 @@ execCommand (MotionCommand x) = do
when (null $ snd $ buffer q) $
modifyBuffer (gotoLeft 1)
+execCommand (MotionCommandWarn x) = do
+ b0 <- gets buffer
+ execCommand (MotionCommand x)
+ b1 <- gets buffer
+
+ -- TODO make this a warning or else ...
+ when (b0 == b1) $
+ throwError (OtherError $ "your motion has no effect: " ++ show x)
+
execCommand (ChangeMode m) =
modify $ \ q -> q { mode = m }