Re: [code] Printing to custom buffer

From: Gabriel Dubatti <gdubatti.att.gmail.com>
Date: Mon, 4 Jun 2018 09:38:34 -0300

Hi Oliver,

El 04/06/2018 a las 09:05, Oliver Jan Krylow escribió:
> Hi Pedro
>
>> For what it may be worth... I always debug printing to stdout because
>> when I debug I call Textadept from the command line... ;-)
>>
>
> I think that is reasonable :). And my usage might be atypical because
> I just started out using ta.
>
> However , bug or not. This should at least be documented.
>
>> Best, /PA
>>
>> On 1 June 2018 at 18:05, Oliver Jan Krylow <oliver.att.bugabinga.net
>> <mailto:oliver.att.bugabinga.net>> wrote:
>>
>>
>>
>> > 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 <mailto:code.att.foicica.com>.
>> > To change subscription settings, send an e-mail to
>> code+help.att.foicica.com <mailto:code%2Bhelp.att.foicica.com>.
>> > To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com
>> <mailto:code%2Bunsubscribe.att.foicica.com>.
>> --
>> You are subscribed to code.att.foicica.com <mailto:code.att.foicica.com>.
>> To change subscription settings, send an e-mail to
>> code+help.att.foicica.com <mailto:code%2Bhelp.att.foicica.com>.
>> To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com
>> <mailto:code%2Bunsubscribe.att.foicica.com>.
>>
>>
>>
>>
>> --
>> Fragen sind nicht da um beantwortet zu werden,
>> Fragen sind da um gestellet zu werden
>> Georg Kreisler
You can use some code like the following to collect log info and show it
later when needed (pressing control+f5).
When I have to debug something, I include log.lua and call
log_event("...") .

-----log.lua-----
local log_ev={}

function log_event(event)
   local line= os.date('%c')..": "..event.."\n"
   log_ev[#log_ev+1]= line
end

keys.cf5 = function()
   buffer.new()
   log_event("DUMP\n")
   for i=1,#log_ev do
     buffer:append_text(log_ev[i])
   end
   buffer:set_save_point()
end

log_event("LOG_START")

function log_event_call(event)
   return function() log_event(event) end
end

events.connect(events.RESET_AFTER, log_event_call("RESET_AFTER"))
events.connect(events.INITIALIZED, log_event_call("INITIALIZED"))
------------------
Cheers,
Gabriel

-- 
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 Mon 04 Jun 2018 - 08:38:34 EDT

This archive was generated by hypermail 2.2.0 : Tue 05 Jun 2018 - 06:50:39 EDT