[NTG-context] How can I remove a blank leading line from a buffer

Rik Kabel context at rik.users.panix.com
Wed Aug 15 23:46:03 CEST 2018

On 8/15/2018 03:07, Hans Hagen wrote:
> On 8/15/2018 5:31 AM, Aditya Mahajan wrote:
>> On Tue, 14 Aug 2018, Rik Kabel wrote:
>>> I really think, though, that a buffers.strip function would be the 
>>> way to go, instead of futzing after the damage is done.
>> In lua, buffers.getcontent('name') gives the contents of the buffer 
>> labelled 'name'. You can post-process this in whatever way you want. 
>> For example, you could write a lua function userdata.strip that 
>> strips the leading and ending black spaces from a string, and then call
>> context(userdata.strip(buffers.getcontent('name)))
> local s = [[
> foo
> bar
> bar
> ]]
> print(string.fullstrip(s))
So, it looks likethe following is closer to working for me in a simple 
test harness, but not in my full-blown work:


(or similar with string.fullstrip).

However, it fails when the buffer starts with an unescaped left square 
bracket. That is probably why the \relax is inserted, and I can see that 
it is not a simple job to handle this. So, I will accept that I must 
either append [] or get rid of the open layout for these cases.

I suspect that the issue in the larger project has to do with quoting 
for the RE ("^\\relax") since compilation fails with:

    %% \stopAttribution ...getcontent("Attribution"),"^\\
    %% relax","")))}\stopparagrap...

Any pointers on such quoting would be appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20180815/2cf2f66f/attachment-0001.html>

More information about the ntg-context mailing list