Re: [code] [textadept] Latest Changes in hg

From: Mitchell <>
Date: Fri, 13 Sep 2013 16:03:35 -0400 (EDT)


On Thu, 12 Sep 2013, Robert Gieseke wrote:

> Am 9/11/13 5:39 PM, schrieb Mitchell:
>>> I'm trying to understand the new INITIALIZED event. My problem is that
>>> modules that piggy-back on user theme styles like Textredux or
>>> highlighting the margins for the active buffer are now loaded before
>>> any buffer is actually loaded.
>> INITIALIZED is not what you want; it is run pretty much at the end of
>> the startup process. Connect to VIEW_NEW for setting view stuff like
>> margin colors and BUFFER_NEW for buffer-specific stuff. Theme colors and
>> styles are available with either event if you need them. Those events
>> are run as early as possible.
>>> For the margin highlighting it's easy to workaround by wrapping the
>>> code in an INITIALIZED event, for Textredux this is a bit more
>>> convoluted since other modules depend on its style module.
>>> Is there a way to get theme properties before any file is loaded?
>>> Maybe I'm misunderstanding things …
>> If you connect to VIEW_NEW or BUFFER_NEW, you can use
>>['...'] to get all theme information. This happens before
>> any file is loaded.
>> I'm not sure I fully understand the problem, but I hope this helps.
> Apologies for not linking to code examples. To highlight the margin I used
> this:
> When I just stop caching the color values this works fine!

If you wrap that code in a `BUFFER_NEW` event, it should work, no?

> But for Textredux I'm still a bit stuck. In the '' we generate
> default styles the other styles used for lists etc. are based on
> ( This
> 'style' module is required by other modules and loaded before INITIALIZED is
> emitted.
> Maybe I have to rewrite this to lazily read the default styles.

Yes, it sounds like you will have to rewrite module code to read your
styles and colors after `require`-time (via events), or use the method you
describe below:

> As a workaround I can wrap requiring like
> events.connect(events.INITIALIZED, function()
> require 'textredux.hijack'
> common = require 'common'
> end)

That is an acceptable way of doing it. (I briefly did this when
`require`ing Textadept key bindings and menus to ensure all of buffer
functions existed at load-time.)

When I ran into this kind of problem, I chose the former and ended up
wrapping all code that depended on buffer properties (like colors) in
VIEW_NEW events. It's more work, but I feel it's cleaner.

One of the things that helps me debug these sorts of situations is to put
a `_G.print(event)` statement at the beginning of `core/events.lua`'s
`emit()` event. Then you can trace the event stack and figure out where
and when your module code is loaded.


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Fri 13 Sep 2013 - 16:03:35 EDT

This archive was generated by hypermail 2.2.0 : Sat 14 Sep 2013 - 06:34:50 EDT