Re: [code] Printing to custom buffer

From: Mitchell <m.att.foicica.com>
Date: Thu, 31 May 2018 22:30:00 -0400 (EDT)

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. 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`.

> 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.

> 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.

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.
Received on Thu 31 May 2018 - 22:30:00 EDT

This archive was generated by hypermail 2.2.0 : Fri 01 Jun 2018 - 06:30:31 EDT