-%% Lisp documentation machinery.
-\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
-\def\describecategoryname#1{%
- \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
- \ifx\@tempa\relax#1\else\@tempa\fi}
-\definedescribecategory{sym}{symbol}
-\definedescribecategory{fun}{function}
-\definedescribecategory{gf}{generic function}
-\definedescribecategory{msg}{message}
-\definedescribecategory{var}{variable}
-\definedescribecategory{modvar}{module variable}
-\definedescribecategory{const}{constant}
-\definedescribecategory{meth}{primary method}
-\definedescribecategory{ar-meth}{around method}
-\definedescribecategory{be-meth}{before method}
-\definedescribecategory{af-meth}{after method}
-\definedescribecategory{cls}{class}
-\definedescribecategory{ty}{type}
-\definedescribecategory{type}{type}
-\definedescribecategory{mac}{macro}
-\definedescribecategory{lmac}{local macro}
-\definedescribecategory{parse}{parser spec}
-\definedescribecategory{parseform}{parser form}
-\definedescribecategory{opt}{option handler}
-\definedescribecategory{optmac}{option macro}
-\definedescribecategory{plug}{pluggable parser}
-\def\nlret{\\\hspace{4em}\returns}
+%%%--------------------------------------------------------------------------
+%%% Environment for setting programs.
+
+%% Main guts of `prog' and `nprog'.
+\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing}
+
+%% Newlines: called by `\\' within a `prog'.
+%%
+%% \\ newline without following break
+%% \\[SKIP] newline /with/ break and vertical glue
+%% \\*[SKIP] newline without break, with optional glue
+%% \\+ newline with break and a vertical gap
+%% \\- newline without break, with a tiny gap
+\def\@progcr{\futurelet\@tempa\@progcr@i}
+\def\@progcr@i{%
+ \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else
+ \if1\ifx\@tempa[1\else
+ \ifx\@tempa*1\else
+ 0\fi\fi
+ \let\next@\prog@@cr\else
+ \if1\ifx\@tempa+1\else
+ \ifx\@tempa-1\else
+ 0\fi\fi
+ \let\next@\@progcr@ii\else
+ \let\next@\@progcr@a\fi\fi\fi
+ \next@}
+\def\@progcr@a{\prog@@cr*{}\ignorespaces}
+\def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces}
+\@namedef{@progcr@+}{\prog@@cr[\medskipamount]}
+\@namedef{@progcr@-}{\prog@@cr*[\jot]}
+{\def\:{\gdef\@progcr@sp}\: {\@progcr}} % \@progcr@sp eats space and recurses
+
+%% Set a program in `codeface', with implicit tabbing and other toys.
+%% Newlines are explicit, because otherwise I need comments in weird places
+%% to make the vertical spacing come out properly. You can write
+%% `\obeylines' if you really want to.
+\def\prog{\quote\@prog}
+\def\endprog{\endtabbing\endquote}
+
+%% Like `prog', but without indenting the code. Use this within environments
+%% which already set their contents out from the body text in some
+%% distinctive way.
+\let\nprog\@prog
+\let\endnprog\endtabbing
+
+%% Indent the following material. Cancel using `\-'.
+\def\ind{\quad\=\+\kill}
+
+%% Show a backslash by the right-hand margin; for multiline macros etc.
+\def\macsl{\`\textbackslash\hskip\leftmargin}
+
+%% \maplist{THING}{{ITEM}...}: Invoke THING{ITEM} for each ITEM in turn.
+\def\maplist#1#2{\map@i{#1}#2\q@}
+\def\map@i#1{\def\next@{\map@ii{#1}}\futurelet\ch@\next@}
+\def\map@ii#1{\ifx\ch@\q@\expandafter\@gobble%
+ \else\def\next@{\map@iii{#1}}\expandafter\next@\fi}
+\def\map@iii#1#2{#1{#2}\map@i{#1}}
+
+%% \crossproduct{THING}{{LIST}...} where each LIST is {ITEM}...
+%% For each possible way of selecting one ITEM from each LIST, in order,
+%% invoke THING{{ITEM}...}
+\toksdef\cprod@new=0
+\toksdef\cprod@old=2
+\toksdef\cprod@head=4
+\toksdef\cprod@tail=6
+\def\crossproduct#1#2{%
+ \cprod@new{{}}%
+ \maplist{\cprod@f{#1}}{#2}%
+ \cprod@head{#1}%
+ \edef\next@{\noexpand\maplist{\the\cprod@head}{\the\cprod@new}}
+ \next@%
+}
+\def\cprod@f#1#2{%
+ \cprod@old\cprod@new\cprod@new{}%
+ \maplist\cprod@g{#2}%
+}
+\def\cprod@g#1{%
+ \cprod@head{#1}%
+ \expandafter\maplist\expandafter\cprod@h\expandafter{\the\cprod@old}%
+}
+\def\cprod@h#1{%
+ \cprod@tail{#1}%
+ \cprod@new\expandafter{\the\expandafter\cprod@new\expandafter{%
+ \the\expandafter\cprod@tail\the\cprod@head}}%
+}
+
+%%%--------------------------------------------------------------------------
+%%% Machinery for describing functions, etc.
+
+%% \definedescribecategory{CAT}[KIND]{NAME}
+%%
+%% Define a category of things to document. CAT is a short label identifying
+%% the category to `\describe', `\descref', and friends. The NAME is the
+%% text to show in the description headline; it is a macro body which is
+%% passed an argument `#1' that applies a modifier to some portion of the
+%% text.
+%%
+%% The KIND allows additional arguments to be collected, included in label
+%% strings, and mentioned in the index. The default is `plain'.
+\def\definedescribecategory#1{%
+ \@ifnextchar[{\def@desc{#1}}{\def@desc{#1}[plain]}}
+\def\def@desc#1[#2]#3{\@namedef{cat!#1}##1{#3}\@namedef{catsw!#1}{#2}}
+
+%% \describecategoryname[MOD]{CAT}
+%%
+%% Typeset the category name for CAT, modified by MOD.
+\def\describecategoryname{\@ifnextchar[\@descname@i{\@descname@i[]}}
+\def\@descname@i[#1]#2{%
+ \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname%
+ \expandafter\let\expandafter\@tempb\csname modcat/#1\endcsname%
+ \ifx\@tempa\relax\@tempb{#2}\else\@tempa\@tempb\fi}
+
+%% Call a modifier method.
+\def\@mod@dispatch#1#2{\csname #1/#2\endcsname}
+
+%% Call a description method given the category.
+\def\@desc@dispatch#1#2{%
+ \csname #1/%
+ \expandafter\ifx\csname catsw!#2\endcsname\relax plain%
+ \else \csname catsw!#2\endcsname \fi%
+ \endcsname%
+}
+
+%% Modifier methods for the default `plain' modifier.
+\@namedef{modcat/plain}#1{#1}
+\@namedef{modlabel/plain}#1{#1}
+\@namedef{modindex/plain}#1{#1@\noexpand\code{#1}}
+
+%% Modifier methods for `setf'. The name text prefixes the relevant word
+%% with `setf-'.
+\@namedef{modcat/setf}#1{\code{setf}-#1}
+\@namedef{modlabel/setf}#1{setf/#1}
+\@namedef{modindex/setf}#1{#1@\noexpand\code{#1}}
+
+%% Modifier methods for words with *earmuffs*. Sort into the index without
+%% the earmuffs.
+\@namedef{modcat/muffs}#1{#1}
+\@namedef{modlabel/muffs}#1{#1}
+\@namedef{modindex/muffs}#1{\@unmuff#1@\noexpand\code{#1}}
+\def\@unmuff*#1*{#1}
+
+%% Modifier methods for :keywords. Sort into the index without the `:'.
+\@namedef{modcat/kwd}#1{#1}
+\@namedef{modlabel/kwd}#1{#1}
+\@namedef{modindex/kwd}#1{\@gobble#1@\noexpand\code{#1}}
+
+%% Category-kind methods for plain categories.
+\@namedef{descargs/plain}#1{#1{}}
+\@namedef{desclabel/plain}#1#2#3{#2:\@mod@dispatch{modlabel}{#1}{#3}}
+\@namedef{descindex/plain}#1#2#3{%
+ \@mod@dispatch{modindex}{#1}{#3}!%
+ \protect\describecategoryname[#1]{#2}%
+}
+
+%% Category-kind methods for `method' categories. Collect an extra argument
+%% listing the specializers: include them in the label, and typeset them in
+%% the index.
+\def\fmtspecs#1#2{%
+ \if!#2!\else\count@\z@\toks@{}#1\fmtspecs@i#2,\q@,\fi}
+\def\fmtspecs@i#1,{%
+ \def\@tempa{#1}%
+ \ifx\@tempa\q@%
+ \ifcase\count@(no args?!)%
+ \or% nothin' doin
+ \or \space and %
+ \else, and %
+ \fi%
+ \the\toks@%
+ \else%
+ \ifnum\count@>\@ne, \fi%
+ \the\toks@%
+ \toks@{\code{#1}}\advance\count@\@ne%
+ \expandafter\fmtspecs@i%
+ \fi%
+}
+\@namedef{descargs/method}#1#2{#1{{#2}}}
+\@namedef{desclabel/method}#1#2#3#4%
+ {#2:\@mod@dispatch{modlabel}{#1}{#4}(#3)}
+\@namedef{descindex/method}#1#2#3#4{%
+ \@mod@dispatch{modindex}{#1}{#4}!%
+ \protect\describecategoryname[#1]{#2}%
+ \protect\fmtspecs{ specialized at }{#3}%
+}