Permalink
Browse files

Added moveToLine

  • Loading branch information...
1 parent 274e44f commit 346797854065a37747c794a30a13613143e62e06 @michaelfeathers committed Aug 15, 2009
Showing with 17 additions and 5 deletions.
  1. +7 −3 editbuffer.hs
  2. +5 −1 todo
  3. +5 −1 vih.hs
View
@@ -10,7 +10,7 @@ module EditBuffer
, insertLineAfter
, deleteLine
, moveLeft, moveRight, moveUp, moveDown
- , moveToHome, moveToEnd
+ , moveToHome, moveToEnd, moveToLine
, moveToLineStart, moveToLineEnd
, wordForward
, frame
@@ -58,8 +58,8 @@ replaceChar replacementChar buffer@(EditBuffer topLine location contents) =
insertLineAfter :: EditBuffer -> EditBuffer
insertLineAfter (EditBuffer topLine _ "") = EditBuffer topLine (0,1) "\n"
insertLineAfter (EditBuffer topLine (_,y) contents) = EditBuffer topLine (0,y+1) newContents
- where newContents = unlines [transform numberedLine | numberedLine <- numberedLines contents]
- transform (line, pos) = if pos == y then line ++ "\n" else line
+ where newContents = unlines . map f . numberedLines $ contents
+ f (line, pos) = if pos == y then line ++ "\n" else line
deleteLine :: EditBuffer ->EditBuffer
deleteLine (EditBuffer topLine location@(_,y) contents) = forceLocation (EditBuffer topLine location newContents)
@@ -78,6 +78,10 @@ moveToEnd :: EditBuffer -> EditBuffer
moveToEnd = saturate (lastPos, lastPos)
where lastPos = (maxBound :: Int) - 1
+moveToLine :: Int -> EditBuffer -> EditBuffer
+moveToLine lineNumber (EditBuffer topLine (x,y) contents) =
+ forceLocation (EditBuffer topLine (x, lineNumber) contents)
+
moveToLineStart :: EditBuffer -> EditBuffer
moveToLineStart (EditBuffer topLine (_,y) contents) = EditBuffer topLine (0,y) contents
View
@@ -1,3 +1,4 @@
+- Add exception handling for goto line so that parse errors don't crash
- Pull frame out of the main loop and attach to all functions which adjust vertical
- Form Arbitraries for QS checks
- Put test driver in place
@@ -6,6 +7,9 @@
- Simplify locationFromPosition. May not need cumulative sum
- Add punct groups as words in wordForward
- Add wordBackward
-- Write f, O, a, goto line, etc.
+x Write goto line
+- Add cw, dw
+- Write f, O, a, etc.
+- forward and backward search
- File operations: e, w, wq, q!
- Need status line
View
@@ -3,6 +3,7 @@ import EditBuffer
import Rendering
import Input
import Char
+import Control.Exception
data EditMode = Command | Insert deriving (Eq,Show)
@@ -54,14 +55,17 @@ mainLoop mode previousBuffer =
_ -> mainLoop mode buffer
+-- aborts when line command is not parseable. Fix with exception catch
handleCommandLine :: EditBuffer -> IO ()
handleCommandLine buffer =
do goto commandHome
putStr ":"
command <- getLine
if head command == 'q'
then return ()
- else mainLoop Command buffer
+ else if isDigit (head command)
+ then mainLoop Command (moveToLine (read command :: Int) buffer)
+ else mainLoop Command buffer
isInputChar :: Char -> Bool

0 comments on commit 3467978

Please sign in to comment.