From ae7dc0431d3e89d1918d9c8b2caba9e1eb93b140 Mon Sep 17 00:00:00 2001
From: tv <tv@shackspace.de>
Date: Fri, 1 Aug 2014 14:39:28 +0200
Subject: s/SilentMotionCommand/MotionCommandWarn/

---
 src/Main.hs | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

(limited to 'src/Main.hs')

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 }
 
-- 
cgit v1.2.3