GtkEditor Tutorial

GtkEditor is a source code editor widget for GTK+. The longterm goal of GtkEditor is to provide a framework for source code editing in GTK+ applications, whether just for editing macros or for full fledged IDEs. We try to achieve this through a highly configurable editor widget sub-classing the GtkText widget. After initialisation, the editor widget can be treated as the usual text widget, and all source-code editing features are taken care of by the widget itself. The behaviour of the editor is decided by dynamic libraries loaded during initialisation of the widget, or statically linked with the application using the widget. These libraries can be hand-coded or created using tools supplied with GtkEditor.

From version 0.1.8 and forth, the underlying text widget is the TkText port that will be the official text widget from gtk+ 1.4, or rather the editor is a subclass of GtkTextBuffer from this widget. This means that applications cannot treat the editor as the gtktext widget of gtk+ 1.2. If this is needed we suggest using GtkEditor version 0.1.5.

In this tutorial we will go through the steps needed to configure the widget to the language it should edit. This configuration amounts to setting up a scanner for the language and associating tokens with font properties to configure syntax highlighting. We will not describe the editor API in detail, nor discuss the inner workings of the editor. For this we refer to [TNG-DD].

This tutorial is written for GtkEditor version 0.1.8. It is not consistent with versions earlier than that, and it might be inconsistent with later versions.

Overview

In the first chapter we describe the creation of a GtkEditor widget. In the second chapter we describe the GtkEditorScanner, what it is used for and how to configure an editor widget to use it. In the following chapter we describe how to configure highlighting once a scanner has been installed.

On the first reading of this tutorial, you might want to skip the section called Linking Scanners with the Application in Chapter 2 and the section called Creating a new Scanner in Chapter 2 and return to them later.