X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/58f9b4000fb24a363ba8843ce999e8b9a27c4052..072f666e09bf7df9846ffbd347183cc83a01b8d7:/doc/sod.sty diff --git a/doc/sod.sty b/doc/sod.sty index 28b6ccc..fb6ce77 100644 --- a/doc/sod.sty +++ b/doc/sod.sty @@ -57,18 +57,28 @@ %% Listings don't need to be small. \let\listingsize\relax +%% Notes for later. +\def\fixme#1{\leavevmode\marginpar{FIXME}\index{FIXME}[FIXME: #1]} + +%% Diagram settings. +\tikzset{ + every picture/.style={>=stealth, thick}, + lit/.style={font=\sffamily} +} + %% Metavariables are italics without decoration. \def\syntleft{\normalfont\itshape} \let\syntright\empty %% Literal code is in sans face. -\let\codeface\sffamily +\def\codeface{\upshape\sffamily} \DeclareRobustCommand\code[1]{% \ifmmode\hbox\else\leavevmode\fi% {\normalfont\codeface\/#1\/}% } \def\ulitleft{\normalfont\codeface} \let\ulitright\empty +\def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}} %% Conditionally enter maths mode. Can't use \ensuremath here because we %% aren't necessarily sure where the maths will actually end. @@ -79,7 +89,7 @@ \atdef <#1>{\synt{#1}\@scripts} \atdef "#1"{\lit*{#1}\@scripts} \atdef `#1'{\lit{#1}\@scripts} -\atdef |#1|{\textsf{#1}\@scripts} +\atdef |#1|{\lit*{#1}\@scripts} %% A handy abbreviation; `\\' itself is too good to steal. \atdef \\{\textbackslash} @@ -119,14 +129,41 @@ \atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi} %% Comment setting. -\atdef ;#1\\{\normalfont\itshape;#1\\} +\def\comment#1{\mbox{\normalfont\itshape\/#1\/}} +\atdef /*#1*/{/*\comment{#1}*/} +\def\@semis{\@ifnextchar;{;\@semis}\@semicomment} +\def\@semicomment#1\\{\comment{#1}\\} +\atdef ;#1\\{;\@semis} %% 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}} +\atdef~{\textasciitilde} +\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\macsl{\`\textbackslash\hskip\leftmargin} %% Put a chunk of text in a box. \newenvironment{boxy}[1][\q@]{% @@ -145,9 +182,13 @@ %% 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} +\def\describecategoryname{\@ifnextchar[\@descname@i{\@descname@i[]}} +\def\@descname@i[#1]#2{% + \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname% + \if!#1!\else\code{#1}-\fi% + \ifx\@tempa\relax#2\else\@tempa\fi} +\def\@maybe@modlabel#1#2{\if!#1!\else#1/\fi#2} + \definedescribecategory{sym}{symbol} \definedescribecategory{fun}{function} \definedescribecategory{gf}{generic function} @@ -160,6 +201,7 @@ \definedescribecategory{be-meth}{before method} \definedescribecategory{af-meth}{after method} \definedescribecategory{cls}{class} +\definedescribecategory{rst}{restart} \definedescribecategory{ty}{type} \definedescribecategory{type}{type} \definedescribecategory{mac}{macro} @@ -172,32 +214,51 @@ \def\nlret{\\\hspace{4em}\returns} \def\q@{\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}} +\def\@setf{setf} + +%% \parse@dhd{NEXT}{CAT}[NAME]{SYNOPSIS} +%% call NEXT{MOD}{CAT}{NAME}{SYNOPSIS} +%% #1 #2 #3 #4 +\def\parse@dhd#1#2{% {NEXT}{CAT} + \@ifnextchar[{\parse@dhd@cc{#1}{#2}}{\parse@dhd@cd{#1}{#2}}} +\def\parse@dhd@cc#1#2[#3]#4{% {NEXT}{CAT}[NAME]{SYNOPSIS} + #1{}{#2}{#3}{#4}} +\def\parse@dhd@cd#1#2#3{% {NEXT}{CAT}{SYNOPSIS} + \parse@dhd@ce{#1}{#2}{#3}#3 \q@} +\def\parse@dhd@ce#1#2#3#4 #5\q@{% + % {NEXT}{CAT}{SYNOPSIS}NAME [ARGS...]\q@ + \def\temp@{#4}% + \ifx\temp@\@setf\def\next@{\parse@dhd@csetf{#1}{#2}{#3}#5 \q@}% + \else\def\next@{#1{}{#2}{#4}{#3}}\fi% + \next@% +} +\def\parse@dhd@csetf#1#2#3(#4 #5\q@{% + % {NEXT}{CAT}{SYNOPSIS}(NAME [ARGS...])\q@ + #1{setf}{#2}{#4}{#3}} \newif\if@dheadfirst \def\dhead{\parse@dhd\dhead@} -\def\dhead@#1#2#3{% +\def\dhead@#1#2#3#4{% {}{CAT}{NAME}{SYNOPSIS} \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}% + {\let\protect\@empty\let\@uscore\relax% + \edef\temp@{#2:\@maybe@modlabel{#1}{#3}}% + \def\@uscore{_\@gobble}\message{\temp@}% + \def\@uscore{-\@gobble}\label{\temp@}}% {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}% \protected@edef\@tempa##1{% \noexpand\index{% - #1@{\noexpand\code{#1}}!% - \csname cat!#2\endcsname% + #3@{\noexpand\code{#3}}!% + \protect\describecategoryname[#1]{#2}% ##1% }% }% - \@tempa{|(}% \toks@\expandafter{\after@desc}% \toks\tw@\expandafter{\@tempa{|)}}% - \xdef\after@desc{\the\toks@\the\toks\tw@}}% + \xdef\after@desc{\the\toks@\the\toks\tw@}% + \@tempa{|(}}% \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries - [\describecategoryname{#2}]}}% - #3% + [\describecategoryname[#1]{#2}]}}% + #4% } \def\desc@begin#1{% @@ -207,10 +268,9 @@ \if@nobreak\else\par\goodbreak\fi% \global\@dheadfirsttrue% \begingroup% - \codeface% \let\@endparenv\relax% \clubpenalty\@M \widowpenalty\@M \interlinepenalty50% - \tabbing#1\endtabbing% + \@prog#1\endtabbing% \endgroup% \penalty\@M\@afterheading% \list{}{\rightmargin\z@\topsep\z@}\item% @@ -220,7 +280,7 @@ \@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}}} +\def\desc@#1#2#3#4{\desc@begin{\dhead@{#1}{#2}{#3}{#4}}} \let\enddescribe\desc@end \def\descref#1{\@ifnextchar[{\descref@i{#1}}{\descref@ii{#1}{}}}