text.multicolumn
- Multicolumn formatting ¶This module provides the means to format a list of words into
a multicolumn text. Think of the output of ls
command.
(display-multicolumn
(string-tokenize "The quick brown fox \
jumps over the lazy dog"))
⇒ prints
The fox the
quick jumps lazy
brown over dog
Various options are provided to customize the output.
{text.multicolumn
}
Display items in a list of strings strs in multicolumn format,
to the current output port.
The items shouldn’t contain newline or tab characters; the procedure
doesn’t treat them specially, so the output would be disturbed.
The width of a column is chosen to contain the longest string in strs or minimum-width, whichever greater. The default of minimum-width is 8.
Then as many columns are displayed as fit in width characters,
whose default is 80. However, the number of columns won’t exceed
max-columns if it is given and not #f
.
The order argument must be either a symbol column
or
row
. If it is column
(default), the items are sorted
column-first; that is, it is filled in the first column from top to
down, then the second column from top to down, and so on.
If it is row
, the items are sorted row-first; it is filled
in the first row from left to right, and then second row, and so on.
The indent argument must be a nonnegative exact integer. If it is greater than zero, that number of whitespaces are prepended before each line. The width includes this indentation; so the actual area of text becomes narrower by indent characters.
The style argument may take either one of the symbols even
or packed
. If it is even
(default), all columnts have
even width, based on the longest item.
If it is packed
, each column gets a width that’s enough to contain
that particular column. It may allow more columns to fit.
The packed
style is particulary effective when you have mostly
short items and just a few long items. With even
style,
columns that do not contain long items still gets the same width,
resulting lots of whitespaces. Packed
style takes width only for
columns that contain long items, leading to more columns, fewer rows,
and more uniform text density.
{text.multicolumn
}
This is an underlying procedure of display-multicolumn
. It returns
a list of text tree (see text.tree
- Lazy text construction). Each text
tree stands for a line, not including the newline character.
This can be handy if you want to modify the layout.
(layout-multicolumn (string-tokenize "The quick brown fox \ jumps over the lazy dog")) ⇒ (("The " "fox " "the") ("quick " "jumps " "lazy") ("brown " "over " "dog"))
NB: The actual structure of each text tree may be changed, but
passing it to tree->string
or write-tree
produces
the line.