Textadept
Defines | Functions | Variables
src/textadept.c File Reference
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "Scintilla.h"
#include "SciLexer.h"
#include "ScintillaWidget.h"
#include "gcocoadialog.h"
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

Defines

#define PLAT_GTK   1
#define SS(view, m, w, l)   scintilla_send_message(SCINTILLA(view), m, w, l)
#define signal(o, s, c)   g_signal_connect(G_OBJECT(o), s, G_CALLBACK(c), 0)
#define l_setglobalview(l, v)   (l_pushview(l, v), lua_setglobal(l, "view"))
#define l_setglobaldoc(l, d)   (l_pushdoc(l, d), lua_setglobal(l, "buffer"))
#define attach(w, x1, x2, y1, y2, xo, yo, xp, yp)   gtk_table_attach(GTK_TABLE(findbox), w, x1, x2, y1, y2, xo, yo, xp, yp)
#define ao_expand   (GtkAttachOptions)(GTK_EXPAND | GTK_FILL)
#define ao_normal   (GtkAttachOptions)(GTK_SHRINK | GTK_FILL)
#define lL_openlib(l, n, f)   (luaL_requiref(l, n, f, 1), lua_pop(l, 1))
#define l_setcfunction(l, n, k, f)   (lua_pushcfunction(l, f), lua_setfield(l, (n > 0) ? n : n - 1, k))
#define l_setmetatable(l, n, k, i, ni)
#define toggled(w)   gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))
#define toggle(w, b)   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b)
#define child1(p)   gtk_paned_get_child1(GTK_PANED(p))
#define child2(p)   gtk_paned_get_child2(GTK_PANED(p))

Functions

static void new_window ()
static GtkWidget * new_view (sptr_t)
static void new_buffer (sptr_t)
static void s_notify (GtkWidget *, gint, gpointer, gpointer)
static void s_command (GtkWidget *, gint, gpointer, gpointer)
static gboolean s_keypress (GtkWidget *, GdkEventKey *, gpointer)
static gboolean s_buttonpress (GtkWidget *, GdkEventButton *, gpointer)
static gboolean w_focus (GtkWidget *, GdkEventFocus *, gpointer)
static gboolean w_keypress (GtkWidget *, GdkEventKey *, gpointer)
static gboolean w_exit (GtkWidget *, GdkEventAny *, gpointer)
static GtkWidget * new_findbox ()
static void f_clicked (GtkWidget *, gpointer)
static int cc_matchfunc (GtkEntryCompletion *, const char *, GtkTreeIter *, gpointer)
static gboolean cc_matchselected (GtkEntryCompletion *, GtkTreeModel *, GtkTreeIter *, gpointer)
static void c_activate (GtkWidget *, gpointer)
static gboolean c_keypress (GtkWidget *, GdkEventKey *, gpointer)
static int lL_init (lua_State *, int, char **, int)
static void l_close (lua_State *)
static int lL_dofile (lua_State *, const char *)
static void lL_addview (lua_State *, GtkWidget *)
static void lL_removeview (lua_State *, GtkWidget *)
static void lL_adddoc (lua_State *, sptr_t)
static void lL_removedoc (lua_State *, sptr_t)
static void lL_gotodoc (lua_State *, GtkWidget *, int, int)
static int lL_event (lua_State *, const char *,...)
static void lL_notify (lua_State *, struct SCNotification *)
static void lL_showcontextmenu (lua_State *, GdkEventButton *)
static void lL_cleartable (lua_State *, int)
static void l_pushview (lua_State *, GtkWidget *)
static void l_pushdoc (lua_State *, sptr_t)
LUALIB_API int() luaopen_lpeg (lua_State *)
LUALIB_API int() luaopen_lfs (lua_State *)
static int lbuf_property (lua_State *)
static int lview__index (lua_State *)
static int lview__newindex (lua_State *)
static int lgui__index (lua_State *)
static int lgui__newindex (lua_State *)
static int lfind__index (lua_State *)
static int lfind__newindex (lua_State *)
static int lce__index (lua_State *)
static int lce__newindex (lua_State *)
static int lbuffer_check_global (lua_State *)
static int lbuffer_delete (lua_State *)
static int lbuffer_new (lua_State *)
static int lbuffer_text_range (lua_State *)
static int lview_split (lua_State *)
static int lview_unsplit (lua_State *)
static int lgui_dialog (lua_State *)
static int lgui_get_split_table (lua_State *)
static int lgui_goto_view (lua_State *)
static int lview_goto_buffer (lua_State *)
static int lgui_gtkmenu (lua_State *)
static int lstring_iconv (lua_State *)
static int lquit (lua_State *)
static int lreset (lua_State *)
static int ltimeout (lua_State *)
static int lfind_focus (lua_State *)
static int lfind_next (lua_State *)
static int lfind_prev (lua_State *)
static int lfind_replace (lua_State *)
static int lfind_replace_all (lua_State *)
static int lce_focus (lua_State *)
static int lce_show_completions (lua_State *)
int main (int argc, char **argv)
static void delete_view (GtkWidget *view)
static void delete_buffer (sptr_t doc)
static void split_view (GtkWidget *view, int vertical)
static void remove_views_from_pane (GtkWidget *pane)
static int unsplit_view (GtkWidget *view)
static void goto_view (GtkWidget *view)
static void find_add_to_history (const char *text, GtkListStore *store)
static GtkWidget * l_toview (lua_State *L, int index)
static sptr_t l_todoc (lua_State *L, int index)
static void warn (const char *s)
static int l_rawgetiint (lua_State *L, int index, int n)
static const char * l_rawgetstr (lua_State *L, int index, const char *k)
static long lL_checkscintillaparam (lua_State *L, int *narg, int type)
static GtkWidget * lL_checkview (lua_State *L, int narg)
static void lL_globaldoccheck (lua_State *L, int narg)
static void l_pushgtkmenu (lua_State *L, int index, GCallback callback, int submenu)
static int l_callscintilla (lua_State *L, int msg, int wtype, int ltype, int rtype, int arg)
static int lbuf_closure (lua_State *L)
static void set_statusbar_text (const char *text, int bar)
static void l_pushsplittable (lua_State *L, GtkWidget *c1, GtkWidget *c2)
static void m_clicked (GtkWidget *menu, gpointer id)
static gboolean emit_timeout (gpointer data)

Variables

GtkWidget * window
GtkWidget * focused_view
GtkWidget * menubar
GtkWidget * statusbar [2]
GtkAccelGroup * accel
char * textadept_home
GtkWidget * findbox
GtkWidget * find_entry
GtkWidget * replace_entry
GtkWidget * fnext_button
GtkWidget * fprev_button
GtkWidget * r_button
GtkWidget * ra_button
GtkWidget * match_case_opt
GtkWidget * whole_word_opt
GtkWidget * lua_opt
GtkWidget * in_files_opt
GtkWidget * flabel
GtkWidget * rlabel
GtkListStore * find_store
GtkListStore * repl_store
GtkWidget * command_entry
GtkListStore * cc_store
GtkEntryCompletion * command_entry_completion
lua_State * lua
int closing = FALSE
char * statusbar_text = 0
static int tVOID = 0
static int tINT = 1
static int tLENGTH = 2
static int tBOOL = 5
static int tKEYMOD = 6
static int tSTRING = 7
static int tSTRINGRESULT = 8

Define Documentation

#define ao_expand   (GtkAttachOptions)(GTK_EXPAND | GTK_FILL)
#define ao_normal   (GtkAttachOptions)(GTK_SHRINK | GTK_FILL)
#define attach (   w,
  x1,
  x2,
  y1,
  y2,
  xo,
  yo,
  xp,
  yp 
)    gtk_table_attach(GTK_TABLE(findbox), w, x1, x2, y1, y2, xo, yo, xp, yp)
#define child1 (   p)    gtk_paned_get_child1(GTK_PANED(p))
#define child2 (   p)    gtk_paned_get_child2(GTK_PANED(p))
#define l_setcfunction (   l,
  n,
  k,
 
)    (lua_pushcfunction(l, f), lua_setfield(l, (n > 0) ? n : n - 1, k))
#define l_setglobaldoc (   l,
 
)    (l_pushdoc(l, d), lua_setglobal(l, "buffer"))
#define l_setglobalview (   l,
 
)    (l_pushview(l, v), lua_setglobal(l, "view"))
#define l_setmetatable (   l,
  n,
  k,
  i,
  ni 
)
Value:
{ \
  if (luaL_newmetatable(l, k)) { \
    l_setcfunction(l, -1, "__index", i); \
    l_setcfunction(l, -1, "__newindex", ni); \
  } \
  lua_setmetatable(l, (n > 0) ? n : n - 1); \
}
#define lL_openlib (   l,
  n,
 
)    (luaL_requiref(l, n, f, 1), lua_pop(l, 1))
#define PLAT_GTK   1
#define signal (   o,
  s,
 
)    g_signal_connect(G_OBJECT(o), s, G_CALLBACK(c), 0)
#define SS (   view,
  m,
  w,
 
)    scintilla_send_message(SCINTILLA(view), m, w, l)
#define toggle (   w,
 
)    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b)
#define toggled (   w)    gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))

Function Documentation

static void c_activate ( GtkWidget *  entry,
gpointer  _ 
) [static]

Signal for the 'enter' key being pressed in the Command Entry.

static gboolean c_keypress ( GtkWidget *  _,
GdkEventKey *  event,
gpointer  __ 
) [static]

Signal for a keypress inside the Command Entry.

static int cc_matchfunc ( GtkEntryCompletion *  _,
const char *  __,
GtkTreeIter *  ___,
gpointer  ____ 
) [static]

The match function for the command entry. Since the completion list is filled by Lua, every item is a "match".

static gboolean cc_matchselected ( GtkEntryCompletion *  _,
GtkTreeModel *  model,
GtkTreeIter *  iter,
gpointer  __ 
) [static]

Replaces the current word (consisting of alphanumeric and underscore characters) with the match text.

static void delete_buffer ( sptr_t  doc) [static]

Removes the Scintilla buffer from the current Scintilla view.

Parameters:
docThe Scintilla document.
See also:
lL_removedoc
static void delete_view ( GtkWidget *  view) [static]

Removes a Scintilla view.

Parameters:
viewThe Scintilla view to remove.
See also:
lL_removeview
static gboolean emit_timeout ( gpointer  data) [static]
static void f_clicked ( GtkWidget *  button,
gpointer  _ 
) [static]

Signal for a find box button click.

static void find_add_to_history ( const char *  text,
GtkListStore *  store 
) [static]

Adds the given text to the find/replace history list if it is not at the top.

Parameters:
textThe text to add.
storeThe GtkListStore to add the text to.
static void goto_view ( GtkWidget *  view) [static]

Change focus to the given Scintilla view. Generates 'view_before_switch' and 'view_after_switch' events.

Parameters:
viewThe Scintilla view to focus.
static int l_callscintilla ( lua_State *  L,
int  msg,
int  wtype,
int  ltype,
int  rtype,
int  arg 
) [static]

Calls a function as a Scintilla function. Does not remove any arguments from the stack, but does push results.

Parameters:
LThe Lua state.
msgThe Scintilla message.
wtypeThe type of Scintilla wParam.
ltypeThe type of Scintilla lParam.
rtypeThe type of the Scintilla return.
argThe stack index of the first Scintilla parameter. Subsequent elements will also be passed to Scintilla as needed.
Returns:
number of results pushed onto the stack.
See also:
lL_checkscintillaparam
static void l_close ( lua_State *  L) [static]

Closes the Lua state. Unsplits and destroys all Scintilla views and removes all Scintilla documents, before closing the state.

Parameters:
LThe Lua state.
static void l_pushdoc ( lua_State *  L,
sptr_t  doc 
) [static]

Pushes the Scintilla document onto the stack. The document must have previously been added with lL_adddoc.

Parameters:
LThe Lua state.
docThe document to push.
See also:
lL_adddoc
static void l_pushgtkmenu ( lua_State *  L,
int  index,
GCallback  callback,
int  submenu 
) [static]

Pushes a GTK menu created from the table at the given valid index onto the stack. Consult the LuaDoc for the table format.

Parameters:
LThe Lua state.
indexThe stack index of the table to create the menu from.
callbackA GCallback associated with each menu item.
submenuFlag indicating whether or not this menu is a submenu.
static void l_pushsplittable ( lua_State *  L,
GtkWidget *  c1,
GtkWidget *  c2 
) [static]
static void l_pushview ( lua_State *  L,
GtkWidget *  view 
) [static]

Pushes the Scintilla view onto the stack. The view must have previously been added with lL_addview.

Parameters:
LThe Lua state.
viewThe Scintilla view to push.
See also:
lL_addview
static int l_rawgetiint ( lua_State *  L,
int  index,
int  n 
) [static]

Returns the value t[n] as an integer where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods.

Parameters:
LThe Lua state.
indexThe stack index of the table.
nThe index in the table to get.
Returns:
integer
static const char* l_rawgetstr ( lua_State *  L,
int  index,
const char *  k 
) [static]

Returns the value t[k] as a string where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods.

Parameters:
LThe Lua state.
indexThe stack index of the table.
kString key in the table to get.
Returns:
string
static sptr_t l_todoc ( lua_State *  L,
int  index 
) [static]

Returns the buffer at the given acceptable index as a Scintilla document.

Parameters:
LThe Lua state.
indexStack index of the buffer.
Returns:
Scintilla document
static GtkWidget* l_toview ( lua_State *  L,
int  index 
) [static]

Returns the view at the given acceptable index as a Scintilla view.

Parameters:
LThe Lua state.
indexStack index of the view.
Returns:
Scintilla view
static int lbuf_closure ( lua_State *  L) [static]
static int lbuf_property ( lua_State *  L) [static]
static int lbuffer_check_global ( lua_State *  L)
static int lbuffer_delete ( lua_State *  L)
static int lbuffer_new ( lua_State *  L)
static int lbuffer_text_range ( lua_State *  L)
static int lce__index ( lua_State *  L)
static int lce__newindex ( lua_State *  L)
static int lce_focus ( lua_State *  L)
static int lce_show_completions ( lua_State *  L)
static int lfind__index ( lua_State *  L)
static int lfind__newindex ( lua_State *  L)
static int lfind_focus ( lua_State *  L)
static int lfind_next ( lua_State *  L)
static int lfind_prev ( lua_State *  L)
static int lfind_replace ( lua_State *  L)
static int lfind_replace_all ( lua_State *  L)
static int lgui__index ( lua_State *  L)
static int lgui__newindex ( lua_State *  L)
static int lgui_dialog ( lua_State *  L)
static int lgui_get_split_table ( lua_State *  L)
static int lgui_goto_view ( lua_State *  L)
static int lgui_gtkmenu ( lua_State *  L)
static void lL_adddoc ( lua_State *  L,
sptr_t  doc 
) [static]

Adds a Scintilla document with a metatable to the 'buffers' registry table.

Parameters:
LThe Lua state.
docThe Scintilla document to add.
static void lL_addview ( lua_State *  L,
GtkWidget *  view 
) [static]

Adds the Scintilla view with a metatable to the 'views' registry table.

Parameters:
LThe Lua state.
viewThe Scintilla view to add.
static long lL_checkscintillaparam ( lua_State *  L,
int *  narg,
int  type 
) [static]

Checks whether the function argument narg is the given Scintilla parameter type and returns it cast to the proper type.

Parameters:
LThe Lua state.
nargThe stack index of the Scintilla parameter.
typeThe Scintilla type to convert to.
Returns:
Scintilla param
static GtkWidget* lL_checkview ( lua_State *  L,
int  narg 
) [static]

Checks whether the function argument narg is a Scintilla view and returns this view cast to a GtkWidget.

Parameters:
LThe Lua state.
nargThe stack index of the Scintilla view.
Returns:
Scintilla view
static void lL_cleartable ( lua_State *  L,
int  index 
) [static]

Clears a table at the given valid index by setting all of its keys to nil.

Parameters:
LThe Lua state.
indexThe stack index of the table.
static int lL_dofile ( lua_State *  L,
const char *  filename 
) [static]

Loads and runs the given file.

Parameters:
LThe Lua state.
filenameThe file name relative to textadept_home.
Returns:
1 if there are no errors or 0 in case of errors.
static int lL_event ( lua_State *  L,
const char *  name,
  ... 
) [static]

Emits an event.

Parameters:
LThe Lua state.
nameThe event name.
...Arguments to pass with the event. Each pair of arguments should be a Lua type followed by the data value itself. For LUA_TLIGHTUSERDATA and LUA_TTABLE types, push the data values to the stack and give the value returned by luaL_ref(); luaL_unref() will be called appropriately. The list must be terminated with a -1.
Returns:
TRUE or FALSE depending on the boolean value returned by the event handler, if any.
static void lL_globaldoccheck ( lua_State *  L,
int  narg 
) [static]

Checks whether the function argument narg is a Scintilla document. If not, raises an error.

Parameters:
LThe Lua state.
nargThe stack index of the Scintilla document.
Returns:
Scintilla document
static void lL_gotodoc ( lua_State *  L,
GtkWidget *  view,
int  n,
int  relative 
) [static]

Switches to a document in the given view.

Parameters:
LThe Lua state.
viewThe Scintilla view.
nRelative or absolute index of the document to switch to. An absolute n of -1 represents the last document.
relativeFlag indicating whether or not n is relative.
static int lL_init ( lua_State *  L,
int  argc,
char **  argv,
int  reinit 
) [static]

Initializes or re-initializes the Lua state. Populates the state with global variables and functions, then runs the 'core/init.lua' script.

Parameters:
LThe Lua state.
argcThe number of command line parameters.
argvThe array of command line parameters.
reinitFlag indicating whether or not to reinitialize the Lua state.
Returns:
TRUE on success, FALSE otherwise.
static void lL_notify ( lua_State *  L,
struct SCNotification *  n 
) [static]

Emits a Scintilla notification event.

Parameters:
LThe Lua state.
nThe Scintilla notification struct.
See also:
lL_event
static void lL_removedoc ( lua_State *  L,
sptr_t  doc 
) [static]

Removes the Scintilla document from the 'buffers' registry table. The document must have been previously added with lL_adddoc. It is removed from any other views showing it first. Therefore, ensure the length of 'buffers' is more than one unless quitting the application.

Parameters:
LThe Lua state.
docThe Scintilla document to remove.
See also:
lL_adddoc
static void lL_removeview ( lua_State *  L,
GtkWidget *  view 
) [static]

Removes the Scintilla view from the 'views' registry table. The view must have been previously added with lL_addview.

Parameters:
LThe Lua state.
viewThe Scintilla view to remove.
See also:
lL_addview
static void lL_showcontextmenu ( lua_State *  L,
GdkEventButton *  event 
) [static]

Shows the context menu for a Scintilla view based on a mouse event.

Parameters:
LThe Lua state.
eventThe mouse button event.
static int lquit ( lua_State *  L)
static int lreset ( lua_State *  L)
static int lstring_iconv ( lua_State *  L)
static int ltimeout ( lua_State *  L)
LUALIB_API int() luaopen_lfs ( lua_State *  )
LUALIB_API int() luaopen_lpeg ( lua_State *  )
static int lview__index ( lua_State *  L)
static int lview__newindex ( lua_State *  L)
static int lview_goto_buffer ( lua_State *  L)
static int lview_split ( lua_State *  L)
static int lview_unsplit ( lua_State *  L)
static void m_clicked ( GtkWidget *  menu,
gpointer  id 
) [static]
int main ( int  argc,
char **  argv 
)

Runs Textadept. Initializes the Lua state, creates the user interface, and then runs `core/init.lua` followed by `init.lua`.

Parameters:
argcThe number of command line params.
argvThe array of command line params.
static void new_buffer ( sptr_t  doc) [static]

Creates a new Scintilla document and adds it to the Lua state. Generates 'buffer_before_switch' and 'buffer_new' events.

Parameters:
docAlmost always zero, except for the first Scintilla view created, in which its doc pointer would be given here.
See also:
lL_adddoc
static GtkWidget * new_findbox ( ) [static]

Creates the Find box.

static GtkWidget * new_view ( sptr_t  doc) [static]

Creates a new Scintilla view. Generates a 'view_new' event.

Parameters:
docThe document to load in the new view. Almost never zero, except for the first Scintilla view created, in which there is no doc pointer.
Returns:
Scintilla view
See also:
lL_addview
static void new_window ( ) [static]

Creates the Textadept window. The window contains a menubar, frame for Scintilla views, hidden find box, hidden command entry, and two status bars: one for notifications and the other for buffer status.

static void remove_views_from_pane ( GtkWidget *  pane) [static]

Remove all Scintilla views from the given pane and delete them.

Parameters:
paneThe GTK pane to remove Scintilla views from.
See also:
delete_view
static gboolean s_buttonpress ( GtkWidget *  _,
GdkEventButton *  event,
gpointer  __ 
) [static]

Signal for a Scintilla mouse click.

static void s_command ( GtkWidget *  view,
gint  wParam,
gpointer  _,
gpointer  __ 
) [static]

Signal for a Scintilla command. Currently handles SCEN_SETFOCUS.

static gboolean s_keypress ( GtkWidget *  view,
GdkEventKey *  event,
gpointer  _ 
) [static]

Signal for a Scintilla keypress.

static void s_notify ( GtkWidget *  view,
gint  _,
gpointer  lParam,
gpointer  __ 
) [static]

Signal for a Scintilla notification.

static void set_statusbar_text ( const char *  text,
int  bar 
) [static]
static void split_view ( GtkWidget *  view,
int  vertical 
) [static]

Splits the given Scintilla view into two views. The new view shows the same document as the original one.

Parameters:
viewThe Scintilla view to split.
verticalFlag indicating whether to split the view vertically or horozontally.
static int unsplit_view ( GtkWidget *  view) [static]

Unsplits the pane a given Scintilla view is in and keeps the view. All views in the other pane are deleted.

Parameters:
viewThe Scintilla view to keep when unsplitting.
See also:
remove_views_from_pane
delete_view
static gboolean w_exit ( GtkWidget *  _,
GdkEventAny *  __,
gpointer  ___ 
) [static]

Signal for exiting Textadept. Generates a 'quit' event. Closes the Lua state and releases resources.

See also:
l_close
static gboolean w_focus ( GtkWidget *  _,
GdkEventFocus *  event,
gpointer  __ 
) [static]

Signal for a Textadept window focus change.

static gboolean w_keypress ( GtkWidget *  _,
GdkEventKey *  event,
gpointer  __ 
) [static]

Signal for a Textadept keypress. Currently handled keypresses:

  • Escape: hides the find box if it is open.
static void warn ( const char *  s) [static]

Prints a warning.

Parameters:
sThe warning to print.

Variable Documentation

GtkAccelGroup* accel
GtkListStore* cc_store
int closing = FALSE
GtkWidget* command_entry
GtkEntryCompletion* command_entry_completion
GtkWidget * find_entry
GtkListStore* find_store
GtkWidget* findbox
GtkWidget * flabel
GtkWidget * fnext_button
GtkWidget * focused_view
GtkWidget * fprev_button
GtkWidget * in_files_opt
lua_State* lua
GtkWidget * lua_opt
GtkWidget * match_case_opt
GtkWidget * menubar
GtkWidget * r_button
GtkWidget * ra_button
GtkListStore * repl_store
GtkWidget * replace_entry
GtkWidget * rlabel
GtkWidget * statusbar[2]
char* statusbar_text = 0
int tBOOL = 5
int tINT = 1
int tKEYMOD = 6
int tLENGTH = 2
int tSTRING = 7
int tSTRINGRESULT = 8
int tVOID = 0 [static]
GtkWidget * whole_word_opt
GtkWidget* window