Re: [code] Printing to custom buffer

From: Oliver Jan Krylow <oliver.att.bugabinga.net>
Date: Fri, 1 Jun 2018 18:05:52 +0200

> Hi Oliver,
>
> On Fri, 1 Jun 2018, Oliver Jan Krylow wrote:
>
>> Hello list!
>>
>> The following `init.lua` causes `ta` to seemingly get stuck in some loop, be
>> unresponsive and take 100% of one CPU core until I SIGTERM it.
>>
>> local function msg(...)
>> ui._print('LOG', ...)
>> end
>>
>> msg(1,2,3, 'START')
>>
>>> Notice the `_print`!
>>
>> Make sure you have no `session` file initially.
>> You have to open `ta` two times to observe this.
>> (Make sure you have not disabled session loading)
>>
>> It seems `ui._print` is only usable after `events.INITIALIZED`. Correct?
>>
>> local function msg(...)
>> ui._print('LOG', ...)
>> end
>>
>> events.connect(events.INITIALIZED, function()
>> ui.print("HELLO")
>> msg(1,2,3, 'START')
>> end)
>
> Yes, it looks like Textadept cannot tolerate having `ui.print()` called on startup from your *init.lua*. I think it's simply because I had never considered the possibility that it might be useful.

I use ui.print for debugging. Printing to stdout is often impractical because I do not use to start ta from a terminal, but a *.desktop file.

> After some brief digging it looks like a lot of startup stuff hinges upon only one Buffer being available until `events.INITIALIZED` is called, so for now you'll have to use `events.INITIALIZED`.

set_theme or set_lexer seems to fail because something is nil in the text adept module. I can produce the relevant logs, if you want.

>
>> This fixes the unresponsive loop issue, but there is another issue after
>> second launch of `ta`. A dialog pops up saying "session LOG cannot be found".
>>
>> This can be fixed by renaming 'LOG' to '[LOG]'. Why?
>
> 'LOG' by itself could be a valid filename when read from a session file. However, your previous call to `ui._print('LOG')` makes it not a normal file. Textadept would not know this when loading a session though. Instead, there is an undocumented convention for print buffers to be of the form `[type]`, so that when loading a session, Textadept does not consider them to be files on disk.

Thanks, that makes sense now.

>
>> I stumbled upon this while trying to create my own custom "Message Buffer"
>> and don't quite understand what is going on.
>>
>> Apologies, if this is documented somewhere and I missed it, but I could not
>> find mention of this in the manual.
>>
>> So, I am just a little confused about what is expected behaviour, what is
>> possibly an issue and if one should generally put the whole `init.lua` in a
>> `events.INITIALZED` handler maybe?
>
> In this case, `ui._print()` calls should be made in an `events.INITIALIZED` handler for now.

What also seems to work, is to cache all calls to ui.print until INITIALIZED is available. Then flush the cache to the [Message Buffer] and discard it.

>
> Cheers,
> Mitchell
> --
> You are subscribed to code.att.foicica.com.
> To change subscription settings, send an e-mail to code+help.att.foicica.com.
> To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 01 Jun 2018 - 12:05:52 EDT

This archive was generated by hypermail 2.2.0 : Sat 02 Jun 2018 - 06:43:31 EDT