%D \module
%D   [       file=strc-ind, % was part of strc-des,
%D        version=2008.10.20,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Indented Text,
%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.

\writestatus{loading}{ConTeXt Structure Macros / Indented Text}

\unprotect

%D \macros
%D   {defineindentedtext,
%D    setupindentedtext}
%D
%D Ok, we keep it but with a different command as it all looks too
%D much like indentation and indenting. We also assume start/stop
%D usage or some explicit par.

\installcorenamespace{indentedtext}

\installcommandhandler \??indentedtext {indentedtext} \??indentedtext

%D \startbuffer
%D \defineindentedtext[one][text=one]
%D \defineindentedtext[two][text=two]
%D
%D \one test test \par
%D \subone test test \par
%D \subtwo test test \par
%D \subsubone test test \par
%D
%D \startone
%D     test test
%D     \startone
%D         test test
%D         \startone
%D             test test
%D         \stopone
%D         \starttwo
%D             test test
%D             \startone
%D                 test test
%D             \stopone
%D         \stoptwo
%D     \stopone
%D \stopone
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\newcount\c_strc_indentedtexts_nesting
\newdimen\d_strc_indentedtexts_width
\newdimen\d_strc_indentedtexts_distance

\appendtoks
   \setuevalue    {\e!start\currentindentedtext}{\strc_indentedtexts_start{\currentindentedtext}\c_strc_indentedtexts_nesting}%
   \setuevalue    {\e!stop \currentindentedtext}{\strc_indentedtexts_stop}%
   % to be avoided ... might go away
   \setuevalue            {\currentindentedtext}{\strc_indentedtexts_direct{\currentindentedtext}{0}}%
   \setuevalue      {\v!sub\currentindentedtext}{\strc_indentedtexts_direct{\currentindentedtext}{1}}%
   \setuevalue{\v!sub\v!sub\currentindentedtext}{\strc_indentedtexts_direct{\currentindentedtext}{2}}%
\to \everydefineindentedtext

\unexpanded\def\strc_indentedtexts_start#1#2% we need to get rid of \spr
  {\par
   \begingroup
   \edef\currentindentedtext{#1}%
   \c_strc_indentedtexts_nesting#2\relax
   \indentedtextparameter\c!before
   \d_strc_indentedtexts_distance\indentedtextparameter\c!distance\relax
   \doifnothing{\indentedtextparameter\c!sample}
     {\setindentedtextparameter\c!sample{\indentedtextparameter\c!text}}%
   \assignwidth
     {\indentedtextparameter\c!width}
     {\d_strc_indentedtexts_width}
     {\useindentedtextstyleandcolor\c!headstyle\c!headcolor
      \indentedtextparameter\c!sample
      \spr{\indentedtextparameter\c!separator}}
     {\d_strc_indentedtexts_distance}%
   \advance\d_strc_indentedtexts_width \d_strc_indentedtexts_distance
   \setbox\scratchbox\hbox to \d_strc_indentedtexts_width
     {\useindentedtextstyleandcolor\c!headstyle\c!headcolor
      \strut
      \indentedtextparameter\c!text
      \hss
      \spr{\indentedtextparameter\c!separator}%
      \hskip\d_strc_indentedtexts_distance}%
   \parindent\zeropoint
   \hskip\c_strc_indentedtexts_nesting\d_strc_indentedtexts_width
   \advance\c_strc_indentedtexts_nesting\plusone
   \dontleavehmode\box\scratchbox
   \hangindent\c_strc_indentedtexts_nesting\d_strc_indentedtexts_width
   \useindentedtextstyleandcolor\c!style\c!color}

\unexpanded\def\strc_indentedtexts_stop
  {\indentedtextparameter\c!after
   \par
   \endgroup}

\unexpanded\def\startindentedtext
  {\dosingleempty\strc_indentedtexts_start_direct}

\def\strc_indentedtexts_start_direct[#1]%
  {\strc_indentedtexts_start{#1}\c_strc_indentedtexts_nesting}

\let\stopindentedtext\strc_indentedtexts_stop

\unexpanded\def\strc_indentedtexts_direct#1#2#3\par % no longer clever grabpar trickery
  {\strc_indentedtexts_start{#1}{#2}#3\strc_indentedtexts_stop}

\setupindentedtext
  [\c!style=\v!normal,
   \c!headstyle=\v!normal,
  %\c!color=,
  %\c!headcolor=,
   \c!width=\v!fit,
   \c!text=\unknown,
  %\c!sample=,
   \c!before=\blank,
   \c!after=\blank,
   \c!distance=1em,
   \c!separator={ :}]

\protect \endinput
