Monday, March 31, 2008

Using JEdit with OpenLaszlo and Flex

I like to use JEdit for many "quick and dirty" revisions, especially when I don't want to deal with a full-fledged Java IDE's need for IDE-specific set-up like projects. JEdit can be especially useful for making minor changes to a particular file. I really grew to like JEdit for Ruby text file editing (no compiling, building, or assembling needed in that situation). In this blog entry, I'll demonstrate how easy it is to configure JEdit to employ XML color coding for OpenLaszlo's XML-based LZX language and for Flex's XML-based MXML language.

If you don't do anything to associate LZX or MXML files with XML in JEdit, they will appear as shown in the following two screen snapshots (click on images to see larger versions). The OpenLaszlo file is shown first, followed by the MXML file. Note that there is no color coded syntax in either example.

To enable color syntax highlighting for any file currently open in the JEdit buffer, one can use JEdit's Utilities->Buffer Options->Edit Mode and select "XML" as the Edit Mode. This is shown in the next screen snapshot.

Color syntax highlighting based on XML grammar will then be applied to the file in the buffer. The primary disadvantage to this approach is that it is only temporary.

A more permanent solution is to use JEdit's Utilities->Global Options->Editing tool. The "Change settings for mode:" option should be changed to XML, the checkbox next to "Use default settings" should be unchecked, and then the extensions "lzx" and "mxml" should be added to the text field next to the label "File name glob:"

The next screen snapshots show this window when XML has been selected, but the Default Settings are still in place and the "mxml" and "lzx" extensions have not been added to the "File name glob" field.

After the changes described above have been made ("lzx" and "mxml" added), the window looks like the next screen snapshot.

With the LZX and MXML file types now associated in JEdit as XML source, color highlighting will be available for those types of files. This is demonstrated in the next two screen snapshots, again with the LZX example first, followed by the MXML example. Notice now they both have color highlighting.

You may also have noticed that the JEdit Global Options window in which we set the "File name glob" also has a "First line glob." What this means is that you don't even need to specify lzx and mxml as file extensions in the "File name glob" if you always have an XML prolog in the first line of your LZX and MXML files. For example, I could add the line <?xml version = '1.0'?> to the top of my .mxml and .lzx files and get XML color coding in JEdit via the XML option without ever explicitly associating those file types with XML. However, I like to explicitly associate MXML and LZX with XML in JEdit as shown above to ensure that my LZX and MXML files are displayed with color syntax even if the prolog line is left off.

JEdit does not supply all the features of a full-fledged IDE, but that is also its primary advantage at times when those additional features are not necessary. However, as proven by a recent online survey ("Do you use syntax coloring?"), nearly every Java developer uses color syntax to some degree. The easy steps demonstrated in this blog entry allow one to enjoy syntax coloring for OpenLaszlo LZX files and for Flex MXML files when using JEdit.

Of course, most modern IDEs and text editors offer similar capabilities for associating other file extensions with a known XML file type. The steps to do this are particular to each IDE or text editor.

No comments: