Here I will show how to create a tags file for matlab files with the ctags program.
The solution is quite simple: Create a .ctags file in your home directory (or change it when it already exists) and add the following lines:
--langdef=matlab --langmap=matlab:.m --regex-matlab=/^function.*=*[ \t]([,a-zA-Z0-9_]+)/\1/f,function/
Now switch to your matlab code (with probably existing subdirectories) and execute the following command:
A "tags" file should appear containing the function definitions of your code.
With great help of Stephen Wilkinson we improved the regular expression above to the following form:
--regex-matlab=/^function( A-Za-z0-9,_+=[ ]?|[ ]+)([^.(]+).*$/\2/f,function/
The difference is that this regular expression can handle output arguments of Matlab functions. I have tested it with the following function prototypes which are all valid in Matlab:
function funname function funname() function funname(a,b,c) function funname(a, b, c) function ab = funname(cc) function [ab] = funname (a,b, c) function [out1, out2] = funname(in1, in2)
and in each case it returns funname.
The regular expression uses the(or) operator. The first captured subexpression (which could be referenced with ) grabs:
The second captured subexpression (which is referenced with \2) grabs the function name, i.e. anything up to a possible open bracket ("
However, this regular expression still has one major drawback: Functions defined over several lines with the '...' statement where 'funname' doesn't appear in the first line are excluded from the tags file. Here is an example:
function [a,b,c,d,e] = ... funname (f,g,h)
According to the ctags homepage this problem can't be solved with regular expressions. It has to be written a parser for that. Well...
An example ctags configuration file is now uploaded to the downloads section below. Saves copy&pase time ;-)
|ctags.zip||241 B||featured by this article|