Function List

From: Jeremy Cowgar <jeremy_at_cowgar.com>
Date: Mon, 21 Jul 2008 12:17:55 -0400

Hello, I made a function called function list. What it does is look at
the doc.syntax for a func_regex ... If not found, it displays an alert
stating so. Otherwise, it searches each line for that regex and builds
an array which is then displayed in a dialog as a list control. When you
select an item, it takes you to the line where that function was defined
on. This is very handy for jumping from function to function inside of a
single file. Here is the code:

/* Function List */
mp.actions['function_list'] = sub(d) {
    local line_count = size(d.txt.lines);
    local line_idx = 0;
    local funcs = [];
    local func_linenos = [];
   
    if (d.syntax == NULL || d.syntax.func_reg == NULL) {
        mp.alert("No function regular expression for mode.");
        return;
    }
   
    while (line_idx < line_count) {
        if (regex(d.syntax.func_regex, d.txt.lines[line_idx])) {
            push(funcs, d.txt.lines[line_idx]);
            push(func_linenos, line_idx);
        }
        line_idx = line_idx + 1;
    }
   
    local r = mp.form( [
        { 'label' => L("Function list"),
          'type' => 'list',
          'list' => funcs,
          'value' => 0
        } ]
    );

    if (r != NULL && r[0] != NULL) {
        mp.set_y(d, func_linenos[r[0]]);
        mp.set_x(d, 0);
    }
};
mp.actdesc['function_list'] = "Function List";

ins(mp.menu[3][1], 'function_list', -1);

The inserting into a menu is optional. The above line inserts it right
above Document List for me in the Goto menu. Further, you may want to
bind it, such as:

mp.keycodes['f4'] = "function_list";

I added:

    'func_regex' => '/^[ \t]*(global|export)*[ \t]*(function|procedure)/',

to the Euphoria mode I posted a few days ago. For testing, I then added:

    'func_regex' => '/^[ \t]*def/',

To the python mode found in mp_syntax.mpsl with the Minimum Profit
distribution.

I think this, or something similar, would make a good addition to MP core?

Jeremy

-- 
To unsubscribe, send mail to mp-unsubscribe_at_lists.triptico.com.
Received on Mon Jul 21 2008 - 18:17:55 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 21 2008 - 19:27:26 CEST