On 3/26/2013 7:11 PM, Wolfgang Schuster wrote:
Hi Hans,

there is a problem with the command handler and nested \setup… commands.

In the following example the setting for the “two” environment are ignored.

<example>
\defineenumeration[one][text=One]
\defineenumeration[two][text=Two]

\setupenumeration[one,two][alternative=serried,color=red]

\starttext

        \startone
        First enumeration.
        \stopone

        \starttwo
        Second enumeration.
        \stoptwo

\stoptext
</example>

The reason for this behavior is the \setupcounter call in 
\everysetupenumeration.

When you look at the internal code for \setupenumeration (mult-aux.mkiv) you 
see that the first
element in \setupernumeration (i.e. “one”) is processed with 
\mult_interfaces_with_comma_list_element,
at the end of this macro \everysetupenumeration. At this point \setupcounter is 
used which
redefines \mult_interfaces_with_comma_list_element. This redefined version is 
used for the next
element (i.e. “two”) in \setupenumeration and the values are no passed 
(“alternative” and “color”)
to \setupcounter.

\unexpanded\def\mult_interfaces_install_setup_handler#1#2#3#4#5#6#7#8%
   {\ifx#3\relax\let#3\empty\fi
    \unexpanded\def#2{\dodoubleempty#4}%
    \unexpanded\def#6{\mult_interfaces_get_parameters{#1#3:}}% no every ! don't 
change it
    \newtoks#5%
    \newtoks#8%
    \unexpanded\def#4[##1][##2]% maybe helper
      {\let#7#3%
       \ifsecondargument
         \def\mult_interfaces_with_comma_list_element####1% we will have a 
simple one as well
           {\edef#3{####1}%
            \mult_interfaces_get_parameters{#1#3:}[##2]%
            \the#5}%
         \processcommalist[##1]\mult_interfaces_with_comma_list_element
       \else
         \let#3\empty
         \mult_interfaces_get_parameters{#1:}[##1]%
         \the#5%
       \fi
       \let#3#7%
       \the#8}}

So we need something like this (lucky us, no performance penalty):

\unexpanded\def\mult_interfaces_install_setup_handler#1#2#3#4#5#6#7#8#9%
  {\ifx#3\relax\let#3\empty\fi
   \unexpanded\def#2{\dodoubleempty#4}%
\unexpanded\def#6{\mult_interfaces_get_parameters{#1#3:}}% no every ! don't change it
   \newtoks#5%
   \newtoks#8%
   \unexpanded\def#4[##1][##2]% maybe helper
     {\let#7#3%
      \ifsecondargument
        \def#9####1% we will have a simple one as well
          {\edef#3{####1}%
           \mult_interfaces_get_parameters{#1#3:}[##2]%
           \the#5}%
        \processcommalist[##1]#9%
      \else
        \let#3\empty
        \mult_interfaces_get_parameters{#1:}[##1]%
        \the#5%
      \fi
      \let#3#7%
      \the#8}}

\unexpanded\def\installsetuphandler#1#2%
  {\normalexpanded
     {\mult_interfaces_install_setup_handler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname setup#2\endcsname
        \expandafter\noexpand\csname current#2\endcsname
        \expandafter\noexpand\csname setup_#2\endcsname % semi-public
        \expandafter\noexpand\csname everysetup#2\endcsname
        \expandafter\noexpand\csname setupcurrent#2\endcsname
        \expandafter\noexpand\csname saved_setup_current#2\endcsname
        \expandafter\noexpand\csname everysetup#2root\endcsname
        \expandafter\noexpand\csname nested_setup_current#2\endcsname}}

\unexpanded

\def\mult_interfaces_install_auto_setup_handler#1#2#3#4#5#6#7#8#9%
  {\ifx#3\relax\let#3\empty\fi
   \unexpanded\def#2{\dotripleempty#4}%
   \unexpanded\def#6{\mult_interfaces_get_parameters{#1#3:}}%
   \newtoks#5%
   \def#4[##1][##2][##3]%
     {\let#8#3%
      \ifthirdargument
        \def#9####1%
          {\edef#3{####1}%
           \expandafter\def\csname#1#3:\s!parent\endcsname{#1##2}%
           \mult_interfaces_get_parameters{#1#3:}[##3]% always sets parent
           \the#5}%
        \processcommalist[##1]#9%
      \else\ifsecondargument
        \def#9####1%
          {\edef#3{####1}%
           #7% checks parent and sets if needed
           \mult_interfaces_get_parameters{#1#3:}[##2]%
           \the#5}%
        \processcommalist[##1]#9%
      \else
        \let#3\empty
        \mult_interfaces_get_parameters{#1:}[##1]%
        \the#5%
      \fi\fi
      \let#3#8}}

\unexpanded\def\installautosetuphandler#1#2%
  {\normalexpanded
     {\mult_interfaces_install_auto_setup_handler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname setup#2\endcsname
        \expandafter\noexpand\csname current#2\endcsname
        \expandafter\noexpand\csname setup_#2\endcsname % semi-public
        \expandafter\noexpand\csname everysetup#2\endcsname
        \expandafter\noexpand\csname setupcurrent#2\endcsname
        \expandafter\noexpand\csname check#2parent\endcsname
        \expandafter\noexpand\csname saved_setup_current#2\endcsname
        \expandafter\noexpand\csname nested_setup_current#2\endcsname}}


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
    tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------
_______________________________________________
dev-context mailing list
dev-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/dev-context

Reply via email to