core-itm.tex / last modification: 2008-10-16 22:37
%D \module
%D   [       file=core-itm, % updated
%D        version=1997.03.31,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=itemgroups,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% new: text + lefttext=(,righttext=)
%      start=

\writestatus{loading}{Context Core Macros / Itemgroups}

\startmessages  dutch  library: layouts
      9: momenteel maximaal -- niveaus in opsommingen
\stopmessages

\startmessages  english  library: layouts
      9: currently no more than -- levels in itemizations
\stopmessages

\startmessages  german  library: layouts
      9: z.Z. nicht mehr als -- Ebenen in Aufzaehlungen
\stopmessages

\startmessages  czech  library: layouts
      9: aktualne ne vice nez -- urovne/urovni vyctu
\stopmessages

\startmessages  italian  library: layouts
      9: attualmente non più di -- livelli di elencazione
\stopmessages

\startmessages  norwegian  library: layouts
      9: for øyeblikket maksimalt -- nivåer i opplisting
\stopmessages

\startmessages  romanian  library: layouts
      9: acum nu se supota mai mult de -- nivele de adancime la iteratii
\stopmessages

\startmessages  french  library: layouts
      9: pas plus de -- niveaux pour l'instant dans les élémentarisations
\stopmessages

\unprotect

% - instellingen in macro
% - [0] voor start op 0
% - start=2

\newconditional\sublistitem       \setfalse\sublistitem
\newconditional\symbollistitem    \setfalse\symbollistitem
\newconditional\headlistitem      \setfalse\headlistitem
\newconditional\introlistitem     \setfalse\introlistitem
\newconditional\randomizeitems    \setfalse\randomizeitems
\newconditional\autointrolistitem \setfalse\autointrolistitem
\newconditional\optimizelistitem  \settrue \optimizelistitem
\newconditional\packlistitem      \setfalse\packlistitem
\newconditional\paragraphlistitem \setfalse\paragraphlistitem
\newconditional\textlistitem      \setfalse\textlistitem
\newconditional\firstlistitem     \setfalse\firstlistitem
\newconditional\beforelistitem    \setfalse\beforelistitem
\newconditional\afterlistitem     \setfalse\afterlistitem
\newconditional\nowhitelistitem   \setfalse\nowhitelistitem
\newconditional\joinedlistitem    \setfalse\joinedwhitelistitem
\newconditional\reverselistitem   \setfalse\reverselistitem
\newconditional\continuelistitems \setfalse\continuelistitems
\newconditional\fittinglistitems  \setfalse\fittinglistitems

\newcount\noflists
\newcount\currentnoflists
\newcount\itemcolumndepth
\newcount\itemdepth
\newcount\maxitemdepth

\definetwopasslist\s!list

\let\currentitemlevel  \!!zerocount
\let\currentitemgroup  \empty
\let\currentnofitems   \!!zerocount
\let\currentmaxnofitems\!!zerocount
\let\currentminnofitems\!!zerocount
\let\currentitemoffset \!!zerocount
\def\currentitemnumber{\countervalue{\@@itemcounter\currentitemlevel}}

% tricky ... we cannot use trialtypesetting here because there can be
% multiple itemizes in e.g. a table, so we need something more advanced
% where counters etc are reset to pre-outertrial values

\def\dolistreference
  {\ifconditional\continuelistitems
     \savetaggedtwopassdata\s!list{\number\currentnoflists}{\number\currentnoflists}%
        {\currentitemlevel:\noflistelements:c:\getitemparameter\currentitemlevel\c!maxwidth}%
   \else
     \savetaggedtwopassdata\s!list{\number\currentnoflists}{\number\currentnoflists}%
        {\currentitemlevel:\noflistelements:n:\getitemparameter\currentitemlevel\c!maxwidth}%
   \fi}

\def\splititemtwopassdata#1%
   {\expanded{\findtwopassdata{\s!list}{\number#1}}%
    \expandafter\dosplititemtwopassdata\twopassdata:0:0:0:0:0\relax}

\def\dosplititemtwopassdata#1:#2:#3:#4:#5\relax
  {\edef\itemdatal{#1}\edef\itemdatan{#2}\edef\itemdatat{#3}\edef\itemdataw{#4}}

\def\checkcurrentnofitems
  {\splititemtwopassdata\currentnoflists
   \iftwopassdatafound
     \ifcase\itemdatan\relax % \scratchcounter
       \let\currentnofitems   \!!zerocount
       \let\currentminnofitems\!!plusone
       \let\currentmaxnofitems\!!zerocount
     \else
       \scratchcounter\itemdatan\relax
       \edef\currentnofitems{\the\scratchcounter}%
       \let\currentitemtag\itemdatat
       \doloop
         {\splititemtwopassdata{\numexpr\currentnoflists+\recurselevel\relax}%
          \iftwopassdatafound
            \ifnum\itemdatal=\currentitemlevel\relax
              \doifelse{c}\itemdatat
                {\advance\scratchcounter\itemdatan\relax}
                {\exitloop}%
            \fi
          \else
            \exitloop
          \fi}%
       \edef\currentmaxnofitems{\the\scratchcounter}%
       \scratchcounter\zerocount
       \doif{c}\currentitemtag
         {\doloop
            {\splititemtwopassdata{\numexpr\currentnoflists-\recurselevel\relax}%
             \iftwopassdatafound
               \ifnum\itemdatal=\currentitemlevel\relax
                 \doifelse{c}\itemdatat
                   {\advance\scratchcounter\itemdatan\relax}
                   {\advance\scratchcounter\itemdatan\exitloop}%
               \fi
             \else
               \exitloop
             \fi}}%
       \advance\scratchcounter\plusone
       \edef\currentminnofitems{\the\scratchcounter}%
     % [[\currentnofitems,\currentminnofitems,\currentmaxnofitems]]
     \fi
   \else % new, when no tuo yet
     \let\currentnofitems   \!!zerocount
     \let\currentminnofitems\!!plusone
     \let\currentmaxnofitems\!!zerocount
   \fi} % [[\currentnofitems,\currentminnofitems,\currentmaxnofitems]]

% \startitemize[n,packed]
% \item test \item test \item test
% \stopitemize
%
% \startitemize[n,packed,reverse]
% \item test \item test \item test
% \stopitemize
%
% \startitemize[n,packed,reverse] \item test \item test \stopitemize
% \startitemize[continue]
% \item test \startitemize[n,packed] \item test \item test \stopitemize
% \item test
% \item test
% \stopitemize
% \startitemize[continue] \item test \stopitemize
%
% \startitemize[n,packed] \item test \item test \stopitemize
% \startitemize[continue] \item test            \stopitemize
% \startitemize[continue] \item test            \stopitemize

\def\unknownitemreference{0} \let\itemreferences\unknownitemreference

% #1=level #2=parameter

\def\getitemparameter #1#2{\csname\??op\currentitemgroup#1#2\endcsname}
\def\setitemparameter #1#2{\@EA\def\csname\??op\currentitemgroup#1#2\endcsname} % #3 -> {#3}
\def\letitemparameter #1#2{\@EA\let\csname\??op\currentitemgroup#1#2\endcsname}

% test this: saves hash entries and is also faster
%
% \let\doinitializeitemgrouplevel\gobbleoneargument % todo ! ! !

\def\getitemparameter#1#2%
  {\executeifdefined{\??op\currentitemgroup#1#2}%
  {\executeifdefined{\??op\currentitemgroup  #2}%
  {\executeifdefined{\??oo                   #2}%
  {}}}}

\def\doitemattributes   #1{\doattributes{\??op\currentitemgroup#1}}

\def\@@globalitemsymbol #1{\??op\currentitemgroup\c!symbol\s!global#1}
\def\@@localitemsymbol  #1{\??op\currentitemgroup\c!symbol\s!local #1}
\def\@@currentitemsymbol#1{\??op\currentitemgroup\c!symbol         #1}

\def\@@itemcounter{\s!itemcount\currentitemgroup}

% \def\doitembreak#1{\ifconditional\textlistitem\else\dosomebreak#1\fi}
%
% s-pre-61 / pre-dis, test extensively, 2004/5

\def\doitembreak#1{\ifconditional\optimizelistitem\ifconditional\textlistitem\else\dosomebreak#1\fi\fi}

\def\initializeitemgroupslevel#1%
  {\ifundefined{\@@globalitemsymbol{#1}}%
     \edef\itemreferences{\itemreferences,#1}%
     \makecounter{\@@itemcounter#1}%
     \setevalue{\@@globalitemsymbol{#1}}{#1}%
   \fi}

\def\initializeitemgrouplevel#1% safeguard
  {\ifundefined{\??op\currentitemgroup#1\c!width}%
     \doinitializeitemgrouplevel{#1}%
   \fi}

\def\doinitializeitemgrouplevel#1%
  {\copyparameters
     [\??op\currentitemgroup#1][\??oo]
     [\c!width,\c!factor,\c!distance,\c!align,\c!symalign,\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!start,\c!lefttext,\c!righttext]}

\def\setupitemgroups
  {\dosingleargument\dosetupitemgroups}

\def\dosetupitemgroups[#1]% still undocumented
  {\getparameters[\??oo][\c!levels=4,#1]%
   % will change (remove)
   \ifnum\@@oolevels>\maxitemdepth
     \maxitemdepth\@@oolevels\relax
     \dorecurse\maxitemdepth{\initializeitemgroupslevel\recurselevel}%
   \fi}

\def\doitemreference#1,#2,#3\\%
  {\ifnum\currentitemlevel>#1\relax
     \ifnum#1>\zerocount \tempsymbol \fi
     \getvalue{\@@currentitemsymbol{#2}}%
     \doitemreference#2,#3\\%
   \fi}

\def\itemreference
  {\expandafter\doitemreference\itemreferences,,\\}

\def\packitems
  {\ifcase\currentitemlevel \else \settrue\packlistitem \fi}

\def\dosetupitemgroupvariable[#1]% [#2]%  niveau instellingen
  {\doifelsenothing{#1}
     {\getparameters[\??op\currentitemgroup\currentitemlevel]}% [#2]}%
     {\getparameters[\??op\currentitemgroup#1]}}%        [#2]}}

\newconditional\inlinelistitem \setfalse\inlinelistitem

\def\dododosetupitemgroupconstant[#1][#2#3#4]% * permits [2]
  {\global\setitemparameter\currentitemlevel\c!maxwidth{0}%
   \processaction
     [#2#3#4]
     [   \v!packed*=>\packitems,
          \v!intro*=>\settrue\introlistitem, % here? not set to false
% no:    \v!random*=>\settrue\randomizeitems,% here? not set to false
      \v!autointro*=>\settrue\autointrolistitem,
          \v!broad*=>\setitemparameter{#1}\c!factor{1},
     #2#3*\v!broad*=>\setitemparameter{#1}\c!factor{#2#3},
       #2*\v!broad*=>\setitemparameter{#1}\c!factor{#2},
           \v!text*=>\settrue\textlistitem
                     \settrue\inlinelistitem
                     \settrue\joinedlistitem % \dosetuppackeditemgroup{#1}%
                     \packitems,
        \v!columns*=>\packitems,
         \v!before*=>\settrue\beforelistitem,
          \v!after*=>\settrue\afterlistitem,
        \v!nowhite*=>\settrue\nowhitelistitem, % \def\packeditemspacing{\nowhitespace},
         \v!margin*=>\setitemparameter{#1}\c!width{-2em}, % signal
       \v!inmargin*=>\setitemparameter{#1}\c!width{-2em}, % signal
       \v!atmargin*=>\doifnot{#1}{1}{\setitemparameter{#1}\c!width{0em}}, % signal
         \v!intext*=>\settrue\inlinelistitem, % new
          \v!loose*=>\setfalse\optimizelistitem,
            \v!fit*=>\settrue\fittinglistitems,
          \v!nofit*=>\setfalse\fittinglistitems,
      \v!paragraph*=>\settrue\paragraphlistitem
                     \packitems,
       \v!joinedup*=>\settrue\joinedlistitem % \dosetuppackeditemgroup{#1}%
                     \packitems,
        \v!serried*=>\setitemparameter{#1}\c!factor{-1},
   #2#3*\v!serried*=>\setitemparameter{#1}\c!factor{-#2#3},
     #2*\v!serried*=>\setitemparameter{#1}\c!factor{-#2},
        \v!stopper*=>\setitemparameter{#1}\c!placestopper{\v!yes}, % keep {}
       \v!unpacked*=>\setfalse\packlistitem,
         \v!repeat*=>\settrue\repeatlistitem, % new
        \v!reverse*=>\settrue\reverselistitem,
       \v!standard*=>\dosetupstandarditemgroup{#1}]}

\def\dosetupstandarditemgroup#1%
  {\getparameters
     [\??op\currentitemgroup#1]
     [\c!width=1.5em,
      \c!factor=0,
      \c!distance=.5em,
      \c!beforehead=,
      \c!afterhead=\blank,
      \c!before=\blank,
      \c!inbetween=\blank,
      \c!after=\blank,
      \c!inner=]}

% \def\packeditemspacing{\empty}

% \setupwhitespace[big]
% \starttext
%     test \startitemize[joinedup]                \item test \item test \stopitemize test \par
%     test \startitemize[joinedup,nowhite]        \item test \item test \stopitemize test \par
%     test \startitemize[joinedup,nowhite,before] \item test \item test \stopitemize test \par
%     test \startitemize[joinedup,nowhite,after]  \item test \item test \stopitemize test \par
% \stoptext

\def\itembeforecommand
  {\ifconditional\nowhitelistitem
     \ifconditional\beforelistitem
       \ifcase\currentitemlevel\or\getitemparameter\currentitemlevel\c!before\fi
     \else
        \nowhitespace
     \fi
   \else\ifconditional\joinedlistitem
     % \empty
   \else
     \getitemparameter\currentitemlevel\c!before
   \fi\fi}

\def\itemaftercommand
  {\ifconditional\nowhitelistitem
     \ifconditional\afterlistitem
       \ifcase\currentitemlevel\or\getitemparameter\currentitemlevel\c!after\fi
     \else
        \nowhitespace
     \fi
   \else\ifconditional\joinedlistitem
     % \empty
   \else
     \getitemparameter\currentitemlevel\c!after
   \fi\fi}

\def\iteminbetweencommand
  {\ifconditional\nowhitelistitem
     \nowhitespace
   \else\ifconditional\joinedlistitem
     % \empty
   \else
     \getitemparameter\currentitemlevel\c!inbetween
   \fi\fi}

\def\itembeforeheadcommand
  {\ifconditional\nowhitelistitem
     \nowhitespace
   \else\ifconditional\joinedlistitem
     % \empty
   \else
     \getitemparameter\currentitemlevel\c!beforehead
   \fi\fi}

\def\itemafterheadcommand
  {\ifconditional\nowhitelistitem
     \nowhitespace
   \else\ifconditional\joinedlistitem
     % \empty
   \else
     \getitemparameter\currentitemlevel\c!afterhead
   \fi\fi}

% \def\dosetuppackeditemgroup#1%
%   {\setitemparameter{#1}\c!beforehead{\packeditemspacing}%
%    \setitemparameter{#1}\c!afterhead {\packeditemspacing}%
%    \setitemparameter{#1}\c!before    {\packeditemspacing}%
%    \setitemparameter{#1}\c!after     {\packeditemspacing}%
%    \setitemparameter{#1}\c!inbetween {\packeditemspacing}}

\def\dosetupitemgroupconstant[#1][#2]%
  {\def\dodosetupitemgroupconstant##1% catches empty in [a,b,] handy for xml
     {\doifsomething{##1}{\dododosetupitemgroupconstant[#1][##1*]}}%
   \processcommacommand[#2]\dodosetupitemgroupconstant} % expansion of #2 is handy for xml

\def\dododododosetupitemgroup[#1][#2]%
  {\doifassignmentelse{#2}%
     {\dosetupitemgroupvariable[#1][#2]}%
     {\setitemparameter{#1}\c!option{#2}}}%

\def\dodododosetupitemgroup[#1][#2]%
  {\ConvertToConstant\doifnot{#2}{}
     {\doifelse{#1}\v!each
        {\dorecurse\maxitemdepth{\ExpandFirstAfter\dododododosetupitemgroup[\recurselevel][#2]}}
        {\ExpandFirstAfter\dododododosetupitemgroup[#1][#2]}}}

\def\dododosetupitemgroup[#1][#2]%
  {\ConvertToConstant\doifelse{#2}{}
     {\ifcase\currentitemlevel\relax
        \dodododosetupitemgroup[\v!each][#1]%
      \else
        \dodododosetupitemgroup[\currentitemlevel][#1]%
      \fi}
     {\doifelsenothing{#1}
        {\dodododosetupitemgroup[\currentitemlevel][#2]}
        {\dodododosetupitemgroup[#1][#2]}}}

\def\dodosetupitemgroup[#1][#2][#3][#4]%
  {\pushmacro\currentitemgroup
   \def\currentitemgroup{#1}%
   \dododosetupitemgroup[#2][#3]%
   \ConvertToConstant\doifnot{#4}{}  % anders wordt #2 overruled
     {\dododosetupitemgroup[#2][#4]}%
   \popmacro\currentitemgroup}

\def\dosetupitemgroup[#1][#2][#3][#4]%
  {\def\docommand##1{\dodosetupitemgroup[##1][#2][#3][#4]}%
   \processcommalist[#1]\docommand}

\def\setupitemgroup
  {\doquadrupleempty\dosetupitemgroup}

\def\doadvanceitem
  {\ifconditional\sublistitem\else\ifconditional\symbollistitem\else
     \pluscounter{\@@itemcounter\currentitemlevel}%
   \fi\fi}

\def\setitemlevel#1%
  {\ifnum\currentitemlevel>\zerocount
     \settrue\firstlistitem
     %
     \expanded{\setitemparameter{\currentitemlevel}{\c!start}{1}}%
     \doifinset{0}{#1}{\setitemparameter\currentitemlevel\c!start{0}}%
     \setcounter{\@@itemcounter\currentitemlevel}{0}%
     \doifelsenothing{\getitemparameter\currentitemlevel\c!start}
       {\def\currentitemoffset{1}}
       {\def\currentitemoffset{\getitemparameter\currentitemlevel\c!start}%
        \letitemparameter\currentitemlevel\c!start\empty}%
     %
     \def\tempnumber
       {\countervalue{\@@itemcounter\currentitemlevel}}%
     \doifelse{\getitemparameter\currentitemlevel\c!placestopper}\v!yes
       {\def\tempsymbol{\getitemparameter\currentitemlevel\c!stopper}}
       {\let\tempsymbol\empty}%
   \fi}

\def\actualitemnumber
  {\ifconditional\reverselistitem
     \convertnumber\currentitemsymbol{\numexpr\currentmaxnofitems+\currentitemoffset-\currentitemnumber+1\relax}%
   \else
     \convertnumber\currentitemsymbol{\numexpr\currentminnofitems+\currentitemoffset+\currentitemnumber-1\relax}%
    \fi}

% PAS OP: ook 'opelkaar' en zo worden getest, nog eens afvangen!

\def\unknownitemsymbol{?}

\def\setitemmark#1% % en pas op: resets \docommand
  {\doifsymboldefinedelse{#1}
     {\edef\currentitemsymbol{#1}%
      \setxvalue{\@@globalitemsymbol\currentitemlevel}{\currentitemsymbol}%
      \setgvalue{\@@localitemsymbol \currentitemlevel}{\unknownitemsymbol}%
      \def\listitem{\symbol[\currentitemsymbol]}%
      \let\@@opsymbol\empty}% \let\docommand\gobbleoneargument}
     {\doifconversiondefinedelse{#1}
        {\edef\currentitemsymbol{#1}%
         \setxvalue{\@@globalitemsymbol\currentitemlevel}{\currentitemsymbol}%
         \setgvalue{\@@localitemsymbol\currentitemlevel }{\actualitemnumber }%
         \ifconditional\textlistitem
           \doifsomething{\getitemparameter\currentitemlevel\c!lefttext}
             {\let\tempsymbol\empty}%
         \fi
         \def\listitem
           {\getitemparameter\currentitemlevel
              {\ifconditional\textlistitem\c!lefttext\else\c!left\fi}%
            \getvalue{\@@localitemsymbol\currentitemlevel}\tempsymbol
            \getitemparameter\currentitemlevel
              {\ifconditional\textlistitem\c!righttext\else\c!right\fi}}%
        \let\@@opsymbol\empty}%\let\docommand\gobbleoneargument}
       {}}}

\def\calculatelistwidth#1#2% distance deals with 'broad'
  {#2=\getitemparameter{#1}\c!distance\relax
   \ifnum\getitemparameter{#1}\c!factor>\zerocount
     \ifdim#2=\zeropoint #2=.5em\fi
   \fi
   \multiply#2 \getitemparameter{#1}\c!factor
   \advance #2 \getitemparameter{#1}\c!width\relax}

% The next conditionals deal with \item \startitemgroup. It
% looks like a hack to skip back, but that way we preserve
% the indentation and bullet placement. It's a rather
% untested feature.

\newconditional\concatnextitem     \setfalse\concatnextitem
\newconditional\autoconcatnextitem \settrue \autoconcatnextitem
\newsignal     \itemsignal

\def\startitemgroup
  {\dotripleempty\dostartitemgroup}

% \def\dostartitemgroup[#1][#2][#3]%
%   {\bgroup
%    \def\currentitemgroup{#1}%
%    \ifthirdargument
%      \dodostartitemgroup[#2][#3]%
%    \else
%      \doifassignmentelse{#2}
%        {\dodostartitemgroup[][#2]}
%        {\dodostartitemgroup[#2][]}%
%    \fi}

\def\dostartitemgroup[#1][#2][#3]%
  {\bgroup
   \ifnum\currentitemlevel=\zerocount
     \def\currentitemgroup{#1}% no nested mixing of itemgroups
   \fi
   \ifthirdargument
     \dodostartitemgroup[#2][#3]%
   \else
     \doifassignmentelse{#2}
       {\dodostartitemgroup[][#2]}
       {\dodostartitemgroup[#2][]}%
   \fi}

\def\dodostartitemgroup[#1]% [#2]%
  {\relax % prevents lookahead
   \ifnum\currentitemlevel=\maxitemdepth\relax
     \showmessage\m!layouts9{\number\maxitemdepth}%
     \let\itemincrement\zerocount
   \else
     \let\itemincrement\plusone
   \fi
   \global\advance\itemdepth\itemincrement
   \xdef\currentitemlevel{\number\itemdepth}%
   \initializeitemgrouplevel\currentitemlevel % safeguard
   \edef\itemgroupoptions{\getitemparameter\currentitemlevel\c!option}%
   \ifx\itemgroupoptions\empty
     \edef\itemgroupoptions{#1}%
   \else
     \doifsomething{#1}{\edef\itemgroupoptions{\itemgroupoptions,#1}}%
   \fi
   \expanded{\redostartitemgroup[\itemgroupoptions]}}% [#2]

\let\startcollectitems\relax
\let\stopcollectitems \relax

%D A nice example of a plugin:
%D
%D \startbuffer
%D \startitemize[a,random,packed]
%D \startitem first  \stopitem \startitem second \stopitem
%D \startitem third  \stopitem \startitem fourth \stopitem
%D \stopitemize
%D
%D \startitemize[a,random,packed]
%D \startitem first  \stopitem \startitem second \stopitem
%D \startitem third  \stopitem \startitem fourth \stopitem
%D \stopitemize
%D
%D \startitemize[a,packed]
%D \startitem first  \stopitem \startitem second \stopitem
%D \startitem third  \stopitem \startitem fourth \stopitem
%D \stopitemize
%D \stopbuffer
%D
%D \typebuffer \getbuffer

% better collectitems als conditional and a real plugin mechanism (some day)

\@EA\long\@EA\def\@EA\collectitemgroupitem\@EA#\@EA1\csname\e!stop\v!item\endcsname
  {\increment\itemcollectcounter
   \long\setvalue{\v!item*\itemcollectcounter}{\item#1\par}}

\def\flushcollecteditems
  {\ifconditional\randomizeitems
     \getrandomnumber\itemcollectcounternow\plusone\itemcollectcounter
   \else
     \increment\itemcollectcounternow
   \fi
   \doifdefined{\v!item*\itemcollectcounternow}
     {\getvalue{\v!item*\itemcollectcounternow}%
      \letbeundefined{\v!item*\itemcollectcounternow}%
      \increment\itemcollectcounterdone}%
   \ifnum\itemcollectcounterdone<\itemcollectcounter\relax
     \expandafter\flushcollecteditems
   \fi}

\def\stopcollectitems
  {\ifconditional\randomizeitems
     \newcounter\itemcollectcounterdone
     \ifnum\itemcollectcounter>\zerocount
       \@EAEAEA\flushcollecteditems
     \fi
   \fi}

\def\startcollectitems
  {\ifconditional\randomizeitems
     \newcounter\itemcollectcounter
     \letvalue{\e!start\v!item}\collectitemgroupitem
   \fi}

%D End of plugin.

\ifx\startcolumns\undefined \def\startcolumns[#1]{} \fi
\ifx\stopcolumns \undefined \let\stopcolumns\relax  \fi

\def\dosetsymalign#1% hm, we should use one of the core-spa macros or make a helper
  {\processaction
      [#1]
      [ \v!flushleft=>\let\symalignleft\relax,
            \v!right=>\let\symalignleft\relax,
       \v!flushright=>\let\symalignleft\hfill,
             \v!left=>\let\symalignleft\hfill,
           \v!middle=>\let\symalignleft\hfil,
           \v!center=>\let\symalignleft\hfil]}

\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