doc/sod.sty: Handle `setf' functions and friends in a more useful way.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 28 Jul 2019 01:28:24 +0000 (02:28 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Aug 2019 15:27:42 +0000 (16:27 +0100)
  * Extend the `dhead' protocol to include a new MOD argument, which is
    usually empty, but may be something like `setf' to denote a modified
    thing.

  * Include the modification (if not empty) in the label, index subitem,
    and the description headline.

This is still rather rough, but will be refined soon.

doc/sod.sty

index 9ff6181..fb6ce77 100644 (file)
 
 %% 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}
 \def\nlret{\\\hspace{4em}\returns}
 
 \def\q@{\q@}
+\def\@setf{setf}
 
 %% \parse@dhd{NEXT}{CAT}[NAME]{SYNOPSIS}
-%% call NEXT{CAT}{NAME}{SYNOPSIS}
-%%            #1   #2      #3
+%% 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}}
+  #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@
-  #1{#2}{#4}{#3}}
+  \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{%  {CAT}{NAME}{SYNOPSIS}
+\def\dhead@#1#2#3#4{%  {}{CAT}{NAME}{SYNOPSIS}
   \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi%
-  {\let\protect\@empty\def\@uscore{_\@gobble}\message{#1:#2}%
-   \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#1:#2}}\@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{%
-       #2@{\noexpand\code{#2}}!%
-       \csname cat!#1\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{#1}]}}%
-  #3%
+      [\describecategoryname[#1]{#2}]}}%
+  #4%
 }
 
 \def\desc@begin#1{%
 \@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}{}}}