Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Build an Eclipse development environment for Perl, Python, and PHP

Use the Dynamic Languages Toolkit (DLTK) to create your own IDE

Matthew Scarpino, Java Developer, Eclipse Engineering, LLC
Matthew Scarpino is a project manager and Java developer at Eclipse Engineering LLC. He is the lead author of SWT/JFace in Action and made a minor but important contribution to the Standard Widget Toolkit (SWT). He enjoys Irish folk music, marathon running, the poetry of William Blake, and the Graphical Editing Framework (GEF).
(An IBM developerWorks Contributing Author)
Nathan A. Good, Senior Consultant and Freelance Developer, Freelance Developer
Nathan Good
Nathan A. Good lives in the Twin Cities area of Minnesota. Professionally, he does software development, software architecture, and systems administration. When he's not writing software, he enjoys building PCs and servers, reading about and working with new technologies, and trying to get his friends to make the move to open source software. He's written and co-written many books and articles, including Professional Red Hat Enterprise Linux 3, Regular Expression Recipes: A Problem-Solution Approach, and Foundations of PEAR: Rapid PHP Development.

Summary:  Eclipse presents a wealth of capabilities for building tools for compiled languages like C and the Java™ programming language but provides little support for scripting languages like Perl, Python, and PHP. For these and similar languages, the Eclipse Dynamic Languages Toolkit (DLTK) comes to the rescue. Walk through the process of building a DLTK-based IDE, and discover sample code for each step.

Date:  27 Oct 2011 (Published 03 Feb 2009)
Level:  Intermediate PDF:  A4 and Letter (596 KB | 38 pages)Get Adobe® Reader®

Activity:  130784 views
Comments:  

Introducing DLTK and the DLTK editor

Eclipse offers many capabilities for building custom development tools, but they're not easy to use or understand. Many of the classes, such as TextEditor, require significant configuration to work properly. In contrast, the DLTK provides a prepackaged development environment that requires only minor tweaking to be operational. Building a development tool with the DLTK is like baking a cake from a mix: The output isn't completely original, but you get a maximum of quality and reliability with a minimum of effort.

A second important difference between DLTK and Eclipse involves the supported languages. Eclipse's build capabilities are based on compiled languages like Java, C, and C++. The DLTK is geared toward dynamic languages, which include scripting languages like PHP, Ruby, and Tcl. Ideally, a development tool for these languages supports easy integration of script interpreters, command evaluation on a line-by-line basis, and the ability to enter commands at a console. Eclipse doesn't provide these features, but the DLTK supports them all.

Install the DLTK

If you haven't installed the DLTK, do so now. Perform the following steps:

  1. Open Eclipse, then click Help > Install New Software.
  2. Select Indigo - http://download.eclipse.org/releases/indigo from the Work with list.
  3. Select the General Purpose Tools > Dynamic Languages Toolkit - Core Frameworks check box, then click Next.
  4. Click Next after reviewing the prerequisites that will also be installed.
  5. If you accept the license agreements, click Finish to install the plug-in.
  6. After installing the files, restart Eclipse.

The DLTK-based plug-in project: The Octave IDE

This tutorial does more than just discuss the DLTK and its features. It walks you through the steps of creating an DLTK-based IDE for the Octave scripting language. Octave is a GPL-licensed toolset for performing mathematical computation, particularly with matrices. Octave commands are easy to understand, and the language closely resembles that of the popular proprietary Matlab tool. You can download the example code from Download.

The Octave IDE you'll be building won't have all of Eclipse's bells and whistles, but you will be able to create Octave scripts (*.m files), edit them in a multifeatured text editor, run the Octave interpreter with the click of a button, and see the result displayed in the IDE's console. Figure 1 shows what the editor and console look like.


Figure 1. The Octave IDE
Screenshot of the Octave ID editing the file test.m with code in the upper window and console output in the lower window

This tutorial explains the process of building the Octave IDE in four steps:

  1. Create the Octave editor and add features.
  2. Store and respond to user preferences.
  3. Integrate the Octave interpreter.
  4. Display the interpreter's output in the console.

The first task deals with the Octave script editor. There's a lot to learn about this subject, but before you start coding, let's take a step back and look at how DLTK editors work. Much of this discussion applies to all Eclipse text editors.


A high-level introduction to the DLTK text editor

At its most basic level, the DLTK text editor is just a regular SWT StyledText widget with a lot of additional capabilities. These capabilities fall into one of two categories:

  • Responding to user events. Changing the editor's display according to the user's keystrokes
  • File I/O. Transferring character data between the IDE and files on the user's system

In DLTK editors, event handling is managed by a ScriptSourceViewer object. This object, created by the ScriptEditor, wraps around the StyledText widget and manages its response to user keystrokes. Typically, this response involves modifying the widget's presentation or updating the editor's internal data. This data is embodied in an IDocument object, which not only stores text but also information related to line numbers, positions, and regions, called partitions.

The ScriptSourceViewer updates the IDocument by accessing an object called a SourceModuleDocumentProvider. In addition to providing access to the IDocument, this object handles file operations. DLTK handles all the editor's file interactions for you, but if you're interested in learning more, read the documentation on the object's superclass: TextFileDocumentProvider.

If you're familiar with the MVC pattern, the relationship between the ScriptSourceViewer, IDocument, and StyledText widget should be clear. The IDocument serves as the editor's Model aspect, containing data independent of its presentation. The StyledText widget represents the editor's View aspect, and the ScriptSourceViewer serves as the Controller, managing communication among the Model, the View, and the user. Figure 2 shows this relationship.


Figure 2. Primary elements of the DLTK editor
Diagram shows the IDocument (model) feeding into the ScriptSourceViewer (controller) which feeds the StyledText (view)

If the explanation thus far makes sense and Figure 2 seems reasonable, you should have no difficulty understanding the technical discussion that follows. In the next section, you start creating the Octave plug-in.

2 of 10 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=366849
TutorialTitle=Build an Eclipse development environment for Perl, Python, and PHP
publish-date=10272011
author1-email=mattscar@yahoo.com
author1-email-cc=
author2-email=mail@nathanagood.com
author2-email-cc=