\unprotect

%D Temporary

\def\c!titleleft{titleleft}
\def\c!titleright{titleright}
\def\c!titlecommand{titlecommand}

%D To be added to syst-ext.tex 

\def\dowithoptargument#1%
  {\def\useoneargument##1{#1{##1}}
   \def\fakeoneargument{#1{}}
   \doifnextcharelse\bgroup{\useoneargument}{\fakeoneargument}}


%D Patch for core-des.tex

\def\@@startdescription[#1][#2]%
  {\def\currentdescription{#1}%
   \doifelse{\descriptionparameter\c!title}\v!yes
     {\dowithoptargument{\@@startsomedescription{#1}[#2]}}
     {\@@startsomedescription{#1}[#2]{}}}

\def\@@description[#1][#2]%
  {\def\currentdescription{#1}%
   \doifelse{\descriptionparameter\c!title}\v!yes
     {\dowithoptargument{\@@somedescription{#1}[#2]}}
     {\@@somedescription{#1}[#2]{}}}

\def\special@@descriptionhandler[#1]#2#3%
  {\strut
   \doifelse{\descriptionparameter\c!number}\v!no
     \!!doneafalse{\doifelse{#1}{-}\!!doneafalse\!!doneatrue}%
   \chardef\descriptioncoupling\zerocount
   \iflocation
     \doifsomething{\descriptionparameter\c!coupling}
       {\processaction % genereert > of <
          [\descriptionparameter\c!couplingway]
          [ \v!local=>\chardef\descriptioncoupling\plusone, % old: default
           \v!global=>\chardef\descriptioncoupling\plustwo]}% new: global crosslinking
   \fi
   \setupnumber % the number is called indirectly
     [\currentdescriptionnumber]
     [\c!sectionnumber=\descriptionparameter\c!sectionnumber]%
   \if!!donea
     \makeprecedingsectionnumber[\currentdescriptionnumber]%
     \prepareprefixnumber{\??dd\currentdescription}\precedingsectionnumber\preparednumber
     \iftrialtypesetting\startlocal\fi
     \getvalue{\e!next\currentdescription}% tricky but we need the preroll
     \iftrialtypesetting\stoplocal\fi
     % \getvalue{\e!next#2#1}%
     \iflocation
       \bgroup
       \letvalue{\??dd\currentdescription\c!sectionnumber}\v!yes
       \protectconversion
       \makeprecedingsectionnumber[\currentdescriptionnumber]%
       \prepareprefixnumber{\??dd\currentdescription}\precedingsectionnumber\preparednumber
       \ifcase\descriptioncoupling \or
         \xdef\@@internalenumber{\doshowdnnumber}%
         \rawreference\s!num{#1:\@@internalenumber}{}%
       \or
         \xdef\@@internalenumber{\countervalue{\??dd\c!coupling\currentdescription}}%
         \rawreference\s!num{\currentdescription:\@@internalenumber}{}%
       \fi
       \egroup
     \fi
    %\makeprecedingsectionnumber[\currentdescriptionnumber]%
    %\prepareprefixnumber{\??dd\currentdescription}\precedingsectionnumber\preparednumber
     \disablepseudocaps   % sorry, uppercase causes troubles
     \doattributes        % \nocase primitive needed
       {\??dd\currentdescription}\c!headstyle\c!headcolor % todo: sub as well
       {\descriptionparameter\c!command
          {\showdntext
%            \domakednnumber % right should be after the title
            \descriptionparameter\c!left
            \strut\doshowdnnumber
           \doif{\descriptionparameter\c!title}\v!yes % new, for david antos
            {\doifsomething{#2}
             {\doattributes{\??dd\currentdescription}\c!titlestyle\c!titlecolor
                {\hskip\descriptionparameter\c!titledistance%
%                   \descriptionparameter\c!titlecommand%
                  {\descriptionparameter\c!titleleft%
                    \begstrut#2\endstrut%
                  \descriptionparameter\c!titleright}}}}%
             % Remaining part of \domakednnumbed
             \descriptionparameter\c!stopper
             \descriptionparameter\c!right
           }}% \c!command is hook for taco
     \doifsomething{\descriptionparameter\c!list} % also for david antos
       {\dowritetolist
          {\descriptionparameter\c!type:\descriptionparameter\c!list}
          {\showdnlisttext\doshowdnnumber}{#2}{\currentdescription}}%
     \iflocation\ifcase\descriptioncoupling \else
       \edef\localconnection{\descriptionparameter\c!coupling:\@@internalenumber}%
       \doifreferencefoundelse\localconnection
         {\in[\localconnection]}\donothing % genereert > of <
     \fi\fi
     \doifnot{#1}{-}{\rawreference\s!num{#1}{\doshowdnnumber}}%
  \else % Why was this strange expansion needed?
     \edef\!!stringa{\showdnpuretext}% nog eens testen binnen \expanded
     \expanded{\doattributes{\??dd\currentdescription}\noexpand\c!headstyle\noexpand\c!headcolor
       {\noexpand\descriptionparameter\noexpand\c!command{\!!stringa}}}%
     \doifnot{#1}{-}{\rawreference\s!num{#1}{}}%
   \fi}
\protect

\starttext

\defineenumeration
  [lemma]
  [             title=yes,
                 text=Lemma,
        titledistance=.5em,
         textdistance=1em,
   %             left=***,
   %            right=**,
   %          command=\framed,
   %     titlecommand=\inframed,
           titlestyle=bold,
            titleleft=(,
           titleright=),
              stopper=.,
             location=hanging,
                style=italic,
  ]

\startlemma[lemma 1] {with a title of a certain length} 
  \input tufte 
\stoplemma

\startlemma[lemma 2]
  With no title 
  \input tufte 
\stoplemma

We have two lemmas, \in Lemma[lemma 1] and \in Lemma[lemma 2].

\stoptext
