comparison Doc/texinputs/python.sty @ 24090:bc00eeef0ac7 legacy-trunk

Abstract the creation of signature lines for callable things; the new \py@sigline macro will wrap the argument list so it will not extend into the right margin. Substantially based on a contribution from Dave Cole. This addresses one of the comments in SF bug #574742.
author Fred Drake <fdrake@acm.org>
date Tue, 02 Jul 2002 20:32:50 +0000
parents 530aba3116a4
children 2670a5db6843
comparison
equal deleted inserted replaced
24089:b185c85952fe 24090:bc00eeef0ac7
579 % This can be used when you don't want to document the parameters to a 579 % This can be used when you don't want to document the parameters to a
580 % function or method, but simply state that it's an alias for 580 % function or method, but simply state that it's an alias for
581 % something else. 581 % something else.
582 \newcommand{\py@unspecified}{...} 582 \newcommand{\py@unspecified}{...}
583 583
584
585 \newlength{\py@argswidth}
586 \newcommand{\py@sigparams}[1]{%
587 \parbox[t]{\py@argswidth}{\py@varvars{#1}\code{)}}}
588 \newcommand{\py@sigline}[2]{%
589 \settowidth{\py@argswidth}{#1\code{(}}%
590 \addtolength{\py@argswidth}{-2\py@argswidth}%
591 \addtolength{\py@argswidth}{\textwidth}%
592 \item[#1\code{(}\py@sigparams{#2}]}
593
584 % C functions ------------------------------------------------------------ 594 % C functions ------------------------------------------------------------
585 % \begin{cfuncdesc}[refcount]{type}{name}{arglist} 595 % \begin{cfuncdesc}[refcount]{type}{name}{arglist}
586 % Note that the [refcount] slot should only be filled in by 596 % Note that the [refcount] slot should only be filled in by
587 % tools/anno-api.py; it pulls the value from the refcounts database. 597 % tools/anno-api.py; it pulls the value from the refcounts database.
588 \newcommand{\cfuncline}[3]{ 598 \newcommand{\cfuncline}[3]{
589 \item[\code{#1 \bfcode{#2}(\py@varvars{#3})}\index{#2@{\py@idxcode{#2()}}}] 599 \py@sigline{\code{#1 \bfcode{#2}}}{#3}%
600 \index{#2@{\py@idxcode{#2()}}}
590 } 601 }
591 \newenvironment{cfuncdesc}[4][\py@badkey]{ 602 \newenvironment{cfuncdesc}[4][\py@badkey]{
592 \begin{fulllineitems} 603 \begin{fulllineitems}
593 \cfuncline{#2}{#3}{#4} 604 \cfuncline{#2}{#3}{#4}
594 \ifx#1\@undefined\else% 605 \ifx#1\@undefined\else%
643 \begin{fulllineitems} 654 \begin{fulllineitems}
644 \funcline{#1}{#2} 655 \funcline{#1}{#2}
645 }{\end{fulllineitems}} 656 }{\end{fulllineitems}}
646 657
647 % similar to {funcdesc}, but doesn't add to the index 658 % similar to {funcdesc}, but doesn't add to the index
648 \newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]} 659 \newcommand{\funclineni}[2]{%
660 \py@sigline{\bfcode{#1}}{#2}}
649 \newenvironment{funcdescni}[2]{ 661 \newenvironment{funcdescni}[2]{
650 \begin{fulllineitems} 662 \begin{fulllineitems}
651 \funclineni{#1}{#2} 663 \funclineni{#1}{#2}
652 }{\end{fulllineitems}} 664 }{\end{fulllineitems}}
653 665
655 % \begin{classdesc}{name}{constructor args} 667 % \begin{classdesc}{name}{constructor args}
656 \newenvironment{classdesc}[2]{ 668 \newenvironment{classdesc}[2]{
657 % Using \renewcommand doesn't work for this, for unknown reasons: 669 % Using \renewcommand doesn't work for this, for unknown reasons:
658 \global\def\py@thisclass{#1} 670 \global\def\py@thisclass{#1}
659 \begin{fulllineitems} 671 \begin{fulllineitems}
660 \item[\strong{class }\code{\bfcode{#1}(\py@varvars{#2})}% 672 \py@sigline{\strong{class }\bfcode{#1}}{#2}%
661 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}] 673 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}
662 }{\end{fulllineitems}} 674 }{\end{fulllineitems}}
663 675
664 % \begin{classdesc*}{name} 676 % \begin{classdesc*}{name}
665 \newenvironment{classdesc*}[1]{ 677 \newenvironment{classdesc*}[1]{
666 % Using \renewcommand doesn't work for this, for unknown reasons: 678 % Using \renewcommand doesn't work for this, for unknown reasons:
674 % but indexes as an exception 686 % but indexes as an exception
675 \newenvironment{excclassdesc}[2]{ 687 \newenvironment{excclassdesc}[2]{
676 % Using \renewcommand doesn't work for this, for unknown reasons: 688 % Using \renewcommand doesn't work for this, for unknown reasons:
677 \global\def\py@thisclass{#1} 689 \global\def\py@thisclass{#1}
678 \begin{fulllineitems} 690 \begin{fulllineitems}
679 \item[\strong{exception }\code{\bfcode{#1}(\py@varvars{#2})}% 691 \py@sigline{\strong{exception }\bfcode{#1}}{#2}%
680 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}] 692 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}
681 }{\end{fulllineitems}} 693 }{\end{fulllineitems}}
682 694
683 % There is no corresponding {excclassdesc*} environment. To describe 695 % There is no corresponding {excclassdesc*} environment. To describe
684 % a class exception without parameters, use the {excdesc} environment. 696 % a class exception without parameters, use the {excdesc} environment.
685 697
707 }{\end{fulllineitems}} 719 }{\end{fulllineitems}}
708 720
709 % similar to {methoddesc}, but doesn't add to the index 721 % similar to {methoddesc}, but doesn't add to the index
710 % (never actually uses the optional argument) 722 % (never actually uses the optional argument)
711 \newcommand{\methodlineni}[3][\py@classbadkey]{% 723 \newcommand{\methodlineni}[3][\py@classbadkey]{%
712 \item[\code{\bfcode{#2}(\py@varvars{#3})}]} 724 \py@sigline{\bfcode{#2}}{#3}}
713 \newenvironment{methoddescni}[3][\py@classbadkey]{ 725 \newenvironment{methoddescni}[3][\py@classbadkey]{
714 \begin{fulllineitems} 726 \begin{fulllineitems}
715 \methodlineni{#2}{#3} 727 \methodlineni{#2}{#3}
716 }{\end{fulllineitems}} 728 }{\end{fulllineitems}}
717 729