summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-07-27 18:55:32 +0200
committertv <tv@shackspace.de>2014-07-27 18:55:32 +0200
commit4589d9cf494d9cca19aa4da8aa754f6b31ef1876 (patch)
tree80dbb4a6f68513ba73bafb0fbfe37d74d21c2482
parenta6b938977705042b5ca0ca9c3272f76f229f1a42 (diff)
s/Go{to,till}Find{Left,Right}/{For,Back}wardWord/
-rw-r--r--Buffer/Motion.hs71
-rw-r--r--Main.hs4
2 files changed, 27 insertions, 48 deletions
diff --git a/Buffer/Motion.hs b/Buffer/Motion.hs
index 9b275d4..86446e0 100644
--- a/Buffer/Motion.hs
+++ b/Buffer/Motion.hs
@@ -15,12 +15,14 @@ data LeftRightMotion
-- | GotoFirstNonBlankChar
| GotoEndOfLine -- XXX in Vi this can go downwards
| GotoColumn Int
- | GotoFindLeft Int Char
- | GotoFindRight Int Char
- | GotillFindLeft Int Char
- | GotillFindRight Int Char
+ -- | GotoFindLeft Int (Char -> Bool) -- TODO don't use functions here
+ -- | GotoFindRight Int (Char -> Bool) -- TODO ^ dto.
+ -- | GotillFindLeft Int Char
+ -- | GotillFindRight Int Char
-- | RepeatLastFind Int
-- | RepeatLastFindReverse Int
+ | WordsForward Int
+ | WordsBackward Int
deriving (Show)
-- TODO fail if cannot splitAt properly OR if we didn't modify the buffer
@@ -38,44 +40,23 @@ gotoEndOfLine (ls, rs) = (ls ++ rs, "")
-- TODO fail if i <= 0 or i > length
gotoColumn i (ls, rs) = splitAt (i - 1) $ ls ++ rs
--- TODO is this definition correct?
-spanEnd :: (a -> Bool) -> [a] -> ([a], [a])
-spanEnd p xs = let ls = dropWhileEnd p xs in (ls, drop (length ls) xs)
-
--- TODO don't allow i == 0 in go{to,till}Find{Left,Right}
-
-gotoFindLeft i c b@(ls, rs)
- | i == 0 = b
- | i > 0 =
- let (lls, rls) = spanEnd (/= c) ls
- in gotoFindLeft (i - 1) c (init lls, last lls : rls ++ rs)
-
-gotoFindRight i c b@(ls, rs)
- | i == 0 = b
- | i > 0 =
- let (lrs, rrs) = span (/= c) rs
- in gotoFindRight (i - 1) c (ls ++ lrs ++ [head rrs], tail rrs)
-
--- TODO this has to fail it there aren't enought c's
-gotillFindLeft i c b@(ls, rs) =
- let (lls, rls) = spanEnd (/= c) ls
- in
- if i > 1
- then gotillFindLeft (i - 1) c (init lls, last lls : rls ++ rs)
- else (lls, rls ++ rs)
-
---gotillFindRight i c b@(ls, rs)
--- | i == 0 = b
--- | i > 0 =
--- let (lrs, rrs) = span (/= c) rs
--- in gotoFindRight (i - 1) c (ls ++ lrs, rrs)
-
-gotillFindRight i c b@(ls, rs) =
- let (lrs, rrs) = span (/= c) rs
- in
- if i > 1
- then gotillFindRight (i - 1) c (ls ++ lrs ++ [head rrs], tail rrs)
- else (ls ++ lrs, rrs)
+wordsForward i (ls, rs) =
+ let rs' = dropWhile (==' ') $ dropWhile (/=' ') rs
+ ls' = ls ++ take (length rs - length rs') rs
+ b' = (ls', rs')
+ in
+ if i > 1
+ then wordsForward (i - 1) b'
+ else b'
+
+wordsBackward i (ls, rs) =
+ let ls' = dropWhileEnd (/=' ') $ dropWhileEnd (==' ') ls
+ rs' = drop (length ls') ls ++ rs
+ b' = (ls', rs')
+ in
+ if i > 1
+ then wordsBackward (i - 1) b'
+ else b'
move :: LeftRightMotion -> Buffer -> Buffer
@@ -84,7 +65,5 @@ move (GotoRight i) = gotoRight i
move GotoFirstChar = gotoFirstChar
move GotoEndOfLine = gotoEndOfLine
move (GotoColumn i) = gotoColumn i
-move (GotoFindLeft i c) = gotoFindLeft i c
-move (GotoFindRight i c) = gotoFindRight i c
-move (GotillFindLeft i c) = gotillFindLeft i c
-move (GotillFindRight i c) = gotillFindRight i c
+move (WordsForward i) = wordsForward i
+move (WordsBackward i) = wordsBackward i
diff --git a/Main.hs b/Main.hs
index e4c9a13..75e031f 100644
--- a/Main.hs
+++ b/Main.hs
@@ -316,8 +316,8 @@ nmap =
-- OR
-- [MotionCommand SkipSpaceRight, MotionCommand $ GotillFindRight 1 ' ']
-- etc.
- , ("\x1bOc", MotionCommand $ GotillFindRight 1 ' ')
- , ("\x1bOd", MotionCommand $ GotillFindLeft 1 ' ')
+ , ("\x1bOc", MotionCommand $ WordsForward 1)
+ , ("\x1bOd", MotionCommand $ WordsBackward 1)
]
++ [unboundSequence "\x1b[2~" "<Insert>"]
++ [unboundSequence "\x1b[5~" "<Prior>"] -- page up