diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/Main.hs b/src/Main.hs index f14d405..da1141d 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -157,8 +157,8 @@ data Command | KillLastChar | KillNextChar | ExecuteInputBuffer - | MotionCommand LeftRightMotion - | MotionCommandWarn LeftRightMotion + | MoveCursor Motion + | MoveCursorWarn Motion | ChangeMode Mode -- TODO Move Count Motion -- Delete Count Register Motion @@ -233,7 +233,7 @@ execCommand :: Command -> VT () execCommand DebugShowVTState = get >>= tell . (:[]) . pp . SGR [35] . Plain . show -execCommand (MotionCommand x) = do +execCommand (MoveCursor x) = do c <- uses count (maybe 1 id) buffer %= move x c @@ -246,9 +246,9 @@ execCommand (MotionCommand x) = do -- failed moves. Currently this is only used to SetCount Nothing (which -- is defunct atm) Alternatively we could simply reset the state when an -- error happens Discus! -execCommand (MotionCommandWarn x) = do +execCommand (MoveCursorWarn x) = do b0 <- use buffer - execCommand (MotionCommand x) + execCommand (MoveCursor x) b1 <- use buffer -- TODO make this a warning or else ... @@ -511,27 +511,34 @@ selectRegisterMap = (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ".%#:-\"")) +-- TODO maybe in normal mode reset count (SetCount Nothing) after each +-- command doesn't alter the count. How would this work together with +-- ChangeMode DeleteMode +-- TODO 2017-08-06 +-- initialize count whenever nmap is entered +-- ditch SetCount Nothing +-- pass count to commands / modes nmap :: Keymap nmap = [ ("\ESC", SetCount Nothing) -- ^TODO RingBell if count is already Nothing -- TODO cancel any unfinished commands , ("i", ChangeMode InsertMode <> SetCount Nothing) - , ("a", ChangeMode InsertMode <> SetCount Nothing <> MotionCommand GotoRight) - , ("I", ChangeMode InsertMode <> MotionCommand GotoFirstChar) - , ("A", ChangeMode InsertMode <> MotionCommand GotoEndOfLine) - , ("|", MotionCommandWarn GotoColumn <> SetCount Nothing) - , ("$", MotionCommandWarn GotoEndOfLine <> SetCount Nothing) - , ("h", MotionCommandWarn GotoLeft <> SetCount Nothing) - , ("l", MotionCommandWarn GotoRight <> SetCount Nothing) - , ("b", MotionCommandWarn WordsBackward <> SetCount Nothing) - , ("w", MotionCommandWarn WordsForward <> SetCount Nothing) + , ("a", ChangeMode InsertMode <> SetCount Nothing <> MoveCursor CharsForward) + , ("I", ChangeMode InsertMode <> MoveCursor ToStartOfLine) + , ("A", ChangeMode InsertMode <> MoveCursor ToEndOfLine) + , ("|", MoveCursorWarn ToColumn <> SetCount Nothing) + , ("$", MoveCursorWarn ToEndOfLine <> SetCount Nothing) + , ("h", MoveCursorWarn CharsBackward <> SetCount Nothing) + , ("l", MoveCursorWarn CharsForward <> SetCount Nothing) + , ("b", MoveCursorWarn WordsBackward <> SetCount Nothing) + , ("w", MoveCursorWarn WordsForward <> SetCount Nothing) , ("d", ChangeMode DeleteMode) , ("\"", ChangeMode SelectRegisterMode <> SetCount Nothing) , ("\ESC[24~", DebugShowVTState) - , ("\ESC[C", MotionCommandWarn GotoRight <> SetCount Nothing) - , ("\ESC[D", MotionCommandWarn GotoLeft <> SetCount Nothing) - , ("\x0a", ExecuteInputBuffer <> ChangeMode InsertMode <> SetCount Nothing) + , ("\ESC[C", MoveCursorWarn CharsForward <> SetCount Nothing) + , ("\ESC[D", MoveCursorWarn CharsBackward <> SetCount Nothing) + , ("\n", ExecuteInputBuffer <> ChangeMode InsertMode <> SetCount Nothing) ] ++ (map (\i -> (show i, AppendCount i)) [0..9]) -- XXX @@ -542,7 +549,7 @@ nmap = -- x = Embed f -- f :: VT Command -- f = gets (isJust . count) >>= - -- return . bool (MotionCommand GotoFirstChar) (AppendCount 0) + -- return . bool (MoveCursor ToStartOfLine) (AppendCount 0) -- bool :: a -> a -> Bool -> a -- bool _ a True = a -- bool a _ False = a @@ -555,20 +562,20 @@ nmap = imap :: Keymap imap = - [ ("\ESC", ChangeMode NormalMode <> MotionCommand GotoLeft) - , ("\x01", MotionCommandWarn GotoFirstChar) - , ("\x05", MotionCommandWarn GotoEndOfLine) + [ ("\ESC", ChangeMode NormalMode <> MoveCursor CharsBackward) + , ("\x01", MoveCursorWarn ToStartOfLine) + , ("\x05", MoveCursorWarn ToEndOfLine) , ("\ESC[24~", DebugShowVTState) , ("\ESC[3~", KillNextChar) - , ("\ESC[C", MotionCommandWarn GotoRight) - , ("\ESC[D", MotionCommandWarn GotoLeft) + , ("\ESC[C", MoveCursorWarn CharsForward) + , ("\ESC[D", MoveCursorWarn CharsBackward) , ("\x16", ChangeMode VerbatimMode) -- ^V , ("\x17", KillLastWord) -- ^W , ("\x0a", ExecuteInputBuffer) , ("\x7f", KillLastChar) -- Delete , ("\x08", KillLastChar) -- BackSpace - , ("\ESCOc", MotionCommandWarn WordsForward) - , ("\ESCOd", MotionCommandWarn WordsBackward) + , ("\ESCOc", MoveCursorWarn WordsForward) + , ("\ESCOd", MoveCursorWarn WordsBackward) ] |