Additional tools
In these days of rapid application development, using plaintext editors like notepad or vi can be really inconvenient and time consuming. Luckily, there is far better alternative— an Integrated Development Environment (IDE). IDEs are tools that allow efficient code creation and editing, support testing your code from within the editor, and usually also offer debugging capabilities.
At the time of writing this book, there are two IDEs worth mentioning: Eclipse and Komodo. Both support syntax highlighting and coloring, auto completion, creating launch configurations, managing projects and dependencies, and have many other useful features.
Eclipse
It is hardly possible that you have not heard about Eclipse nowadays. An open source IDE supporting a wide variety of languages, extensible with plugins is considered as one of the best programming environments, and it is all free. Due to the fact that Eclipse was developed in Java, the CPU/memory requirements may be slightly higher than in case of native applications, but in return, it is available for the Windows, Linux, and Mac platforms.
First you have to install the Java Runtime Environment (JRE), we strongly suggest installing latest version available (at the moment it is version 6 Update 17), you can get it from http://java.com. We will discuss Eclipse Classic 3.5.0 available for download at http://www.eclipse.org/downloads/. The installation process is simple—just download and unzip the file to a location of your choice and run eclipse.exe
. The full description of Eclipse is out of scope of this book, we will present only the necessary steps to get it running for Tcl development purposes.
By default, Eclipse supports only Java development, so we have to install an additional extension called the Dynamic Languages Toolkit (DLTK) for Tcl support. In order to do this it, you have to navigate to the Help | Install New Software… menu. A new window will show up, as shown in the following screenshot:
First, select the Galileo site from the list at the top. Eclipse will download a list of all available extensions from this site; this may take a while. Once the list is visible, expand Programming Languages and select Dynamic Languages Toolkit TCL Development Tools. Once you click on Next, Eclipse will automatically resolve dependencies and select all the necessary plugins to install. In this case, it will choose to install the DLTK Core and Eclipse Modelling Framework (EMF) extensions, as shown in the following screenshot:
Following this, Eclipse will download and install all the necessary files, and ask you to restart. Once it is done, you have to configure installed Tcl interpreters. Eclipse requires at least one interpreter in order to be able to run scripts. To configure it, navigate to Window | Preferences to open the preferences dialog, and then go to Tcl | Interpreters. Click the Add… button on this pane, and then Browse… and navigate to the interpreter binary, which is installed at C:\Tcl\bin\tclsh85.exe
. Once done, you should have configured the default interpreter like here, as shown in the following screenshot:
Now you have your Eclipse fully configured to create and run Tcl scripts! To get a taste of working with Eclipse, let's create the same Hello World example. Navigate to File | New | Project… and choose Tcl Project from the Tcl category and then create a project named TclHelloWorld—it will be shown in the Script Explorer view (by default, on the left of the Eclipse window). The next step is to right-click on the project name in this view and select Tcl File, and name it main.tcl
. As a template, select Tcl File. Eclipse will create the file with a specific header that we will explain later. Add the puts
command to that script, just as you did in the previous example. Now it is time to execute the script—right-click on it and select Run As | Tcl Script. The output of this execution will be visible in the Console view. The following screen illustrates it:
Komodo
Komodo, available for download at http://www.activestate.com/komodo, comes in two flavors: free Komodo Edit and paid Komodo IDE. Both support a wide range of scripting languages, including PHP, Ruby, Python, and of course Tcl. The first one is a simple editor with syntax checking and coloring, and also Project Management abilities. The second one extends the offered functionality as it comes with a debugger.
Similar to Eclipse, you can create a project (using File | New | New Project…) and a file inside it (right-click on project name in the left pane and select Add | New file…). The new file is created based on a language-specific template, which comes with the universal header described later in this chapter.
To run the script, navigate to Tools | Run Command… and enter tclsh85 %F
in the Run dialog, and then click on the Run button.
tkcon an alternate Tcl shell
If you find the standard Tcl shell too primitive, you must definitely have a look at tkcon—a standard console replacement with many useful features including a command history and syntax highlighting. What is even more interesting is that it is implemented as another Tcl package, and therefore it is perfectly possible to embed tkcon in to your Tcl application. The following is a screenshot of tkcon console, with the puts $auto_path
command's output:
Tkcon is, by default, included in the ActiveTcl distribution. To install it on Ubuntu, enter:
% sudo apt-get install tkcon .
In order to run it, simply execute the command tkcon
.