Skip to main content

pprint-tab

pprint-tab Function

Syntax:

pprint-tab kind colnum colinc &optional stream → nil

Arguments and Values:

kind—one of :line, :section, :line-relative, or :section-relative.

colnum—a non-negative integer .

colinc—a non-negative integer .

stream—an output stream designator .

Description:

Specifies tabbing to stream as performed by the standard ~T format directive. If stream is a pretty printing stream and the value of *print-pretty* is true, tabbing is performed; otherwise, pprint-tab has no effect.

The arguments colnum and colinc correspond to the two parameters to ~T and are in terms of ems. The kind argument specifies the style of tabbing. It must be one of :line (tab as by ~T), :section (tab as by ~:T, but measuring horizontal positions relative to the start of the dynamically enclosing section), :line-relative (tab as by ~@T), or :section-relative (tab as by ~:@T, but measuring

horizontal positions relative to the start of the dynamically enclosing section).

Exceptional Situations:

An error is signaled if kind is not one of :line, :section, :line-relative, or :section-relative.

See Also:

pprint-logical-block

Expanded Reference: pprint-tab

Tab Kinds

pprint-tab specifies tabbing within a pretty-printing stream. It takes a kind, column number, column increment, and optional stream. The kind determines how tabbing is computed:

  • :line -- absolute tab (like ~T in format)
  • :line-relative -- relative tab (like ~@T)
  • :section -- absolute tab relative to the start of the enclosing section
  • :section-relative -- relative tab from current position within a section

:line -- Absolute Column Tab

Tabs to an absolute column position on the line.

(let ((*print-pretty* t))
(with-output-to-string (s)
(pprint-logical-block (s nil)
(write-string "Name" s)
(pprint-tab :line 20 1 s)
(write-string "Value" s))))
=> "Name Value"

:section-relative -- Relative Within Section

Tabs relative to the current position, used with column increments for alignment in columnar output.

(let ((*print-pretty* t)
(*print-right-margin* 35))
(with-output-to-string (s)
(pprint-logical-block (s '(alpha beta gamma delta) :prefix "(" :suffix ")")
(loop (write (pprint-pop) :stream s)
(pprint-exit-if-list-exhausted)
(write-char #\Space s)
(pprint-tab :section-relative 0 12 s)
(pprint-newline :fill s)))))
=> "(ALPHA BETA GAMMA
DELTA)"

No Effect Outside Pretty Printing

Like other pretty-printing functions, pprint-tab has no effect when *print-pretty* is false.

(let ((*print-pretty* nil))
(with-output-to-string (s)
(pprint-tab :line 10 1 s)))
=> ""