ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Rik Kabel <context@rik.users.panix.com>
To: Hans Hagen <j.hagen@xs4all.nl>,
	mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: How can I remove a blank leading line from a buffer
Date: Mon, 13 Aug 2018 10:28:47 -0400	[thread overview]
Message-ID: <c2d5ef02-54c0-c26e-8fd9-7d8b70a51489@rik.users.panix.com> (raw)
In-Reply-To: <1cd49a92-b6c9-0c48-d148-c863a503a809@xs4all.nl>


[-- Attachment #1.1: Type: text/plain, Size: 4428 bytes --]

On 8/13/2018 03:01, Hans Hagen wrote:
> On 8/13/2018 5:18 AM, Rik Kabel wrote:
>> %% How can one remove blank lines at the start of a buffer so that
>> %%   commands that grab a buffer can be used in the same way as, for
>> %%   example, \startparagraph...\stopparagraph, which allow blank
>> %%   lines around the content?
>> %%
>> %% The problem appears when an optional argument is allowed but none
>> %%   is provided. Adding \relax does not help; adding empty brackets
>> %%   does. I see no way to distinguish between a buffer without
>> %%   leading blank lines and a buffer that was created when brackets
>> %%   are provided.
>> %%
>> %% \inlinebuffer handles the leading blank lines when there is
>> %%   nothing prepended, but I need to prepend. (It also handles the
>> %%   unwanted trailing line, but that is not an issue here).
>> %%
>> %% How can I unpack the buffer, apply the equivalent functions of
>> %%   ignorespaspaces and removeunwantedspaces to it, and repack it?
>> %%   The buffer may contain internal blank lines and macros, and
>> %%   those should be retained. Or, is there already a function to
>> %%   strip a buffer in the manner that string.strip does a string?
>>
>> \setupwhitespace[none]
>> \setupindenting[none]
>> \define\Mark{\color[middlegray]{\itb¿\ }}
>> \define\First{nothing yet}
>> \define\Arg{nothing yet}
>> \setuplanguage[en][spacing=packed]
>>
>> \starttexdefinition unexpanded startBufTest
>>    \bgroup
>>    \dosingleempty\dostartBufTest
>> \stoptexdefinition
>>
>> \starttexdefinition dostartBufTest [#SETUPS]
>>    \doifsomethingelse{#{SETUPS}}
>>                      {\define\Arg{yes}}
>>                      {\define\Arg{no}}
>>    \iffirstargument
>>      \define\First{yes}
>>    \else
>>      \define\First{no}
>>    \fi
>>    \relax
>>    \getrawparameters[BufTest][xx=yy,#SETUPS]
>>    \grabbufferdata[TestBuffer][startBufTest][stopBufTest]
>> \stoptexdefinition
>>
>> \starttexdefinition stopBufTest
>>
>>    \startparagraph
>>
>>      \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer]
>>      \ (first: \First, arg: \Arg)
>>
>>    \stopparagraph
>>
>>    \egroup
>> \stoptexdefinition
>>
>> \starttext
>>
>> \startparagraph
>>
>>    A starting paragraph.
>>
>> \stopparagraph
>>
>> \startBufTest
>>    Buffer without blank lines.
>> \stopBufTest
>>
>> \startparagraph
>>
>>    An intervening paragraph.
>>
>> \stopparagraph
>>
>> \startBufTest
>>
>>    Buffer with blank lines.
>>
>> \stopBufTest
>>
>> \startparagraph
>>
>>    An intervening paragraph.
>>
>> \stopparagraph
>>
>> \startBufTest\relax
>>
>>    Buffer with \tex{relax}.
>>
>> \stopBufTest
>>
>> \startparagraph
>>
>>    An intervening paragraph.
>>
>> \stopparagraph
>>
>> \startBufTest[]
>>
>>    Buffer with \type{[]}.
>>
>> \stopBufTest
>>
>> \startparagraph
>>
>>    An intervening paragraph.
>>
>> \stopparagraph
>>
>> \startBufTest[key=value]
>>
>>    Buffer with \type{[key=value]}.
>>
>> \stopBufTest
>>
>> \startparagraph
>>
>>    A closing paragraph.
>>
>> \stopparagraph
>>
>> \stoptext
>
>   \startparagraph
>
> %     \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer]
> %     \ (first: \First, arg: \Arg)
>
>     \margintext{\Mark}
>
>     \setupparagraphintro[first][(first: \First, arg: \Arg)]
>    %\setupparagraphintro[next][(first: \First, arg: \Arg)]
>
>     \getbuffer[TestBuffer]
>
>   \stopparagraph 

Hans,

That works for the over-simplified case here, but fails in practice. For 
a \startnarrower[left] paragraph, the mark is still in the main margin, 
not the 'margin' of the narrowed paragraph. Also, the placement of the 
text in the margin is wrong and not easily controlled as with \llap and 
\rlap. The code started out more like:

    \define\Mark{\color[middlegray]{\hskip.6cm\itb¿\ }}
    \setwidthof{\Mark}\to\MarkWidth
    ...
    \starttexdefinition stopBufTest
       \startluacode
    buffers.prepend("TestBuffer","\\dontleavehmode\\llap{\\Mark}")
       \stopluacode
       \setupnarrower[left=\MarkWidth]
       \startnarrower[left,right]
       \startparagraph
         \inlinebuffer[TestBuffer]
       \stopparagraph
       \stopnarrower
       \egroup
    \stoptexdefinition


So I am still looking for a way to do this. Meanwhile I am trying to 
understand Aditya's examples.

-- 
Rik


[-- Attachment #1.2: Type: text/html, Size: 7356 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2018-08-13 14:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-13  3:18 Rik Kabel
2018-08-13  3:44 ` Aditya Mahajan
2018-08-13  3:46 ` Henri Menke
2018-08-13  7:02   ` Hans Hagen
2018-08-13  7:01 ` Hans Hagen
2018-08-13 14:28   ` Rik Kabel [this message]
2018-08-13 16:04     ` Wolfgang Schuster
2018-08-13 17:09       ` Rik Kabel
2018-08-13 17:46         ` Wolfgang Schuster
2018-08-13 18:27           ` Rik Kabel
2018-08-13 19:52             ` Wolfgang Schuster
2018-08-13 22:43               ` Rik Kabel
2018-08-14 14:46                 ` Rik Kabel
2018-08-15  3:31                   ` Aditya Mahajan
2018-08-15  7:07                     ` Hans Hagen
2018-08-15 21:46                       ` Rik Kabel
2018-08-16 14:55                         ` Aditya Mahajan
2018-08-16 20:02                           ` Rik
2018-08-13 16:15     ` Rik Kabel
2018-08-13 17:51     ` Rik Kabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c2d5ef02-54c0-c26e-8fd9-7d8b70a51489@rik.users.panix.com \
    --to=context@rik.users.panix.com \
    --cc=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).