jump to navigation

Tags for Erlang 17 March 2008

Posted by Oliver Mason in erlang.
Tags:
trackback

The ‘ctags’ program creates a ‘tags’ file, which indexes routines/methods/functions in C source files (and a variety of other languages. The editor vile (my ‘IDE’) can make use of those: you position the cursor on the name of a function, press ^], and the editor jumps to its definition (loading the appropriate source file). The tags file consists of the function name, the file name, and a search pattern.

Running ctags on an Erlang source file does not produce any usable results, unsurprisingly. However, the file format is so simple that a straightforward shell-script will do:

#!/bin/sh
rm -f tags
for i in *.erl
do
cat $i | grep "^[a-z0-9_]*(" |
sed "s/^\([^(]*\)(.*$/\1/" | uniq |
awk  -v file=$i '{printf("%s    %s\\
   /^%s(/\n",$0,file,$0);}' >> tags
done

(The double backslash indicates a line break, as the end of the line would otherwise be outside the box and invisible)

This file processes all *.erl files in a directory, extracts the function names (a sequence of letters, numbers, underscores beginning on the first column and followed by an open round bracket), and creates the correct lines for the tags file.

Works fine so far.

Advertisements

Comments»

1. Geoff Cant - 18 March 2008

Hi there – you might be interested to know that OTP includes a TAGS file generator – tags:dir(“src/”, [{outdir, “src/”}]). should create src/TAGS from src/*.erl.

2. ojmason - 18 March 2008

Thanks! That’s actually one of my problems with the whole Erlang system: there’s so much of it, and for a beginner it’s hard to see what there is and how best to make use of it. It’s fine to learn the basics of the language, and some of the more accessible modules (such as lists and string), and so I’ll probably be re-inventing the wheel occasionally.

I guess it could be because Erlang was initially developed as an in-house system, and only became public later on?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: