Guile Library

(string wrap)

Overview

Module (string wrap) provides functions for formatting text strings such that they fill a given width field. A class, <text-wrapper>, does the work, but two convenience methods create instances of it for one-shot use, and in the process make for a more ``schemey'' interface. If many strings will be formatted with the same parameters, it might be better performance-wise to create and use a single <text-wrapper>.

Usage

<text-wrapper>
[Class]

This class encapsulates the parameters needing to be fed to the text wrapping algorithm. The following are the recognized keywords on the call to make:

#:line-width

This is the target length used when deciding where to wrap lines. Default is 80.

#:expand-tabs?

Boolean describing whether tabs in the input should be expanded. Default is #t.

#:tab-width

If tabs are expanded, this will be the number of spaces to which they expand. Default is 8.

#:collapse-whitespace?

Boolean describing whether the whitespace inside the existing text should be removed or not. Default is #t.

If text is already well-formatted, and is just being wrapped to fit in a different width, then setting this to #f. This way, many common text conventions (such as two spaces between sentences) can be preserved if in the original text. If the input text spacing cannot be trusted, then leave this setting at the default, and all repeated whitespace will be collapsed down to a single space.

#:initial-indent

Defines a string that will be put in front of the first line of wrapped text. Default is the empty string, ``''.

#:subsequent-indent

Defines a string that will be put in front of all lines of wrapped text, except the first one. Default is the empty string, ``''.

#:break-long-words?

If a single word is too big to fit on a line, this setting tells the wrapper what to do. Defaults to #t, which will break up long words. When set to #f, the line will be allowed, even though it is longer than the defined #:line-width.

Here's an example of creating a <text-wrapper>:

 (make <text-wrapper> #:line-width 48 #:break-long-words? #f)
fill-string
[Generic]

fill-string str keywds .... Wraps the text given in string str according to the parameters provided in keywds, or the default setting if they are not given. Returns a single string with the wrapped text. Valid keyword arguments are discussed with the <text-wrapper> class.

fill-string tw str. fills str using the instance of <text-wrapper> given as tw.

fill-string (tw <text-wrapper>) (str <top>)
[Method]
fill-string (str <top>) (keywds <top>)...
[Method]
string->wrapped-lines
[Generic]

string->wrapped-lines str keywds .... Wraps the text given in string str according to the parameters provided in keywds, or the default setting if they are not given. Returns a list of strings representing the formatted lines. Valid keyword arguments are discussed with the <text-wrapper> class.

string->wrapped-lines tw str. Wraps the text given in string str according to the given <text-wrapper> tw. Returns a list of strings representing the formatted lines. Valid keyword arguments are discussed with the <text-wrapper> class.

string->wrapped-lines (tw <text-wrapper>) (str <top>)
[Method]
string->wrapped-lines (str <top>) (keywds <top>)...
[Method]