diff options
| author | tv <tv@shackspace.de> | 2014-07-27 17:24:17 +0200 | 
|---|---|---|
| committer | tv <tv@shackspace.de> | 2014-07-27 17:24:17 +0200 | 
| commit | a6b938977705042b5ca0ca9c3272f76f229f1a42 (patch) | |
| tree | 9671fc855380f665a8b330e22dbb906b5c4a4caf | |
| parent | c3e9446f79998b78cfe47aec26baa148403d8dfa (diff) | |
purge non-MotionCommand motion commands
| -rw-r--r-- | Buffer/Motion.hs | 1 | ||||
| -rw-r--r-- | Main.hs | 51 | 
2 files changed, 29 insertions, 23 deletions
| diff --git a/Buffer/Motion.hs b/Buffer/Motion.hs index 3918e1b..9b275d4 100644 --- a/Buffer/Motion.hs +++ b/Buffer/Motion.hs @@ -21,6 +21,7 @@ data LeftRightMotion    | GotillFindRight Int Char    -- | RepeatLastFind Int    -- | RepeatLastFindReverse Int +  deriving (Show)  -- TODO fail if cannot splitAt properly OR if we didn't modify the buffer  gotoLeft i (ls, rs) = @@ -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 | 
