summaryrefslogtreecommitdiffstats
path: root/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs51
1 files changed, 28 insertions, 23 deletions
diff --git a/Main.hs b/Main.hs
index 484f72f..e4c9a13 100644
--- a/Main.hs
+++ b/Main.hs
@@ -77,6 +77,15 @@ uiThread mod lock = do
ringBell >>
putStrLn (prettyError err)
+ -- TODO move this to execCommand / throwError
+ case c of
+ MotionCommand motion ->
+ when (buffer st == buffer st') $
+ ringBell >>
+ putStrLn (prettyError $ OtherError $ "motion failed: " ++ show motion)
+ _ -> return ()
+
+
when (show (mode st) /= show (mode st')) $ do
putStrLn $ "change mode: " ++ (show $ mode st')
@@ -92,15 +101,16 @@ data Command
| InsertChar Char
| InsertNextCharVerbatim
| InsertCharThenChangeMode Char Mode
- | MoveCursorRight
- | MoveCursorLeft
| KillLastWord
| KillLastChar
| KillNextChar
| ExecuteInputBuffer
| UnboundSequence String String
- | GotoBOL
- | GotoEOL
+ | MotionCommand LeftRightMotion
+ -- TODO Move Count Motion
+ -- Delete Count Register Motion
+ -- etc.
+
data ExecError
= UnboundSequenceError String String
@@ -175,21 +185,8 @@ insertChar c (ls, rs) = (ls ++ [c], rs)
execCommand :: Command -> ExecM ()
-execCommand GotoBOL =
- modifyBuffer (move GotoFirstChar)
-
-execCommand GotoEOL =
- modifyBuffer (move GotoEndOfLine)
-
-execCommand MoveCursorLeft = do
- get >>= flip (when . null . fst . buffer)
- (throwError $ OtherError "no char to move left")
- modifyBuffer (move $ GotoLeft 1)
-
-execCommand MoveCursorRight = do
- get >>= flip (when . null . snd . buffer)
- (throwError $ OtherError "no char to move right")
- modifyBuffer (move $ GotoRight 1)
+execCommand (MotionCommand x) =
+ modifyBuffer (move x)
execCommand (InsertChar c) =
modifyBuffer (insertChar c)
@@ -303,16 +300,24 @@ charToCode c = "\\x" ++ showIntAtBase 16 intToDigit (ord c) ""
-- TODO pressing ESC, then F11 etc. is ugly
nmap =
- [ ("\x01", GotoBOL)
- , ("\x05", GotoEOL)
+ [ ("\x01", MotionCommand GotoFirstChar)
+ , ("\x05", MotionCommand GotoEndOfLine)
, ("\x1b[3~", KillNextChar)
- , ("\x1b[C", MoveCursorRight)
- , ("\x1b[D", MoveCursorLeft)
+ , ("\x1b[C", MotionCommand $ GotoRight 1)
+ , ("\x1b[D", MotionCommand $ GotoLeft 1)
, ("\x16", InsertNextCharVerbatim) -- ^V
, ("\x17", KillLastWord) -- ^W
, ("\x0a", ExecuteInputBuffer)
, ("\x7f", KillLastChar) -- Delete
, ("\x08", KillLastChar) -- BackSpace
+
+ -- TODO replace by backward-word
+ -- forward-word
+ -- OR
+ -- [MotionCommand SkipSpaceRight, MotionCommand $ GotillFindRight 1 ' ']
+ -- etc.
+ , ("\x1bOc", MotionCommand $ GotillFindRight 1 ' ')
+ , ("\x1bOd", MotionCommand $ GotillFindLeft 1 ' ')
]
++ [unboundSequence "\x1b[2~" "<Insert>"]
++ [unboundSequence "\x1b[5~" "<Prior>"] -- page up