I was writing a quick answer to a reader concerning how to use jEdit to browse ActionScript code in a tree view, and when I suddenly realized the current solution wasn’t good enough. But after banging around on some source code this evening (and with the help of Ali Rantakari), order I think I’ve managed to make an AS 1, check 2 or 3 code browser that rivals a few I’ve seen on other platforms. Isn’t open source wonderful?
Warning: This article goes into some depth regarding customizing jEdit, Ctags and the Sidekick plugin. If you want to be spared the details, you can always skip to the end and just reap the rewards: A shiny new code browser custom-made for ActionScript!
A little background
JEdit’s optional CTagsSidekick plugin can be used to parse any language supported by the Exuberant Ctags parser. The plugin uses Ctags to parse through the current buffer and present the defined tags it finds in the SideKick tree.
Unfortunately, ActionScript is not one of the 34 languages supported “out of the box” by Ctags, so we have to do a little hacking to get things to work the way we want. Thanks to the work of a few pioneers, however, it’s easy enough to introduce ActionScript parsing to Ctags, and therefore, to jEdit itself.
Much of the credit for this hack goes to Sean Voisen, who did a lot of work three years ago to bring peace between the warring jEdit and ActionScript development. Unfortunately, I was a day late getting to Sean’s site, and he wiped it clean of all things jEdit last month (d’oh!). Fortunately, Richard Leider’s site still contains mention of Sean’s work, and also provides a copy of a language definition file that I used as the basis for my own AS 1, 2 and 3 parser, actionscript.c, which Ali Rantakari immediately made even better. (Update: Ali’s changes have been incorporated into both the source code here and the precompiled binary available below.)
To get everything I wanted out of the Sidekick panel, I had to gather a couple of things from elsewhere on the Web, as well as make a few files of my own:
- Start with Shlomy Reinstein’s CtagsSidekick plugin for jEdit. This can be installed through the editor’s Plugin Manager and docked on either side of the main edit window. To provide its power, it relies on the Exuberant CTags command-line tool, so of course we’ll also need…
- The latest “Source only distribution” of Exuberant Ctags. (Note: If the idea of compiling C source files makes you queasy, I’ve provided a link to a precompiled version of the modified file in Step 5B below.)
- Our edited actionscript.c file (Again, if you plan to use the precompiled version, you can skip this file, too).
- Our “easy-on-the-eyes” replacement icons for the CtagsSidekick plugin (This is optional. You may be perfectly happy with the default CtagsSidekick icon set. Personally, it hurts my ears.)
Step 0: Set up jEdit to parse AS files
Once you have installed the CtagsSidekick plugin, you must instruct jEdit to use the new plugin when parsing *.as files. To do so, select Plugins>Plugin Options>Sidekick>Parsers and set the actionscript Mode‘s Parser value to ctags. Press Ok, and jEdit is ready to go. (Unfortunately, CTags is not, but we’re going to fix that). You can close jEdit for now.
As I mentioned above, the instructions presented below detail how to build and modify the CTags command-line tool to your own liking. If you want to skip the technical details, you can always skip to Step 5B, download the precompiled OS X binary, and be done with it. Otherwise, let’s get on with it…
Step 1: Create the files necessary to build ctags
Open a terminal window and change to the directory in which you saved the ctags-*.*.tar.gz file above. For me, this was my Desktop, so I entered:
Then, unpack the source archive (Note: I was using ctags version 5.7; if yours is different, use the filename you downloaded above):
tar xzf ctags-5.7.tar.gz
This will create a folder named ctags-5.7 on your desktop (or in whichever folder you happen to be working). Now you must move the downloaded actionscript.c file into this folder. You can do this by dragging it in the finder or, since you’re already using the terminal, by entering the following (assuming you saved the actionscript.c file to the same folder in which you save the ctags archive:
mv actionscript.c ctags-5.7
Note: I like a lot of information (function arguments, variable datatypes and return types, for instance) in my code tree, so the actionscript.c file (and the resulting binary) has been tuned to my tastes. If you’re feeling ambitious (or just hate what I’ve done), feel free to edit the regular expressions to your own tastes and recompile at will.
And now, let’s change to the source directory for our next step:
Step 2: Add ActionScript support to the cTags source:
Now we need to edit two files, source.mak and parsers.h to ensure that ctags knows what it needs to properly parse ActionScript code (Bonus tip: From a terminal window, you can launch files in jEdit by typing
open -a jedit filename).
In source.mak, we need to add a line that says “
actionscript.c \” under SOURCES and “
actionscript.$(OBJEXT) \” under OBJECTS.
In parsers.h, we need to add the following line under #define PARSER_LIST:
Step 3: Build the ctags binary from source
In the terminal window, make sure you are still in the ctags source directory (and that the actionscript.c you downloaded earlier is there, too) and type:
If everything works out, you should see a series of “checking for…” lines and eventually, you’ll return to a command prompt (and no error messages). If you see error messages, check your work above and try, try again. Otherwise, go ahead and “make” the ctags application:
And if that works, install your shiny new ctags tool (you will need your administrative password for this one):
sudo make install
Step 5: Verify ctags has ActionScript support now
Still at the command prompt, type the following and ensure that you you see “ActionScript” in the list of languages that appears:
If you see “ActionScript” somewhere in the list, you’re good to go! If not, chances are you have anotherversion of ctags somewhere in your command path that may be taking precedence over the new one. If this is the case, and you can’t figure it out, drop me a line. Maybe we can muck through it together.
Step 5b: Cheat and download our prebuilt binary
Ok, if all those steps confound you, or if you just don’t want to bother rolling your own command-line tools (and if you’re using OS X), you can skip all the make/compile stuff and just download our precompiled ctags binary package, unzip the file, and place the included ctags file somewhere in your path (e.g., /usr/local/bin). You may need to make the file executable as well (from the terminal,
chmod 755 /path/to/ctags).
Step 6: Parse some ActionScript
Launch jEdit, and open an ActionScript file. If the Sidekick dock is not already open, use the Plugins Options menu to open it. You should see a list of all the methods, variables, classes, etc. in the current buffer (If not, hmmph… check your work above.) It will look something like this:
Step 7: Make it prettier (optional)
I say something like this, because you may notice that the icons look different from those shown above. That’s because I made my own, which you can download from here, unzip, and install by running the enclosed install.sh shell file in a terminal window (be sure you’re in the same directory as the install file. You may need to
chmod 755 install.sh before you can run it). Note: The file contains a README.txt file that offers alternate installation instructions, too.
Note: On windows, you can unzip the file, change to the resulting directory within a command line window, and type
jar uf /path/to/jars/CtagsSideKick.jar -C . icons, replacing the path with the correct value for your system.
And now the shortcut:
I know it sounds like a lot of work, but it’s actually not, now that most of the work has been done. This is the beauty of open-source software â€“ one person can muck around and make changes, improvements, etc. â€“ and anyone else can benefit.
In fact, all the steps and procedures defined above can now be boiled down to two or three items (if any of ’em confuse you, you can always peek up at the explanations above):
- Download and unpack ctags with actionscript support and place the ctags file in your executable path. (More detail in comment No. 7 below!)
- Install the CtagsSidekick plugin through jEdit’s Plugin Manager and change the Sidekick plugins’ settings to use Ctags to parse ActionScript.
- Install the optional icon sets. Instructions are included within the zip file.
And that’s it! Go and code your masterpiece!