\unprotect

\def\c!itemalign{itemalign}

\def\doinitializeitemgrouplevel#1%
  {\copyparameters
     [\??op\currentitemgroup#1][\??oo]
     [\c!width,\c!factor,\c!distance,\c!align,\c!option,
      \c!style,\c!marstyle,\c!symstyle,\c!headstyle,
      \c!color,\c!marcolor,\c!symcolor,\c!headcolor,
      \c!beforehead,\c!afterhead,\c!before,\c!inbetween,\c!after,
      \c!stopper,\c!placestopper,\c!indenting,
      \c!n,\c!inner,\c!symbol,\c!margin,\c!items,
      \c!leftmargin,\c!rightmargin,\c!indentnext,
      \c!command,\c!itemalign,
      \c!start,\c!lefttext,\c!righttext]}

\def\redostartitemgroup[#1][#2]%
  {\setfalse\inlinelistitem % new, no indent (leftskip)
   \setfalse\concatnextitem % new, concat
   \setfalse\txtlistitem
   \ifhmode
     \ifconditional\autoconcatnextitem % new, concat
       \ifdim\lastskip=\itemsignal     % new, concat
         \settrue\concatnextitem       % new, concat
       \fi                             % new, concat
     \fi                               % new, concat
     \ifconditional\textlistitem\else\doifnotinset\v!text{#1}\par\fi % suboptimal
   \fi
   \begingroup
% new where, ok or not / we should integrate random, intro, continue here
\setfalse\reverselistitem
\setfalse\introlistitem
\setfalse\autointrolistitem
\setfalse\beforelistitem
\setfalse\afterlistitem
\setfalse\nowhitelistitem
\setfalse\randomizeitems
%
   \doifinsetelse\v!intro   {#1}{\settrue\introlistitem    }{\setfalse\introlistitem    }%
   \doifinsetelse\v!random  {#1}{\settrue\randomizeitems   }{\setfalse\randomizeitems   }%
   \doifinsetelse\v!continue{#1}{\settrue\continuelistitems}{\setfalse\continuelistitems}%
   % == \doifinsetelse\v!intro{#1}\settrue\setfalse\introlistitem
   \doglobal\increment\noflists
   \let\currentlist\noflists
   \newcounter\noflistelements
   \setfalse\headlistitem
   \setfalse\sublistitem
   \setfalse\symbollistitem
   \let\marsymbol\relax
   \globallet\somdestination\empty
   \let\symsymbol\empty
   \the\itemgroupcommands
\checkcurrentnofitems
   % \getitemparameter\itemlevel\empty
   \let\listitem\empty % ** start value
   \doifelsenothing{#1} % iffirstargument
     {\edef\@@opsymbol{\getitemparameter\itemlevel\c!symbol}%
      \letgvalueempty{\@@globalitemsymbol\itemlevel}%
      \global\letitemparameter\itemlevel\v!continue\empty
    % \setitemmark\@@opsymbol % ** default value
      \dosetupitemgroupvariable[\itemlevel][#2]}
     {\dosetupitemgroupconstant[\itemlevel][#1]%
      \dosetupitemgroupvariable[\itemlevel][#2]%
      \doifinsetelse\v!continue{#1}% \noexpand, else problems in non-etex with chinese
        {\edef\@@opsymbol{\noexpand\getvalue{\@@globalitemsymbol\itemlevel}}%
         \getitemparameter\itemlevel\v!continue}
        {\edef\@@opsymbol{\noexpand\getitemparameter{\itemlevel}{\c!symbol}}%
         \global\setitemparameter\itemlevel\v!continue
           {\dosetupitemgroupconstant[\itemlevel][#1]%
            \dosetupitemgroupvariable[\itemlevel][#2]}}%
      \def\docommand##1% \setitemmark resets \docommand
        {\doifnot{##1}{0}{\setitemmark{##1}}}%
    % \processcommalist[#1,\@@opsymbol]\docommand
      \processcommalist[#1]\docommand}% ** preset sequence or provided sequence
   % moved to here, after settings
   \ifnum\itemlevel=\plusone % NIEUW
     \doadaptleftskip {\getitemparameter1\c!margin}%
     \doadaptleftskip {\getitemparameter1\c!leftmargin}%
     \doadaptrightskip{\getitemparameter1\c!rightmargin}%
   \fi
   \dosetraggedcommand{\getitemparameter\itemlevel\c!align}\raggedcommand
   \doifsomething{\getitemparameter\itemlevel\c!indenting}
     {% is \expanded needed?
      \expanded{\setupindenting[\getitemparameter\itemlevel\c!indenting]}}%
   %
   \setitemlevel{#1}% moved to here
   \ifx\listitem\empty
     \setitemmark\@@opsymbol % ** default value
     \ifx\listitem\empty
       \edef\currentitemsymbol{\itemlevel}% ** fall back
     \fi
   \fi
   \ifconditional\autointrolistitem\ifnum\prevgraf<3
     \settrue\introlistitem
   \fi\fi
   \ifconditional\paragraphlistitem
     \ifnum\itemlevel>\plusone
       \letitemparameter\itemlevel\c!inbetween\empty
     \fi
   \fi
   \ifconditional\packlistitem
     \letitemparameter\itemlevel\c!inbetween\empty
   \fi
   \doifinset\v!columns{#1}%
     {\ifinsidecolumns\else\ifnum\itemcolumndepth=\zerocount
        \globallet\itemcolumndepth\itemlevel
        \itembeforecommand
        \processfirstactioninset
          [#1]
          [  \v!one=>\!!counta1\relax,
             \v!two=>\!!counta2\relax,
           \v!three=>\!!counta3\relax,
            \v!four=>\!!counta4\relax,
            \v!five=>\!!counta5\relax,
         \s!unknown=>\@EA\!!counta\getitemparameter\itemlevel\c!n]%
        \ifinner
	      \dontleavehmode\vbox\bgroup
	        \scratchdimen\hsize
	        \advance\scratchdimen-\dimexpr\getitemparameter\itemlevel\c!width\relax
	        \hsize\scratchdimen
	        \startsimplecolumns
	          [\c!n=\!!counta]
	    \else
          \startcolumns
            [\c!n=\!!counta, % netter \??op\itemlevel\c!n
             \c!height=,
             \c!rule=\v!off,
             \c!balance=\v!yes,
             \c!align=\v!no]%
      \fi\fi\fi}
   \calculatelistwidth\itemlevel{\dimen0}%
   \ifdim\dimen0>\zeropoint\relax
     \ifconditional\inlinelistitem\else
       \advance\leftskip \dimen0\relax
     \fi
   \fi
   \startcollectitems}

\def\stopitemgroup
  {\stopcollectitems
   \ifconditional\textlistitem
     \removeunwantedspaces\space\ignorespaces
   \else
     \par
   \fi
   \ifnum\itemcolumndepth=\zerocount \dolistreference \fi % beware !
   \ifconditional\firstlistitem \else \endgroup \fi % toegevoegd, eerste \som opent groep
   \ifnum\itemcolumndepth=\itemlevel\relax
     \ifinner
       \stopsimplecolumns\egroup
     \else
       \stopcolumns
     \fi
     \doglobal\newcounter\itemcolumndepth
     \itemaftercommand
     \dontrechecknextindentation
   \else
     \ifnum\itemlevel=\plusone
       \doitembreak\allowbreak           % toegevoegd
       \itemaftercommand % \getitemparameter\itemlevel\c!after
       % was: \dochecknextindentation\??oo, is now:
       \dochecknextindentation{\??op\currentitemgroup\itemlevel}%
     \else
       % nieuw, not yet nobreak handling
       \ifcase\autoitemgroupspacing
         \itemaftercommand
       \or
         \itemaftercommand
       \fi
       \dontrechecknextindentation
     \fi
   \fi
   \endgroup
   \doglobal\decrement(\itemlevel,\itemincrement)%
   \egroup
   % new needed in sidefloats (surfaced in volker's proceedings)
   \ifconditional\textlistitem\else\par\fi
   \dorechecknextindentation}

\def\dolistitem % evt aantal items opslaan per niveau, scheelt zoeken
  {\ifconditional\textlistitem
    % begin of item
   \else
     \par
   \fi
%    \ignorespaces
   \increment\noflistelements
   \optimizelistitemsbreak
   \noindent
   \setbox8\hbox
     {\ifconditional\headlistitem
        \ifconditional\symbollistitem
          \symsymbol
        \else
          \doitemattributes\itemlevel\c!headstyle\c!headcolor{\listitem}%
        \fi
      \else
        \ifconditional\symbollistitem
          \symsymbol % no attributes, why?
        \else
          \doitemattributes\itemlevel\c!style\c!color{\listitem}%
        \fi
      \fi}%
   \doifsomething\somdestination
     {\setbox8\hbox{\goto{\box8}[\somdestination]}}%
   \globallet\somdestination\empty
   \dimen2=\getitemparameter\itemlevel\c!width\relax
   % new, prevents loops when symbol is (not yet found) graphic
   \ht8=\strutheight
   \dp8=\strutdepth
   % so that content differs per run (esp mp graphics afterwards)
   \checkforrepeatedlistitem
   \ifdim\dimen2<\zeropoint\relax
     \llap{\ifconditional\sublistitem\llap{+}\fi\box8\hskip\leftmargindistance}%
   \else
     \ifdim\dimen2=\zeropoint\relax
       \calculatelistwidth1{\dimen0}%
     \else
       \calculatelistwidth\itemlevel{\dimen0}%
     \fi
     \ifconditional\textlistitem
       \hbox{\ifconditional\sublistitem+\fi\box8\hskip\interwordspace}\nobreak
     \else\ifconditional\inlinelistitem
       \hbox to \dimen0{\ifconditional\sublistitem\llap{+}\fi\box8\hfill}%
     \else\ifconditional\txtlistitem
       \dodotxtitem
     \else
       % todo: align+marge binnen de hbox
       \llap{\hbox to \dimen0{\ifconditional\sublistitem\llap{+}\fi
         \doifelse{\getitemparameter\itemlevel\c!itemalign}\v!right
           {\box8\hfill}
           {\hfill\box8\hskip\getitemparameter\itemlevel\c!distance}}}%
     \fi\fi\fi
   \fi
   \forceunexpanded % needed for m conversion (\os) / i need to look into this
   \setevalue{\@@currentitemsymbol\itemlevel}%
     {\getvalue{\@@localitemsymbol\itemlevel}}% still problems with \uchar ?
    %{\noexpand\getvalue{\@@localitemsymbol\itemlevel}}% no, spoils subrefs
   \resetunexpanded
   \setfalse\headlistitem
   \setfalse\sublistitem
   \setfalse\symbollistitem
   \EveryPar{\ignorespaces}% needed ?
   \ignorespaces}

\setupitemgroups
  [\c!itemalign=\v!right]

\protect \endinput
