Hi Alan,

>> > In addition to \startbuffer \stopbuffer
>> > it would be nice to have \startappendbuffer \stopappendbuffer.
>> >
>> > I see that the lua function buffer.append() exists but I have not
>> > worked-out how to add this functionality cleanly as conTeXt macros.

Here you go!

% We want to join appended pieces with a newline
% but '\n' is a bit rotten to pass inside \ctxlua
% so we simply prepare the appending function inside \startluacode, instead
\startluacode
    userdata = userdata or { }
    function userdata.addTempToBuffer(buffername)
        buffers.append(
            buffername,
            '\n' .. buffers.getcontent('APPENDTEMP')
        )
    end
\stopluacode

\def\startappendbuffer[#1]%
  {% 1: create a \stopappendbuffer that appends APPENDTEMP to the buffer #1
   \def\stopappendbuffer%
      {\ctxlua{userdata.addTempToBuffer('#1')}}
   % 2: write the buffer to APPENDTEMP instead of overwriting buffer #1
   % then addTempToBuffer will take care of the appending.
   \dostartbuffer[APPENDTEMP][startappendbuffer][stopappendbuffer]}


%%% --- And here is an example --- %%%
%%% --- With my respects to Dorothy L. Sayers --- %%%


\setuplayout[backspace=6cm, leftmargin=5cm, width=11cm]
\showframe

\starttext

\startbuffer[x]
\inmargin{Harriet Vane}
Here then at home, by no more storms distrest,
Folding laborious hands we sit, wings furled;
Here in close perfume lies the rose-leaf curled,
Here the sun stands and knows not east nor west,
Here no tide runs; we have come, last and best,
>From the wide zone through dizzying circles hurled,
To that still centre where the spinning world
Sleeps on its axis, to the heart of rest.
\stopbuffer

\startlines
\getbuffer[x]
\stoplines

------

\startappendbuffer[x]

\inmargin{Lord Peter Wimsey}
Lay on thy whips, O Love, that we upright,
Poised on the perilous point, in no lax bed
May sleep, as tension at the verberant core
Of music sleeps; for, if thou spare to smite,
Staggering, we stoop, stooping, fall dumb and dead,
And, dying so, sleep our sweet sleep no more.
\stopappendbuffer

\startlines
\getbuffer[x]
\stoplines

------

\typebuffer[x]

\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to