%D \module
%D   [       file=x-set-11,
%D        version=2004.10.31,
%D         remark=setupx.tex: 1998.07.20 and later,
%D          title=\CONTEXT\ Setup Definitions,
%D       subtitle=Macro Definitions,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% we can make this module a bit cleaner using more recent features
% like sorting the xml directly

% \startluacode
%     collectgarbage("stop")
%     function collectgarbage() return 0 end
% \stopluacode

% todo: for fun: pure lua interface, but as this style evolved over 15 years
% it's a waste of time
%
% todo:
%
% \setup{setupinterlinespace}
% \setup{setupinterlinespace:1}
% \setup{setupinterlinespace:2}
%
% cd:include -> filename
% cd:choice
%
% register, interaction

\startmessages  dutch  library: setup
        title:  setup
      formula:  formule
       number:  getal
         list:  lijst
    dimension:  maat
         mark:  markering
    reference:  verwijzing
      command:  commando
         file:  file
         name:  naam
   identifier:  naam
         text:  tekst
      section:  sectie
     singular:  naam enkelvoud
       plural:  naam meervoud
       matrix:  n*m
          see:  zie
     inherits:  erft van
            1:  de karakters < en > zijn globaal actief!
            2:  -- wordt verwerkt
            3:  -- is niet gedefinieerd
            4:  -- wordt nogmaals verwerkt
     optional:  opt
  displaymath:  formule
        index:  ingang
         math:  formule
      nothing:  leeg
         file:  file
     position:  positie
    reference:  verwijzing
       csname:  naam
  destination:  bestemming
      triplet:  triplet
         word:  woord
      content:  tekst
\stopmessages

\startmessages  english  library: setup
        title:  setup
      formula:  formula
       number:  number
         list:  list
    dimension:  dimension
         mark:  mark
    reference:  reference
      command:  command
         file:  file
         name:  name
   identifier:  identifier
         text:  text
      section:  section
     singular:  singular name
       plural:  plural name
       matrix:  n*m
          see:  see
     inherits:  inherits from
            1:  the characters < and > are globally active!
            2:  -- is processed
            3:  -- is undefined
            4:  -- is processed again
     optional:  opt
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  german library: setup
        title:  Setup
      formula:  Formel
       number:  Nummer
         list:  Liste
    dimension:  Dimension
         mark:  Beschriftung
    reference:  Referenz
      command:  Befehl
         file:  Datei
         name:  Name
   identifier:  Name
         text:  Text
      section:  Abschnitt
     singular:  singular
       plural:  plural
       matrix:  n*m
          see:  siehe
     inherits:  inherits from
            1:  Die Zeichen < und > gelten global!
            2:  -- wird verarbeitet
            3:  -- ist undefiniert
            4:  -- ist mehrmals verarbeitet
     optional:  opt
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  czech  library: setup
        title:  setup
      formula:  rovnice
       number:  cislo
         list:  seznam
    dimension:  dimenze
         mark:  znacka
    reference:  reference
      command:  prikaz
         file:  soubor
         name:  jmeno
   identifier:  jmeno
         text:  text
      section:  sekce
     singular:  jmeno v singularu
       plural:  jmeno v pluralu
       matrix:  n*m
          see:  viz
     inherits:  inherits from
            1:  znaky < a > jsou globalne aktivni!
            2:  -- je zpracovano
            3:  -- je nedefinovano
            4:  -- je zpracovano znovu
     optional:  opt
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  italian library: setup
        title:  setup
      formula:  formula
       number:  number
         list:  list
    dimension:  dimension
         mark:  mark
    reference:  reference
      command:  command
         file:  file
         name:  name
   identifier:  name
         text:  text
      section:  section
     singular:  singular name
       plural:  plural name
       matrix:  n*m
          see:  see
     inherits:  inherits from
            1:  the characters < and > are globally active!
            2:  -- is processed
            3:  -- is undefined
            4:  -- is processed again
     optional:  opt
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  romanian library: setup
        title:  setari
      formula:  formula
       number:  numar
         list:  lista
    dimension:  dimensiune
         mark:  marcaj
    reference:  referinta
      command:  comanda
         file:  fisier
         name:  nume
   identifier:  nume
         text:  text
      section:  sectiune
     singular:  nume singular
       plural:  nume pluram
       matrix:  n*m
          see:  vezi
     inherits:  inherits from
            1:  caracterele < si > sunt active global!
            2:  este procesat --
            3:  -- este nedefinit
            4:  -- este procesat din nou
     optional:  opt
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  french  library: setup
        title:  réglage
      formula:  formule
       number:  numéro
         list:  liste
    dimension:  dimension
         mark:  marquage
    reference:  reference
      command:  commande
         file:  fichier
         name:  nom
   identifier:  identificateur
         text:  texte
      section:  section
     singular:  nom singulier
       plural:  nom pluriel
       matrix:  n*m
          see:  vois
     inherits:  herite de
            1:  les caractères < et > sont globalement actifs !
            2:  -- est traité
            3:  -- n'est pas défini
            4:  -- est traité de nouveau
     optional:  opt
  displaymath:  formule
        index:  entrée
         math:  formule
      nothing:  vide
         file:  fichier
     position:  position
    reference:  réference
       csname:  nom
  destination:  destination
      triplet:  triplet
         word:  mot
      content:  texte
\stopmessages

\unprotect

% general

\unexpanded\def\setupnumfont {}
\unexpanded\def\setuptxtfont {}
\unexpanded\def\setupintfont {\WORD}
\unexpanded\def\setupvarfont {\sl}
\unexpanded\def\setupoptfont {\sl}
\unexpanded\def\setupalwcolor{}
\unexpanded\def\setupoptcolor{darkgray}

\def\c!setup!definereserved#1#2%
  {\setvalue{c!setup!:r:#1}{#2}}

\def\c!setup!reserved!#1%
  {\executeifdefined{c!setup!:r:#1}{#1}}

\def\c!setup!internal!#1%
  {\dontleavehmode
   \begingroup
   \setupintfont{#1}%
   \endgroup}

\def\c!setup!text!#1%
  {\dontleavehmode
   \begingroup
   \setupvarfont{#1}%
   \endgroup}

\def\c!setup!command!#1%
  {{\setupvarfont{\texescape...#1}}}

\def\??stp{@@stp}

\defineregister
  [texmacro]
% [texmacros]

\definesorting
  [texcommand]
% [texcommands]

\setupsorting
  [texcommand]
  [\c!command=\showsetupinlist,
   \c!criterium=\@@stpcriterium]

\pushmacro\setuptext

\defineframedtext
  [setuptext]
  [\c!width=\hsize,
   \c!height=\v!fit,
   \c!align=\v!right,
   \c!offset=0.75em]

\popmacro\setuptext

%D Loading:

\let\currentSETUPfullname\s!unknown

\startxmlsetups xml:setups:assemblename
    \doifelse {\xmlatt{#1}{type}} {environment} {
        \let\currentSETUPprefix\e!start
    } {
        \let\currentSETUPprefix\empty
    }
  % \edef\currentSETUPname{\xmlatt{#1}{name}}
    \edef\currentSETUPname{\xmlattribute{#1}{/sequence/string[1]}{value}}%
    \doifelse {\xmlatt{#1}{generated}} {yes} {
        \def\currentSETUPgenerated{*}
    } {
        \let\currentSETUPgenerated\empty
    }
    \doifelsenothing {\xmlatt{#1}{variant}} {
        \let\currentSETUPvariant\empty
    } {
        \def\currentSETUPvariant{:\xmlatt{#1}{variant}}
    }
    \edef\currentSETUPfullname {
        \currentSETUPprefix
        \currentSETUPname
        \currentSETUPvariant
        \currentSETUPgenerated
    }
\stopxmlsetups

\startxmlsetups xml:setups:register
    \xmlsetup{#1}{xml:setups:assemblename}
    % not really needed if we just use setups
    \expanded{\texcommand[stp:x:\currentSETUPfullname]{#1}}
\stopxmlsetups

\startxmlsetups xml:setups:basics
    \xmlinclude{#1}{include}{filename}%
    \xmlsetsetup {#1} {
        sequence|string|variable|assignments|keywords|content|displaymath|index|math|
        nothing|file|position|reference|csname|destination|triplet|word|
        resolve|parameter|constant|inherit|parameter|define
    } {xml:setups:*}
\stopxmlsetups

\xmlregisterdocumentsetup{setups}{xml:setups:basics}

\unexpanded\def\loadsetups{\complexorsimple\loadsetups}

\let\loadedsetups\empty % we load more setups, setups:<name>

\def\simpleloadsetups
  {\doifnotmode{no-setup-main}{\complexloadsetups[cont-en.xml]}}

\def\complexloadsetups[#1]%
  {\doifsomething{#1}
     {\doonlyonce{setups:#1}
        {\doglobal\prependtocommalist{setups:#1}\loadedsetups % last overloads first
         \xmlloadonly{setups:#1}{#1}{setups}%
         \xmlfilter{setups:#1}{/interface/command/command(xml:setups:register)}}}} % qualified path saves > 50% runtime

\newif\ifshortsetup

\unexpanded\def\setup     {\shortsetupfalse\doshowsetup}
\unexpanded\def\showsetup {\shortsetupfalse\doshowsetup}
\unexpanded\def\shortsetup{\shortsetuptrue \doshowsetup}
\unexpanded\def\setupsetup{\dodoubleargument\getparameters[\??stp]}

%unexpanded\def\showsetupinlist#1#2#3{\shortsetupfalse\showsetupindeed{#3}\par}
\unexpanded\def\showsetupinlist#1#2#3{\shortsetupfalse\xmlsetup{#3}{xml:setups:typeset}\par}

% todo: only references in lists

\def\doshowsetup
  {\dosingleempty\dodoshowsetup}

\def\dodoshowsetup[#1]%
  {\iffirstargument
     \dododoshowsetup{#1}%
   \else
     \expandafter\dododoshowsetup
   \fi}

\def\dododoshowsetup#1% this will trigger 'used'
  {\registersort[texcommand][stp:x:#1]%
   \showsetupindeed{#1}}

% \def\showsetupindeed#1%
%   {\xmlfilterlist{\loadedsetups}{interface/command[@name='#1']/command(xml:setups:typeset)}}

% \def\showsetupindeed#1%
%   {\xmlfilterlist{\loadedsetups}{/interface/command['#1' == (@type=='environment' and 'start' or '') .. @name]/command(xml:setups:typeset)}}

% \setelementnature[setup][display]
% \setelementnature[setup][mixed]

\def\showsetupindeed#1%
  {\startelement[setup][name=#1]%
     \startelement[noexport][comment={setup definition #1}]
       \xmlfilterlist{\loadedsetups}{/interface/command['#1' == (@type=='environment' and '\e!start' or '') .. @name]/command(xml:setups:typeset)}%
     \stopelement
   \stopelement}

\unexpanded\def\placesetup    {\placelistofsorts[texcommand][\c!criterium=\v!used]}
\unexpanded\def\placeallsetups{\placelistofsorts[texcommand][\c!criterium=\v!all ]}

\let\placeeverysetup\placeallsetups

%D Typesetting:

\setupxml
  [%\c!method=mkiv,       % mixed mode
   \c!default=\v!hidden, % ignore elements that are not defined
   \c!compress=\v!yes,   % strip comment
   \c!entities=\v!yes]   % replace entities

\newcounter\currentSETUPargument
\newcounter\maximumSETUPargument

\def\currentSETUPwidth{0pt}

\startxmlsetups xml:setups:typeset
    \getvalue{\e!start setuptext}
        \tttf
        \nohyphens
        \veryraggedright
        \doglobal\newcounter\currentSETUPargument
        \xdef\maximumSETUPargument{\xmlcount{#1}{/arguments/*}}
        \edef\currentSETUPhash{\xmlatt{#1}{hash}}
        \bgroup
            \enablemode[setups-pass-one]%
            \doif {\xmlatt{#1}{generated}} {yes} {
                \ttsl
            }
            \letterbackslash
            \doif {\xmlatt{#1}{type}} {environment} {
                \e!start
            }
            \xmlfilter{#1}{/sequence/first()}
            \ignorespaces
        \egroup
        \ifshortsetup
            % nothing
        \else
            \xmldoif{#1}{/arguments} {
                \bgroup
                    \enablemode[setups-pass-one]
                    \doglobal\newcounter\currentSETUPargument
                    \ignorespaces
                    \xmlfilter{#1}{/arguments/text()}
                \egroup
            }
            \doif {\xmlatt{#1}{type}} {environment} {
                \bgroup
                    \enablemode[setups-pass-one]%
                    \hskip.5em\unknown\hskip.5em
                    \doif {\xmlatt{#1}{generated}} {yes} {
                        \ttsl
                    }
                    \tex{\e!stop}
                    \xmlfilter{#1}{/sequence/first()}
                    \ignorespaces
                \egroup
            }
            \endgraf
            \xmldoif{#1}{/arguments} {
                \bgroup
                    \enablemode[setups-pass-two]
                    \doglobal\newcounter\currentSETUPargument
                   %\blank[\v!line] % packed mode (we could do \startunpacked ...)
                    \godown[.75\lineheight]
                    \switchtobodyfont[\v!small]
                    \ignorespaces\xmlfilter{#1}{/arguments/text()}\endgraf
                \egroup
            }
        \fi
    \getvalue{\e!stop setuptext}
\stopxmlsetups

\setupsetup
  [\c!before=,
   \c!after=,
   \c!command=\setup,
   \c!criterium=\v!used]

\startxmlsetups xml:setups:resolve
    \ignorespaces
    \xmlfilterlist{\loadedsetups}{/interface/define[@name='\xmlatt{#1}{name}']/first()}
\stopxmlsetups

%D This is the first pass; here we generate the top line.

\startxmlsetups xml:setups:define
    \ignorespaces\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:setups:sequence
    \ignorespaces\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:setups:string
    \xmlatt{#1}{value}\ignorespaces
\stopxmlsetups

\startxmlsetups xml:setups:content     \showSETUPcomponent{#1}{content}    {content}     \stopxmlsetups
\startxmlsetups xml:setups:displaymath \showSETUPcomponent{#1}{displaymath}{display math}\stopxmlsetups
\startxmlsetups xml:setups:index       \showSETUPcomponent{#1}{index}      {index}       \stopxmlsetups
\startxmlsetups xml:setups:math        \showSETUPcomponent{#1}{math}       {math}        \stopxmlsetups
\startxmlsetups xml:setups:nothing     \showSETUPcomponent{#1}{nothing}    {nothing}     \stopxmlsetups
\startxmlsetups xml:setups:file        \showSETUPcomponent{#1}{file}       {file name}   \stopxmlsetups
\startxmlsetups xml:setups:position    \showSETUPcomponent{#1}{position}   {position}    \stopxmlsetups
\startxmlsetups xml:setups:reference   \showSETUPcomponent{#1}{reference}  {reference}   \stopxmlsetups
\startxmlsetups xml:setups:csname      \showSETUPcomponent{#1}{csname}     {csname}      \stopxmlsetups
\startxmlsetups xml:setups:destination \showSETUPcomponent{#1}{destination}{destination} \stopxmlsetups
\startxmlsetups xml:setups:triplet     \showSETUPcomponent{#1}{triplet}    {triplet}     \stopxmlsetups
\startxmlsetups xml:setups:word        \showSETUPcomponent{#1}{word}       {word}        \stopxmlsetups

\def\showSETUPcomponent#1#2#3%
  {\doifelsemode{setups-pass-one}
     {\getvalue{showSETUP#2}{#1}}
     {\simpleSETUPargument{#3}}}

%D This is the second pass; here we generate the table.

\unexpanded\def\startfirstSETUPcolumn#1%
  {\bgroup
   \advance\leftskip 2em
   \noindent\llap{\hbox to 2em{#1\hss}}}

\unexpanded\def\stopfirstSETUPcolumn
  {\endgraf
   \egroup}

\unexpanded\def\startsecondSETUPcolumn#1#2%
  {\bgroup
   \advance\hangindent\dimexpr\currentSETUPwidth+2.5em\relax
   \noindent \hbox to \hangindent{#1\hss\hbox to 2.5em{\hss#2\hss}}}

\unexpanded\def\stopsecondSETUPcolumn
  {\endgraf
   \egroup}

\def\secondSETUPcolumn#1#2%
  {\startsecondSETUPcolumn{#1}{#2}\stopsecondSETUPcolumn}

\def\previousSETUPargument{\currentSETUPargument}

\startxmlsetups xml:setups:parameter:measure
    \setbox0=\hbox{\c!setup!reserved!{\xmlatt{#1}{name}}}
    \ifdim\wd0>\currentSETUPwidth\xdef\currentSETUPwidth{\the\wd0}\fi
\stopxmlsetups

\startxmlsetups xml:setups:assignments
    \doifelsemode{setups-pass-one} {
        \showSETUPassignment{#1}
    } {
        \xdef\currentSETUPwidth{0pt}%
        \bgroup
            \xmlfilter{#1}{/parameter/command(xml:setups:parameter:measure)}
        \egroup
        \startfirstSETUPcolumn{\showSETUPnumber}%
            \ignorespaces
            \xmldoifelse{#1}{/(parameter|inherit)}{
                \xmlflush{#1}
            } {
             ...
            }
            \let\previousSETUPargument\currentSETUPargument
        \stopfirstSETUPcolumn
        \blank[\v!halfline]
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:keywords
    \doifelsemode{setups-pass-one} {
        \showSETUPkeyword{#1}
    } {
        \startfirstSETUPcolumn{\showSETUPnumber}%
            \ignorespaces
            \xmlflush{#1}
            \let\previousSETUPargument\currentSETUPargument
        \stopfirstSETUPcolumn
        \blank[\v!halfline]
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:parameter
    \startsecondSETUPcolumn{\c!setup!reserved!{\xmlatt{#1}{name}}}{=}
        \ignorespaces
        \xmlflush{#1}
        \doifmode{interface:setup:defaults} {
            \ifx\currentSETUPhash\empty \else
                \begingroup
                    % todo, make a one level expansion of parameter
                    \let\emwidth \relax
                    \let\exheight\relax
                    \edef\currentSETUPvalue{\csname named\currentSETUPhash parameter\endcsname\empty{\xmlatt{#1}{name}}}
                    \ifx\currentSETUPvalue\empty \else
                        =\space
                        \detokenize\expandafter{\currentSETUPvalue}
                    \fi
                \endgroup
            \fi
        }
    \stopsecondSETUPcolumn
    \ignorespaces
\stopxmlsetups

\startxmlsetups xml:setups:constant
    \doifelsemode {setups-pass-one} {
    } {
        \doif {\xmlatt{#1}{default}} {yes} {
            \underbar % next needs to be {braced}
        }
        {\c!setup!reserved!{\xmlatt{#1}{type}}}
        \space
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:variable
    \doifelsemode {setups-pass-one} {
        \expanded{\setupintfont{\xmlatt{#1}{value}}}\ignorespaces
    } {
        \c!setup!reserved!{\xmlatt{#1}{value}}
        \space
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:inherit
   \secondSETUPcolumn {
        \c!setup!text!{\getmessage{setup}{inherits}}
        \enspace
        \letterbackslash
        \xmlatt{#1}{name}
    } {}
    \ignorespaces
\stopxmlsetups

\def\simpleSETUPargument#1%
  {\startfirstSETUPcolumn{\showSETUPnumber}%
      \c!setup!internal!{#1}%
   \stopfirstSETUPcolumn
   \blank[\v!halfline]
   \ignorespaces}

\c!setup!definereserved {cd:command}        {\c!setup!internal!{\getmessage{setup}{command}}}
\c!setup!definereserved {cd:dimension}      {\c!setup!internal!{\getmessage{setup}{dimension}}}
\c!setup!definereserved {cd:file}           {\c!setup!internal!{\getmessage{setup}{file}}}
\c!setup!definereserved {cd:name}           {\c!setup!internal!{\getmessage{setup}{identifier}}}
\c!setup!definereserved {cd:character}      {\c!setup!internal!{\getmessage{setup}{character}}}
\c!setup!definereserved {cd:mark}           {\c!setup!internal!{\getmessage{setup}{mark}}}
\c!setup!definereserved {cd:number}         {\c!setup!internal!{\getmessage{setup}{number}}}
\c!setup!definereserved {cd:reference}      {\c!setup!internal!{\getmessage{setup}{reference}}}
\c!setup!definereserved {cd:plural}         {\c!setup!internal!{\getmessage{setup}{plural}}}
\c!setup!definereserved {cd:singular}       {\c!setup!internal!{\getmessage{setup}{singular}}}
\c!setup!definereserved {cd:text}           {\c!setup!internal!{\getmessage{setup}{text}}}
\c!setup!definereserved {cd:formula}        {\c!setup!internal!{\getmessage{setup}{formula}}}
\c!setup!definereserved {cd:file}           {\c!setup!internal!{\getmessage{setup}{file}}}
\c!setup!definereserved {cd:matrix}         {\c!setup!internal!{\getmessage{setup}{matrix}}}
\c!setup!definereserved {cd:list}           {\c!setup!internal!{\getmessage{setup}{list}}}
\c!setup!definereserved {cd:section}        {\c!setup!internal!{\getmessage{setup}{section}}}

\c!setup!definereserved {cd:noargument}     {\c!setup!command! {}}
\c!setup!definereserved {cd:oneargument}    {\c!setup!command! {\#1}}
\c!setup!definereserved {cd:twoarguments}   {\c!setup!command! {\#1\#2}}
\c!setup!definereserved {cd:threearguments} {\c!setup!command! {\#1\#2\#3}}

%D Auxiliary.

\unexpanded\def\showSETUP#1#2#3%
  {\bgroup
   \doglobal\increment\currentSETUPargument
   \setbox0=\hbox
     {\doifelse{\xmlatt{#1}{list}}{yes}{#3}{#2}}%
   \setbox2=\hbox to \wd0
     {\hss
      \raise1ex\hbox
        {\tx\ifcase\maximumSETUPargument\relax
           \or*\else\currentSETUPargument
         \fi}%
      \hss}%
   \setbox4=\hbox to \wd0
     {\hss
      \lower2ex\hbox
        \bgroup
          \txx\doif{\xmlatt{#1}{optional}}{yes}{\c!setup!internal!{\getmessage{setup}{optional}}}%
        \egroup
      \hss}%
   \ht2\ht\strutbox
   \dp4\dp\strutbox
   \hskip.5em\hsmash{\box0}\hsmash{\box4}\box2%
   \egroup
   \ignorespaces}

\def\showSETUPnumber
  {\doglobal\increment\currentSETUPargument
   \hbox to 2em
     {\ifcase\maximumSETUPargument\relax
        \or*\else\currentSETUPargument
      \fi
      \hss}}

\def\showSETUPassignment #1{\showSETUP{#1}{[.\lower.5ex\hbox{=}.]}              {[..,.\lower.5ex\hbox{=}.,..]}}
\def\showSETUPkeyword    #1{\showSETUP{#1}{[...]}                               {[...,...]}}
\def\showSETUPargument   #1{\showSETUP{#1}{\leftargument..\rightargument}       {\leftargument..,...,..\rightargument}}
\def\showSETUPdisplaymath#1{\showSETUP{#1}{\$\$...\$\$}                         {\$\$...\$\$}}
\def\showSETUPindex      #1{\showSETUP{#1}{\leftargument...\rightargument}      {\leftargument..+...+..\rightargument}}
\def\showSETUPmath       #1{\showSETUP{#1}{\$...\$}                             {\$...\$}}
\def\showSETUPnothing    #1{\showSETUP{#1}{...}                                 {}}
\def\showSETUPfile       #1{\showSETUP{#1}{~...~}                               {}}
\def\showSETUPposition   #1{\showSETUP{#1}{(...)}                               {(...,...)}}
\def\showSETUPreference  #1{\showSETUP{#1}{[...]}                               {[...,...]}}
\def\showSETUPcsname     #1{\showSETUP{#1}{{\c!setup!command!{}}}               {}}
\def\showSETUPdestination#1{\showSETUP{#1}{[\leftargument..[ref]\rightargument]}{[..,\leftargument..[ref,..]\rightargument,..]}}
\def\showSETUPtriplet    #1{\showSETUP{#1}{[x:y:z=]}                            {[x:y:z=,..]}}
\def\showSETUPword       #1{\showSETUP{#1}{\leftargument...\rightargument}      {\leftargument.. ... ..\rightargument}}
\def\showSETUPcontent    #1{\showSETUP{#1}{\leftargument...\rightargument}      {\leftargument.. ... ..\rightargument}}

% A prelude to a rewrite and some more:

\definetype[parametercommand][type]
\definetype[parameterkey]    [type]
\definetype[parametervalue]  [type][space=on]

\setuptype[parametercommand] [color=darkmagenta]
\setuptype[parametervalue]   [color=darkyellow]

\startxmlsetups xml:setups:parameters:value
    \edef\currentsetupparameterkey  {\xmlatt{#1}{name}}
    \edef\currentsetupparametervalue{\csname named\currentsetupparametercategory parameter\endcsname\currentsetupparameterinstance\currentsetupparameterkey}
    \ifx\currentsetupparameterinstance\empty
        \expanded {
            \NC \parameterkey  {\currentsetupparameterkey}
            \NC \parametervalue{\detokenize\expandafter{\currentsetupparametervalue}}
            \NC \NR
        }
    \else\ifx\currentsetupparametervalue\empty
    \else
        \edef\currentsetupparameterdefault{\csname named\currentsetupparametercategory parameter\endcsname\empty\currentsetupparameterkey}
        \ifx\currentsetupparametervalue\currentsetupparameterdefault
            % skip
        \else
            \expanded {
                \NC \parameterkey  {\currentsetupparameterkey}
                \NC \parametervalue{\detokenize\expandafter{\currentsetupparametervalue}}
                \NC \NR
            }
        \fi
    \fi\fi
\stopxmlsetups

\startxmlsetups xml:setups:parameters:values
    \blank[big]
    \expanded {
        \parametercommand {
            \currentsetupparametercommand
            \space:\space
            \ifx\currentsetupparameterinstance\empty
                defaults
            \else
                \currentsetupparameterinstance
            \fi
        }
    }
    \blank[big,samepage]
    \starttabulate[|l|p|]
        \xmlall
            {#1}
            {/interface/command[@name=='\currentsetupparametercommand']/arguments/assignments/parameter/command(xml:setups:parameters:value)}
        \ifnum\noftabulaterows = \zerocount
            \NC \parameterkey{no specific settings} \NC \NC \NR
        \fi
    \stoptabulate
\stopxmlsetups

\starttexdefinition showrootvalues [#1]
    \edef\currentsetupparametercategory{#1}
    \edef\currentsetupparametercommand{setup#1}
    \let\currentsetupparameterinstance\empty
    \xmlsetup{\loadedsetups}{xml:setups:parameters:values}
\stoptexdefinition

\starttexdefinition showinstancevalues [#1]#2[#3]
    \edef\currentsetupparametercategory{#1}
    \edef\currentsetupparametercommand{setup#1}
    \edef\currentsetupparameterinstance{#3}
    \xmlsetup{\loadedsetups}{xml:setups:parameters:values}
\stoptexdefinition

\protect \endinput
