Contents

events

Textadept’s core event structure and handlers.

Overview

Textadept is very event-driven. Most of its functionality comes through event handlers. Events occur when you create a new buffer, press a key, click on a menu, etc. You can even make an event occur with Lua code. Instead of having a single event handler however, each event can have a set of handlers. These handlers are simply Lua functions that are called in the order they were added to an event. This enables dynamically loaded modules to add their own handlers to events.

Events themselves are nothing special. They do not have to be declared in order to be used. They are simply strings containing an arbitrary event name. When an event of this name occurs, either generated by Textadept or you, all event handlers assigned to it are run.

Events can be given any number of arguments. These arguments will be passed to the event’s handler functions. If a handler returns either true or false explicitly, all subsequent handlers are not called. This is useful if you want to stop the propagation of an event like a keypress.

Textadept Events

This is the set of default events that Textadept emits with the arguments they pass. Events that modules emit are listed on their respective LuaDoc pages.

Example

The following Lua code generates and handles a custom my_event event:

function my_event_handler(message)
  gui.print(message)
end

events.connect('my_event', my_event_handler)
events.emit('my_event', 'my message') -- prints 'my message' to a view

Functions


connect (event, f, index)

Adds a handler function to an event.

Parameters:

Return:

See also:


disconnect (event, index)

Disconnects a handler function from an event.

Parameters:

See also:


emit (event, …)

Calls all handlers for the given event in sequence (effectively “generating” the event). If true or false is explicitly returned by any handler, the event is not propagated any further; iteration ceases.

Parameters:

Return:


Tables


handlers

A table of event names and a table of functions connected to them.