Friday, December 5, 2008

Setting up Erlang

I've been hearing alot about Erlang lately. However, I have yet to see a good guide on getting it set up in an IDE. So without further ado, a step by step guide to getting started with Erlang in Textpad:

  • Download and install the Erlang run-time from here.
  • If you do not already have TextPad, obtain it here.

That was the easy part. Now lets set up TextPad to do some code highlighting.

  • Download a .syn file for Erlang and place it in the system folder of TextPad. For me, this folder was C:\Program Files\TextPad 5\system. I'm not quite sure who did this syn file (the site is in another language), but they did a good enough job.
  • Open up TextPad. Ensure no files are opened. Go to the 'Configure' menu, and select 'Preferences'. In the preferences window, click 'Document Classes'. There should be a list of currently recognized languages. Click the 'New' button (it is right under the list of languages), and type 'Erlang'. Click apply.
  • Click the '+' button next to 'Document Classes'. This should expand the list, and Erlang should now be on it. Click Erlang. You should see a list of file extensions associated with Erlang, click 'New', and type '*.erl'.
  • Now click the '+' button next to 'Erlang' on the left. This should expand a list of several more menus. Click on 'Syntax'. Click the drop down menu and select erlang.syn. If erlang.syn is not there, then the .syn file was not properly placed.
  • Feel free to edit some other syntax options to customize TextPad to your liking.

Now we have set up TextPad to highlight Erlang files. The last thing we will learn to do is set up TextPad to compile Erlang files.

  • In the preferences menu again, click 'tools' on the left.
  • Click the 'Add' button and select 'Program...'. Navigate to the erl5.6.5\erts-5.6.5\bin\ folder and select erlc.exe. Select and single click the new entry in the list to rename it. Click 'Apply'.
  • Now click the '+' button next to Tools on the left. Select erlc, or whatever you have named the new tool (I named mine 'Compile Erlang'). The parameters field needs to read '$File', and the initial folder field should read '$FileDir'.

Now you should be able to compile your Erlang files from the tools -> external tools menu, or of course much more efficiently by keyboard shortcut. Note: compiling from within TextPad has major problems and will drive you crazy. More on this later.

From this point on, simply follow whatever tutorial your using. If you haven't found good one yet, this one is pretty useful, and includes instructions on how to interact with the shell(which you will need to actually run Erlang), and of course, how to actually write Erlang programs.

Now, there are two things I would like to know. Number one: how can TextPad be set up so that, when there is a compilation error, a user can double click the error to have the offending line highlighted? It works with java, there may be a way to do it with Erlang. Number two: how can TextPad be set up so that Erlang programs can actually be run from it?