move-pos: calculates the effect of printing a displayed string on
_move-pos_: calculates the effect of printing a displayed string on
line/column positions.
Danny Yoo (dyoo@cs.wpi.edu / dyoo@hkn.eecs.berkeley.edu)
Introduction
------------
_move-pos.ss_ is a simple library that figures out what line and
column we're on after a given string is displayed. It takes as input
the location that we're at and the displayed string, and returns a
location that represents the cursor movement.
Example
-------
> (require (planet "move-pos.ss" ("dyoo" "move-pos.plt" 1)))
>
> (let ([line 0]
[column 0]
[pos 0])
(apply-move (get-move (open-input-string "hello"))
(make-loc line column pos)))
#(struct:loc 0 5 5)
>
> (let ([line 0]
[column 13]
[pos 13])
(apply-move (get-move (open-input-string "hello"))
(make-loc line column pos)))
#(struct:loc 0 18 18)
>
> (let ([line 0]
[column 13]
[pos 13])
(apply-move (get-move (open-input-string "hello\nworld"))
(make-loc line column pos)))
#(struct:loc 1 5 24)
Data defintions
---------------
There are two data definitions: a _location_ to represent where we
are, and a _move_ to represent the line/column shifting after a
display.
A _location_ is a:
(define-struct loc (line col pos) #f)
where line, column, and pos are natural numbers.
A _move_ is an opaque structure that can be applied on locations to
make them shift around.
API
---
> loc?: any -> boolean
Returns #t if the datum is a location structure.
> move?: any -> boolean
Returns #t if the datum is a move structure.
> get-move: input-port -> move
Constructs a move that simulates the line/column shifting effect of
displaying the content on the given input-port.
> apply-move: move loc -> loc
Given a move, shifts the given location.
> move-compose: move move -> move
Creates a new move whose effect is the first move followed by the second. So
(apply-move (move-compose move-1 move-2) pos)
should be equivalent to:
(apply-move move-2 (apply-move move-1 pos))
Parameters
----------
> current-line-break-mode: (parameterof symbol)
Defines the line-breaking lexer what interpretation to choose for the
line breaking character sequence, similar to what _read-line_ uses.
Supported values are 'linefeed, 'return, 'return-linefeed, 'any, and
'anyone. The default is 'any.
> current-tab-break-length: (parameterof natural-number)
Defines the tab break length we use when we see a #\tab. The default
value is 8.