X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/780dfb99b08e565eeeb5d94d4d8fd0604b8c54d0..8d952432c8b961e4e0891eb78620615a8ae14f05:/doc/sod.sty

diff --git a/doc/sod.sty b/doc/sod.sty
index 2894feb..9c9aaf8 100644
--- a/doc/sod.sty
+++ b/doc/sod.sty
@@ -7,7 +7,7 @@
 
 %%%----- Licensing notice ---------------------------------------------------
 %%%
-%%% This file is part of the Sensble Object Design, an object system for C.
+%%% This file is part of the Sensible Object Design, an object system for C.
 %%%
 %%% SOD is free software; you can redistribute it and/or modify
 %%% it under the terms of the GNU General Public License as published by
@@ -41,6 +41,16 @@
 \let\implies\Rightarrow
 \let\epsilon\varepsilon
 
+%% A table heading cell.  Clone and hack \multicolumn.
+\def\thd{\omit\@ifnextchar[\thd@{\thd@[l]}}
+\def\thd@[#1]#2{%
+  \begingroup
+    \tab@multicol \tab@initread \let\tab@looped\tab@err@multi
+    \tab@preamble{}\def\tab@midtext{\bfseries#2}\tab@readpreamble{#1}%
+    \the\tab@preamble
+  \endgroup \ignorespaces
+}
+
 %% Unix manpage references.
 \def\man#1#2{\textbf{#1}(#2)}
 
@@ -53,7 +63,10 @@
 
 %% Literal code is in sans face.
 \let\codeface\sffamily
-\def\code#1{\ifmmode\hbox\fi{\normalfont\codeface\/#1\/}}
+\DeclareRobustCommand\code[1]{%
+  \ifmmode\hbox\else\leavevmode\fi%
+  {\normalfont\codeface\/#1\/}%
+}
 \def\ulitleft{\normalfont\codeface}
 \let\ulitright\empty
 
@@ -103,7 +116,7 @@
 \atdef !{\m@maybe|\@scripts}
 \def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
 \atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
-\atdef -#1{\if>#1{\ensuremath\rightarrow}\fi}
+\atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi}
 
 %% Comment setting.
 \atdef ;#1\\{\normalfont\itshape;#1\\}
@@ -111,12 +124,34 @@
 %% Environment for setting programs.  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{\codeface\quote\tabbing}
+\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing}
+\def\prog{\quote\@prog}
 \def\endprog{\endtabbing\endquote}
+\let\nprog\@prog
+\let\endnprog\endtabbing
 \def\ind{\quad\=\+\kill}
+\def\@progcr{\futurelet\@tempa\@progcr@i}
+{\def\:{\gdef\@progcr@sp}\: {\@progcr}}
+\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]}
 
 %% Put a chunk of text in a box.
 \newenvironment{boxy}[1][\q@]{%
+  \savenotes
   \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
   \medskip%
   \vbox\bgroup\hrule\hbox\bgroup\vrule%
@@ -126,6 +161,7 @@
   \endminipage\hskip1ex\egroup\vskip1ex\egroup%
   \vrule\egroup\hrule\egroup%
   \medskip%
+  \spewnotes%
 }
 
 %% Lisp documentation machinery.
@@ -133,40 +169,88 @@
 \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{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}
 
 \def\q@{\q@}
-\newenvironment{describe}[3][\q@]{%
+\def\parse@dhd#1{\@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
+\def\parse@dhd@a#1[#2]{#1{#2}}
+\def\parse@dhd@c#1#2#3{\parse@dhd@cc{#1}{#2}{#3}#3 \q@}
+\def\parse@dhd@cc#1#2#3#4 #5\q@{#1{#4}{#2}{#3}}
+
+\newif\if@dheadfirst
+\def\dhead{\parse@dhd\dhead@}
+\def\dhead@#1#2#3{%
+  \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi%
+  {\let\protect\@empty\def\@uscore{_\@gobble}\message{#2:#1}%
+   \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#2:#1}}\@tempa}%
+  {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}%
+   \protected@edef\@tempa##1{%
+     \noexpand\index{%
+       #1@{\noexpand\code{#1}}!%
+       \csname cat!#2\endcsname%
+       ##1%
+     }%
+   }%
+   \@tempa{|(}%
+   \toks@\expandafter{\after@desc}%
+   \toks\tw@\expandafter{\@tempa{|)}}%
+   \xdef\after@desc{\the\toks@\the\toks\tw@}}%
+  \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries
+      [\describecategoryname{#2}]}}%
+  #3%
+}
+
+\def\desc@begin#1{%
+  \let\saved@after@desc\after@desc%
+  \gdef\after@desc{}%
   \normalfont%
-  \par\goodbreak%
-  \vspace{\bigskipamount}%
-  \setbox\z@\hbox{\bfseries[\describecategoryname{#2}]}%
-  \dimen@\linewidth\advance\dimen@-\wd\z@%
-  \def\@temp##1 ##2\q@{%
-    \message{#2:##1}%
-    {\def\@uscore####1{-}\edef\@tempb{\noexpand\label{#2:##1}}\@tempb}%
-  }%
-  \def\@tempa{#1}\ifx\@tempa\q@\@temp#3 \q@\else\@temp{#1} \q@\fi%
-  \edef\@temp{{\the\linewidth}{@{}p{\the\dimen@}%
-      @{\extracolsep{\fill}}l@{\extracolsep{0pt}}}}%
-  \noindent\csname tabular*\expandafter\endcsname\@temp%
-  \tabbing\codeface#3\endtabbing&\unhbox\z@\\\endtabular%
-%  \@afterheading%
-  \list{}{\rightmargin\z@}\item%
-}{%
-  \endlist%
+  \if@nobreak\else\par\goodbreak\fi%
+  \global\@dheadfirsttrue%
+  \begingroup%
+    \let\@endparenv\relax%
+    \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
+    \@prog#1\endtabbing%
+  \endgroup%
+  \penalty\@M\@afterheading%
+  \list{}{\rightmargin\z@\topsep\z@}\item%
+}
+\def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc}
+
+\@namedef{describe*}#1{\desc@begin{#1}}
+\expandafter\let\csname enddescribe*\endcsname\desc@end
+\def\describe{\parse@dhd\desc@}
+\def\desc@#1#2#3{\desc@begin{\dhead@{#1}{#2}{#3}}}
+\let\enddescribe\desc@end
+
+\def\descref#1{\@ifnextchar[{\descref@i{#1}}{\descref@ii{#1}{}}}
+\def\descref@i#1[#2]{\descref@ii{#1}{ #2}}
+\def\descref@ii#1#2#3{%
+  \code{#1}#2 (page~%
+  {\let\protect\@empty%
+   \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\pageref{#3:#1}}\@tempa}%
+  )%
 }
 
-%%% ----- That's all, folks --------------------------------------------------
-\endinput
\ No newline at end of file
+%%%----- That's all, folks --------------------------------------------------
+\endinput
