8.10
9 Racket S-Expression Indentation and Navigation
The "syntax-color" collection provides Racket indentation and
navigation functions that take advantage of the token categories and
parenthesis information produced by a coloring lexer. They can work
with any object that implements color-textoid<%>, which
is extended by color:text<%>.
Added in version 1.3.
9.1 S-Expression Navigation
Each of these functions takes a position pos within
text and returns a position corresponding to S-expression
movement. The result is #f if no movement in the
corresponding direction is possible.
Returns whether the content at pos in text
corresponds to a token that should “stick” to the following
parenthesized sequence for navigation purposes. For example, the
result is #t when the token corresponds to ',
`, or #'.
9.2 S-Expression Indentation
Returns an amount of indentation to use for the line in text
that contains the position pos. The result may be more or
less than the current amount of indentation on the line.
The head-sexp-type function is used to map identifiers at the
start of an S-expression to the indentation rule that the identifier
should use. See compute-racket-amount-to-indent in racket:text<%>
for more information.
The graphical-width function is used to
get the graphical width (distance between the “x” coordinates)
of content in text between a start
and end position. If graphical-width returns #f, then
characters in text are assumed to be all the same width. If
graphical-width is #f, it is treated the same as if
it had been (λ (t start end) #f).
Changed in version 1.5 of package syntax-color-lib: Allow graphical-width to return #f.
Converts a serializable representation
spec of an indentation
configuration to a function suitable for use with
racket-amount-to-indent.
The first element of spec maps individual symbols to
indentation styles. The remaining elements provide patterns to
recognize identifiers with the corresponding style, in the order
'lambda, 'define, 'begin, and
'for/fold.