Re: [code] Confused about Events

From: Robert Gieseke <>
Date: Fri, 02 Jan 2015 12:10:33 +0100


the handling of language module functionality can indeed be confusing,
so I try some explanations:

The lexer_loaded event is fired every time a buffer's lexer is set, to
confirm put
events.connect(events.LEXER_LOADED, function(lang)
  ui.statusbar_text = lang
in your `.textadept/init.lua`. This is used to adjust buffer-specific
properties like indentation size for a language.

A `post_init.lua` file is loaded only once by loading the file as a
module using Lua's require mechanism. So rest/init.lua is loaded first,
then rest/post_init.lua if it exists. The first file could be located in
Textadept's module directory (the offical rest module available in the
modules package) and the second in .textadept/modules/rest.

For your autocompile command you could start with the following in

events.connect(events.FILE_AFTER_SAVE, function()
  if buffer:get_lexer() ~= 'rest' then return end
  ui.statusbar_text = 'after save from post_init'

See also
as an example how the rest syntax checking is done.

As for the build command the %(filename) etc. syntax is available in
Textadept's run module. You could define a command like = 'rst %(filepath) …'

If you prefer to compile on every save using the FILE_AFTER_SAVE event,
you could follow the approach in the linked example above to get the

Hope this helps!

Am 02/01/15 um 10:38 schrieb DrTebi:
> Hello,
> I am a new Textadept user and have started to write some custom functions.
> What I am trying to accomplish is the following when I am in 'rst'
> mode (ReStructuredText):
> - pressing Ctrl+S saves the file
> - after saving the file Textadept runs an external command (rst2html)
> From the manual I have gathered so far that I should create the file
> ~/.textadept/modules/rest/post_init.lua
> And that I can then add this functionality somehow like this:
> events.connect(events.LEXER_LOADED, function(lang)
> if lang == 'rest' then
> events.connect(events.FILE_AFTER_SAVE, function(f)
> os.execute('rst2html "%(filepath)" "%d%e.html"')
> end)
> end
> end)
> Before I actually tried the rst2html command, I tested this by
> displaying a message box (ui.dialogs.ok_msgbox{title=f}) and noticed
> that my function runs in every mode, not just rst.
> Well, that's where the main problem is... I assume I have to put these
> custom events somewhere else?
> I would also appreciate help with constructing the rst2html command,
> as I am not certain whether the %-variables can be used.
> Thanks,
> DrTebi

You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Fri 02 Jan 2015 - 06:10:33 EST

This archive was generated by hypermail 2.2.0 : Fri 02 Jan 2015 - 06:31:47 EST