ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* buffers (append)
@ 2013-01-14  8:00 Alan BRASLAU
  2013-01-14  8:34 ` Wolfgang Schuster
  0 siblings, 1 reply; 4+ messages in thread
From: Alan BRASLAU @ 2013-01-14  8:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello,

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.
I imagine that this might be quite trivial for our TeX programming
experts... (for once, a [useful?] suggestion that in the end will not
entail many hours of work? :)

Alan
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: buffers (append)
  2013-01-14  8:00 buffers (append) Alan BRASLAU
@ 2013-01-14  8:34 ` Wolfgang Schuster
  2013-01-14 13:48   ` Alan BRASLAU
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Schuster @ 2013-01-14  8:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 14.01.2013 um 09:00 schrieb Alan BRASLAU <alan.braslau@cea.fr>:

> Hello,
> 
> 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.
> I imagine that this might be quite trivial for our TeX programming
> experts... (for once, a [useful?] suggestion that in the end will not
> entail many hours of work? :)


\startbuffer[a]
Line 1
\stopbuffer

\startbuffer[b]
Line 2
\stopbuffer

\starttext

\startlines
\getbuffer[a,b]
\stoplines

\stoptext

Wolfgang
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: buffers (append)
  2013-01-14  8:34 ` Wolfgang Schuster
@ 2013-01-14 13:48   ` Alan BRASLAU
  2013-01-15 13:41     ` Sietse Brouwer
  0 siblings, 1 reply; 4+ messages in thread
From: Alan BRASLAU @ 2013-01-14 13:48 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: wolfgang.schuster

On Mon, 14 Jan 2013 09:34:08 +0100
Wolfgang Schuster <wolfgang.schuster@gmail.com> wrote:

> 
> Am 14.01.2013 um 09:00 schrieb Alan BRASLAU <alan.braslau@cea.fr>:
> 
> > Hello,
> > 
> > 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.
> > I imagine that this might be quite trivial for our TeX programming
> > experts... (for once, a [useful?] suggestion that in the end will
> > not entail many hours of work? :)
> 
> 
> \startbuffer[a]
> Line 1
> \stopbuffer
> 
> \startbuffer[b]
> Line 2
> \stopbuffer
> 
> \starttext
> 
> \startlines
> \getbuffer[a,b]
> \stoplines
> 
> \stoptext
> 
> Wolfgang

Thank you Wolfgang, this is useful.

However, it would still be helpful to be able to generically add to a
buffer without having to rename a new one. Shouldn't be very difficult
but I did not find that anything like this already exists. I often
think this way when I teach, adding steps to an example while repeating
the previous steps.

\startbuffer[a]
Line 1
\stopbuffer

\getbuffer[a]

\startaddtobuffer[a]
Line 2
\stopaddtobuffer

\getbuffer[a]

Alan
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: buffers (append)
  2013-01-14 13:48   ` Alan BRASLAU
@ 2013-01-15 13:41     ` Sietse Brouwer
  0 siblings, 0 replies; 4+ messages in thread
From: Sietse Brouwer @ 2013-01-15 13:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-15 13:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-14  8:00 buffers (append) Alan BRASLAU
2013-01-14  8:34 ` Wolfgang Schuster
2013-01-14 13:48   ` Alan BRASLAU
2013-01-15 13:41     ` Sietse Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).