diff options
author | tv <tv@krebsco.de> | 2017-08-06 23:04:35 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2017-08-06 23:58:41 +0200 |
commit | 5e9ee547af994a88da8bbaa638c3e94f16795aac (patch) | |
tree | 58e4b2ed6516d36786688f3adaf864b3c3b7657b /src | |
parent | 83f37966cf8d1467f748e15b9d73e2597e307bf9 (diff) |
Buffer.Motion: LeftRightMotion -> Motion
Diffstat (limited to 'src')
-rw-r--r-- | src/Buffer/Motion.hs | 27 | ||||
-rw-r--r-- | src/Main.hs | 57 |
2 files changed, 44 insertions, 40 deletions
diff --git a/src/Buffer/Motion.hs b/src/Buffer/Motion.hs index 1333b78..8e59789 100644 --- a/src/Buffer/Motion.hs +++ b/src/Buffer/Motion.hs @@ -3,18 +3,15 @@ module Buffer.Motion where import Data.List (dropWhileEnd) import Buffer.Class ---data Motion = Motion Int LeftRightMotion - - -- TODO factor Count -- TODO various Vim gX -data LeftRightMotion - = GotoLeft - | GotoRight - | GotoFirstChar +data Motion + = CharsBackward + | CharsForward + | ToStartOfLine -- | GotoFirstNonBlankChar - | GotoEndOfLine -- XXX in Vi this can go downwards - | GotoColumn + | ToEndOfLine -- XXX in Vi this can go downwards + | ToColumn -- | GotoFindLeft (Char -> Bool) -- TODO don't use functions here -- | GotoFindRight (Char -> Bool) -- TODO ^ dto. -- | GotillFindLeft Char @@ -73,11 +70,11 @@ wordsBackward i (ls, rs) = else b' -move :: LeftRightMotion -> Int -> Buffer -> Buffer -move GotoLeft c = gotoLeft c -move GotoRight c = gotoRight c -move GotoFirstChar _ = gotoFirstChar -- TODO use count -move GotoEndOfLine _ = gotoEndOfLine -- TODO use count -move GotoColumn c = gotoColumn c +move :: Motion -> Int -> Buffer -> Buffer +move CharsBackward c = gotoLeft c +move CharsForward c = gotoRight c +move ToStartOfLine _ = gotoFirstChar -- TODO use count +move ToEndOfLine _ = gotoEndOfLine -- TODO use count +move ToColumn c = gotoColumn c move WordsForward c = wordsForward c move WordsBackward c = wordsBackward c 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) ] |