%D \module
%D   [      file=t-fixme,
%D        version=2009.11.08,
%D          title=\CONTEXT\ User Module,
%D       subtitle=FiXme,
%D         author=Wolfgang Schuster,
%D           date=\currentdate,
%D      copyright=Wolfgang Schuster,
%D          email=schuster.wolfgang@googlemail.com,
%D        license=Public Domain]

\writestatus{loading}{Context User Module / FiXme}

\unprotect

%D Logo

\def\fixmelogo{{\ss FiXme}} \logo[FIXME]{\fixmelogo}

\startinterface all
  \setinterfaceconstant {version} {version}
\stopinterface

\startinterface all
  \setinterfacevariable {fixme}     {fixme}
  \setinterfacevariable {fixmes}    {fixmes}
  \setinterfacevariable {fatal}     {fatal}
  \setinterfacevariable {note}      {note}
  \setinterfacevariable {warning}   {warning}
  \setinterfacevariable {error}     {error}
  \setinterfacevariable {total}     {total}
  \setinterfacevariable {draft}     {draft}
  \setinterfacevariable {fxnote}    {fxnote}
  \setinterfacevariable {fxwarning} {fxwarning}
  \setinterfacevariable {fxerror}   {fxerror}
\stopinterface

%D Messages

\definemessageconstant {fixme}

\startinterface all
  \setinterfacemessage{fixme}{title}{FiXme}
  \setinterfacemessage{fixme}{1}    {Number of notes: --}
  \setinterfacemessage{fixme}{2}    {Number of warnings: --}
  \setinterfacemessage{fixme}{3}    {Number of errors:}
  \setinterfacemessage{fixme}{4}    {Number of fatal errors: --}
  \setinterfacemessage{fixme}{5}    {Total: --}
\stopinterface

%D \macros
%D   {setupfixme}
%D
%D Namespace and setup command

\def\????fx{@@@@fx} % FiXme

\def\setupfixme
  {\dosingleargument\dosetupfixme}

\def\dosetupfixme[#1]%
  {\doifassignmentelse{#1}
     {\getparameters[\????fx][#1]}
     {\setvalue{\????fx\c!version}{#1}}}

%D Lists

\definelist[\v!fixme][\c!width=\zeropoint]

\setvalue{\e!place   \e!listof\v!fixmes}{\dodoubleempty\doplacelist     [\v!fixme]}
\setvalue{\e!complete\e!listof\v!fixmes}{\dotripleempty\dodocompletelist[\v!fixme][\v!fixmes]}

%D \macros
%D   {fixme,fxnote,fxwarning,fxerror,
%D    definefixme,definefixmelocation}
%D
%D Commands

\makecounter{\????fx\v!note   } % \pluscounter is not so
\makecounter{\????fx\v!warning} % clever as \increment 
\makecounter{\????fx\v!error  } % and I have to define
\makecounter{\????fx\v!fatal  } % the counters before
\makecounter{\????fx\v!total  } % I can use them

\def\dofixme[#1][#2]#3%
  {\removeunwantedspaces
   \bgroup
   \ifsecondargument
     \setvalue{\????fx\c!location}{#2}%
   \fi
   \expanded{\writetolist[\v!fixme]{}{\labeltext{fixme#1}#3}}%
   \pluscounter{\????fx\v!total}%
   \pluscounter{\????fx      #1}%
   \doif\@@@@fxversion\v!draft{\processcommacommand[\@@@@fxlocation]{\dofixmelocation{#1}{#3}}}%
   \egroup}

\def\dofixmelocation#1#2#3{\executeifdefined{@@fixme@@#3}\gobbleoneargument{\labeltext{fixme#1}#2}}

\def\definefixmelocation
  {\dodoubleargument\dodefinefixmelocation}

\def\dodefinefixmelocation[#1][#2]%
  {\setvalue{@@fixme@@#1}{#2}}

\definefixmelocation [\v!text    ] [\ifhmode\normalspace\fi]
\definefixmelocation [\v!margin  ] [\inright               ]
\definefixmelocation [\v!footnote] [\footnote              ]
\definefixmelocation [\v!left    ] [\inleft                ]
\definefixmelocation [\v!right   ] [\inright               ]
\definefixmelocation [\v!inner   ] [\ininner               ]
\definefixmelocation [\v!outer   ] [\inouter               ]

\def\dostartfixme[#1][#2]%
  {\bgroup
   \setupfixme[\c!list=,#2]%
   \doifsomething\@@@@fxlist{\expanded{\writetolist[\v!fixme]{}{\labeltext{fixme#1}\@@@@fxlist}}}%
   \pluscounter{\????fx\v!total}%
   \pluscounter{\????fx      #1}%
   \@@@@fxbefore}

\def\dostopfixme
  {\@@@@fxafter
   \egroup}

\def\definefixme
  {\dodoubleargument\dodefinefixme}

\def\dodefinefixme[#1][#2]%
  {\setvalue        {#1}{\dodoubleempty\dofixme     [#2]}%
   \setvalue{\e!start#1}{\dodoubleempty\dostartfixme[#2]}%
   \setvalue{\e!stop #1}{\dostopfixme}}

\definefixme [\v!fixme    ] [\v!fatal  ]
\definefixme [\v!fxnote   ] [\v!note   ]
\definefixme [\v!fxwarning] [\v!warning]
\definefixme [\v!fxerror  ] [\v!error  ]

\appendtoks
    \showmessage\m!fixme{1}{\countervalue{\????fx\v!note   }}%
    \showmessage\m!fixme{2}{\countervalue{\????fx\v!warning}}%
    \showmessage\m!fixme{3}{\countervalue{\????fx\v!error  }}%
    \showmessage\m!fixme{4}{\countervalue{\????fx\v!fatal  }}%
    \showmessage\m!fixme{5}{\countervalue{\????fx\v!total  }}%
\to \everynotabene

%D Labels

\setupheadtext[\s!en][fixmes=List of Corrections]
\setupheadtext[\s!de][fixmes=Verzeichnis der Korrekturen]
\setupheadtext[\s!fr][fixmes=Liste des Corrections]
\setupheadtext[\s!it][fixmes=Corrigenda]
\setupheadtext[\s!es][fixmes=Lista de Correcciones]
\setupheadtext[\s!da][fixmes=Rettelser]
\setupheadtext[\s!hr][fixmes=Popis korekcija]

\setuplabeltext[\s!en][fixmenote=\fixmelogo~Note: ]
\setuplabeltext[\s!en][fixmewarning=\fixmelogo~Warning: ]
\setuplabeltext[\s!en][fixmeerror=\fixmelogo~Error: ]
\setuplabeltext[\s!en][fixmefatal=\fixmelogo: ]

\setuplabeltext[\s!de][fixmenote=\fixmelogo~Anm.: ]
\setuplabeltext[\s!de][fixmewarning=\fixmelogo~Warnung: ]
\setuplabeltext[\s!de][fixmeerror=\fixmelogo~Fehler: ]
\setuplabeltext[\s!de][fixmefatal=\fixmelogo]

\setuplabeltext[\s!fr][fixmenoteprefix=\fixmelogo~Note: ]
\setuplabeltext[\s!fr][fixmewarningprefix=\fixmelogo~Attention: ]
\setuplabeltext[\s!fr][fixmeerrorprefix=\fixmelogo~Erreur: ]
\setuplabeltext[\s!fr][fixmefatalprefix=\fixmelogo: ]

\setuplabeltext[\s!it][fixmenoteprefix=\fixmelogo~Nota: ]
\setuplabeltext[\s!it][fixmewarningprefix=\fixmelogo~Avviso: ]
\setuplabeltext[\s!it][fixmeerrorprefix=\fixmelogo~Errore: ]
\setuplabeltext[\s!it][fixmefatalprefix=\fixmelogo: ]

\setuplabeltext[\s!es][fixmenoteprefix=\fixmelogo~Nota: ]
\setuplabeltext[\s!es][fixmewarningprefix=\fixmelogo~Aviso: ]
\setuplabeltext[\s!es][fixmeerrorprefix=\fixmelogo~Error: ]
\setuplabeltext[\s!es][fixmefatalprefix=\fixmelogo: ]

\setuplabeltext[\s!da][fixmenoteprefix=\fixmelogo~Note: ]
\setuplabeltext[\s!da][fixmewarningprefix=\fixmelogo~Advarsel: ]
\setuplabeltext[\s!da][fixmeerrorprefix=\fixmelogo~Fejl: ]
\setuplabeltext[\s!da][fixmefatalprefix=\fixmelogo: ]

\setuplabeltext[\s!hr][fixmenoteprefix=\fixmelogo~Poruka: ]
\setuplabeltext[\s!hr][fixmewarningprefix=\fixmelogo~Upozorenje: ]
\setuplabeltext[\s!hr][fixmeerrorprefix=\fixmelogo~Gre\scaron ska: ]
\setuplabeltext[\s!hr][fixmefatalprefix=\fixmelogo: ]

%D Defaults

\setupfixme
  [\c!before=\startquotation,
   \c!after=\stopquotation,
   \c!location=\v!margin,
   \c!version=\v!draft]

\protect \endinput
